forked from BLC/sgeUpdated
new message and multiple emissionsources
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -4,9 +4,7 @@ import com.fasterxml.jackson.annotation.JsonManagedReference;
|
|||||||
import com.sgs.graphql.area.domain.Area;
|
import com.sgs.graphql.area.domain.Area;
|
||||||
import com.sgs.graphql.sector.domain.Sector;
|
import com.sgs.graphql.sector.domain.Sector;
|
||||||
import com.sgs.graphql.subSector.domain.SubSector;
|
import com.sgs.graphql.subSector.domain.SubSector;
|
||||||
import com.sgs.graphql.emissionSource.domain.EmissionSource;
|
|
||||||
import com.sgs.graphql.emissionScope.domain.EmissionScope;
|
import com.sgs.graphql.emissionScope.domain.EmissionScope;
|
||||||
import com.sgs.graphql.consuptionUnit.domain.ConsuptionUnit;
|
|
||||||
import com.sgs.graphql.activitySubUnit.domain.ActivitySubUnit;
|
import com.sgs.graphql.activitySubUnit.domain.ActivitySubUnit;
|
||||||
import com.sgs.lib.dao.domain.BaseDomain;
|
import com.sgs.lib.dao.domain.BaseDomain;
|
||||||
|
|
||||||
@@ -14,6 +12,8 @@ import javax.persistence.*;
|
|||||||
|
|
||||||
import org.hibernate.annotations.LazyCollection;
|
import org.hibernate.annotations.LazyCollection;
|
||||||
import org.hibernate.annotations.LazyCollectionOption;
|
import org.hibernate.annotations.LazyCollectionOption;
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -30,13 +30,12 @@ public class DataCenter extends BaseDomain {
|
|||||||
private Integer number;
|
private Integer number;
|
||||||
private Area area;
|
private Area area;
|
||||||
|
|
||||||
private List<Project> projects = new ArrayList<>();
|
private List<PhysicalMachine> physicalMachines = new ArrayList<>();
|
||||||
|
private List<DataCenterEmissionSource> dataCenterEmissionSources = new ArrayList<>();
|
||||||
private Sector sector;
|
private Sector sector;
|
||||||
private SubSector subSector;
|
private SubSector subSector;
|
||||||
private EmissionSource emissionSource;
|
|
||||||
private EmissionScope emissionScope;
|
private EmissionScope emissionScope;
|
||||||
private Double consuptionAmount;
|
private Double consuptionAmount;
|
||||||
private ConsuptionUnit consuptionUnit;
|
|
||||||
private ActivitySubUnit activitySubUnit;
|
private ActivitySubUnit activitySubUnit;
|
||||||
|
|
||||||
// New attributes
|
// New attributes
|
||||||
@@ -63,12 +62,23 @@ public class DataCenter extends BaseDomain {
|
|||||||
|
|
||||||
@OneToMany(mappedBy = "dataCenter", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
@OneToMany(mappedBy = "dataCenter", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||||
@JsonManagedReference
|
@JsonManagedReference
|
||||||
public List<Project> getProjects() {
|
public List<PhysicalMachine> getPhysicalMachines() {
|
||||||
return projects;
|
return physicalMachines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjects(List<Project> projects) {
|
public void setPhysicalMachines(List<PhysicalMachine> physicalMachines) {
|
||||||
this.projects = projects;
|
this.physicalMachines = physicalMachines;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "dataCenter", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
@JsonManagedReference
|
||||||
|
public List<DataCenterEmissionSource> getDataCenterEmissionSources() {
|
||||||
|
return dataCenterEmissionSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataCenterEmissionSources(List<DataCenterEmissionSource> dataCenterEmissionSources) {
|
||||||
|
this.dataCenterEmissionSources = dataCenterEmissionSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExternalId(Integer externalId) {
|
public void setExternalId(Integer externalId) {
|
||||||
@@ -114,16 +124,6 @@ public class DataCenter extends BaseDomain {
|
|||||||
this.consuptionAmount = consuptionAmount;
|
this.consuptionAmount = consuptionAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
|
||||||
@JoinColumn(name = "consuption_unit_id")
|
|
||||||
public ConsuptionUnit getConsuptionUnit() {
|
|
||||||
return consuptionUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConsuptionUnit(ConsuptionUnit consuptionUnit) {
|
|
||||||
this.consuptionUnit = consuptionUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "area_id")
|
@JoinColumn(name = "area_id")
|
||||||
public Area getArea() {
|
public Area getArea() {
|
||||||
@@ -144,16 +144,6 @@ public class DataCenter extends BaseDomain {
|
|||||||
this.subSector = subSector;
|
this.subSector = subSector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
|
||||||
@JoinColumn(name = "emission_source_id")
|
|
||||||
public EmissionSource getEmissionSource() {
|
|
||||||
return emissionSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmissionSource(EmissionSource emissionSource) {
|
|
||||||
this.emissionSource = emissionSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "activity_sub_unit_id")
|
@JoinColumn(name = "activity_sub_unit_id")
|
||||||
public ActivitySubUnit getActivitySubUnit() {
|
public ActivitySubUnit getActivitySubUnit() {
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
|
import com.sgs.graphql.emissionSource.domain.EmissionSource;
|
||||||
|
import com.sgs.graphql.consuptionUnit.domain.ConsuptionUnit;
|
||||||
|
import com.sgs.lib.dao.domain.BaseDomain;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "data_center_emission_source")
|
||||||
|
public class DataCenterEmissionSource extends BaseDomain {
|
||||||
|
|
||||||
|
private DataCenter dataCenter;
|
||||||
|
private EmissionSource emissionSource;
|
||||||
|
private ConsuptionUnit consuptionUnit;
|
||||||
|
private Boolean isDefault = false; // To mark which one is the default emission source
|
||||||
|
private Double percentage; // Percentage allocation for this emission source (optional)
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "data_center_id", nullable = false)
|
||||||
|
@JsonBackReference
|
||||||
|
public DataCenter getDataCenter() {
|
||||||
|
return dataCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataCenter(DataCenter dataCenter) {
|
||||||
|
this.dataCenter = dataCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "emission_source_id", nullable = false)
|
||||||
|
public EmissionSource getEmissionSource() {
|
||||||
|
return emissionSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmissionSource(EmissionSource emissionSource) {
|
||||||
|
this.emissionSource = emissionSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "consuption_unit_id", nullable = false)
|
||||||
|
public ConsuptionUnit getConsuptionUnit() {
|
||||||
|
return consuptionUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsuptionUnit(ConsuptionUnit consuptionUnit) {
|
||||||
|
this.consuptionUnit = consuptionUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column(name = "is_default")
|
||||||
|
public Boolean getIsDefault() {
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDefault(Boolean isDefault) {
|
||||||
|
this.isDefault = isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column(name = "percentage")
|
||||||
|
public Double getPercentage() {
|
||||||
|
return percentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPercentage(Double percentage) {
|
||||||
|
this.percentage = percentage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,9 +14,10 @@ public class PhysicalMachine extends BaseDomain {
|
|||||||
private String name;
|
private String name;
|
||||||
private String ip;
|
private String ip;
|
||||||
private String tag;
|
private String tag;
|
||||||
|
private String cloudSystem;
|
||||||
private Double power;
|
private Double power;
|
||||||
private List<VM> vms = new ArrayList<>();
|
private List<VM> vms = new ArrayList<>();
|
||||||
private Project project;
|
private DataCenter dataCenter;
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -45,6 +46,15 @@ public class PhysicalMachine extends BaseDomain {
|
|||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Column(name = "cloud_system")
|
||||||
|
public String getCloudSystem() {
|
||||||
|
return cloudSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCloudSystem(String cloudSystem) {
|
||||||
|
this.cloudSystem = cloudSystem;
|
||||||
|
}
|
||||||
|
|
||||||
@Column(name = "power")
|
@Column(name = "power")
|
||||||
public Double getPower() {
|
public Double getPower() {
|
||||||
return power;
|
return power;
|
||||||
@@ -65,13 +75,13 @@ public class PhysicalMachine extends BaseDomain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.EAGER)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "project_id")
|
@JoinColumn(name = "data_center_id")
|
||||||
@JsonBackReference
|
@JsonBackReference
|
||||||
public Project getProject() {
|
public DataCenter getDataCenter() {
|
||||||
return project;
|
return dataCenter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProject(Project project) {
|
public void setDataCenter(DataCenter dataCenter) {
|
||||||
this.project = project;
|
this.dataCenter = dataCenter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.sgs.graphql.dataCenter.domain;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
|
||||||
import com.sgs.lib.dao.domain.BaseDomain;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "project")
|
|
||||||
public class Project extends BaseDomain{
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private List<PhysicalMachine> physicalMachines;
|
|
||||||
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "project", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
|
|
||||||
@JsonManagedReference
|
|
||||||
public List<PhysicalMachine> getPhysicalMachines() {
|
|
||||||
return physicalMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPhysicalMachines(List<PhysicalMachine> physicalMachines) {
|
|
||||||
this.physicalMachines = physicalMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This creates a foreign key in the `project` table
|
|
||||||
private DataCenter dataCenter;
|
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "name")
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "data_center_id")
|
|
||||||
@JsonBackReference
|
|
||||||
public DataCenter getDataCenter() {
|
|
||||||
return dataCenter;
|
|
||||||
}
|
|
||||||
public void setDataCenter(DataCenter dataCenter) {
|
|
||||||
this.dataCenter = dataCenter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,6 +23,7 @@ public class VM extends BaseDomain {
|
|||||||
private String host;
|
private String host;
|
||||||
private String flavorName;
|
private String flavorName;
|
||||||
private String tag;
|
private String tag;
|
||||||
|
private String project; // UUID of the project this VM belongs to
|
||||||
private String emissionSourceData; // JSON string to store emission source map
|
private String emissionSourceData; // JSON string to store emission source map
|
||||||
private Config config;
|
private Config config;
|
||||||
private PhysicalMachine physicalMachine;
|
private PhysicalMachine physicalMachine;
|
||||||
@@ -100,6 +101,15 @@ public class VM extends BaseDomain {
|
|||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Column(name = "project")
|
||||||
|
public String getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProject(String project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
@Column(name = "ip")
|
@Column(name = "ip")
|
||||||
public String getIp() {
|
public String getIp() {
|
||||||
return ip;
|
return ip;
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ public class DataCenterDto {
|
|||||||
private Integer externalId;
|
private Integer externalId;
|
||||||
private Integer number;
|
private Integer number;
|
||||||
private AreaDto area;
|
private AreaDto area;
|
||||||
private Map<String, ProjectDto> projects;
|
|
||||||
|
@JsonProperty("physical_machine")
|
||||||
|
private Map<String, PhysicalMachineDto> physicalMachine;
|
||||||
|
|
||||||
// Emission calculation fields
|
// Emission calculation fields
|
||||||
private SectorDto sector;
|
private SectorDto sector;
|
||||||
@@ -68,12 +70,12 @@ public class DataCenterDto {
|
|||||||
this.area = area;
|
this.area = area;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, ProjectDto> getProjects() {
|
public Map<String, PhysicalMachineDto> getPhysicalMachine() {
|
||||||
return projects;
|
return physicalMachine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjects(Map<String, ProjectDto> projects) {
|
public void setPhysicalMachine(Map<String, PhysicalMachineDto> physicalMachine) {
|
||||||
this.projects = projects;
|
this.physicalMachine = physicalMachine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SectorDto getSector() {
|
public SectorDto getSector() {
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class DataCenterEmissionSourceDto {
|
||||||
|
|
||||||
|
@JsonProperty("emission_source_id")
|
||||||
|
private String emissionSourceId;
|
||||||
|
|
||||||
|
@JsonProperty("consuption_unit_id")
|
||||||
|
private String consuptionUnitId;
|
||||||
|
|
||||||
|
@JsonProperty("is_default")
|
||||||
|
private Boolean isDefault = false;
|
||||||
|
|
||||||
|
@JsonProperty("percentage")
|
||||||
|
private Double percentage;
|
||||||
|
|
||||||
|
public String getEmissionSourceId() {
|
||||||
|
return emissionSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmissionSourceId(String emissionSourceId) {
|
||||||
|
this.emissionSourceId = emissionSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsuptionUnitId() {
|
||||||
|
return consuptionUnitId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsuptionUnitId(String consuptionUnitId) {
|
||||||
|
this.consuptionUnitId = consuptionUnitId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsDefault() {
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDefault(Boolean isDefault) {
|
||||||
|
this.isDefault = isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPercentage() {
|
||||||
|
return percentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPercentage(Double percentage) {
|
||||||
|
this.percentage = percentage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.sgs.graphql.dataCenter.dto;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MainOptimizationSpaceDto {
|
|
||||||
private Map<String, VMDto> vms;
|
|
||||||
private Map<String, PhysicalMachineDto> pms;
|
|
||||||
|
|
||||||
public Map<String, VMDto> getVms() {
|
|
||||||
return vms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVms(Map<String, VMDto> vms) {
|
|
||||||
this.vms = vms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, PhysicalMachineDto> getPms() {
|
|
||||||
return pms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPms(Map<String, PhysicalMachineDto> pms) {
|
|
||||||
this.pms = pms;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package com.sgs.graphql.dataCenter.dto;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PhysicalMachineDto {
|
public class PhysicalMachineDto {
|
||||||
@JsonProperty("name")
|
@JsonProperty("name")
|
||||||
@@ -10,12 +11,18 @@ public class PhysicalMachineDto {
|
|||||||
@JsonProperty("tag")
|
@JsonProperty("tag")
|
||||||
private String tag;
|
private String tag;
|
||||||
|
|
||||||
|
@JsonProperty("cloud_system")
|
||||||
|
private String cloudSystem;
|
||||||
|
|
||||||
@JsonProperty("power")
|
@JsonProperty("power")
|
||||||
private double power;
|
private double power;
|
||||||
|
|
||||||
@JsonProperty("confg") // Note: keeping the typo from JSON
|
@JsonProperty("confg") // Note: keeping the typo from JSON
|
||||||
private List<Object> confg;
|
private List<Object> confg;
|
||||||
|
|
||||||
|
@JsonProperty("vms")
|
||||||
|
private Map<String, VMDto> vms;
|
||||||
|
|
||||||
private String ip; // IP address from the message key
|
private String ip; // IP address from the message key
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -34,6 +41,14 @@ public class PhysicalMachineDto {
|
|||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCloudSystem() {
|
||||||
|
return cloudSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCloudSystem(String cloudSystem) {
|
||||||
|
this.cloudSystem = cloudSystem;
|
||||||
|
}
|
||||||
|
|
||||||
public double getPower() {
|
public double getPower() {
|
||||||
return power;
|
return power;
|
||||||
}
|
}
|
||||||
@@ -57,4 +72,12 @@ public class PhysicalMachineDto {
|
|||||||
public void setIp(String ip) {
|
public void setIp(String ip) {
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, VMDto> getVms() {
|
||||||
|
return vms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVms(Map<String, VMDto> vms) {
|
||||||
|
this.vms = vms;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.sgs.graphql.dataCenter.dto;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
|
|
||||||
public class ProjectDto {
|
|
||||||
@JsonProperty("main_optimization_space")
|
|
||||||
private MainOptimizationSpaceDto mainOptimizationSpace;
|
|
||||||
|
|
||||||
@JsonProperty("sub_optimization_space")
|
|
||||||
private SubOptimizationSpaceDto subOptimizationSpace;
|
|
||||||
|
|
||||||
// Legacy field - kept for backward compatibility with older message formats
|
|
||||||
@JsonProperty("physical_machines")
|
|
||||||
private List<PhysicalMachineDto> physicalMachines;
|
|
||||||
|
|
||||||
// These fields are derived from the map key and entity relationships, not from the message
|
|
||||||
private String id; // This will be set from the map key
|
|
||||||
private String name; // This will be derived or set separately
|
|
||||||
|
|
||||||
public MainOptimizationSpaceDto getMainOptimizationSpace() {
|
|
||||||
return mainOptimizationSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMainOptimizationSpace(MainOptimizationSpaceDto mainOptimizationSpace) {
|
|
||||||
this.mainOptimizationSpace = mainOptimizationSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SubOptimizationSpaceDto getSubOptimizationSpace() {
|
|
||||||
return subOptimizationSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubOptimizationSpace(SubOptimizationSpaceDto subOptimizationSpace) {
|
|
||||||
this.subOptimizationSpace = subOptimizationSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public List<PhysicalMachineDto> getPhysicalMachines() {
|
|
||||||
return physicalMachines;
|
|
||||||
}
|
|
||||||
public void setPhysicalMachines(List<PhysicalMachineDto> physicalMachines) {
|
|
||||||
this.physicalMachines = physicalMachines;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.sgs.graphql.dataCenter.dto;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DTO for sub_optimization_space in the message format.
|
|
||||||
* Currently appears to be empty in the message structure.
|
|
||||||
*/
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
||||||
public class SubOptimizationSpaceDto {
|
|
||||||
// Currently empty based on the message format
|
|
||||||
// Can be extended if needed in the future
|
|
||||||
|
|
||||||
// Add a placeholder field to make Jackson happy
|
|
||||||
private boolean isEmpty = true;
|
|
||||||
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return isEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmpty(boolean empty) {
|
|
||||||
this.isEmpty = empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,6 +26,9 @@ public class VMDto {
|
|||||||
@JsonProperty("tag")
|
@JsonProperty("tag")
|
||||||
private String tag;
|
private String tag;
|
||||||
|
|
||||||
|
@JsonProperty("project")
|
||||||
|
private String project;
|
||||||
|
|
||||||
@JsonProperty("confg") // Note: keeping the typo from JSON
|
@JsonProperty("confg") // Note: keeping the typo from JSON
|
||||||
private List<Object> confg;
|
private List<Object> confg;
|
||||||
|
|
||||||
@@ -101,6 +104,14 @@ public class VMDto {
|
|||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProject(String project) {
|
||||||
|
this.project = project;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Object> getConfg() {
|
public List<Object> getConfg() {
|
||||||
return confg;
|
return confg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import javax.validation.constraints.NotBlank;
|
|||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DataCenterCreateInput extends BaseCreateInput {
|
public class DataCenterCreateInput extends BaseCreateInput {
|
||||||
@NotBlank(message = "Data center adı gereklidir")
|
@NotBlank(message = "Data center adı gereklidir")
|
||||||
@@ -22,11 +23,12 @@ public class DataCenterCreateInput extends BaseCreateInput {
|
|||||||
private UUID sectorId;
|
private UUID sectorId;
|
||||||
|
|
||||||
private UUID subSectorId;
|
private UUID subSectorId;
|
||||||
private UUID emissionSourceId;
|
|
||||||
private UUID emissionScopeId;
|
private UUID emissionScopeId;
|
||||||
private UUID consuptionUnitId;
|
|
||||||
private UUID activitySubUnitId;
|
private UUID activitySubUnitId;
|
||||||
|
|
||||||
|
// Multiple emission sources support - each with exactly one unit
|
||||||
|
private List<DataCenterEmissionSourceInput> dataCenterEmissionSources;
|
||||||
|
|
||||||
// New attributes
|
// New attributes
|
||||||
private String ayposURL;
|
private String ayposURL;
|
||||||
private String address;
|
private String address;
|
||||||
@@ -55,18 +57,15 @@ public class DataCenterCreateInput extends BaseCreateInput {
|
|||||||
public UUID getSubSectorId() { return subSectorId; }
|
public UUID getSubSectorId() { return subSectorId; }
|
||||||
public void setSubSectorId(UUID subSectorId) { this.subSectorId = subSectorId; }
|
public void setSubSectorId(UUID subSectorId) { this.subSectorId = subSectorId; }
|
||||||
|
|
||||||
public UUID getEmissionSourceId() { return emissionSourceId; }
|
|
||||||
public void setEmissionSourceId(UUID emissionSourceId) { this.emissionSourceId = emissionSourceId; }
|
|
||||||
|
|
||||||
public UUID getEmissionScopeId() { return emissionScopeId; }
|
public UUID getEmissionScopeId() { return emissionScopeId; }
|
||||||
public void setEmissionScopeId(UUID emissionScopeId) { this.emissionScopeId = emissionScopeId; }
|
public void setEmissionScopeId(UUID emissionScopeId) { this.emissionScopeId = emissionScopeId; }
|
||||||
|
|
||||||
public UUID getConsuptionUnitId() { return consuptionUnitId; }
|
|
||||||
public void setConsuptionUnitId(UUID consuptionUnitId) { this.consuptionUnitId = consuptionUnitId; }
|
|
||||||
|
|
||||||
public UUID getActivitySubUnitId() { return activitySubUnitId; }
|
public UUID getActivitySubUnitId() { return activitySubUnitId; }
|
||||||
public void setActivitySubUnitId(UUID activitySubUnitId) { this.activitySubUnitId = activitySubUnitId; }
|
public void setActivitySubUnitId(UUID activitySubUnitId) { this.activitySubUnitId = activitySubUnitId; }
|
||||||
|
|
||||||
|
public List<DataCenterEmissionSourceInput> getDataCenterEmissionSources() { return dataCenterEmissionSources; }
|
||||||
|
public void setDataCenterEmissionSources(List<DataCenterEmissionSourceInput> dataCenterEmissionSources) { this.dataCenterEmissionSources = dataCenterEmissionSources; }
|
||||||
|
|
||||||
// New attribute getters and setters
|
// New attribute getters and setters
|
||||||
public String getAyposURL() { return ayposURL; }
|
public String getAyposURL() { return ayposURL; }
|
||||||
public void setAyposURL(String ayposURL) { this.ayposURL = ayposURL; }
|
public void setAyposURL(String ayposURL) { this.ayposURL = ayposURL; }
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.mutation.input;
|
||||||
|
|
||||||
|
public class DataCenterEmissionSourceInput {
|
||||||
|
private String emissionSourceId;
|
||||||
|
private String consuptionUnitId;
|
||||||
|
private Boolean isDefault = false;
|
||||||
|
private Double percentage;
|
||||||
|
|
||||||
|
public String getEmissionSourceId() {
|
||||||
|
return emissionSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmissionSourceId(String emissionSourceId) {
|
||||||
|
this.emissionSourceId = emissionSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsuptionUnitId() {
|
||||||
|
return consuptionUnitId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsuptionUnitId(String consuptionUnitId) {
|
||||||
|
this.consuptionUnitId = consuptionUnitId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getIsDefault() {
|
||||||
|
return isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsDefault(Boolean isDefault) {
|
||||||
|
this.isDefault = isDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPercentage() {
|
||||||
|
return percentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPercentage(Double percentage) {
|
||||||
|
this.percentage = percentage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.sgs.graphql.dataCenter.mutation.input;
|
package com.sgs.graphql.dataCenter.mutation.input;
|
||||||
|
|
||||||
import com.sgs.lib.dao.mutation.input.BaseUpdateInput;
|
import com.sgs.lib.dao.mutation.input.BaseUpdateInput;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DataCenterUpdateInput extends BaseUpdateInput {
|
public class DataCenterUpdateInput extends BaseUpdateInput {
|
||||||
@@ -12,11 +13,12 @@ public class DataCenterUpdateInput extends BaseUpdateInput {
|
|||||||
private UUID areaId;
|
private UUID areaId;
|
||||||
private UUID sectorId;
|
private UUID sectorId;
|
||||||
private UUID subSectorId;
|
private UUID subSectorId;
|
||||||
private UUID emissionSourceId;
|
|
||||||
private UUID emissionScopeId;
|
private UUID emissionScopeId;
|
||||||
private UUID consuptionUnitId;
|
|
||||||
private UUID activitySubUnitId;
|
private UUID activitySubUnitId;
|
||||||
|
|
||||||
|
// Multiple emission sources with units
|
||||||
|
private List<DataCenterEmissionSourceInput> dataCenterEmissionSources;
|
||||||
|
|
||||||
// New attributes
|
// New attributes
|
||||||
private String ayposURL;
|
private String ayposURL;
|
||||||
private String address;
|
private String address;
|
||||||
@@ -45,18 +47,19 @@ public class DataCenterUpdateInput extends BaseUpdateInput {
|
|||||||
public UUID getSubSectorId() { return subSectorId; }
|
public UUID getSubSectorId() { return subSectorId; }
|
||||||
public void setSubSectorId(UUID subSectorId) { this.subSectorId = subSectorId; }
|
public void setSubSectorId(UUID subSectorId) { this.subSectorId = subSectorId; }
|
||||||
|
|
||||||
public UUID getEmissionSourceId() { return emissionSourceId; }
|
|
||||||
public void setEmissionSourceId(UUID emissionSourceId) { this.emissionSourceId = emissionSourceId; }
|
|
||||||
|
|
||||||
public UUID getEmissionScopeId() { return emissionScopeId; }
|
public UUID getEmissionScopeId() { return emissionScopeId; }
|
||||||
public void setEmissionScopeId(UUID emissionScopeId) { this.emissionScopeId = emissionScopeId; }
|
public void setEmissionScopeId(UUID emissionScopeId) { this.emissionScopeId = emissionScopeId; }
|
||||||
|
|
||||||
public UUID getConsuptionUnitId() { return consuptionUnitId; }
|
|
||||||
public void setConsuptionUnitId(UUID consuptionUnitId) { this.consuptionUnitId = consuptionUnitId; }
|
|
||||||
|
|
||||||
public UUID getActivitySubUnitId() { return activitySubUnitId; }
|
public UUID getActivitySubUnitId() { return activitySubUnitId; }
|
||||||
public void setActivitySubUnitId(UUID activitySubUnitId) { this.activitySubUnitId = activitySubUnitId; }
|
public void setActivitySubUnitId(UUID activitySubUnitId) { this.activitySubUnitId = activitySubUnitId; }
|
||||||
|
|
||||||
|
public List<DataCenterEmissionSourceInput> getDataCenterEmissionSources() {
|
||||||
|
return dataCenterEmissionSources;
|
||||||
|
}
|
||||||
|
public void setDataCenterEmissionSources(List<DataCenterEmissionSourceInput> dataCenterEmissionSources) {
|
||||||
|
this.dataCenterEmissionSources = dataCenterEmissionSources;
|
||||||
|
}
|
||||||
|
|
||||||
// New attribute getters and setters
|
// New attribute getters and setters
|
||||||
public String getAyposURL() { return ayposURL; }
|
public String getAyposURL() { return ayposURL; }
|
||||||
public void setAyposURL(String ayposURL) { this.ayposURL = ayposURL; }
|
public void setAyposURL(String ayposURL) { this.ayposURL = ayposURL; }
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.sgs.graphql.dataCenter.mutation.mapper;
|
package com.sgs.graphql.dataCenter.mutation.mapper;
|
||||||
|
|
||||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||||
|
import com.sgs.graphql.dataCenter.domain.DataCenterEmissionSource;
|
||||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterCreateInput;
|
import com.sgs.graphql.dataCenter.mutation.input.DataCenterCreateInput;
|
||||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterUpdateInput;
|
import com.sgs.graphql.dataCenter.mutation.input.DataCenterUpdateInput;
|
||||||
|
import com.sgs.graphql.dataCenter.mutation.input.DataCenterEmissionSourceInput;
|
||||||
import com.sgs.graphql.area.service.AreaService;
|
import com.sgs.graphql.area.service.AreaService;
|
||||||
import com.sgs.graphql.sector.service.SectorService;
|
import com.sgs.graphql.sector.service.SectorService;
|
||||||
import com.sgs.graphql.subSector.service.SubSectorService;
|
import com.sgs.graphql.subSector.service.SubSectorService;
|
||||||
@@ -13,6 +15,9 @@ import com.sgs.graphql.activitySubUnit.service.ActivitySubUnitService;
|
|||||||
import com.sgs.lib.dao.mutation.mapper.BaseCreateUpdateMapper;
|
import com.sgs.lib.dao.mutation.mapper.BaseCreateUpdateMapper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DataCenterMapper extends BaseCreateUpdateMapper<DataCenter, DataCenterCreateInput, DataCenterUpdateInput> {
|
public class DataCenterMapper extends BaseCreateUpdateMapper<DataCenter, DataCenterCreateInput, DataCenterUpdateInput> {
|
||||||
@@ -62,18 +67,10 @@ public class DataCenterMapper extends BaseCreateUpdateMapper<DataCenter, DataCen
|
|||||||
entity.setSubSector(subSectorService.findById(input.getSubSectorId()).orElse(null));
|
entity.setSubSector(subSectorService.findById(input.getSubSectorId()).orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.getEmissionSourceId() != null) {
|
|
||||||
entity.setEmissionSource(emissionSourceService.findById(input.getEmissionSourceId()).orElse(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.getEmissionScopeId() != null) {
|
if (input.getEmissionScopeId() != null) {
|
||||||
entity.setEmissionScope(emissionScopeService.findById(input.getEmissionScopeId()).orElse(null));
|
entity.setEmissionScope(emissionScopeService.findById(input.getEmissionScopeId()).orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.getConsuptionUnitId() != null) {
|
|
||||||
entity.setConsuptionUnit(consuptionUnitService.findById(input.getConsuptionUnitId()).orElse(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.getActivitySubUnitId() != null) {
|
if (input.getActivitySubUnitId() != null) {
|
||||||
entity.setActivitySubUnit(activitySubUnitService.findById(input.getActivitySubUnitId()).orElse(null));
|
entity.setActivitySubUnit(activitySubUnitService.findById(input.getActivitySubUnitId()).orElse(null));
|
||||||
}
|
}
|
||||||
@@ -84,6 +81,34 @@ public class DataCenterMapper extends BaseCreateUpdateMapper<DataCenter, DataCen
|
|||||||
entity.setLatitude(input.getLatitude());
|
entity.setLatitude(input.getLatitude());
|
||||||
entity.setLongitude(input.getLongitude());
|
entity.setLongitude(input.getLongitude());
|
||||||
|
|
||||||
|
// Handle multiple emission sources if provided
|
||||||
|
if (input.getDataCenterEmissionSources() != null && !input.getDataCenterEmissionSources().isEmpty()) {
|
||||||
|
List<DataCenterEmissionSource> dataCenterEmissionSources = new ArrayList<>();
|
||||||
|
|
||||||
|
for (DataCenterEmissionSourceInput emissionSourceInput : input.getDataCenterEmissionSources()) {
|
||||||
|
DataCenterEmissionSource dcEmissionSource = new DataCenterEmissionSource();
|
||||||
|
dcEmissionSource.setDataCenter(entity);
|
||||||
|
|
||||||
|
// Set EmissionSource
|
||||||
|
if (emissionSourceInput.getEmissionSourceId() != null) {
|
||||||
|
dcEmissionSource.setEmissionSource(emissionSourceService.findById(UUID.fromString(emissionSourceInput.getEmissionSourceId())).orElse(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set ConsuptionUnit
|
||||||
|
if (emissionSourceInput.getConsuptionUnitId() != null) {
|
||||||
|
dcEmissionSource.setConsuptionUnit(consuptionUnitService.findById(UUID.fromString(emissionSourceInput.getConsuptionUnitId())).orElse(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set optional fields
|
||||||
|
dcEmissionSource.setIsDefault(emissionSourceInput.getIsDefault() != null ? emissionSourceInput.getIsDefault() : false);
|
||||||
|
dcEmissionSource.setPercentage(emissionSourceInput.getPercentage());
|
||||||
|
|
||||||
|
dataCenterEmissionSources.add(dcEmissionSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setDataCenterEmissionSources(dataCenterEmissionSources);
|
||||||
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,22 +144,40 @@ public class DataCenterMapper extends BaseCreateUpdateMapper<DataCenter, DataCen
|
|||||||
entity.setSubSector(subSectorService.findById(input.getSubSectorId()).orElse(null));
|
entity.setSubSector(subSectorService.findById(input.getSubSectorId()).orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.getEmissionSourceId() != null) {
|
|
||||||
entity.setEmissionSource(emissionSourceService.findById(input.getEmissionSourceId()).orElse(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.getEmissionScopeId() != null) {
|
if (input.getEmissionScopeId() != null) {
|
||||||
entity.setEmissionScope(emissionScopeService.findById(input.getEmissionScopeId()).orElse(null));
|
entity.setEmissionScope(emissionScopeService.findById(input.getEmissionScopeId()).orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.getConsuptionUnitId() != null) {
|
|
||||||
entity.setConsuptionUnit(consuptionUnitService.findById(input.getConsuptionUnitId()).orElse(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.getActivitySubUnitId() != null) {
|
if (input.getActivitySubUnitId() != null) {
|
||||||
entity.setActivitySubUnit(activitySubUnitService.findById(input.getActivitySubUnitId()).orElse(null));
|
entity.setActivitySubUnit(activitySubUnitService.findById(input.getActivitySubUnitId()).orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle multiple emission sources update if provided
|
||||||
|
if (input.getDataCenterEmissionSources() != null) {
|
||||||
|
// Clear existing emission sources and add new ones
|
||||||
|
entity.getDataCenterEmissionSources().clear();
|
||||||
|
|
||||||
|
List<DataCenterEmissionSource> dataCenterEmissionSources = new ArrayList<>();
|
||||||
|
for (DataCenterEmissionSourceInput emissionSourceInput : input.getDataCenterEmissionSources()) {
|
||||||
|
DataCenterEmissionSource dcEmissionSource = new DataCenterEmissionSource();
|
||||||
|
dcEmissionSource.setDataCenter(entity);
|
||||||
|
|
||||||
|
if (emissionSourceInput.getEmissionSourceId() != null) {
|
||||||
|
dcEmissionSource.setEmissionSource(emissionSourceService.findById(UUID.fromString(emissionSourceInput.getEmissionSourceId())).orElse(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emissionSourceInput.getConsuptionUnitId() != null) {
|
||||||
|
dcEmissionSource.setConsuptionUnit(consuptionUnitService.findById(UUID.fromString(emissionSourceInput.getConsuptionUnitId())).orElse(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
dcEmissionSource.setIsDefault(emissionSourceInput.getIsDefault() != null ? emissionSourceInput.getIsDefault() : false);
|
||||||
|
dcEmissionSource.setPercentage(emissionSourceInput.getPercentage());
|
||||||
|
|
||||||
|
dataCenterEmissionSources.add(dcEmissionSource);
|
||||||
|
}
|
||||||
|
entity.setDataCenterEmissionSources(dataCenterEmissionSources);
|
||||||
|
}
|
||||||
|
|
||||||
// New attributes (partial update - only if provided)
|
// New attributes (partial update - only if provided)
|
||||||
if (input.getAyposURL() != null) {
|
if (input.getAyposURL() != null) {
|
||||||
entity.setAyposURL(input.getAyposURL());
|
entity.setAyposURL(input.getAyposURL());
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class DataCenterQueryResolver implements GraphQLQueryResolver {
|
|||||||
return dataCenterRepo.findByNumber(id).stream().findFirst();
|
return dataCenterRepo.findByNumber(id).stream().findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PhysicalMachine> physicalMachines(UUID datacenterId, UUID projectId) {
|
public List<PhysicalMachine> physicalMachines(UUID datacenterId) {
|
||||||
return physicalMachineRepo.findByDatacenterIdAndProjectId(datacenterId, projectId);
|
return physicalMachineRepo.findByDatacenterId(datacenterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.sgs.graphql.dataCenter.repo;
|
||||||
|
|
||||||
|
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||||
|
import com.sgs.graphql.dataCenter.domain.DataCenterEmissionSource;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface DataCenterEmissionSourceRepo extends JpaRepository<DataCenterEmissionSource, String> {
|
||||||
|
|
||||||
|
List<DataCenterEmissionSource> findByDataCenter(DataCenter dataCenter);
|
||||||
|
|
||||||
|
Optional<DataCenterEmissionSource> findByDataCenterAndIsDefaultTrue(DataCenter dataCenter);
|
||||||
|
|
||||||
|
@Query("SELECT dces FROM DataCenterEmissionSource dces WHERE dces.dataCenter.id = :dataCenterId")
|
||||||
|
List<DataCenterEmissionSource> findByDataCenterId(@Param("dataCenterId") String dataCenterId);
|
||||||
|
|
||||||
|
void deleteByDataCenter(DataCenter dataCenter);
|
||||||
|
}
|
||||||
@@ -13,15 +13,10 @@ import java.util.UUID;
|
|||||||
public interface PhysicalMachineRepo extends BaseRepo<PhysicalMachine> {
|
public interface PhysicalMachineRepo extends BaseRepo<PhysicalMachine> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all physical machines by datacenter ID and project ID
|
* Find all physical machines by datacenter ID
|
||||||
* @param datacenterId Datacenter ID
|
* @param datacenterId Datacenter ID
|
||||||
* @param projectId Project ID
|
|
||||||
* @return List of physical machines
|
* @return List of physical machines
|
||||||
*/
|
*/
|
||||||
@Query("SELECT pm FROM PhysicalMachine pm " +
|
@Query("SELECT pm FROM PhysicalMachine pm WHERE pm.dataCenter.id = :datacenterId")
|
||||||
"JOIN pm.project p " +
|
List<PhysicalMachine> findByDatacenterId(@Param("datacenterId") UUID datacenterId);
|
||||||
"JOIN p.dataCenter dc " +
|
|
||||||
"WHERE dc.id = :datacenterId AND p.id = :projectId")
|
|
||||||
List<PhysicalMachine> findByDatacenterIdAndProjectId(@Param("datacenterId") UUID datacenterId,
|
|
||||||
@Param("projectId") UUID projectId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,19 +74,16 @@ public class MessageListener {
|
|||||||
System.out.println(" External ID: " + dto.getId());
|
System.out.println(" External ID: " + dto.getId());
|
||||||
System.out.println(" Number: " + dto.getNumber());
|
System.out.println(" Number: " + dto.getNumber());
|
||||||
System.out.println(" Consumption Amount: " + dto.getConsuptionAmount());
|
System.out.println(" Consumption Amount: " + dto.getConsuptionAmount());
|
||||||
System.out.println(" Projects Count: " + (dto.getProjects() != null ? dto.getProjects().size() : 0));
|
System.out.println(" Physical Machines Count: " + (dto.getPhysicalMachine() != null ? dto.getPhysicalMachine().size() : 0));
|
||||||
|
|
||||||
// Log MainOptimizationSpace info for each project
|
// Log Physical Machine info
|
||||||
if (dto.getProjects() != null) {
|
if (dto.getPhysicalMachine() != null) {
|
||||||
for (Map.Entry<String, ProjectDto> projectEntry : dto.getProjects().entrySet()) {
|
for (Map.Entry<String, PhysicalMachineDto> pmEntry : dto.getPhysicalMachine().entrySet()) {
|
||||||
String projectId = projectEntry.getKey();
|
String pmIp = pmEntry.getKey();
|
||||||
ProjectDto project = projectEntry.getValue();
|
PhysicalMachineDto pm = pmEntry.getValue();
|
||||||
if (project.getMainOptimizationSpace() != null) {
|
System.out.println(" Physical Machine " + pm.getName() + " (IP: " + pmIp + "):");
|
||||||
MainOptimizationSpaceDto mainOpt = project.getMainOptimizationSpace();
|
System.out.println(" Power: " + pm.getPower());
|
||||||
System.out.println(" Project " + projectId + ":");
|
System.out.println(" VMs: " + (pm.getVms() != null ? pm.getVms().size() : 0));
|
||||||
System.out.println(" PMs: " + (mainOpt.getPms() != null ? mainOpt.getPms().size() : 0));
|
|
||||||
System.out.println(" VMs: " + (mainOpt.getVms() != null ? mainOpt.getVms().size() : 0));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,18 +100,18 @@ public class MessageListener {
|
|||||||
|
|
||||||
// System.out.println(entity.toString());
|
// System.out.println(entity.toString());
|
||||||
System.out.println("✅ Raw JSON message:\n" + message);
|
System.out.println("✅ Raw JSON message:\n" + message);
|
||||||
System.out.println("✅ DTO parsed:\n" + objectMapper.writeValueAsString(dto));
|
//System.out.println("✅ DTO parsed:\n" + objectMapper.writeValueAsString(dto));
|
||||||
//System.out.println("✅ Entity:\n" + objectMapper.writeValueAsString(entity));
|
//System.out.println("✅ Entity:\n" + objectMapper.writeValueAsString(entity));
|
||||||
System.out.println("🚨 DataCenter name: " + dataCenter.getDataCenter());
|
System.out.println("🚨 DataCenter name: " + dataCenter.getDataCenter());
|
||||||
System.out.println("🚨 External ID: " + dataCenter.getExternalId());
|
System.out.println("🚨 External ID: " + dataCenter.getExternalId());
|
||||||
System.out.println("🚨 Projects count: " + (dataCenter.getProjects() != null ? dataCenter.getProjects().size() : 0));
|
System.out.println("🚨 Physical Machines count: " + (dataCenter.getPhysicalMachines() != null ? dataCenter.getPhysicalMachines().size() : 0));
|
||||||
if (dataCenter.getProjects() != null && !dataCenter.getProjects().isEmpty()) {
|
if (dataCenter.getPhysicalMachines() != null && !dataCenter.getPhysicalMachines().isEmpty()) {
|
||||||
Project firstProject = dataCenter.getProjects().get(0);
|
PhysicalMachine firstPM = dataCenter.getPhysicalMachines().get(0);
|
||||||
System.out.println("🚨 PMs in first project: " + firstProject.getPhysicalMachines().size());
|
System.out.println("🚨 VMs in first PM: " + firstPM.getVms().size());
|
||||||
|
|
||||||
// Show VM assignment summary
|
// Show VM assignment summary
|
||||||
int totalVMs = 0;
|
int totalVMs = 0;
|
||||||
for (PhysicalMachine pm : firstProject.getPhysicalMachines()) {
|
for (PhysicalMachine pm : dataCenter.getPhysicalMachines()) {
|
||||||
int vmCount = pm.getVms() != null ? pm.getVms().size() : 0;
|
int vmCount = pm.getVms() != null ? pm.getVms().size() : 0;
|
||||||
totalVMs += vmCount;
|
totalVMs += vmCount;
|
||||||
System.out.println(" PM " + pm.getName() + " (IP: " + pm.getIp() + "): " + vmCount + " VMs");
|
System.out.println(" PM " + pm.getName() + " (IP: " + pm.getIp() + "): " + vmCount + " VMs");
|
||||||
@@ -157,6 +154,7 @@ public class MessageListener {
|
|||||||
entity.setHost(dto.getHost());
|
entity.setHost(dto.getHost());
|
||||||
entity.setFlavorName(dto.getFlavorName());
|
entity.setFlavorName(dto.getFlavorName());
|
||||||
entity.setTag(dto.getTag());
|
entity.setTag(dto.getTag());
|
||||||
|
entity.setProject(dto.getProject());
|
||||||
|
|
||||||
// Set calcOn - you may want to derive this from state or other logic
|
// Set calcOn - you may want to derive this from state or other logic
|
||||||
entity.setCalcOn(dto.isCalcOn());
|
entity.setCalcOn(dto.isCalcOn());
|
||||||
@@ -168,7 +166,7 @@ public class MessageListener {
|
|||||||
entity.setEmissionSource(dto.getEmissionSource());
|
entity.setEmissionSource(dto.getEmissionSource());
|
||||||
|
|
||||||
// Debug logging
|
// Debug logging
|
||||||
System.out.println("🔍 VM Entity Created: " + dto.getVmName() + " - state = " + dto.getState() + " - calcOn = " + dto.isCalcOn());
|
System.out.println("🔍 VM Entity Created: " + dto.getVmName() + " - state = " + dto.getState() + " - calcOn = " + dto.isCalcOn() + " - project = " + dto.getProject());
|
||||||
if (dto.getEmissionSource() != null && !dto.getEmissionSource().isEmpty()) {
|
if (dto.getEmissionSource() != null && !dto.getEmissionSource().isEmpty()) {
|
||||||
System.out.println(" Emission Sources: " + dto.getEmissionSource());
|
System.out.println(" Emission Sources: " + dto.getEmissionSource());
|
||||||
}
|
}
|
||||||
@@ -184,6 +182,7 @@ public class MessageListener {
|
|||||||
entity.setName(dto.getName());
|
entity.setName(dto.getName());
|
||||||
entity.setIp(dto.getIp());
|
entity.setIp(dto.getIp());
|
||||||
entity.setTag(dto.getTag());
|
entity.setTag(dto.getTag());
|
||||||
|
entity.setCloudSystem(dto.getCloudSystem());
|
||||||
entity.setPower(dto.getPower());
|
entity.setPower(dto.getPower());
|
||||||
|
|
||||||
// VMs are now processed separately from the new message format
|
// VMs are now processed separately from the new message format
|
||||||
@@ -207,113 +206,43 @@ public class MessageListener {
|
|||||||
// ConsuptionUnit, and ActivitySubUnit are no longer received in the message
|
// ConsuptionUnit, and ActivitySubUnit are no longer received in the message
|
||||||
// These will need to be set via the DataCenter CRUD operations
|
// These will need to be set via the DataCenter CRUD operations
|
||||||
|
|
||||||
// Convert Projects
|
// Convert Physical Machines directly
|
||||||
if (dto.getProjects() != null) {
|
if (dto.getPhysicalMachine() != null) {
|
||||||
List<Project> projects = new ArrayList<>();
|
List<PhysicalMachine> physicalMachines = new ArrayList<>();
|
||||||
for (Map.Entry<String, ProjectDto> projectEntry : dto.getProjects().entrySet()) {
|
for (Map.Entry<String, PhysicalMachineDto> pmEntry : dto.getPhysicalMachine().entrySet()) {
|
||||||
String projectId = projectEntry.getKey();
|
String pmIp = pmEntry.getKey();
|
||||||
ProjectDto projectDto = projectEntry.getValue();
|
PhysicalMachineDto pmDto = pmEntry.getValue();
|
||||||
|
|
||||||
// Set the project ID and a default name if not provided
|
PhysicalMachine pm = new PhysicalMachine();
|
||||||
projectDto.setId(projectId);
|
pm.setName(pmDto.getName());
|
||||||
if (projectDto.getName() == null || projectDto.getName().isEmpty()) {
|
pm.setIp(pmIp); // Use the IP from the map key
|
||||||
projectDto.setName("Project-" + projectId.substring(0, 8)); // Use first 8 chars of ID as name
|
pm.setTag(pmDto.getTag());
|
||||||
|
pm.setPower(pmDto.getPower());
|
||||||
|
pm.setDataCenter(entity);
|
||||||
|
|
||||||
|
// Process VMs for this PM
|
||||||
|
if (pmDto.getVms() != null) {
|
||||||
|
List<VM> vms = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, VMDto> vmEntry : pmDto.getVms().entrySet()) {
|
||||||
|
String vmIp = vmEntry.getKey();
|
||||||
|
VMDto vmDto = vmEntry.getValue();
|
||||||
|
|
||||||
|
VM vm = toVMEntity(vmDto);
|
||||||
|
vm.setIp(vmIp); // Use the IP from the map key
|
||||||
|
vm.setPhysicalMachine(pm);
|
||||||
|
vms.add(vm);
|
||||||
|
}
|
||||||
|
pm.setVms(vms);
|
||||||
}
|
}
|
||||||
|
|
||||||
Project project = toProjectEntity(projectDto);
|
physicalMachines.add(pm);
|
||||||
project.setDataCenter(entity);
|
|
||||||
projects.add(project);
|
|
||||||
}
|
}
|
||||||
entity.setProjects(projects);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Project toProjectEntity(ProjectDto dto){
|
|
||||||
if (dto == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
Project entity = new Project();
|
|
||||||
entity.setName(dto.getName());
|
|
||||||
|
|
||||||
// Process MainOptimizationSpace instead of physical machines list
|
|
||||||
if (dto.getMainOptimizationSpace() != null) {
|
|
||||||
List<PhysicalMachine> physicalMachines = processMainOptimizationSpace(dto.getMainOptimizationSpace());
|
|
||||||
// Set project reference for each PM
|
|
||||||
physicalMachines.forEach(pm -> pm.setProject(entity));
|
|
||||||
entity.setPhysicalMachines(physicalMachines);
|
entity.setPhysicalMachines(physicalMachines);
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Process MainOptimizationSpaceDto and assign VMs to their hosting PMs
|
|
||||||
*/
|
|
||||||
private List<PhysicalMachine> processMainOptimizationSpace(MainOptimizationSpaceDto mainOptSpace) {
|
|
||||||
List<PhysicalMachine> physicalMachines = new ArrayList<>();
|
|
||||||
|
|
||||||
if (mainOptSpace.getPms() == null || mainOptSpace.getVms() == null) {
|
|
||||||
System.out.println("⚠️ MainOptimizationSpace has null PMs or VMs");
|
|
||||||
return physicalMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("🔍 Processing MainOptimizationSpace with " +
|
|
||||||
mainOptSpace.getPms().size() + " PMs and " +
|
|
||||||
mainOptSpace.getVms().size() + " VMs");
|
|
||||||
|
|
||||||
// Convert PMs from DTO to Entity
|
|
||||||
for (Map.Entry<String, PhysicalMachineDto> pmEntry : mainOptSpace.getPms().entrySet()) {
|
|
||||||
String pmIp = pmEntry.getKey();
|
|
||||||
PhysicalMachineDto pmDto = pmEntry.getValue();
|
|
||||||
|
|
||||||
// Set the IP from the map key
|
|
||||||
pmDto.setIp(pmIp);
|
|
||||||
|
|
||||||
PhysicalMachine pm = toPhysicalMachineEntity(pmDto);
|
|
||||||
physicalMachines.add(pm);
|
|
||||||
|
|
||||||
System.out.println("✅ Created PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign VMs to their hosting PMs
|
|
||||||
for (Map.Entry<String, VMDto> vmEntry : mainOptSpace.getVms().entrySet()) {
|
|
||||||
String vmIp = vmEntry.getKey();
|
|
||||||
VMDto vmDto = vmEntry.getValue();
|
|
||||||
|
|
||||||
// Set the IP from the map key
|
|
||||||
vmDto.setIp(vmIp);
|
|
||||||
|
|
||||||
VM vm = toVMEntity(vmDto);
|
|
||||||
|
|
||||||
// Find the hosting PM by IP
|
|
||||||
String hostingPmIp = vmDto.getHostingPm();
|
|
||||||
PhysicalMachine hostingPm = physicalMachines.stream()
|
|
||||||
.filter(pm -> pm.getIp().equals(hostingPmIp))
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
|
|
||||||
if (hostingPm != null) {
|
|
||||||
// Assign VM to PM
|
|
||||||
vm.setPhysicalMachine(hostingPm);
|
|
||||||
if (hostingPm.getVms() == null) {
|
|
||||||
hostingPm.setVms(new ArrayList<>());
|
|
||||||
}
|
|
||||||
hostingPm.getVms().add(vm);
|
|
||||||
|
|
||||||
System.out.println("✅ Assigned VM: " + vm.getVmName() + " (IP: " + vm.getIp() +
|
|
||||||
") to PM: " + hostingPm.getName() + " (IP: " + hostingPm.getIp() + ")");
|
|
||||||
} else {
|
|
||||||
System.err.println("❌ Could not find hosting PM with IP: " + hostingPmIp +
|
|
||||||
" for VM: " + vm.getVmName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return physicalMachines;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public DataCenter createDataCenter(DataCenter newDc) {
|
public DataCenter createDataCenter(DataCenter newDc) {
|
||||||
try {
|
try {
|
||||||
@@ -335,123 +264,116 @@ public class MessageListener {
|
|||||||
// Note: DataCenter name and emission-related fields are no longer updated from the message
|
// Note: DataCenter name and emission-related fields are no longer updated from the message
|
||||||
// These are now managed via DataCenter CRUD operations
|
// These are now managed via DataCenter CRUD operations
|
||||||
|
|
||||||
for (Project newProject : newDc.getProjects()) {
|
// Ensure datacenter has initialized physical machines list
|
||||||
Optional<Project> existingProjOpt = dc.getProjects().stream()
|
if (dc.getPhysicalMachines() == null) {
|
||||||
.filter(p -> p.getName().equalsIgnoreCase(newProject.getName()))
|
dc.setPhysicalMachines(new ArrayList<>());
|
||||||
.findFirst();
|
}
|
||||||
|
|
||||||
Project project;
|
// Process Physical Machines directly from the message structure
|
||||||
if (existingProjOpt.isPresent()) {
|
for (PhysicalMachine newPm : newDc.getPhysicalMachines()) {
|
||||||
project = existingProjOpt.get();
|
Optional<PhysicalMachine> existingPmOpt = dc.getPhysicalMachines().stream()
|
||||||
project.setName(newProject.getName());
|
.filter(pm -> pm.getIp().equals(newPm.getIp())) // Match by IP instead of name
|
||||||
System.out.println("✅ Updated existing project: " + project.getName());
|
.findFirst();
|
||||||
} else {
|
|
||||||
project = newProject;
|
PhysicalMachine pm;
|
||||||
project.setDataCenter(dc);
|
if (existingPmOpt.isPresent()) {
|
||||||
dc.getProjects().add(project);
|
// Update existing PM
|
||||||
System.out.println("✅ Created new project: " + project.getName());
|
pm = existingPmOpt.get();
|
||||||
|
pm.setName(newPm.getName());
|
||||||
|
pm.setIp(newPm.getIp());
|
||||||
|
pm.setTag(newPm.getTag());
|
||||||
|
pm.setPower(newPm.getPower());
|
||||||
|
|
||||||
|
System.out.println("✅ Updated existing PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
||||||
|
} else {
|
||||||
|
// Create new PM
|
||||||
|
pm = newPm;
|
||||||
|
pm.setDataCenter(dc);
|
||||||
|
dc.getPhysicalMachines().add(pm);
|
||||||
|
|
||||||
|
System.out.println("✅ Created new PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process VMs that are already assigned to this PM
|
||||||
|
if (newPm.getVms() != null && !newPm.getVms().isEmpty()) {
|
||||||
|
System.out.println("🔍 Processing " + newPm.getVms().size() + " VMs for PM: " + newPm.getName());
|
||||||
|
|
||||||
|
// Ensure PM has VM list initialized
|
||||||
|
if (pm.getVms() == null) {
|
||||||
|
pm.setVms(new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure project has initialized physical machines list
|
// Clear existing VMs to replace with new ones
|
||||||
if (project.getPhysicalMachines() == null) {
|
pm.getVms().clear();
|
||||||
project.setPhysicalMachines(new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process Physical Machines (VMs are already assigned to PMs from MainOptimizationSpace)
|
// Process each VM that's already assigned to this PM
|
||||||
for (PhysicalMachine newPm : newProject.getPhysicalMachines()) {
|
for (VM newVm : newPm.getVms()) {
|
||||||
Optional<PhysicalMachine> existingPmOpt = project.getPhysicalMachines().stream()
|
if (newVm == null) continue;
|
||||||
.filter(pm -> pm.getIp().equals(newPm.getIp())) // Match by IP instead of name
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
PhysicalMachine pm;
|
// Find existing VM by vmName
|
||||||
if (existingPmOpt.isPresent()) {
|
Optional<VM> existingVmOpt = Optional.empty();
|
||||||
// Update existing PM
|
String vmLookupName = newVm.getVmName();
|
||||||
pm = existingPmOpt.get();
|
if (vmLookupName != null) {
|
||||||
pm.setName(newPm.getName());
|
existingVmOpt = vmRepo.findFirstByVmNameOrderByIdDesc(vmLookupName);
|
||||||
pm.setIp(newPm.getIp());
|
|
||||||
pm.setTag(newPm.getTag());
|
|
||||||
pm.setPower(newPm.getPower());
|
|
||||||
|
|
||||||
System.out.println("✅ Updated existing PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
|
||||||
} else {
|
|
||||||
// Create new PM
|
|
||||||
pm = newPm;
|
|
||||||
pm.setProject(project);
|
|
||||||
project.getPhysicalMachines().add(pm);
|
|
||||||
|
|
||||||
System.out.println("✅ Created new PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process VMs that are already assigned to this PM
|
VM vm;
|
||||||
if (newPm.getVms() != null && !newPm.getVms().isEmpty()) {
|
if (existingVmOpt.isPresent()) {
|
||||||
System.out.println("🔍 Processing " + newPm.getVms().size() + " VMs for PM: " + newPm.getName());
|
// Update existing VM
|
||||||
|
vm = existingVmOpt.get();
|
||||||
|
|
||||||
// Ensure PM has VM list initialized
|
// IMPORTANT: Remove VM from its current Physical Machine first
|
||||||
if (pm.getVms() == null) {
|
if (vm.getPhysicalMachine() != null) {
|
||||||
pm.setVms(new ArrayList<>());
|
PhysicalMachine currentPM = vm.getPhysicalMachine();
|
||||||
|
if (currentPM.getVms() != null) {
|
||||||
|
currentPM.getVms().remove(vm);
|
||||||
|
System.out.println("🔄 Removed VM " + vm.getVmName() + " from previous PM: " + currentPM.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear existing VMs to replace with new ones
|
vm.setState(newVm.getState());
|
||||||
pm.getVms().clear();
|
vm.setVmName(newVm.getVmName());
|
||||||
|
vm.setIp(newVm.getIp());
|
||||||
|
vm.setPower(newVm.getPower());
|
||||||
|
vm.setCalcOn(newVm.getCalcOn());
|
||||||
|
vm.setHostingPm(newVm.getHostingPm());
|
||||||
|
vm.setHost(newVm.getHost());
|
||||||
|
vm.setFlavorName(newVm.getFlavorName());
|
||||||
|
vm.setTag(newVm.getTag());
|
||||||
|
vm.setEmissionSource(newVm.getEmissionSource());
|
||||||
|
vm.setProject(newVm.getProject());
|
||||||
|
|
||||||
// Process each VM that's already assigned to this PM
|
System.out.println("✅ Updated existing VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
||||||
for (VM newVm : newPm.getVms()) {
|
} else {
|
||||||
if (newVm == null) continue;
|
// Use new VM
|
||||||
|
vm = newVm;
|
||||||
|
|
||||||
// Find existing VM by vmName
|
System.out.println("✅ Created new VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
||||||
Optional<VM> existingVmOpt = Optional.empty();
|
}
|
||||||
String vmLookupName = newVm.getVmName();
|
|
||||||
if (vmLookupName != null) {
|
|
||||||
existingVmOpt = vmRepo.findFirstByVmNameOrderByIdDesc(vmLookupName);
|
|
||||||
}
|
|
||||||
|
|
||||||
VM vm;
|
// Set physical machine relationship
|
||||||
if (existingVmOpt.isPresent()) {
|
vm.setPhysicalMachine(pm);
|
||||||
// Update existing VM
|
pm.getVms().add(vm);
|
||||||
vm = existingVmOpt.get();
|
|
||||||
vm.setState(newVm.getState());
|
|
||||||
vm.setVmName(newVm.getVmName());
|
|
||||||
vm.setIp(newVm.getIp());
|
|
||||||
vm.setPower(newVm.getPower());
|
|
||||||
vm.setCalcOn(newVm.getCalcOn());
|
|
||||||
vm.setHostingPm(newVm.getHostingPm());
|
|
||||||
vm.setHost(newVm.getHost());
|
|
||||||
vm.setFlavorName(newVm.getFlavorName());
|
|
||||||
vm.setTag(newVm.getTag());
|
|
||||||
vm.setEmissionSource(newVm.getEmissionSource());
|
|
||||||
|
|
||||||
System.out.println("✅ Updated existing VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
// Update config
|
||||||
} else {
|
if (newVm.getConfig() != null) {
|
||||||
// Use new VM
|
if (vm.getConfig() == null) {
|
||||||
vm = newVm;
|
vm.setConfig(newVm.getConfig());
|
||||||
|
vm.getConfig().setVm(vm);
|
||||||
System.out.println("✅ Created new VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
} else {
|
||||||
}
|
vm.getConfig().setCpu(newVm.getConfig().getCpu());
|
||||||
|
vm.getConfig().setRam(newVm.getConfig().getRam());
|
||||||
// Set physical machine relationship
|
vm.getConfig().setDisk(newVm.getConfig().getDisk());
|
||||||
vm.setPhysicalMachine(pm);
|
|
||||||
pm.getVms().add(vm);
|
|
||||||
|
|
||||||
// Update config
|
|
||||||
if (newVm.getConfig() != null) {
|
|
||||||
if (vm.getConfig() == null) {
|
|
||||||
vm.setConfig(newVm.getConfig());
|
|
||||||
vm.getConfig().setVm(vm);
|
|
||||||
} else {
|
|
||||||
vm.getConfig().setCpu(newVm.getConfig().getCpu());
|
|
||||||
vm.getConfig().setRam(newVm.getConfig().getRam());
|
|
||||||
vm.getConfig().setDisk(newVm.getConfig().getDisk());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Before Save: DataCenter=" + dc.getDataCenter());
|
System.out.println("Before Save: DataCenter=" + dc.getDataCenter());
|
||||||
System.out.println("External ID=" + dc.getExternalId());
|
System.out.println("External ID=" + dc.getExternalId());
|
||||||
System.out.println("Number=" + dc.getNumber());
|
System.out.println("Number=" + dc.getNumber());
|
||||||
System.out.println("Projects=" + (dc.getProjects() != null ? dc.getProjects().size() : 0));
|
System.out.println("Physical Machines=" + (dc.getPhysicalMachines() != null ? dc.getPhysicalMachines().size() : 0));
|
||||||
|
|
||||||
DataCenter saved = dataCenterService.save(dc);
|
DataCenter saved = dataCenterService.save(dc);
|
||||||
System.out.println("✅ Saved: ID=" + saved.getId());
|
System.out.println("✅ Saved: ID=" + saved.getId());
|
||||||
@@ -525,41 +447,29 @@ public class MessageListener {
|
|||||||
int failedCalculations = 0;
|
int failedCalculations = 0;
|
||||||
int totalEmissionSources = 0;
|
int totalEmissionSources = 0;
|
||||||
|
|
||||||
for (Project project : dataCenter.getProjects()) {
|
for (PhysicalMachine pm : dataCenter.getPhysicalMachines()) {
|
||||||
for (PhysicalMachine pm : project.getPhysicalMachines()) {
|
if (pm.getVms() != null) {
|
||||||
if (pm.getVms() != null) {
|
// Calculate for all VMs (only those with calcOn = true)
|
||||||
// Calculate for all VMs (only those with calcOn = true)
|
for (VM vm : pm.getVms()) {
|
||||||
for (VM vm : pm.getVms()) {
|
totalVMs++;
|
||||||
totalVMs++;
|
if (vm.getCalcOn() != null && vm.getCalcOn()) {
|
||||||
if (vm.getCalcOn() != null && vm.getCalcOn()) {
|
eligibleVMs++;
|
||||||
eligibleVMs++;
|
if (vm.getPower() != null && vm.getPower() > 0) {
|
||||||
if (vm.getPower() != null && vm.getPower() > 0) {
|
System.out.println("✅ Processing VM " + vm.getVmName() + " (calcOn = true)");
|
||||||
System.out.println("✅ Processing VM " + vm.getVmName() + " (calcOn = true)");
|
processedVMs++;
|
||||||
processedVMs++;
|
|
||||||
|
|
||||||
// Check if VM has emission sources
|
// Check if VM has emission sources
|
||||||
Map<String, Integer> emissionSources = vm.getEmissionSource();
|
Map<String, Integer> emissionSources = vm.getEmissionSource();
|
||||||
if (emissionSources != null && !emissionSources.isEmpty()) {
|
if (emissionSources != null && !emissionSources.isEmpty()) {
|
||||||
// Create separate emission record for each emission source
|
// Create separate emission record for each emission source
|
||||||
System.out.println("🔍 VM has " + emissionSources.size() + " emission sources");
|
System.out.println("🔍 VM has " + emissionSources.size() + " emission sources");
|
||||||
totalEmissionSources += emissionSources.size();
|
totalEmissionSources += emissionSources.size();
|
||||||
for (Map.Entry<String, Integer> sourceEntry : emissionSources.entrySet()) {
|
for (Map.Entry<String, Integer> sourceEntry : emissionSources.entrySet()) {
|
||||||
String sourceName = sourceEntry.getKey();
|
String sourceName = sourceEntry.getKey();
|
||||||
Integer percentage = sourceEntry.getValue();
|
Integer percentage = sourceEntry.getValue();
|
||||||
System.out.println(" - " + sourceName + ": " + percentage + "%");
|
System.out.println(" - " + sourceName + ": " + percentage + "%");
|
||||||
|
|
||||||
boolean success = createVMEmissionRecordForSource(dataCenter, vm, project, pm, sourceName, percentage);
|
boolean success = createVMEmissionRecordForSource(dataCenter, vm, pm, sourceName, percentage);
|
||||||
if (success) {
|
|
||||||
successfulCalculations++;
|
|
||||||
} else {
|
|
||||||
failedCalculations++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback to default emission source if VM has no emission sources
|
|
||||||
System.out.println("⚠️ VM has no emission sources, using default");
|
|
||||||
totalEmissionSources++;
|
|
||||||
boolean success = createVMEmissionRecord(dataCenter, vm, project, pm);
|
|
||||||
if (success) {
|
if (success) {
|
||||||
successfulCalculations++;
|
successfulCalculations++;
|
||||||
} else {
|
} else {
|
||||||
@@ -567,11 +477,21 @@ public class MessageListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("⚠️ Skipping VM " + vm.getVmName() + " (calcOn = true) - no power consumption data");
|
// Fallback to default emission source if VM has no emission sources
|
||||||
|
System.out.println("⚠️ VM has no emission sources, using default");
|
||||||
|
totalEmissionSources++;
|
||||||
|
boolean success = createVMEmissionRecord(dataCenter, vm, pm);
|
||||||
|
if (success) {
|
||||||
|
successfulCalculations++;
|
||||||
|
} else {
|
||||||
|
failedCalculations++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("⏭️ Skipping VM " + vm.getVmName() + " - calcOn = " + vm.getCalcOn());
|
System.out.println("⚠️ Skipping VM " + vm.getVmName() + " (calcOn = true) - no power consumption data");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("⏭️ Skipping VM " + vm.getVmName() + " - calcOn = " + vm.getCalcOn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -587,7 +507,7 @@ public class MessageListener {
|
|||||||
System.out.println(" Failed emission calculations: " + failedCalculations);
|
System.out.println(" Failed emission calculations: " + failedCalculations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean createVMEmissionRecord(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
private boolean createVMEmissionRecord(DataCenter dataCenter, VM vm, PhysicalMachine pm) {
|
||||||
try {
|
try {
|
||||||
// Check if VM has an ID (is persisted)
|
// Check if VM has an ID (is persisted)
|
||||||
if (vm.getId() == null) {
|
if (vm.getId() == null) {
|
||||||
@@ -595,7 +515,7 @@ public class MessageListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainDataTableCreateInput input = createVMMainDataTableInput(dataCenter, vm, project, pm);
|
MainDataTableCreateInput input = createVMMainDataTableInput(dataCenter, vm, pm);
|
||||||
System.out.println("🔍 Creating emission record for VM: " + vm.getVmName() + " (Power: " + vm.getPower() + "W)");
|
System.out.println("🔍 Creating emission record for VM: " + vm.getVmName() + " (Power: " + vm.getPower() + "W)");
|
||||||
|
|
||||||
MainDataTable result = callMainDataTableMutation(input);
|
MainDataTable result = callMainDataTableMutation(input);
|
||||||
@@ -619,7 +539,7 @@ public class MessageListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean createVMEmissionRecordForSource(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm, String emissionSourceName, Integer percentage) {
|
private boolean createVMEmissionRecordForSource(DataCenter dataCenter, VM vm, PhysicalMachine pm, String emissionSourceName, Integer percentage) {
|
||||||
try {
|
try {
|
||||||
// Check if VM has an ID (is persisted)
|
// Check if VM has an ID (is persisted)
|
||||||
if (vm.getId() == null) {
|
if (vm.getId() == null) {
|
||||||
@@ -639,7 +559,13 @@ public class MessageListener {
|
|||||||
// Calculate power consumption for this emission source (percentage of total VM power)
|
// Calculate power consumption for this emission source (percentage of total VM power)
|
||||||
double sourceSpecificPower = vm.getPower() * (percentage / 100.0);
|
double sourceSpecificPower = vm.getPower() * (percentage / 100.0);
|
||||||
|
|
||||||
MainDataTableCreateInput input = createVMMainDataTableInputForSource(dataCenter, vm, project, pm, emissionSource, sourceSpecificPower, percentage);
|
MainDataTableCreateInput input = createVMMainDataTableInputForSource(dataCenter, vm, pm, emissionSource, sourceSpecificPower, percentage);
|
||||||
|
|
||||||
|
if (input == null) {
|
||||||
|
System.err.println("❌ Failed to create input for VM emission calculation - skipping");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("🔍 Creating emission record for VM: " + vm.getVmName() +
|
System.out.println("🔍 Creating emission record for VM: " + vm.getVmName() +
|
||||||
" - Source: " + emissionSourceName + " (" + percentage + "%) - Power: " + sourceSpecificPower + "W");
|
" - Source: " + emissionSourceName + " (" + percentage + "%) - Power: " + sourceSpecificPower + "W");
|
||||||
|
|
||||||
@@ -665,7 +591,7 @@ public class MessageListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MainDataTableCreateInput createVMMainDataTableInput(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
private MainDataTableCreateInput createVMMainDataTableInput(DataCenter dataCenter, VM vm, PhysicalMachine pm) {
|
||||||
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
||||||
|
|
||||||
// Copy datacenter-level information (if available)
|
// Copy datacenter-level information (if available)
|
||||||
@@ -692,8 +618,15 @@ public class MessageListener {
|
|||||||
input.setSubSector(dataCenter.getSubSector().getId());
|
input.setSubSector(dataCenter.getSubSector().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getEmissionSource() != null) {
|
// Handle multiple emission sources - use the default one for emission calculations
|
||||||
input.setEmissionSource(dataCenter.getEmissionSource().getId());
|
if (dataCenter.getDataCenterEmissionSources() != null && !dataCenter.getDataCenterEmissionSources().isEmpty()) {
|
||||||
|
// Find the default emission source or use the first one
|
||||||
|
DataCenterEmissionSource defaultEmissionSource = dataCenter.getDataCenterEmissionSources().stream()
|
||||||
|
.filter(DataCenterEmissionSource::getIsDefault)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(dataCenter.getDataCenterEmissionSources().get(0));
|
||||||
|
|
||||||
|
input.setEmissionSource(defaultEmissionSource.getEmissionSource().getId());
|
||||||
} else {
|
} else {
|
||||||
// Fallback to default emission source for electricity
|
// Fallback to default emission source for electricity
|
||||||
try {
|
try {
|
||||||
@@ -711,8 +644,16 @@ public class MessageListener {
|
|||||||
input.setActivitySubUnit(dataCenter.getActivitySubUnit().getId());
|
input.setActivitySubUnit(dataCenter.getActivitySubUnit().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getConsuptionUnit() != null) {
|
// Handle consumption unit from emission sources - use the default one for VM calculations
|
||||||
input.setConsuptionUnit(dataCenter.getConsuptionUnit().getId());
|
if (dataCenter.getDataCenterEmissionSources() != null && !dataCenter.getDataCenterEmissionSources().isEmpty()) {
|
||||||
|
DataCenterEmissionSource defaultEmissionSource = dataCenter.getDataCenterEmissionSources().stream()
|
||||||
|
.filter(DataCenterEmissionSource::getIsDefault)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(dataCenter.getDataCenterEmissionSources().get(0));
|
||||||
|
|
||||||
|
if (defaultEmissionSource.getConsuptionUnit() != null) {
|
||||||
|
input.setConsuptionUnit(defaultEmissionSource.getConsuptionUnit().getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to Kapsam-3 if no emission scope is set
|
// Default to Kapsam-3 if no emission scope is set
|
||||||
@@ -739,68 +680,134 @@ public class MessageListener {
|
|||||||
System.out.println(" VM Name: " + vm.getVmName());
|
System.out.println(" VM Name: " + vm.getVmName());
|
||||||
System.out.println(" Power: " + vm.getPower() + "W");
|
System.out.println(" Power: " + vm.getPower() + "W");
|
||||||
System.out.println(" Physical Machine: " + pm.getName());
|
System.out.println(" Physical Machine: " + pm.getName());
|
||||||
System.out.println(" Project: " + project.getName());
|
|
||||||
System.out.println(" DataCenter Sector: " + (dataCenter.getSector() != null ? dataCenter.getSector().getTag() : "NOT SET"));
|
System.out.println(" DataCenter Sector: " + (dataCenter.getSector() != null ? dataCenter.getSector().getTag() : "NOT SET"));
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MainDataTableCreateInput createVMMainDataTableInputForSource(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm, EmissionSource emissionSource, double sourceSpecificPower, Integer percentage) {
|
private MainDataTableCreateInput createVMMainDataTableInputForSource(DataCenter dataCenter, VM vm, PhysicalMachine pm, EmissionSource emissionSource, double sourceSpecificPower, Integer percentage) {
|
||||||
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
||||||
|
|
||||||
// Copy datacenter-level information (if available)
|
// Copy datacenter-level information (if available)
|
||||||
input.setYear("2025");
|
input.setYear("2025");
|
||||||
input.setMonth("07");
|
input.setMonth("07");
|
||||||
|
|
||||||
|
// Validate required fields
|
||||||
|
if (dataCenter == null) {
|
||||||
|
System.err.println("❌ DataCenter is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm == null) {
|
||||||
|
System.err.println("❌ VM is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emissionSource == null) {
|
||||||
|
System.err.println("❌ EmissionSource is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Note: These fields are no longer received in the message
|
// Note: These fields are no longer received in the message
|
||||||
// They need to be set via DataCenter CRUD operations first
|
// They need to be set via DataCenter CRUD operations first
|
||||||
if (dataCenter.getArea() != null && !dataCenter.getArea().getCities().isEmpty()) {
|
if (dataCenter.getArea() != null && !dataCenter.getArea().getCities().isEmpty()) {
|
||||||
input.setCity(dataCenter.getArea().getCities().get(0).getId());
|
input.setCity(dataCenter.getArea().getCities().get(0).getId());
|
||||||
|
System.out.println("🔍 Setting City: " + dataCenter.getArea().getCities().get(0).getId());
|
||||||
|
} else {
|
||||||
|
System.out.println("⚠️ Warning: No city available for DataCenter");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getArea() != null && !dataCenter.getArea().getDistricts().isEmpty()) {
|
if (dataCenter.getArea() != null && !dataCenter.getArea().getDistricts().isEmpty()) {
|
||||||
input.setDistrict(dataCenter.getArea().getDistricts().get(0).getId());
|
input.setDistrict(dataCenter.getArea().getDistricts().get(0).getId());
|
||||||
|
System.out.println("🔍 Setting District: " + dataCenter.getArea().getDistricts().get(0).getId());
|
||||||
|
} else {
|
||||||
|
System.out.println("⚠️ Warning: No district available for DataCenter");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getSector() != null) {
|
if (dataCenter.getSector() != null) {
|
||||||
input.setSector(dataCenter.getSector().getId());
|
input.setSector(dataCenter.getSector().getId());
|
||||||
|
System.out.println("🔍 Setting Sector: " + dataCenter.getSector().getId() + " (" + dataCenter.getSector().getTag() + ")");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("⚠️ Warning: DataCenter has no sector set - emission calculation may fail");
|
System.err.println("❌ Error: DataCenter has no sector set - this is required for emission calculation");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getSubSector() != null) {
|
if (dataCenter.getSubSector() != null) {
|
||||||
input.setSubSector(dataCenter.getSubSector().getId());
|
input.setSubSector(dataCenter.getSubSector().getId());
|
||||||
|
System.out.println("🔍 Setting SubSector: " + dataCenter.getSubSector().getId());
|
||||||
|
} else {
|
||||||
|
System.out.println("⚠️ Warning: DataCenter has no subsector set");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the specific emission source for this calculation
|
// Use the specific emission source for this calculation
|
||||||
input.setEmissionSource(emissionSource.getId());
|
input.setEmissionSource(emissionSource.getId());
|
||||||
|
System.out.println("🔍 Setting EmissionSource: " + emissionSource.getId() + " (" + emissionSource.getTag() + ")");
|
||||||
|
|
||||||
if (dataCenter.getActivitySubUnit() != null) {
|
if (dataCenter.getActivitySubUnit() != null) {
|
||||||
input.setActivitySubUnit(dataCenter.getActivitySubUnit().getId());
|
input.setActivitySubUnit(dataCenter.getActivitySubUnit().getId());
|
||||||
|
System.out.println("🔍 Setting ActivitySubUnit: " + dataCenter.getActivitySubUnit().getId());
|
||||||
|
} else {
|
||||||
|
System.out.println("⚠️ Warning: DataCenter has no activity sub unit set");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getConsuptionUnit() != null) {
|
// Handle consumption unit from emission sources - use the emission source's unit
|
||||||
input.setConsuptionUnit(dataCenter.getConsuptionUnit().getId());
|
if (emissionSource != null) {
|
||||||
|
// Find the DataCenterEmissionSource that matches this emissionSource
|
||||||
|
System.out.println("🔍 Looking for consumption unit for emission source: " + emissionSource.getTag());
|
||||||
|
|
||||||
|
if (dataCenter.getDataCenterEmissionSources() == null || dataCenter.getDataCenterEmissionSources().isEmpty()) {
|
||||||
|
System.err.println("❌ Error: DataCenter has no emission sources configured - cannot find consumption unit");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean foundUnit = false;
|
||||||
|
for (DataCenterEmissionSource dces : dataCenter.getDataCenterEmissionSources()) {
|
||||||
|
if (dces.getEmissionSource() != null && dces.getEmissionSource().getId().equals(emissionSource.getId())) {
|
||||||
|
if (dces.getConsuptionUnit() != null) {
|
||||||
|
input.setConsuptionUnit(dces.getConsuptionUnit().getId());
|
||||||
|
System.out.println("🔍 Setting ConsumptionUnit: " + dces.getConsuptionUnit().getId() + " (" + dces.getConsuptionUnit().getTag() + ")");
|
||||||
|
foundUnit = true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
System.err.println("❌ Error: DataCenterEmissionSource has no consumption unit set for emission source: " + emissionSource.getTag());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundUnit) {
|
||||||
|
System.err.println("❌ Error: Could not find matching DataCenterEmissionSource for emission source: " + emissionSource.getTag());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to Kapsam-3 if no emission scope is set
|
// Default to Kapsam-3 if no emission scope is set
|
||||||
input.setScope(dataCenter.getEmissionScope() != null ?
|
input.setScope(dataCenter.getEmissionScope() != null ?
|
||||||
dataCenter.getEmissionScope().getTag().equals("Kapsam-3") : true);
|
dataCenter.getEmissionScope().getTag().equals("Kapsam-3") : true);
|
||||||
|
System.out.println("🔍 Setting Scope: " + (dataCenter.getEmissionScope() != null ?
|
||||||
|
dataCenter.getEmissionScope().getTag() : "Kapsam-3 (default)"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Organization> organizations = organizationRepo.findAll();
|
List<Organization> organizations = organizationRepo.findAll();
|
||||||
if (!organizations.isEmpty()) {
|
if (!organizations.isEmpty()) {
|
||||||
input.setOrganization(organizations.get(0).getId());
|
input.setOrganization(organizations.get(0).getId());
|
||||||
|
System.out.println("🔍 Setting Organization: " + organizations.get(0).getId());
|
||||||
|
} else {
|
||||||
|
System.err.println("❌ Error: No organizations found in database - this is required");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("❌ Error finding organization: " + e.getMessage());
|
System.err.println("❌ Error finding organization: " + e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set VM-specific fields
|
// Set VM-specific fields
|
||||||
input.setVmId(vm.getId());
|
input.setVmId(vm.getId());
|
||||||
|
System.out.println("🔍 Setting VM ID: " + vm.getId());
|
||||||
|
|
||||||
// Use the source-specific power consumption (percentage of total VM power)
|
// Use the source-specific power consumption (percentage of total VM power)
|
||||||
input.setConsuptionAmount(String.valueOf(sourceSpecificPower));
|
input.setConsuptionAmount(String.valueOf(sourceSpecificPower));
|
||||||
|
System.out.println("🔍 Setting Consumption Amount: " + sourceSpecificPower + "W");
|
||||||
|
|
||||||
System.out.println("🔍 VM Emission Input for Source:");
|
System.out.println("🔍 VM Emission Input for Source:");
|
||||||
System.out.println(" VM ID: " + vm.getId());
|
System.out.println(" VM ID: " + vm.getId());
|
||||||
@@ -809,7 +816,6 @@ public class MessageListener {
|
|||||||
System.out.println(" Percentage: " + percentage + "%");
|
System.out.println(" Percentage: " + percentage + "%");
|
||||||
System.out.println(" Source Power: " + sourceSpecificPower + "W");
|
System.out.println(" Source Power: " + sourceSpecificPower + "W");
|
||||||
System.out.println(" Physical Machine: " + pm.getName());
|
System.out.println(" Physical Machine: " + pm.getName());
|
||||||
System.out.println(" Project: " + project.getName());
|
|
||||||
System.out.println(" DataCenter Sector: " + (dataCenter.getSector() != null ? dataCenter.getSector().getTag() : "NOT SET"));
|
System.out.println(" DataCenter Sector: " + (dataCenter.getSector() != null ? dataCenter.getSector().getTag() : "NOT SET"));
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
@@ -828,6 +834,34 @@ public class MessageListener {
|
|||||||
try {
|
try {
|
||||||
System.out.println("🔄 Calling mainDataTableMutation.createMainDataTable...");
|
System.out.println("🔄 Calling mainDataTableMutation.createMainDataTable...");
|
||||||
|
|
||||||
|
// Validate input fields before making the call
|
||||||
|
if (input.getSector() == null) {
|
||||||
|
System.err.println("❌ Sector is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.getEmissionSource() == null) {
|
||||||
|
System.err.println("❌ EmissionSource is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.getConsuptionUnit() == null) {
|
||||||
|
System.err.println("❌ ConsumptionUnit is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.getOrganization() == null) {
|
||||||
|
System.err.println("❌ Organization is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.getVmId() == null) {
|
||||||
|
System.err.println("❌ VM ID is null - cannot create emission record");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("🔍 Input validation passed - proceeding with mutation call");
|
||||||
|
|
||||||
// Call the mutation method - pass null environment since we've already patched the logging
|
// Call the mutation method - pass null environment since we've already patched the logging
|
||||||
MainDataTable result = mainDataTableMutation.createMainDataTable(input, null);
|
MainDataTable result = mainDataTableMutation.createMainDataTable(input, null);
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ input DataCenterCreateInput {
|
|||||||
sectorId: ID
|
sectorId: ID
|
||||||
subSectorId: ID
|
subSectorId: ID
|
||||||
activitySubUnitId: ID
|
activitySubUnitId: ID
|
||||||
emissionSourceId: ID
|
|
||||||
consuptionUnitId: ID
|
# Multiple emission sources support - each with exactly one unit
|
||||||
|
dataCenterEmissionSources: [DataCenterEmissionSourceInput!]
|
||||||
|
|
||||||
consuptionAmount: Float
|
consuptionAmount: Float
|
||||||
areaId: ID
|
areaId: ID
|
||||||
number: Int
|
number: Int
|
||||||
@@ -23,8 +25,10 @@ input DataCenterUpdateInput {
|
|||||||
sectorId: ID
|
sectorId: ID
|
||||||
subSectorId: ID
|
subSectorId: ID
|
||||||
activitySubUnitId: ID
|
activitySubUnitId: ID
|
||||||
emissionSourceId: ID
|
|
||||||
consuptionUnitId: ID
|
# Multiple emission sources support - each with exactly one unit
|
||||||
|
dataCenterEmissionSources: [DataCenterEmissionSourceInput!]
|
||||||
|
|
||||||
consuptionAmount: Float
|
consuptionAmount: Float
|
||||||
areaId: ID
|
areaId: ID
|
||||||
number: Int
|
number: Int
|
||||||
@@ -33,3 +37,10 @@ input DataCenterUpdateInput {
|
|||||||
latitude: Float
|
latitude: Float
|
||||||
longitude: Float
|
longitude: Float
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input DataCenterEmissionSourceInput {
|
||||||
|
emissionSourceId: ID!
|
||||||
|
consuptionUnitId: ID!
|
||||||
|
isDefault: Boolean
|
||||||
|
percentage: Float
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ extend type Query{
|
|||||||
dataCenters(criteria: DataCenterCriteria, sortBy: [SortBy!]): [DataCenter!]
|
dataCenters(criteria: DataCenterCriteria, sortBy: [SortBy!]): [DataCenter!]
|
||||||
paginateDataCenters(pagination : Pagination!, criteria: DataCenterCriteria, sortBy:[SortBy!] ) : DataCenterPageable!
|
paginateDataCenters(pagination : Pagination!, criteria: DataCenterCriteria, sortBy:[SortBy!] ) : DataCenterPageable!
|
||||||
getByNumber(number: Int!): DataCenter
|
getByNumber(number: Int!): DataCenter
|
||||||
physicalMachines(datacenterId: ID!, projectId: ID!): [PhysicalMachine!]!
|
physicalMachines(datacenterId: ID!): [PhysicalMachine!]!
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,13 @@ type DataCenter {
|
|||||||
sector: Sector
|
sector: Sector
|
||||||
subSector: SubSector
|
subSector: SubSector
|
||||||
activitySubUnit: ActivitySubUnit
|
activitySubUnit: ActivitySubUnit
|
||||||
emissionSource: EmissionSource
|
|
||||||
consuptionUnit: ConsuptionUnit
|
# Multiple emission sources support - each with exactly one unit
|
||||||
|
dataCenterEmissionSources: [DataCenterEmissionSource]
|
||||||
|
|
||||||
consuptionAmount: Float
|
consuptionAmount: Float
|
||||||
|
|
||||||
projects: [Project]
|
physicalMachines: [PhysicalMachine]
|
||||||
area: Area
|
area: Area
|
||||||
number: Int
|
number: Int
|
||||||
|
|
||||||
@@ -21,11 +23,12 @@ type DataCenter {
|
|||||||
longitude: Float
|
longitude: Float
|
||||||
}
|
}
|
||||||
|
|
||||||
type Project {
|
type DataCenterEmissionSource {
|
||||||
id: ID
|
id: ID
|
||||||
name: String
|
emissionSource: EmissionSource
|
||||||
physicalMachines: [PhysicalMachine]
|
consuptionUnit: ConsuptionUnit
|
||||||
dataCenter: DataCenter
|
isDefault: Boolean
|
||||||
|
percentage: Float
|
||||||
}
|
}
|
||||||
|
|
||||||
type PhysicalMachine {
|
type PhysicalMachine {
|
||||||
@@ -33,12 +36,13 @@ type PhysicalMachine {
|
|||||||
name: String
|
name: String
|
||||||
ip: String
|
ip: String
|
||||||
tag: String
|
tag: String
|
||||||
|
cloudSystem: String
|
||||||
power: Float
|
power: Float
|
||||||
vms: [Vm]
|
vms: [VM]
|
||||||
project: Project
|
dataCenter: DataCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vm {
|
type VM {
|
||||||
id: ID
|
id: ID
|
||||||
state: String
|
state: String
|
||||||
vmName: String
|
vmName: String
|
||||||
@@ -49,6 +53,7 @@ type Vm {
|
|||||||
host: String
|
host: String
|
||||||
flavorName: String
|
flavorName: String
|
||||||
tag: String
|
tag: String
|
||||||
|
project: String
|
||||||
emissionSource: EmissionSourceMap
|
emissionSource: EmissionSourceMap
|
||||||
config: Config
|
config: Config
|
||||||
physicalMachine: PhysicalMachine
|
physicalMachine: PhysicalMachine
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ type MainDataTable {
|
|||||||
proteinAmount:Float
|
proteinAmount:Float
|
||||||
burnOrOpenBurn:Boolean
|
burnOrOpenBurn:Boolean
|
||||||
scopeCheck:Boolean
|
scopeCheck:Boolean
|
||||||
vm: Vm
|
vm: VM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vm {
|
type VM {
|
||||||
id: ID
|
id: ID
|
||||||
state: String
|
state: String
|
||||||
vmName: String
|
vmName: String
|
||||||
@@ -41,6 +41,7 @@ type Vm {
|
|||||||
host: String
|
host: String
|
||||||
flavorName: String
|
flavorName: String
|
||||||
tag: String
|
tag: String
|
||||||
|
project: String
|
||||||
config: Config
|
config: Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user