New listener
This commit is contained in:
493
sge-backend/message.json
Normal file
493
sge-backend/message.json
Normal file
@@ -0,0 +1,493 @@
|
||||
{
|
||||
"158f073fbd554d4a9c32309ea7d1865e":{
|
||||
"main_optimization_space":{
|
||||
"vms":{
|
||||
"10.150.1.131":{
|
||||
"vm_name":"BLC-AYPOS-Development-20",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.10",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-20",
|
||||
2,
|
||||
1,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.186":{
|
||||
"vm_name":"BLC-AYPOS-Development-21",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.10",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-21",
|
||||
2,
|
||||
1,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"pms":{
|
||||
"10.150.1.33":{
|
||||
"tag":"None",
|
||||
"name":"compute2",
|
||||
"power":177.83822950819666,
|
||||
"confg":[
|
||||
"compute2",
|
||||
3,
|
||||
94,
|
||||
59,
|
||||
114
|
||||
]
|
||||
},
|
||||
"10.150.1.34":{
|
||||
"tag":"None",
|
||||
"name":"compute3",
|
||||
"power":21.3385737704918,
|
||||
"confg":[
|
||||
"compute3",
|
||||
24,
|
||||
115,
|
||||
151,
|
||||
114
|
||||
]
|
||||
},
|
||||
"10.150.1.35":{
|
||||
"tag":"None",
|
||||
"name":"compute4",
|
||||
"power":152.66185245901653,
|
||||
"confg":[
|
||||
"compute4",
|
||||
-13,
|
||||
28,
|
||||
103,
|
||||
114
|
||||
]
|
||||
},
|
||||
"10.150.1.32":{
|
||||
"tag":"None",
|
||||
"name":"compute1",
|
||||
"power":36.34004918032787,
|
||||
"confg":[
|
||||
"compute1",
|
||||
10,
|
||||
97,
|
||||
211,
|
||||
114
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"sub_optimization_space":{
|
||||
|
||||
}
|
||||
},
|
||||
"48966d34ff274def88db7f7b6d9f5cdc":{
|
||||
"main_optimization_space":{
|
||||
"vms":{
|
||||
"10.150.1.101":{
|
||||
"vm_name":"Bgreen",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"m1.medium",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"Bgreen",
|
||||
2,
|
||||
4,
|
||||
40,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.107":{
|
||||
"vm_name":"BLC-AYPOS-Development-1",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.34",
|
||||
"host":"compute3",
|
||||
"flavor_name":"aypos.test.flavour.8",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-1",
|
||||
3,
|
||||
3,
|
||||
8,
|
||||
"compute3"
|
||||
]
|
||||
},
|
||||
"10.150.1.112":{
|
||||
"vm_name":"nginx-proxyV2",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"m1.small",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"nginx-proxyV2",
|
||||
1,
|
||||
2,
|
||||
20,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.114":{
|
||||
"vm_name":"BLC-AYPOS-Development-5",
|
||||
"power":8.541673488756713,
|
||||
"state":"active",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"aypos.test.flavour.19",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-5",
|
||||
2,
|
||||
3,
|
||||
8,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.123":{
|
||||
"vm_name":"SGE",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"ForJAVA",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"SGE",
|
||||
8,
|
||||
32,
|
||||
150,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.130":{
|
||||
"vm_name":"aybuke",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"m1.public",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"aybuke",
|
||||
8,
|
||||
8,
|
||||
50,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.133":{
|
||||
"vm_name":"BLC-AYPOS-Development-2",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.34",
|
||||
"host":"compute3",
|
||||
"flavor_name":"aypos.test.flavour.15",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-2",
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
"compute3"
|
||||
]
|
||||
},
|
||||
"10.150.1.141":{
|
||||
"vm_name":"BLC-AYPOS-Development-0",
|
||||
"power":10.146380530416682,
|
||||
"state":"active",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.11",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-0",
|
||||
3,
|
||||
3,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.145":{
|
||||
"vm_name":"BLC-AYPOS-Development-9",
|
||||
"power":12.464360819208926,
|
||||
"state":"active",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.0",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-9",
|
||||
2,
|
||||
1,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.150":{
|
||||
"vm_name":"blc-cloud",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.32",
|
||||
"host":"compute1",
|
||||
"flavor_name":"m1.xlarge",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"blc-cloud",
|
||||
8,
|
||||
16,
|
||||
160,
|
||||
"compute1"
|
||||
]
|
||||
},
|
||||
"10.150.1.155":{
|
||||
"vm_name":"Aypos-Ulak",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"m1.vrealize",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"Aypos-Ulak",
|
||||
8,
|
||||
16,
|
||||
50,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.167":{
|
||||
"vm_name":"prometheus_serverV3",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"ayposYedek",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"prometheus_serverV3",
|
||||
2,
|
||||
6,
|
||||
60,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.171":{
|
||||
"vm_name":"blc-meet",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"m1.devstack",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"blc-meet",
|
||||
4,
|
||||
7,
|
||||
60,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.172":{
|
||||
"vm_name":"blc-office",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.32",
|
||||
"host":"compute1",
|
||||
"flavor_name":"m1.large",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"blc-office",
|
||||
4,
|
||||
8,
|
||||
80,
|
||||
"compute1"
|
||||
]
|
||||
},
|
||||
"10.150.1.174":{
|
||||
"vm_name":"mail-server",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"mail-server",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"mail-server",
|
||||
4,
|
||||
8,
|
||||
100,
|
||||
"compute4"
|
||||
]
|
||||
},
|
||||
"10.150.1.175":{
|
||||
"vm_name":"BLC-AYPOS-Development-7",
|
||||
"power":16.084780100161176,
|
||||
"emissionsource":{
|
||||
"dizel":30,
|
||||
"coal":40,
|
||||
"solar energy":30
|
||||
},
|
||||
"state":"active",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.19",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-7",
|
||||
2,
|
||||
3,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.180":{
|
||||
"vm_name":"BLC-AYPOS-Development-8",
|
||||
"power":22.454381667855632,
|
||||
"state":"active",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.6",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-8",
|
||||
1,
|
||||
2,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.190":{
|
||||
"vm_name":"BLC-AYPOS-Development-6",
|
||||
"power":36.17691364518403,
|
||||
"state":"active",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"aypos.test.flavour.16",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-6",
|
||||
2,
|
||||
4,
|
||||
8,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.193":{
|
||||
"vm_name":"BLC-AYPOS-Development-4",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.34",
|
||||
"host":"compute3",
|
||||
"flavor_name":"aypos.test.flavour.4",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"BLC-AYPOS-Development-4",
|
||||
2,
|
||||
1,
|
||||
8,
|
||||
"compute3"
|
||||
]
|
||||
},
|
||||
"10.150.1.199":{
|
||||
"vm_name":"gitea-server",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.33",
|
||||
"host":"compute2",
|
||||
"flavor_name":"m1.large",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"gitea-server",
|
||||
4,
|
||||
8,
|
||||
80,
|
||||
"compute2"
|
||||
]
|
||||
},
|
||||
"10.150.1.200":{
|
||||
"vm_name":"ollama",
|
||||
"power":0,
|
||||
"state":"inactive",
|
||||
"hosting_pm":"10.150.1.35",
|
||||
"host":"compute4",
|
||||
"flavor_name":"m1.vrealize",
|
||||
"tag":"None",
|
||||
"confg":[
|
||||
"ollama",
|
||||
8,
|
||||
16,
|
||||
50,
|
||||
"compute4"
|
||||
]
|
||||
}
|
||||
},
|
||||
"pms":{
|
||||
"10.150.1.33":{
|
||||
"tag":"None",
|
||||
"name":"compute2",
|
||||
"power":177.83822950819666,
|
||||
"confg":[
|
||||
"compute2",
|
||||
3,
|
||||
94,
|
||||
59,
|
||||
114
|
||||
]
|
||||
},
|
||||
"10.150.1.34":{
|
||||
"tag":"None",
|
||||
"name":"compute3",
|
||||
"power":21.3385737704918,
|
||||
"confg":[
|
||||
"compute3",
|
||||
24,
|
||||
115,
|
||||
151,
|
||||
114
|
||||
]
|
||||
},
|
||||
"10.150.1.35":{
|
||||
"tag":"None",
|
||||
"name":"compute4",
|
||||
"power":152.66185245901653,
|
||||
"confg":[
|
||||
"compute4",
|
||||
-13,
|
||||
28,
|
||||
103,
|
||||
114
|
||||
]
|
||||
},
|
||||
"10.150.1.32":{
|
||||
"tag":"None",
|
||||
"name":"compute1",
|
||||
"power":36.34004918032787,
|
||||
"confg":[
|
||||
"compute1",
|
||||
10,
|
||||
97,
|
||||
211,
|
||||
114
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"sub_optimization_space":{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
0
sge-backend/mvnw
vendored
Normal file → Executable file
0
sge-backend/mvnw
vendored
Normal file → Executable file
@@ -4,14 +4,12 @@ import com.sgs.graphql.activitySubUnit.query.pagination.ActivitySubUnitPageable;
|
||||
import com.sgs.graphql.activitySubUnit.domain.ActivitySubUnit;
|
||||
import com.sgs.graphql.activitySubUnit.repo.criteria.ActivitySubUnitCriteria;
|
||||
import com.sgs.graphql.activitySubUnit.service.ActivitySubUnitService;
|
||||
import com.sgs.graphql.permission.domain.PermissionName;
|
||||
import com.sgs.lib.dao.query.pagination.Pagination;
|
||||
import com.sgs.lib.dao.query.sort.SortBy;
|
||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -33,7 +31,6 @@ public class ActivitySubUnitQueryResolver implements GraphQLQueryResolver {
|
||||
return activitySubUnitService.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.ACTIVITY_SUB_UNITS_GET + "')")
|
||||
public List<ActivitySubUnit> activitySubUnits(ActivitySubUnitCriteria criteria, List<SortBy> sortBy) {
|
||||
return activitySubUnitService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new ActivitySubUnitCriteria()),
|
||||
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
||||
|
||||
@@ -39,6 +39,12 @@ public class DataCenter extends BaseDomain {
|
||||
private ConsuptionUnit consuptionUnit;
|
||||
private ActivitySubUnit activitySubUnit;
|
||||
|
||||
// New attributes
|
||||
private String ayposURL;
|
||||
private String address;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
|
||||
@Column(name = "data_center_name")
|
||||
@Transactional
|
||||
@@ -118,13 +124,8 @@ public class DataCenter extends BaseDomain {
|
||||
this.consuptionUnit = consuptionUnit;
|
||||
}
|
||||
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "area_id")
|
||||
@JsonBackReference("area-datacenter")
|
||||
@JoinTable(name = "relation_datacenter_area",
|
||||
joinColumns = @JoinColumn(name = "datacenter_id", referencedColumnName = "id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "area_id", referencedColumnName = "id"))
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
public Area getArea() {
|
||||
return area;
|
||||
}
|
||||
@@ -162,4 +163,41 @@ public class DataCenter extends BaseDomain {
|
||||
public void setActivitySubUnit(ActivitySubUnit activitySubUnit) {
|
||||
this.activitySubUnit = activitySubUnit;
|
||||
}
|
||||
|
||||
// New attribute getters and setters
|
||||
@Column(name = "aypos_url")
|
||||
public String getAyposURL() {
|
||||
return ayposURL;
|
||||
}
|
||||
|
||||
public void setAyposURL(String ayposURL) {
|
||||
this.ayposURL = ayposURL;
|
||||
}
|
||||
|
||||
@Column(name = "address")
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Column(name = "latitude")
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
@Column(name = "longitude")
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
}
|
||||
@@ -5,27 +5,18 @@ import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.sgs.lib.dao.domain.BaseDomain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Entity
|
||||
@Table(name = "physical_machine")
|
||||
public class PhysicalMachine extends BaseDomain {
|
||||
private String status;
|
||||
private String name;
|
||||
private Double powerConsumption;
|
||||
private Vms vms;
|
||||
private String ip;
|
||||
private String tag;
|
||||
private Double power;
|
||||
private List<VM> vms = new ArrayList<>();
|
||||
private Project project;
|
||||
//private DataCenter dataCenter;
|
||||
//private Project project;
|
||||
//private Zone zone;
|
||||
|
||||
@Column(name = "status")
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Column(name = "name")
|
||||
public String getName() {
|
||||
@@ -36,23 +27,40 @@ public class PhysicalMachine extends BaseDomain {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Column(name = "power_consumption", nullable = false)
|
||||
public Double getPowerConsumption() {
|
||||
return powerConsumption;
|
||||
@Column(name = "ip")
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setPowerConsumption(Double powerConsumption) {
|
||||
this.powerConsumption = powerConsumption;
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "vms_id")
|
||||
@Column(name = "tag")
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Column(name = "power")
|
||||
public Double getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(Double power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "physicalMachine", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JsonManagedReference
|
||||
public Vms getVms() {
|
||||
public List<VM> getVms() {
|
||||
return vms;
|
||||
}
|
||||
|
||||
public void setVms(Vms vms) {
|
||||
public void setVms(List<VM> vms) {
|
||||
this.vms = vms;
|
||||
}
|
||||
|
||||
@@ -66,6 +74,4 @@ public class PhysicalMachine extends BaseDomain {
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,30 +9,34 @@ import javax.persistence.*;
|
||||
@Entity
|
||||
@Table(name = "vm")
|
||||
public class VM extends BaseDomain {
|
||||
private String status;
|
||||
private String name;
|
||||
private String state;
|
||||
private String vmName;
|
||||
private String ip;
|
||||
private Double power;
|
||||
private Boolean calcOn = false;
|
||||
private String hostingPm;
|
||||
private String host;
|
||||
private String flavorName;
|
||||
private String tag;
|
||||
private Config config;
|
||||
private Vms activeVms;
|
||||
private Vms inactiveVms;
|
||||
private PhysicalMachine physicalMachine;
|
||||
|
||||
@Column(name = "status")
|
||||
public String getStatus() {
|
||||
return status;
|
||||
@Column(name = "state")
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Column(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
@Column(name = "vm_name")
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setVmName(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
@Column(name = "power", nullable = false)
|
||||
@@ -53,6 +57,51 @@ public class VM extends BaseDomain {
|
||||
this.calcOn = calcOn;
|
||||
}
|
||||
|
||||
@Column(name = "hosting_pm")
|
||||
public String getHostingPm() {
|
||||
return hostingPm;
|
||||
}
|
||||
|
||||
public void setHostingPm(String hostingPm) {
|
||||
this.hostingPm = hostingPm;
|
||||
}
|
||||
|
||||
@Column(name = "host")
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
@Column(name = "flavor_name")
|
||||
public String getFlavorName() {
|
||||
return flavorName;
|
||||
}
|
||||
|
||||
public void setFlavorName(String flavorName) {
|
||||
this.flavorName = flavorName;
|
||||
}
|
||||
|
||||
@Column(name = "tag")
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Column(name = "ip")
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "vm")
|
||||
@JsonManagedReference
|
||||
public Config getConfig() {
|
||||
@@ -63,28 +112,15 @@ public class VM extends BaseDomain {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "active_vms_id")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "physical_machine_id")
|
||||
@JsonBackReference
|
||||
public Vms getActiveVms() {
|
||||
return activeVms;
|
||||
public PhysicalMachine getPhysicalMachine() {
|
||||
return physicalMachine;
|
||||
}
|
||||
|
||||
public void setActiveVms(Vms activeVms) {
|
||||
this.activeVms = activeVms;
|
||||
}
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "inactive_vms_id")
|
||||
@JsonBackReference
|
||||
public Vms getInactiveVms() {
|
||||
return inactiveVms;
|
||||
}
|
||||
|
||||
public void setInactiveVms(Vms inactiveVms) {
|
||||
this.inactiveVms = inactiveVms;
|
||||
public void setPhysicalMachine(PhysicalMachine physicalMachine) {
|
||||
this.physicalMachine = physicalMachine;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.sgs.graphql.dataCenter.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.sgs.lib.dao.domain.BaseDomain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "vms")
|
||||
public class Vms extends BaseDomain {
|
||||
private List<VM> active;
|
||||
private List<VM> inactive;
|
||||
private PhysicalMachine physicalMachine;
|
||||
|
||||
// Default constructor to initialize collections
|
||||
public Vms() {
|
||||
this.active = new ArrayList<>();
|
||||
this.inactive = new ArrayList<>();
|
||||
}
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "active_vms_id")
|
||||
@JsonManagedReference
|
||||
public List<VM> getActive() {
|
||||
return active;
|
||||
}
|
||||
public void setActive(List<VM> active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "inactive_vms_id")
|
||||
@JsonManagedReference
|
||||
public List<VM> getInactive() {
|
||||
return inactive;
|
||||
}
|
||||
|
||||
public void setInactive(List<VM> inactive) {
|
||||
this.inactive = inactive;
|
||||
}
|
||||
|
||||
@OneToOne(mappedBy = "vms")
|
||||
@JsonBackReference
|
||||
public PhysicalMachine getPhysicalMachine() {
|
||||
return physicalMachine;
|
||||
}
|
||||
|
||||
public void setPhysicalMachine(PhysicalMachine physicalMachine) {
|
||||
this.physicalMachine = physicalMachine;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import com.sgs.graphql.emissionScope.dto.EmissionScopeDto;
|
||||
import com.sgs.graphql.consuptionUnit.dto.ConsuptionUnitDto;
|
||||
import com.sgs.graphql.activitySubUnit.dto.ActivitySubUnitDto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataCenterDto {
|
||||
@JsonProperty("data_center")
|
||||
@@ -16,9 +16,8 @@ public class DataCenterDto {
|
||||
private int id;
|
||||
private Integer externalId;
|
||||
private Integer number;
|
||||
|
||||
private AreaDto area;
|
||||
private List<ProjectDto> projects;
|
||||
private Map<String, ProjectDto> projects;
|
||||
|
||||
// Emission calculation fields
|
||||
private SectorDto sector;
|
||||
@@ -69,11 +68,11 @@ public class DataCenterDto {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public List<ProjectDto> getProjects() {
|
||||
public Map<String, ProjectDto> getProjects() {
|
||||
return projects;
|
||||
}
|
||||
|
||||
public void setProjects(List<ProjectDto> projects) {
|
||||
public void setProjects(Map<String, ProjectDto> projects) {
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
package com.sgs.graphql.dataCenter.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
public class PhysicalMachineDto {
|
||||
private String status;
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("power_consumption")
|
||||
private double powerConsumption;
|
||||
@JsonProperty("tag")
|
||||
private String tag;
|
||||
|
||||
private VmsDto vms;
|
||||
@JsonProperty("power")
|
||||
private double power;
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
@JsonProperty("confg") // Note: keeping the typo from JSON
|
||||
private List<Object> confg;
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
private String ip; // IP address from the message key
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -27,19 +26,35 @@ public class PhysicalMachineDto {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public double getPowerConsumption() {
|
||||
return powerConsumption;
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setPowerConsumption(double powerConsumption) {
|
||||
this.powerConsumption = powerConsumption;
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public VmsDto getVms() {
|
||||
return vms;
|
||||
public double getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setVms(VmsDto vms) {
|
||||
this.vms = vms;
|
||||
public void setPower(double power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public List<Object> getConfg() {
|
||||
return confg;
|
||||
}
|
||||
|
||||
public void setConfg(List<Object> confg) {
|
||||
this.confg = confg;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,48 @@ import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class ProjectDto {
|
||||
private int id;
|
||||
private String name;
|
||||
@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;
|
||||
|
||||
public int getId() {
|
||||
// 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(int id) {
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,60 @@
|
||||
package com.sgs.graphql.dataCenter.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
public class VMDto {
|
||||
private String status;
|
||||
private String name;
|
||||
@JsonProperty("vm_name")
|
||||
private String vmName;
|
||||
|
||||
@JsonProperty("power")
|
||||
private double power;
|
||||
private boolean calcOn;
|
||||
|
||||
@JsonProperty("config")
|
||||
private ConfigDto config;
|
||||
@JsonProperty("state")
|
||||
private String state;
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
@JsonProperty("hosting_pm")
|
||||
private String hostingPm;
|
||||
|
||||
@JsonProperty("host")
|
||||
private String host;
|
||||
|
||||
@JsonProperty("flavor_name")
|
||||
private String flavorName;
|
||||
|
||||
@JsonProperty("tag")
|
||||
private String tag;
|
||||
|
||||
@JsonProperty("confg") // Note: keeping the typo from JSON
|
||||
private List<Object> confg;
|
||||
|
||||
private String ip; // IP address from the message key
|
||||
private boolean calcOn = false; // Derived from state: active = true, inactive = false
|
||||
|
||||
public String getVmName() {
|
||||
return vmName;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
public void setVmName(String vmName) {
|
||||
this.vmName = vmName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
// Automatically set calcOn based on state
|
||||
this.calcOn = "active".equalsIgnoreCase(state);
|
||||
}
|
||||
|
||||
public double getPower() {
|
||||
@@ -35,12 +65,44 @@ public class VMDto {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public ConfigDto getConfig() {
|
||||
return config;
|
||||
public String getHostingPm() {
|
||||
return hostingPm;
|
||||
}
|
||||
|
||||
public void setConfig(ConfigDto config) {
|
||||
this.config = config;
|
||||
public void setHostingPm(String hostingPm) {
|
||||
this.hostingPm = hostingPm;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getFlavorName() {
|
||||
return flavorName;
|
||||
}
|
||||
|
||||
public void setFlavorName(String flavorName) {
|
||||
this.flavorName = flavorName;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public List<Object> getConfg() {
|
||||
return confg;
|
||||
}
|
||||
|
||||
public void setConfg(List<Object> confg) {
|
||||
this.confg = confg;
|
||||
}
|
||||
|
||||
public boolean isCalcOn() {
|
||||
@@ -50,4 +112,20 @@ public class VMDto {
|
||||
public void setCalcOn(boolean calcOn) {
|
||||
this.calcOn = calcOn;
|
||||
}
|
||||
|
||||
// Helper method to get config as ConfigDto
|
||||
public ConfigDto getConfig() {
|
||||
if (confg != null && confg.size() >= 5) {
|
||||
ConfigDto config = new ConfigDto();
|
||||
try {
|
||||
config.setCpu(((Number) confg.get(1)).intValue());
|
||||
config.setRam(((Number) confg.get(2)).intValue());
|
||||
config.setDisk(((Number) confg.get(3)).intValue());
|
||||
return config;
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error parsing config from confg array: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.sgs.graphql.dataCenter.mutation;
|
||||
|
||||
import com.sgs.graphql.dataCenter.mutation.mapper.DataCenterMapper;
|
||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterCreateInput;
|
||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterUpdateInput;
|
||||
import com.sgs.graphql.permission.domain.PermissionName;
|
||||
import graphql.kickstart.tools.GraphQLMutationResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.UUID;
|
||||
|
||||
@Validated
|
||||
@Component
|
||||
public class DataCenterMutation implements GraphQLMutationResolver {
|
||||
|
||||
private final DataCenterService dataCenterService;
|
||||
private final DataCenterMapper dataCenterMapper;
|
||||
|
||||
@Autowired
|
||||
public DataCenterMutation(DataCenterService dataCenterService, DataCenterMapper dataCenterMapper) {
|
||||
this.dataCenterService = dataCenterService;
|
||||
this.dataCenterMapper = dataCenterMapper;
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_CREATE + "')")
|
||||
public DataCenter createDataCenter(@Valid DataCenterCreateInput input) {
|
||||
// Check for duplicate externalId
|
||||
if (input.getExternalId() != null && dataCenterService.existsByExternalId(input.getExternalId())) {
|
||||
throw new RuntimeException("This external id already exists: " + input.getExternalId());
|
||||
}
|
||||
|
||||
DataCenter dataCenter = dataCenterMapper.toEntity(input);
|
||||
|
||||
// Set auto-generated number if not provided
|
||||
if (dataCenter.getNumber() == null) {
|
||||
Integer maxNumber = dataCenterService.getRepository().findMaxNumber();
|
||||
dataCenter.setNumber((maxNumber == null) ? 1 : maxNumber + 1);
|
||||
}
|
||||
|
||||
return dataCenterService.save(dataCenter);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_UPDATE + "')")
|
||||
public DataCenter updateDataCenter(UUID id, @Valid DataCenterUpdateInput input) {
|
||||
return dataCenterService.findById(id)
|
||||
.map(dataCenter -> {
|
||||
// Check for duplicate externalId if it's being updated
|
||||
if (input.getExternalId() != null &&
|
||||
!input.getExternalId().equals(dataCenter.getExternalId()) &&
|
||||
dataCenterService.existsByExternalId(input.getExternalId())) {
|
||||
throw new RuntimeException("This external id already exists: " + input.getExternalId());
|
||||
}
|
||||
return dataCenterService.update(dataCenterMapper.updateEntity(dataCenter, input));
|
||||
})
|
||||
.orElseThrow(() -> new RuntimeException("Data center not found with ID: " + id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('" + PermissionName.DATA_CENTER_DELETE + "')")
|
||||
public Boolean deleteDataCenter(UUID id) {
|
||||
try {
|
||||
DataCenter dataCenter = dataCenterService.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Data center not found with ID: " + id));
|
||||
|
||||
dataCenterService.delete(dataCenter);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("DataCenter deletion error: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.sgs.graphql.dataCenter.mutation.input;
|
||||
|
||||
import com.sgs.lib.dao.mutation.input.BaseCreateInput;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Min;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataCenterCreateInput extends BaseCreateInput {
|
||||
@NotBlank(message = "Data center adı gereklidir")
|
||||
private String dataCenter;
|
||||
|
||||
@Min(value = 1, message = "External ID pozitif bir sayı olmalıdır")
|
||||
private Integer externalId;
|
||||
private Integer number;
|
||||
private Double consuptionAmount;
|
||||
|
||||
@NotNull(message = "Alan ID gereklidir")
|
||||
private UUID areaId;
|
||||
|
||||
@NotNull(message = "Sektör ID gereklidir")
|
||||
private UUID sectorId;
|
||||
|
||||
private UUID subSectorId;
|
||||
private UUID emissionSourceId;
|
||||
private UUID emissionScopeId;
|
||||
private UUID consuptionUnitId;
|
||||
private UUID activitySubUnitId;
|
||||
|
||||
// New attributes
|
||||
private String ayposURL;
|
||||
private String address;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
// Getters and Setters
|
||||
public String getDataCenter() { return dataCenter; }
|
||||
public void setDataCenter(String dataCenter) { this.dataCenter = dataCenter; }
|
||||
|
||||
public Integer getExternalId() { return externalId; }
|
||||
public void setExternalId(Integer externalId) { this.externalId = externalId; }
|
||||
|
||||
public Integer getNumber() { return number; }
|
||||
public void setNumber(Integer number) { this.number = number; }
|
||||
|
||||
public Double getConsuptionAmount() { return consuptionAmount; }
|
||||
public void setConsuptionAmount(Double consuptionAmount) { this.consuptionAmount = consuptionAmount; }
|
||||
|
||||
public UUID getAreaId() { return areaId; }
|
||||
public void setAreaId(UUID areaId) { this.areaId = areaId; }
|
||||
|
||||
public UUID getSectorId() { return sectorId; }
|
||||
public void setSectorId(UUID sectorId) { this.sectorId = sectorId; }
|
||||
|
||||
public UUID getSubSectorId() { return 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 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 void setActivitySubUnitId(UUID activitySubUnitId) { this.activitySubUnitId = activitySubUnitId; }
|
||||
|
||||
// New attribute getters and setters
|
||||
public String getAyposURL() { return ayposURL; }
|
||||
public void setAyposURL(String ayposURL) { this.ayposURL = ayposURL; }
|
||||
|
||||
public String getAddress() { return address; }
|
||||
public void setAddress(String address) { this.address = address; }
|
||||
|
||||
public Double getLatitude() { return latitude; }
|
||||
public void setLatitude(Double latitude) { this.latitude = latitude; }
|
||||
|
||||
public Double getLongitude() { return longitude; }
|
||||
public void setLongitude(Double longitude) { this.longitude = longitude; }
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.sgs.graphql.dataCenter.mutation.input;
|
||||
|
||||
import com.sgs.lib.dao.mutation.input.BaseUpdateInput;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DataCenterUpdateInput extends BaseUpdateInput {
|
||||
private String dataCenter;
|
||||
private Integer externalId;
|
||||
private Integer number;
|
||||
private Double consuptionAmount;
|
||||
|
||||
private UUID areaId;
|
||||
private UUID sectorId;
|
||||
private UUID subSectorId;
|
||||
private UUID emissionSourceId;
|
||||
private UUID emissionScopeId;
|
||||
private UUID consuptionUnitId;
|
||||
private UUID activitySubUnitId;
|
||||
|
||||
// New attributes
|
||||
private String ayposURL;
|
||||
private String address;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
// Getters and Setters
|
||||
public String getDataCenter() { return dataCenter; }
|
||||
public void setDataCenter(String dataCenter) { this.dataCenter = dataCenter; }
|
||||
|
||||
public Integer getExternalId() { return externalId; }
|
||||
public void setExternalId(Integer externalId) { this.externalId = externalId; }
|
||||
|
||||
public Integer getNumber() { return number; }
|
||||
public void setNumber(Integer number) { this.number = number; }
|
||||
|
||||
public Double getConsuptionAmount() { return consuptionAmount; }
|
||||
public void setConsuptionAmount(Double consuptionAmount) { this.consuptionAmount = consuptionAmount; }
|
||||
|
||||
public UUID getAreaId() { return areaId; }
|
||||
public void setAreaId(UUID areaId) { this.areaId = areaId; }
|
||||
|
||||
public UUID getSectorId() { return sectorId; }
|
||||
public void setSectorId(UUID sectorId) { this.sectorId = sectorId; }
|
||||
|
||||
public UUID getSubSectorId() { return 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 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 void setActivitySubUnitId(UUID activitySubUnitId) { this.activitySubUnitId = activitySubUnitId; }
|
||||
|
||||
// New attribute getters and setters
|
||||
public String getAyposURL() { return ayposURL; }
|
||||
public void setAyposURL(String ayposURL) { this.ayposURL = ayposURL; }
|
||||
|
||||
public String getAddress() { return address; }
|
||||
public void setAddress(String address) { this.address = address; }
|
||||
|
||||
public Double getLatitude() { return latitude; }
|
||||
public void setLatitude(Double latitude) { this.latitude = latitude; }
|
||||
|
||||
public Double getLongitude() { return longitude; }
|
||||
public void setLongitude(Double longitude) { this.longitude = longitude; }
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.sgs.graphql.dataCenter.mutation.mapper;
|
||||
|
||||
import com.sgs.graphql.dataCenter.domain.DataCenter;
|
||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterCreateInput;
|
||||
import com.sgs.graphql.dataCenter.mutation.input.DataCenterUpdateInput;
|
||||
import com.sgs.graphql.area.service.AreaService;
|
||||
import com.sgs.graphql.sector.service.SectorService;
|
||||
import com.sgs.graphql.subSector.service.SubSectorService;
|
||||
import com.sgs.graphql.emissionSource.service.EmissionSourceService;
|
||||
import com.sgs.graphql.emissionScope.service.EmissionScopeService;
|
||||
import com.sgs.graphql.consuptionUnit.service.ConsuptionUnitService;
|
||||
import com.sgs.graphql.activitySubUnit.service.ActivitySubUnitService;
|
||||
import com.sgs.lib.dao.mutation.mapper.BaseCreateUpdateMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DataCenterMapper extends BaseCreateUpdateMapper<DataCenter, DataCenterCreateInput, DataCenterUpdateInput> {
|
||||
|
||||
private final AreaService areaService;
|
||||
private final SectorService sectorService;
|
||||
private final SubSectorService subSectorService;
|
||||
private final EmissionSourceService emissionSourceService;
|
||||
private final EmissionScopeService emissionScopeService;
|
||||
private final ConsuptionUnitService consuptionUnitService;
|
||||
private final ActivitySubUnitService activitySubUnitService;
|
||||
|
||||
@Autowired
|
||||
public DataCenterMapper(AreaService areaService, SectorService sectorService,
|
||||
SubSectorService subSectorService, EmissionSourceService emissionSourceService,
|
||||
EmissionScopeService emissionScopeService, ConsuptionUnitService consuptionUnitService,
|
||||
ActivitySubUnitService activitySubUnitService) {
|
||||
this.areaService = areaService;
|
||||
this.sectorService = sectorService;
|
||||
this.subSectorService = subSectorService;
|
||||
this.emissionSourceService = emissionSourceService;
|
||||
this.emissionScopeService = emissionScopeService;
|
||||
this.consuptionUnitService = consuptionUnitService;
|
||||
this.activitySubUnitService = activitySubUnitService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenter toEntity(DataCenterCreateInput input) {
|
||||
DataCenter entity = new DataCenter();
|
||||
|
||||
// Basic fields
|
||||
entity.setDataCenter(input.getDataCenter());
|
||||
entity.setExternalId(input.getExternalId());
|
||||
entity.setNumber(input.getNumber());
|
||||
entity.setConsuptionAmount(input.getConsuptionAmount());
|
||||
|
||||
// Convert ID references to entities
|
||||
if (input.getAreaId() != null) {
|
||||
entity.setArea(areaService.findById(input.getAreaId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getSectorId() != null) {
|
||||
entity.setSector(sectorService.findById(input.getSectorId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getSubSectorId() != 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) {
|
||||
entity.setEmissionScope(emissionScopeService.findById(input.getEmissionScopeId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getConsuptionUnitId() != null) {
|
||||
entity.setConsuptionUnit(consuptionUnitService.findById(input.getConsuptionUnitId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getActivitySubUnitId() != null) {
|
||||
entity.setActivitySubUnit(activitySubUnitService.findById(input.getActivitySubUnitId()).orElse(null));
|
||||
}
|
||||
|
||||
// New attributes
|
||||
entity.setAyposURL(input.getAyposURL());
|
||||
entity.setAddress(input.getAddress());
|
||||
entity.setLatitude(input.getLatitude());
|
||||
entity.setLongitude(input.getLongitude());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenter updateEntity(DataCenter entity, DataCenterUpdateInput input) {
|
||||
// Update only provided fields (partial update)
|
||||
if (input.getDataCenter() != null) {
|
||||
entity.setDataCenter(input.getDataCenter());
|
||||
}
|
||||
|
||||
if (input.getExternalId() != null) {
|
||||
entity.setExternalId(input.getExternalId());
|
||||
}
|
||||
|
||||
if (input.getNumber() != null) {
|
||||
entity.setNumber(input.getNumber());
|
||||
}
|
||||
|
||||
if (input.getConsuptionAmount() != null) {
|
||||
entity.setConsuptionAmount(input.getConsuptionAmount());
|
||||
}
|
||||
|
||||
// Update relationships only if provided
|
||||
if (input.getAreaId() != null) {
|
||||
entity.setArea(areaService.findById(input.getAreaId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getSectorId() != null) {
|
||||
entity.setSector(sectorService.findById(input.getSectorId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getSubSectorId() != 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) {
|
||||
entity.setEmissionScope(emissionScopeService.findById(input.getEmissionScopeId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getConsuptionUnitId() != null) {
|
||||
entity.setConsuptionUnit(consuptionUnitService.findById(input.getConsuptionUnitId()).orElse(null));
|
||||
}
|
||||
|
||||
if (input.getActivitySubUnitId() != null) {
|
||||
entity.setActivitySubUnit(activitySubUnitService.findById(input.getActivitySubUnitId()).orElse(null));
|
||||
}
|
||||
|
||||
// New attributes (partial update - only if provided)
|
||||
if (input.getAyposURL() != null) {
|
||||
entity.setAyposURL(input.getAyposURL());
|
||||
}
|
||||
|
||||
if (input.getAddress() != null) {
|
||||
entity.setAddress(input.getAddress());
|
||||
}
|
||||
|
||||
if (input.getLatitude() != null) {
|
||||
entity.setLatitude(input.getLatitude());
|
||||
}
|
||||
|
||||
if (input.getLongitude() != null) {
|
||||
entity.setLongitude(input.getLongitude());
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,6 @@ public interface DataCenterRepo extends BaseRepo<DataCenter> {
|
||||
|
||||
Optional<DataCenter> findByExternalId(Integer externalId);
|
||||
|
||||
boolean existsByExternalId(Integer externalId);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ public interface VMRepo extends BaseRepo<VM> {
|
||||
Optional<VM> findById(UUID id);
|
||||
|
||||
/**
|
||||
* Find all VMs by name (handles duplicates)
|
||||
* @param name VM name
|
||||
* @return List of VMs with the given name
|
||||
* Find all VMs by vmName
|
||||
* @param vmName VM name
|
||||
* @return List of VMs with the given vmName
|
||||
*/
|
||||
List<VM> findAllByName(String name);
|
||||
List<VM> findAllByVmName(String vmName);
|
||||
|
||||
/**
|
||||
* Find first VM by name ordered by ID (most recent first)
|
||||
* @param name VM name
|
||||
* Find first VM by vmName ordered by ID (most recent first)
|
||||
* @param vmName VM name
|
||||
* @return Optional VM
|
||||
*/
|
||||
Optional<VM> findFirstByNameOrderByIdDesc(String name);
|
||||
Optional<VM> findFirstByVmNameOrderByIdDesc(String vmName);
|
||||
}
|
||||
@@ -15,4 +15,8 @@ public class DataCenterService extends BaseService<DataCenter, DataCenterRepo, D
|
||||
public DataCenterService(DataCenterRepo repository, DataCenterCriteriaSpec criteriaSpec) {
|
||||
super(repository, criteriaSpec);
|
||||
}
|
||||
|
||||
public boolean existsByExternalId(Integer externalId) {
|
||||
return getRepository().existsByExternalId(externalId);
|
||||
}
|
||||
}
|
||||
@@ -5,31 +5,13 @@ import com.sgs.config.RabbitMQConfig;
|
||||
import com.sgs.graphql.dataCenter.domain.*;
|
||||
|
||||
import com.sgs.graphql.dataCenter.dto.*;
|
||||
import com.sgs.graphql.sector.dto.SectorDto;
|
||||
import com.sgs.graphql.subSector.dto.SubSectorDto;
|
||||
import com.sgs.graphql.emissionSource.dto.EmissionSourceDto;
|
||||
import com.sgs.graphql.emissionScope.dto.EmissionScopeDto;
|
||||
import com.sgs.graphql.consuptionUnit.dto.ConsuptionUnitDto;
|
||||
import com.sgs.graphql.activitySubUnit.dto.ActivitySubUnitDto;
|
||||
|
||||
import com.sgs.graphql.dataCenter.repo.DataCenterRepo;
|
||||
import com.sgs.graphql.dataCenter.repo.VMRepo;
|
||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
||||
import com.sgs.graphql.district.domain.District;
|
||||
import com.sgs.graphql.district.repo.DistrictRepo;
|
||||
import com.sgs.graphql.sector.domain.Sector;
|
||||
import com.sgs.graphql.sector.repo.SectorRepo;
|
||||
import com.sgs.graphql.subSector.domain.SubSector;
|
||||
import com.sgs.graphql.subSector.repo.SubSectorRepo;
|
||||
import com.sgs.graphql.emissionSource.domain.EmissionSource;
|
||||
import com.sgs.graphql.emissionSource.repo.EmissionSourceRepo;
|
||||
import com.sgs.graphql.mainDataTable.mutation.MainDataTableMutation;
|
||||
import com.sgs.graphql.emissionScope.domain.EmissionScope;
|
||||
import com.sgs.graphql.emissionScope.repo.EmissionScopeRepo;
|
||||
import com.sgs.graphql.consuptionUnit.domain.ConsuptionUnit;
|
||||
import com.sgs.graphql.consuptionUnit.repo.ConsuptionUnitRepo;
|
||||
import com.sgs.graphql.activitySubUnit.domain.ActivitySubUnit;
|
||||
import com.sgs.graphql.activitySubUnit.repo.ActivitySubUnitRepo;
|
||||
import com.sgs.graphql.systemHistory.enums.LogType;
|
||||
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
||||
import com.sgs.graphql.organization.domain.Organization;
|
||||
@@ -39,10 +21,6 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.sgs.graphql.area.domain.Area;
|
||||
import com.sgs.graphql.area.repo.AreaRepo; // Or AreaRepository
|
||||
import com.sgs.graphql.city.domain.City;
|
||||
import com.sgs.graphql.city.repo.CityRepo;
|
||||
|
||||
import com.sgs.graphql.mainDataTable.domain.MainDataTable;
|
||||
import com.sgs.graphql.mainDataTable.mutation.input.MainDataTableCreateInput;
|
||||
@@ -51,7 +29,8 @@ import java.util.Optional;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
@@ -66,40 +45,21 @@ public class MessageListener {
|
||||
private final DataCenterService dataCenterService;
|
||||
private final DataCenterRepo dataCenterRepo;
|
||||
private final VMRepo vmRepo;
|
||||
private final AreaRepo areaRepo;
|
||||
private final DistrictRepo districtRepo;
|
||||
private final CityRepo cityRepo;
|
||||
private final SectorRepo sectorRepo;
|
||||
private final SubSectorRepo subSectorRepo;
|
||||
private final EmissionSourceRepo emissionSourceRepo;
|
||||
private final EmissionScopeRepo emissionScopeRepo;
|
||||
private final ConsuptionUnitRepo consuptionUnitRepo;
|
||||
private final ActivitySubUnitRepo activitySubUnitRepo;
|
||||
private final OrganizationRepo organizationRepo;
|
||||
|
||||
@Autowired
|
||||
private MainDataTableMutation mainDataTableMutation;
|
||||
|
||||
public MessageListener(@Qualifier("singleQuoteObjectMapper") ObjectMapper objectMapper, SystemLogger systemLogger,
|
||||
DataCenterService dataCenterService, DataCenterRepo dataCenterRepo, VMRepo vmRepo, AreaRepo areaRepo,
|
||||
DistrictRepo districtRepo, CityRepo cityRepo, SectorRepo sectorRepo,
|
||||
SubSectorRepo subSectorRepo, EmissionSourceRepo emissionSourceRepo,
|
||||
EmissionScopeRepo emissionScopeRepo, ConsuptionUnitRepo consuptionUnitRepo,
|
||||
ActivitySubUnitRepo activitySubUnitRepo, OrganizationRepo organizationRepo) {
|
||||
DataCenterService dataCenterService, DataCenterRepo dataCenterRepo, VMRepo vmRepo,
|
||||
EmissionSourceRepo emissionSourceRepo, OrganizationRepo organizationRepo) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.systemLogger = systemLogger;
|
||||
this.dataCenterService = dataCenterService;
|
||||
this.dataCenterRepo = dataCenterRepo;
|
||||
this.vmRepo = vmRepo;
|
||||
this.areaRepo = areaRepo;
|
||||
this.districtRepo = districtRepo;
|
||||
this.cityRepo = cityRepo;
|
||||
this.sectorRepo = sectorRepo;
|
||||
this.subSectorRepo = subSectorRepo;
|
||||
this.emissionSourceRepo = emissionSourceRepo;
|
||||
this.emissionScopeRepo = emissionScopeRepo;
|
||||
this.consuptionUnitRepo = consuptionUnitRepo;
|
||||
this.activitySubUnitRepo = activitySubUnitRepo;
|
||||
this.organizationRepo = organizationRepo;
|
||||
}
|
||||
|
||||
@@ -109,14 +69,26 @@ public class MessageListener {
|
||||
try {
|
||||
DataCenterDto dto = objectMapper.readValue(message, DataCenterDto.class);
|
||||
|
||||
// 🔍 Log emission-related fields to verify only tags are received
|
||||
System.out.println("🔍 EMISSION FIELDS RECEIVED:");
|
||||
System.out.println(" Sector: " + (dto.getSector() != null ? dto.getSector().getTag() : "null"));
|
||||
System.out.println(" SubSector: " + (dto.getSubSector() != null ? dto.getSubSector().getTag() : "null"));
|
||||
System.out.println(" EmissionSource: " + (dto.getEmissionSource() != null ? dto.getEmissionSource().getTag() : "null"));
|
||||
System.out.println(" EmissionScope: " + (dto.getEmissionScope() != null ? dto.getEmissionScope().getTag() : "null"));
|
||||
System.out.println(" ConsuptionUnit: " + (dto.getConsuptionUnit() != null ? dto.getConsuptionUnit().getTag() : "null"));
|
||||
System.out.println(" ActivitySubUnit: " + (dto.getActivitySubUnit() != null ? dto.getActivitySubUnit().getTag() : "null"));
|
||||
// 🔍 Log basic fields received
|
||||
System.out.println("🔍 MESSAGE RECEIVED:");
|
||||
System.out.println(" External ID: " + dto.getId());
|
||||
System.out.println(" Number: " + dto.getNumber());
|
||||
System.out.println(" Consumption Amount: " + dto.getConsuptionAmount());
|
||||
System.out.println(" Projects Count: " + (dto.getProjects() != null ? dto.getProjects().size() : 0));
|
||||
|
||||
// Log MainOptimizationSpace info for each project
|
||||
if (dto.getProjects() != null) {
|
||||
for (Map.Entry<String, ProjectDto> projectEntry : dto.getProjects().entrySet()) {
|
||||
String projectId = projectEntry.getKey();
|
||||
ProjectDto project = projectEntry.getValue();
|
||||
if (project.getMainOptimizationSpace() != null) {
|
||||
MainOptimizationSpaceDto mainOpt = project.getMainOptimizationSpace();
|
||||
System.out.println(" Project " + projectId + ":");
|
||||
System.out.println(" PMs: " + (mainOpt.getPms() != null ? mainOpt.getPms().size() : 0));
|
||||
System.out.println(" VMs: " + (mainOpt.getVms() != null ? mainOpt.getVms().size() : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataCenter entity = toDataCenterEntity(dto);
|
||||
DataCenter dataCenter = createDataCenter(entity);
|
||||
@@ -127,12 +99,23 @@ public class MessageListener {
|
||||
System.out.println("✅ DTO parsed:\n" + objectMapper.writeValueAsString(dto));
|
||||
//System.out.println("✅ Entity:\n" + objectMapper.writeValueAsString(entity));
|
||||
System.out.println("🚨 DataCenter name: " + dataCenter.getDataCenter());
|
||||
System.out.println("🚨 Area: " + dataCenter.getArea()); // could be null
|
||||
System.out.println("PMs in first project: " + dataCenter.getProjects().get(0).getPhysicalMachines().size());
|
||||
System.out.println("🚨 External ID: " + dataCenter.getExternalId());
|
||||
System.out.println("🚨 Projects count: " + (dataCenter.getProjects() != null ? dataCenter.getProjects().size() : 0));
|
||||
if (dataCenter.getProjects() != null && !dataCenter.getProjects().isEmpty()) {
|
||||
Project firstProject = dataCenter.getProjects().get(0);
|
||||
System.out.println("🚨 PMs in first project: " + firstProject.getPhysicalMachines().size());
|
||||
|
||||
// Show VM assignment summary
|
||||
int totalVMs = 0;
|
||||
for (PhysicalMachine pm : firstProject.getPhysicalMachines()) {
|
||||
int vmCount = pm.getVms() != null ? pm.getVms().size() : 0;
|
||||
totalVMs += vmCount;
|
||||
System.out.println(" PM " + pm.getName() + " (IP: " + pm.getIp() + "): " + vmCount + " VMs");
|
||||
}
|
||||
System.out.println("🚨 Total VMs assigned: " + totalVMs);
|
||||
}
|
||||
|
||||
//System.out.println("✅ Saved DataCenter:\n" + objectMapper.writeValueAsString(dataCenter));
|
||||
|
||||
// Perform emission calculations
|
||||
} catch (Exception e) {
|
||||
System.err.println("Mesaj işlenirken hata oluştu: " + e.getMessage());
|
||||
}
|
||||
@@ -154,39 +137,24 @@ public class MessageListener {
|
||||
return null;
|
||||
|
||||
VM entity = new VM();
|
||||
entity.setStatus(dto.getStatus());
|
||||
entity.setName(dto.getName());
|
||||
|
||||
// Map new fields
|
||||
entity.setState(dto.getState());
|
||||
entity.setVmName(dto.getVmName());
|
||||
entity.setPower(dto.getPower());
|
||||
entity.setCalcOn(dto.isCalcOn()); // Set calcOn from DTO
|
||||
entity.setHostingPm(dto.getHostingPm());
|
||||
entity.setHost(dto.getHost());
|
||||
entity.setFlavorName(dto.getFlavorName());
|
||||
entity.setTag(dto.getTag());
|
||||
|
||||
// Set calcOn - you may want to derive this from state or other logic
|
||||
entity.setCalcOn(dto.isCalcOn());
|
||||
|
||||
// Handle config from confg array
|
||||
entity.setConfig(toConfigEntity(dto.getConfig()));
|
||||
|
||||
// Debug logging
|
||||
System.out.println("🔍 VM Entity Created: " + dto.getName() + " - calcOn = " + dto.isCalcOn());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Vms toVmsEntity(VmsDto dto) {
|
||||
if (dto == null)
|
||||
return null;
|
||||
|
||||
Vms entity = new Vms();
|
||||
|
||||
if (dto.getActive() != null) {
|
||||
List<VM> activeVMs = dto.getActive().stream()
|
||||
.map(this::toVMEntity)
|
||||
.peek(vm -> vm.setActiveVms(entity))
|
||||
.collect(Collectors.toList());
|
||||
entity.setActive(activeVMs);
|
||||
}
|
||||
|
||||
if (dto.getInactive() != null) {
|
||||
List<VM> inactiveVMs = dto.getInactive().stream()
|
||||
.map(this::toVMEntity)
|
||||
.peek(vm -> vm.setInactiveVms(entity))
|
||||
.collect(Collectors.toList());
|
||||
entity.setInactive(inactiveVMs);
|
||||
}
|
||||
System.out.println("🔍 VM Entity Created: " + dto.getVmName() + " - state = " + dto.getState() + " - calcOn = " + dto.isCalcOn());
|
||||
|
||||
return entity;
|
||||
}
|
||||
@@ -196,98 +164,49 @@ public class MessageListener {
|
||||
return null;
|
||||
|
||||
PhysicalMachine entity = new PhysicalMachine();
|
||||
entity.setStatus(dto.getStatus());
|
||||
entity.setName(dto.getName());
|
||||
entity.setPowerConsumption(dto.getPowerConsumption());
|
||||
entity.setIp(dto.getIp());
|
||||
entity.setTag(dto.getTag());
|
||||
entity.setPower(dto.getPower());
|
||||
|
||||
Vms vms = toVmsEntity(dto.getVms());
|
||||
if (vms != null) {
|
||||
entity.setVms(vms);
|
||||
vms.setPhysicalMachine(entity);
|
||||
}
|
||||
// VMs are now processed separately from the new message format
|
||||
entity.setVms(new ArrayList<>());
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public Area toAreaEntity(AreaDto dto) {
|
||||
if (dto == null) return null;
|
||||
|
||||
Optional<Area> areaOptional = areaRepo.findByTag(dto.getTag());
|
||||
City city = cityRepo.findByName(dto.getCity());
|
||||
District district = districtRepo.findByName(dto.getDistrict());
|
||||
|
||||
Area area = areaOptional.orElseGet(Area::new);
|
||||
|
||||
area.setTag(dto.getTag());
|
||||
area.setDeleted(dto.isDeleted());
|
||||
area.setDefaultArea(dto.isDefaultArea());
|
||||
|
||||
if (city != null) {
|
||||
List<City> cities = area.getCities();
|
||||
if (!cities.contains(city)) {
|
||||
cities.add(city);
|
||||
}
|
||||
area.setCities(cities); // optional — can be skipped if JPA updates in-place
|
||||
}
|
||||
|
||||
if (district != null) {
|
||||
List<District> districts = area.getDistricts();
|
||||
if (!districts.contains(district)) {
|
||||
districts.add(district);
|
||||
}
|
||||
area.setDistricts(districts);
|
||||
}
|
||||
|
||||
Area savedArea = areaRepo.save(area);
|
||||
System.out.println("✅ Saved Area: tag=" + savedArea.getTag());
|
||||
System.out.println("✅ Cities: " + savedArea.getCities().stream().map(City::getName).toList());
|
||||
System.out.println("✅ Districts: " + savedArea.getDistricts().stream().map(District::getName).toList());
|
||||
|
||||
|
||||
return savedArea;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public DataCenter toDataCenterEntity(DataCenterDto dto) {
|
||||
if (dto == null)
|
||||
return null;
|
||||
|
||||
DataCenter entity = new DataCenter();
|
||||
entity.setDataCenter(dto.getDataCenter());
|
||||
// Note: DataCenter name is no longer received in the message
|
||||
// The DataCenter name will be set via CRUD operations
|
||||
entity.setExternalId(dto.getId());
|
||||
entity.setNumber(dto.getNumber());
|
||||
entity.setConsuptionAmount(dto.getConsuptionAmount());
|
||||
|
||||
// Convert Area
|
||||
Area area = toAreaEntity(dto.getArea());
|
||||
entity.setArea(area);
|
||||
|
||||
// Convert emission-related entities
|
||||
Sector sector = toSectorEntity(dto.getSector());
|
||||
entity.setSector(sector);
|
||||
|
||||
SubSector subSector = toSubSectorEntity(dto.getSubSector());
|
||||
entity.setSubSector(subSector);
|
||||
|
||||
EmissionSource emissionSource = toEmissionSourceEntity(dto.getEmissionSource());
|
||||
entity.setEmissionSource(emissionSource);
|
||||
|
||||
EmissionScope emissionScope = toEmissionScopeEntity(dto.getEmissionScope());
|
||||
entity.setEmissionScope(emissionScope);
|
||||
|
||||
ConsuptionUnit consuptionUnit = toConsuptionUnitEntity(dto.getConsuptionUnit());
|
||||
entity.setConsuptionUnit(consuptionUnit);
|
||||
|
||||
ActivitySubUnit activitySubUnit = toActivitySubUnitEntity(dto.getActivitySubUnit());
|
||||
entity.setActivitySubUnit(activitySubUnit);
|
||||
// Note: Area, Sector, SubSector, EmissionSource, EmissionScope,
|
||||
// ConsuptionUnit, and ActivitySubUnit are no longer received in the message
|
||||
// These will need to be set via the DataCenter CRUD operations
|
||||
|
||||
// Convert Projects
|
||||
if (dto.getProjects() != null) {
|
||||
List<Project> projects = dto.getProjects().stream()
|
||||
.map(this::toProjectEntity)
|
||||
.peek(proj -> proj.setDataCenter(entity))
|
||||
.collect(Collectors.toList());
|
||||
List<Project> projects = new ArrayList<>();
|
||||
for (Map.Entry<String, ProjectDto> projectEntry : dto.getProjects().entrySet()) {
|
||||
String projectId = projectEntry.getKey();
|
||||
ProjectDto projectDto = projectEntry.getValue();
|
||||
|
||||
// Set the project ID and a default name if not provided
|
||||
projectDto.setId(projectId);
|
||||
if (projectDto.getName() == null || projectDto.getName().isEmpty()) {
|
||||
projectDto.setName("Project-" + projectId.substring(0, 8)); // Use first 8 chars of ID as name
|
||||
}
|
||||
|
||||
Project project = toProjectEntity(projectDto);
|
||||
project.setDataCenter(entity);
|
||||
projects.add(project);
|
||||
}
|
||||
entity.setProjects(projects);
|
||||
}
|
||||
|
||||
@@ -301,147 +220,105 @@ public class MessageListener {
|
||||
Project entity = new Project();
|
||||
entity.setName(dto.getName());
|
||||
|
||||
if (dto.getPhysicalMachines() != null) {
|
||||
List<PhysicalMachine> physicalMachines = dto.getPhysicalMachines().stream()
|
||||
.map(this::toPhysicalMachineEntity)
|
||||
.peek(pm -> pm.setProject(entity))
|
||||
.collect(Collectors.toList());
|
||||
// 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);
|
||||
}
|
||||
|
||||
// if (dto.getPhysicalMachines() != null) {
|
||||
// List<Aggregate> aggregates = dto.getAggregates().stream()
|
||||
// .map(this::toAggregateEntity)
|
||||
// .peek(pm -> pm.setProject(entity))
|
||||
// .collect(Collectors.toList());
|
||||
// entity.setAggregates(aggregates);
|
||||
// }
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process MainOptimizationSpaceDto and assign VMs to their hosting PMs
|
||||
*/
|
||||
private List<PhysicalMachine> processMainOptimizationSpace(MainOptimizationSpaceDto mainOptSpace) {
|
||||
List<PhysicalMachine> physicalMachines = new ArrayList<>();
|
||||
|
||||
// public Aggregate toAggregateEntity(AggregateDto dto){
|
||||
// if (dto == null)
|
||||
// return null;
|
||||
|
||||
// Aggregate entity = new Aggregate();
|
||||
// entity.setStatus(dto.getStatus());
|
||||
// entity.setName(dto.getName());
|
||||
|
||||
// if (dto.getPhysicalMachines() != null) {
|
||||
// List<PhysicalMachine> physicalMachines = dto.getPhysicalMachines().stream()
|
||||
// .map(this::toPhysicalMachineEntity)
|
||||
// .peek(pm -> pm.setAggregate(entity))
|
||||
// .collect(Collectors.toList());
|
||||
// entity.setPhysicalMachines(physicalMachines);
|
||||
// }
|
||||
// return entity;
|
||||
// }
|
||||
|
||||
|
||||
public Sector toSectorEntity(SectorDto dto) {
|
||||
if (dto == null) return null;
|
||||
|
||||
Sector sector = sectorRepo.findByTag(dto.getTag());
|
||||
if (sector == null) {
|
||||
System.err.println("❌ Sector not found with tag: " + dto.getTag());
|
||||
return null;
|
||||
if (mainOptSpace.getPms() == null || mainOptSpace.getVms() == null) {
|
||||
System.out.println("⚠️ MainOptimizationSpace has null PMs or VMs");
|
||||
return physicalMachines;
|
||||
}
|
||||
|
||||
System.out.println("✅ Found Sector: tag=" + sector.getTag());
|
||||
return sector;
|
||||
}
|
||||
System.out.println("🔍 Processing MainOptimizationSpace with " +
|
||||
mainOptSpace.getPms().size() + " PMs and " +
|
||||
mainOptSpace.getVms().size() + " VMs");
|
||||
|
||||
public EmissionScope toEmissionScopeEntity(EmissionScopeDto dto) {
|
||||
if (dto == null) return null;
|
||||
// Convert PMs from DTO to Entity
|
||||
for (Map.Entry<String, PhysicalMachineDto> pmEntry : mainOptSpace.getPms().entrySet()) {
|
||||
String pmIp = pmEntry.getKey();
|
||||
PhysicalMachineDto pmDto = pmEntry.getValue();
|
||||
|
||||
EmissionScope emissionScope = emissionScopeRepo.findByTag(dto.getTag());
|
||||
if (emissionScope == null) {
|
||||
System.err.println("❌ EmissionScope not found with tag: " + dto.getTag());
|
||||
return null;
|
||||
// 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() + ")");
|
||||
}
|
||||
|
||||
System.out.println("✅ Found EmissionScope: tag=" + emissionScope.getTag());
|
||||
return emissionScope;
|
||||
}
|
||||
// Assign VMs to their hosting PMs
|
||||
for (Map.Entry<String, VMDto> vmEntry : mainOptSpace.getVms().entrySet()) {
|
||||
String vmIp = vmEntry.getKey();
|
||||
VMDto vmDto = vmEntry.getValue();
|
||||
|
||||
public ConsuptionUnit toConsuptionUnitEntity(ConsuptionUnitDto dto) {
|
||||
if (dto == null) return null;
|
||||
// Set the IP from the map key
|
||||
vmDto.setIp(vmIp);
|
||||
|
||||
List<ConsuptionUnit> consuptionUnits = consuptionUnitRepo.findByTag(dto.getTag());
|
||||
if (consuptionUnits.isEmpty()) {
|
||||
System.err.println("❌ ConsuptionUnit not found with tag: " + dto.getTag());
|
||||
return null;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
ConsuptionUnit consuptionUnit = consuptionUnits.get(0); // Take the first one if multiple exist
|
||||
System.out.println("✅ Found ConsuptionUnit: tag=" + consuptionUnit.getTag());
|
||||
return consuptionUnit;
|
||||
}
|
||||
|
||||
public SubSector toSubSectorEntity(SubSectorDto dto) {
|
||||
if (dto == null) return null;
|
||||
|
||||
SubSector subSector = subSectorRepo.findByTag(dto.getTag());
|
||||
if (subSector == null) {
|
||||
System.err.println("❌ SubSector not found with tag: " + dto.getTag());
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("✅ Found SubSector: tag=" + subSector.getTag());
|
||||
return subSector;
|
||||
}
|
||||
|
||||
public EmissionSource toEmissionSourceEntity(EmissionSourceDto dto) {
|
||||
if (dto == null) return null;
|
||||
|
||||
List<EmissionSource> emissionSources = emissionSourceRepo.findByTag(dto.getTag());
|
||||
if (emissionSources.isEmpty()) {
|
||||
System.err.println("❌ EmissionSource not found with tag: " + dto.getTag());
|
||||
return null;
|
||||
}
|
||||
|
||||
EmissionSource emissionSource = emissionSources.get(0); // Take the first one if multiple exist
|
||||
System.out.println("✅ Found EmissionSource: tag=" + emissionSource.getTag());
|
||||
return emissionSource;
|
||||
}
|
||||
|
||||
public ActivitySubUnit toActivitySubUnitEntity(ActivitySubUnitDto dto) {
|
||||
if (dto == null) return null;
|
||||
|
||||
ActivitySubUnit activitySubUnit = activitySubUnitRepo.findByTag(dto.getTag());
|
||||
if (activitySubUnit == null) {
|
||||
System.err.println("❌ ActivitySubUnit not found with tag: " + dto.getTag());
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("✅ Found ActivitySubUnit: tag=" + activitySubUnit.getTag());
|
||||
return activitySubUnit;
|
||||
return physicalMachines;
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public DataCenter createDataCenter(DataCenter newDc) {
|
||||
try {
|
||||
// First, validate that a DataCenter with this external ID exists
|
||||
Optional<DataCenter> existingDcOpt = dataCenterRepo.findByExternalId(newDc.getExternalId());
|
||||
DataCenter dc;
|
||||
|
||||
if (existingDcOpt.isPresent()) {
|
||||
dc = existingDcOpt.get();
|
||||
dc.setDataCenter(newDc.getDataCenter());
|
||||
dc.setArea(newDc.getArea());
|
||||
if (!existingDcOpt.isPresent()) {
|
||||
String errorMessage = "❌ No DataCenter found with external ID: " + newDc.getExternalId() +
|
||||
". DataCenter must be created via CRUD operations before receiving VM data.";
|
||||
System.err.println(errorMessage);
|
||||
systemLogger.createSystemLog(LogType.ERROR, errorMessage);
|
||||
throw new RuntimeException(errorMessage);
|
||||
}
|
||||
|
||||
// Update emission-related fields
|
||||
dc.setSector(newDc.getSector());
|
||||
dc.setSubSector(newDc.getSubSector());
|
||||
dc.setEmissionSource(newDc.getEmissionSource());
|
||||
dc.setEmissionScope(newDc.getEmissionScope());
|
||||
dc.setConsuptionAmount(newDc.getConsuptionAmount());
|
||||
dc.setConsuptionUnit(newDc.getConsuptionUnit());
|
||||
dc.setActivitySubUnit(newDc.getActivitySubUnit());
|
||||
System.out.println("✅ Found existing DataCenter with external ID: " + newDc.getExternalId());
|
||||
|
||||
for (Project newProject : newDc.getProjects()) {
|
||||
DataCenter dc = existingDcOpt.get();
|
||||
|
||||
// Note: DataCenter name and emission-related fields are no longer updated from the message
|
||||
// These are now managed via DataCenter CRUD operations
|
||||
|
||||
for (Project newProject : newDc.getProjects()) {
|
||||
Optional<Project> existingProjOpt = dc.getProjects().stream()
|
||||
.filter(p -> p.getName().equalsIgnoreCase(newProject.getName()))
|
||||
.findFirst();
|
||||
@@ -450,134 +327,102 @@ public class MessageListener {
|
||||
if (existingProjOpt.isPresent()) {
|
||||
project = existingProjOpt.get();
|
||||
project.setName(newProject.getName());
|
||||
System.out.println("✅ Updated existing project: " + project.getName());
|
||||
} else {
|
||||
project = newProject;
|
||||
project.setDataCenter(dc);
|
||||
dc.getProjects().add(project);
|
||||
System.out.println("✅ Created new project: " + project.getName());
|
||||
}
|
||||
|
||||
// REMOVED: Aggregate processing loop
|
||||
// Ensure project has initialized physical machines list
|
||||
if (project.getPhysicalMachines() == null) {
|
||||
project.setPhysicalMachines(new ArrayList<>());
|
||||
}
|
||||
|
||||
// Process Physical Machines (VMs are already assigned to PMs from MainOptimizationSpace)
|
||||
for (PhysicalMachine newPm : newProject.getPhysicalMachines()) {
|
||||
Optional<PhysicalMachine> existingPmOpt = project.getPhysicalMachines().stream()
|
||||
.filter(pm -> pm.getName().equalsIgnoreCase(newPm.getName()))
|
||||
.filter(pm -> pm.getIp().equals(newPm.getIp())) // Match by IP instead of name
|
||||
.findFirst();
|
||||
|
||||
PhysicalMachine pm;
|
||||
if (existingPmOpt.isPresent()) {
|
||||
// Update existing PM
|
||||
pm = existingPmOpt.get();
|
||||
pm.setStatus(newPm.getStatus());
|
||||
pm.setPowerConsumption(newPm.getPowerConsumption());
|
||||
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.setProject(project); // Set project directly
|
||||
pm.setProject(project);
|
||||
project.getPhysicalMachines().add(pm);
|
||||
|
||||
System.out.println("✅ Created new PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
||||
}
|
||||
|
||||
// ✅ FIXED: VM upsert logic with global VM lookup
|
||||
if (newPm.getVms() != null) {
|
||||
System.out.println("🔍 Processing VMs for PM: " + newPm.getName());
|
||||
// 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 Vms());
|
||||
pm.getVms().setPhysicalMachine(pm);
|
||||
pm.setVms(new ArrayList<>());
|
||||
}
|
||||
|
||||
// Active VMs - Use global VM lookup to avoid duplicates
|
||||
if (newPm.getVms().getActive() != null) {
|
||||
for (VM newVm : newPm.getVms().getActive()) {
|
||||
// First, try to find existing VM globally by name, most recent first
|
||||
Optional<VM> existingVmOpt = vmRepo.findFirstByNameOrderByIdDesc(newVm.getName());
|
||||
// Clear existing VMs to replace with new ones
|
||||
pm.getVms().clear();
|
||||
|
||||
VM vm;
|
||||
if (existingVmOpt.isPresent()) {
|
||||
// Update existing VM
|
||||
vm = existingVmOpt.get();
|
||||
vm.setStatus(newVm.getStatus());
|
||||
vm.setPower(newVm.getPower());
|
||||
vm.setCalcOn(newVm.getCalcOn());
|
||||
// Process each VM that's already assigned to this PM
|
||||
for (VM newVm : newPm.getVms()) {
|
||||
if (newVm == null) continue;
|
||||
|
||||
// Ensure it's in the correct parent collection
|
||||
if (pm.getVms().getActive() == null) {
|
||||
pm.getVms().setActive(new java.util.ArrayList<>());
|
||||
}
|
||||
if (!pm.getVms().getActive().contains(vm)) {
|
||||
pm.getVms().getActive().add(vm);
|
||||
}
|
||||
vm.setActiveVms(pm.getVms());
|
||||
|
||||
System.out.println("✅ Updated existing VM: " + vm.getName() + " (ID: " + vm.getId() + ") - calcOn = " + vm.getCalcOn());
|
||||
} else {
|
||||
// Create new VM
|
||||
vm = newVm;
|
||||
vm.setActiveVms(pm.getVms());
|
||||
if (pm.getVms().getActive() == null) {
|
||||
pm.getVms().setActive(new java.util.ArrayList<>());
|
||||
}
|
||||
pm.getVms().getActive().add(vm);
|
||||
|
||||
System.out.println("✅ Created new VM: " + vm.getName() + " - calcOn = " + vm.getCalcOn());
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
// Find existing VM by vmName
|
||||
Optional<VM> existingVmOpt = Optional.empty();
|
||||
String vmLookupName = newVm.getVmName();
|
||||
if (vmLookupName != null) {
|
||||
existingVmOpt = vmRepo.findFirstByVmNameOrderByIdDesc(vmLookupName);
|
||||
}
|
||||
}
|
||||
|
||||
// Inactive VMs - Use global VM lookup to avoid duplicates
|
||||
if (newPm.getVms().getInactive() != null) {
|
||||
for (VM newVm : newPm.getVms().getInactive()) {
|
||||
// First, try to find existing VM globally by name, most recent first
|
||||
Optional<VM> existingVmOpt = vmRepo.findFirstByNameOrderByIdDesc(newVm.getName());
|
||||
VM vm;
|
||||
if (existingVmOpt.isPresent()) {
|
||||
// Update existing 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 vm;
|
||||
if (existingVmOpt.isPresent()) {
|
||||
// Update existing VM
|
||||
vm = existingVmOpt.get();
|
||||
vm.setStatus(newVm.getStatus());
|
||||
vm.setPower(newVm.getPower());
|
||||
vm.setCalcOn(newVm.getCalcOn());
|
||||
System.out.println("✅ Updated existing VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
||||
} else {
|
||||
// Use new VM
|
||||
vm = newVm;
|
||||
|
||||
// Ensure it's in the correct parent collection
|
||||
if (pm.getVms().getInactive() == null) {
|
||||
pm.getVms().setInactive(new java.util.ArrayList<>());
|
||||
}
|
||||
if (!pm.getVms().getInactive().contains(vm)) {
|
||||
pm.getVms().getInactive().add(vm);
|
||||
}
|
||||
vm.setInactiveVms(pm.getVms());
|
||||
System.out.println("✅ Created new VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
||||
}
|
||||
|
||||
System.out.println("✅ Updated existing inactive VM: " + vm.getName() + " (ID: " + vm.getId() + ") - calcOn = " + vm.getCalcOn());
|
||||
// Set physical machine relationship
|
||||
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 {
|
||||
// Create new VM
|
||||
vm = newVm;
|
||||
vm.setInactiveVms(pm.getVms());
|
||||
if (pm.getVms().getInactive() == null) {
|
||||
pm.getVms().setInactive(new java.util.ArrayList<>());
|
||||
}
|
||||
pm.getVms().getInactive().add(vm);
|
||||
|
||||
System.out.println("✅ Created new inactive VM: " + vm.getName() + " - calcOn = " + vm.getCalcOn());
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
vm.getConfig().setCpu(newVm.getConfig().getCpu());
|
||||
vm.getConfig().setRam(newVm.getConfig().getRam());
|
||||
vm.getConfig().setDisk(newVm.getConfig().getDisk());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -585,14 +430,9 @@ public class MessageListener {
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Integer maxNumber = dataCenterRepo.findMaxNumber();
|
||||
newDc.setNumber((maxNumber == null) ? 1 : maxNumber + 1);
|
||||
dc = newDc;
|
||||
}
|
||||
|
||||
System.out.println("Before Save: DataCenter=" + dc.getDataCenter());
|
||||
System.out.println("Area=" + (dc.getArea() != null ? dc.getArea().getTag() : "null"));
|
||||
System.out.println("External ID=" + dc.getExternalId());
|
||||
System.out.println("Number=" + dc.getNumber());
|
||||
System.out.println("Projects=" + (dc.getProjects() != null ? dc.getProjects().size() : 0));
|
||||
|
||||
DataCenter saved = dataCenterService.save(dc);
|
||||
@@ -611,20 +451,17 @@ public class MessageListener {
|
||||
|
||||
|
||||
public void processEmissionCalculations(DataCenter dataCenter) {
|
||||
System.out.println("🔍 Starting VM-level emission calculations for DataCenter: " + dataCenter.getDataCenter());
|
||||
System.out.println("🔍 Starting VM-level emission calculations for DataCenter ID: " + dataCenter.getId() +
|
||||
" (Name: " + dataCenter.getDataCenter() + ")");
|
||||
try {
|
||||
setupSecurityContext();
|
||||
|
||||
// Check if this is Sabit Enerji sector
|
||||
if (dataCenter.getSector() != null && dataCenter.getSector().getTag().equals("Sabit Enerji")) {
|
||||
// Note: Sector information is no longer received in the message
|
||||
// VM emission calculations will be performed regardless of sector
|
||||
// The sector requirement can be set via DataCenter CRUD operations
|
||||
|
||||
// Calculate emissions for each VM instead of datacenter level
|
||||
calculateVMEmissions(dataCenter);
|
||||
calculateVMEmissions(dataCenter);
|
||||
|
||||
} else {
|
||||
System.err.println("❌ DataCenter sector is not 'Sabit Enerji'. Current sector: " +
|
||||
(dataCenter.getSector() != null ? dataCenter.getSector().getTag() : "null"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ Error during emission calculations: " + e.getMessage());
|
||||
System.err.println("❌ Exception type: " + e.getClass().getSimpleName());
|
||||
@@ -635,29 +472,29 @@ public class MessageListener {
|
||||
}
|
||||
|
||||
private void calculateVMEmissions(DataCenter dataCenter) {
|
||||
System.out.println("🔍 Calculating emissions for active VMs with calcOn=true in DataCenter: " + dataCenter.getDataCenter());
|
||||
int totalActiveVMs = 0;
|
||||
System.out.println("🔍 Calculating emissions for VMs with calcOn=true in DataCenter ID: " + dataCenter.getId() +
|
||||
" (Name: " + dataCenter.getDataCenter() + ")");
|
||||
int totalVMs = 0;
|
||||
int eligibleVMs = 0;
|
||||
int successfulCalculations = 0;
|
||||
|
||||
for (Project project : dataCenter.getProjects()) {
|
||||
for (PhysicalMachine pm : project.getPhysicalMachines()) {
|
||||
if (pm.getVms() != null) {
|
||||
|
||||
// Calculate for Active VMs only (only those with calcOn = true)
|
||||
for (VM vm : pm.getVms().getActive()) {
|
||||
totalActiveVMs++;
|
||||
// Calculate for all VMs (only those with calcOn = true)
|
||||
for (VM vm : pm.getVms()) {
|
||||
totalVMs++;
|
||||
if (vm.getCalcOn() != null && vm.getCalcOn()) {
|
||||
eligibleVMs++;
|
||||
if (vm.getPower() != null && vm.getPower() > 0) {
|
||||
System.out.println("✅ Processing VM " + vm.getName() + " (calcOn = true)");
|
||||
System.out.println("✅ Processing VM " + vm.getVmName() + " (calcOn = true)");
|
||||
boolean success = createVMEmissionRecord(dataCenter, vm, project, pm);
|
||||
if (success) successfulCalculations++;
|
||||
} else {
|
||||
System.out.println("⚠️ Skipping VM " + vm.getName() + " (calcOn = true) - no power consumption data");
|
||||
System.out.println("⚠️ Skipping VM " + vm.getVmName() + " (calcOn = true) - no power consumption data");
|
||||
}
|
||||
} else {
|
||||
System.out.println("⏭️ Skipping VM " + vm.getName() + " - calcOn = " + vm.getCalcOn());
|
||||
System.out.println("⏭️ Skipping VM " + vm.getVmName() + " - calcOn = " + vm.getCalcOn());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -665,9 +502,9 @@ public class MessageListener {
|
||||
}
|
||||
|
||||
System.out.println("🎯 VM Emission Calculation Summary:");
|
||||
System.out.println(" Total active VMs found: " + totalActiveVMs);
|
||||
System.out.println(" Active VMs with calcOn = true: " + eligibleVMs);
|
||||
System.out.println(" Active VMs skipped (calcOn = false or null): " + (totalActiveVMs - eligibleVMs));
|
||||
System.out.println(" Total VMs found: " + totalVMs);
|
||||
System.out.println(" VMs with calcOn = true: " + eligibleVMs);
|
||||
System.out.println(" VMs skipped (calcOn = false or null): " + (totalVMs - eligibleVMs));
|
||||
System.out.println(" Successful emission calculations: " + successfulCalculations);
|
||||
System.out.println(" Failed calculations: " + (eligibleVMs - successfulCalculations));
|
||||
}
|
||||
@@ -675,25 +512,25 @@ public class MessageListener {
|
||||
private boolean createVMEmissionRecord(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
||||
try {
|
||||
MainDataTableCreateInput input = createVMMainDataTableInput(dataCenter, vm, project, pm);
|
||||
System.out.println("🔍 Creating emission record for VM: " + vm.getName() + " (Power: " + vm.getPower() + "W)");
|
||||
System.out.println("🔍 Creating emission record for VM: " + vm.getVmName() + " (Power: " + vm.getPower() + "W)");
|
||||
|
||||
MainDataTable result = callMainDataTableMutation(input);
|
||||
|
||||
if (result != null) {
|
||||
System.out.println("✅ VM Emission calculation completed:");
|
||||
System.out.println(" - VM: " + vm.getName());
|
||||
System.out.println(" - VM: " + vm.getVmName());
|
||||
System.out.println(" - Power: " + vm.getPower() + "W");
|
||||
System.out.println(" - CO2: " + result.getCo2());
|
||||
System.out.println(" - Total Emission: " + result.getTotalEmission());
|
||||
System.out.println(" - Record ID: " + result.getId());
|
||||
return true;
|
||||
} else {
|
||||
System.err.println("❌ Failed to create emission record for VM: " + vm.getName());
|
||||
System.err.println("❌ Failed to create emission record for VM: " + vm.getVmName());
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ Error calculating emissions for VM " + vm.getName() + ": " + e.getMessage());
|
||||
System.err.println("❌ Error calculating emissions for VM " + vm.getVmName() + ": " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -701,10 +538,12 @@ public class MessageListener {
|
||||
private MainDataTableCreateInput createVMMainDataTableInput(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
||||
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
||||
|
||||
// Copy datacenter-level information
|
||||
// Copy datacenter-level information (if available)
|
||||
input.setYear("2025");
|
||||
input.setMonth("07");
|
||||
|
||||
// Note: These fields are no longer received in the message
|
||||
// They need to be set via DataCenter CRUD operations first
|
||||
if (dataCenter.getArea() != null && !dataCenter.getArea().getCities().isEmpty()) {
|
||||
input.setCity(dataCenter.getArea().getCities().get(0).getId());
|
||||
}
|
||||
@@ -715,6 +554,8 @@ public class MessageListener {
|
||||
|
||||
if (dataCenter.getSector() != null) {
|
||||
input.setSector(dataCenter.getSector().getId());
|
||||
} else {
|
||||
System.out.println("⚠️ Warning: DataCenter has no sector set - emission calculation may fail");
|
||||
}
|
||||
|
||||
if (dataCenter.getSubSector() != null) {
|
||||
@@ -724,11 +565,12 @@ public class MessageListener {
|
||||
if (dataCenter.getEmissionSource() != null) {
|
||||
input.setEmissionSource(dataCenter.getEmissionSource().getId());
|
||||
} else {
|
||||
// Fallback to default emission source for Sabit Enerji
|
||||
// Fallback to default emission source for electricity
|
||||
try {
|
||||
List<EmissionSource> elektrikSources = emissionSourceRepo.findByTag("Doğalgaz(Elektrik Üretimi)");
|
||||
if (!elektrikSources.isEmpty()) {
|
||||
input.setEmissionSource(elektrikSources.get(0).getId());
|
||||
System.out.println("⚠️ Using default emission source: Doğalgaz(Elektrik Üretimi)");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("❌ Error finding default emission source: " + e.getMessage());
|
||||
@@ -743,7 +585,9 @@ public class MessageListener {
|
||||
input.setConsuptionUnit(dataCenter.getConsuptionUnit().getId());
|
||||
}
|
||||
|
||||
input.setScope(dataCenter.getEmissionScope() != null && dataCenter.getEmissionScope().getTag().equals("Kapsam-3"));
|
||||
// Default to Kapsam-3 if no emission scope is set
|
||||
input.setScope(dataCenter.getEmissionScope() != null ?
|
||||
dataCenter.getEmissionScope().getTag().equals("Kapsam-3") : true);
|
||||
|
||||
try {
|
||||
List<Organization> organizations = organizationRepo.findAll();
|
||||
@@ -762,10 +606,11 @@ public class MessageListener {
|
||||
|
||||
System.out.println("🔍 VM Emission Input:");
|
||||
System.out.println(" VM ID: " + vm.getId());
|
||||
System.out.println(" VM Name: " + vm.getName());
|
||||
System.out.println(" VM Name: " + vm.getVmName());
|
||||
System.out.println(" Power: " + vm.getPower() + "W");
|
||||
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"));
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ security.jwt.token.secret-key=secret
|
||||
|
||||
app.survey.base-url=http://localhost.com
|
||||
|
||||
#spring.rabbitmq.host=188.132.198.145
|
||||
# spring.rabbitmq.host=188.132.198.145
|
||||
# spring.rabbitmq.port=5672
|
||||
# spring.rabbitmq.username=testuser
|
||||
# spring.rabbitmq.password=JGasF24561AZv2894De
|
||||
spring.rabbitmq.host=localhost
|
||||
spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.username=guest
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
input DataCenterCreateInput {
|
||||
dataCenter: String!
|
||||
externalId: Int
|
||||
emissionScopeId: ID
|
||||
sectorId: ID
|
||||
subSectorId: ID
|
||||
activitySubUnitId: ID
|
||||
emissionSourceId: ID
|
||||
consuptionUnitId: ID
|
||||
consuptionAmount: Float
|
||||
areaId: ID
|
||||
number: Int
|
||||
ayposURL: String
|
||||
address: String
|
||||
latitude: Float
|
||||
longitude: Float
|
||||
}
|
||||
|
||||
input DataCenterUpdateInput {
|
||||
dataCenter: String
|
||||
externalId: Int
|
||||
emissionScopeId: ID
|
||||
sectorId: ID
|
||||
subSectorId: ID
|
||||
activitySubUnitId: ID
|
||||
emissionSourceId: ID
|
||||
consuptionUnitId: ID
|
||||
consuptionAmount: Float
|
||||
areaId: ID
|
||||
number: Int
|
||||
ayposURL: String
|
||||
address: String
|
||||
latitude: Float
|
||||
longitude: Float
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
extend type Mutation {
|
||||
createDataCenter(input: DataCenterCreateInput!): DataCenter
|
||||
updateDataCenter(id: ID!, input: DataCenterUpdateInput!): DataCenter
|
||||
deleteDataCenter(id: ID!): Boolean
|
||||
}
|
||||
@@ -13,38 +13,12 @@ type DataCenter {
|
||||
|
||||
projects: [Project]
|
||||
area: Area
|
||||
number:Int
|
||||
}
|
||||
number: Int
|
||||
|
||||
type EmissionScope{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type Sector{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type SubSector{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type ActivitySubUnit{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type EmissionSource{
|
||||
tag: String
|
||||
}
|
||||
|
||||
type ConsuptionUnit{
|
||||
tag: String
|
||||
}
|
||||
|
||||
|
||||
type Area {
|
||||
tag: String
|
||||
cityNames: [String]
|
||||
districtNames: [String]
|
||||
ayposURL: String
|
||||
address: String
|
||||
latitude: Float
|
||||
longitude: Float
|
||||
}
|
||||
|
||||
type Project {
|
||||
@@ -55,24 +29,24 @@ type Project {
|
||||
|
||||
type PhysicalMachine {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
powerConsumption: Float
|
||||
vms: Vms
|
||||
}
|
||||
|
||||
type Vms {
|
||||
id: ID
|
||||
active: [Vm]
|
||||
inactive: [Vm]
|
||||
ip: String
|
||||
tag: String
|
||||
power: Float
|
||||
vms: [Vm]
|
||||
}
|
||||
|
||||
type Vm {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
state: String
|
||||
vmName: String
|
||||
ip: String
|
||||
power: Float
|
||||
calcOn: Boolean
|
||||
hostingPm: String
|
||||
host: String
|
||||
flavorName: String
|
||||
tag: String
|
||||
config: Config
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,15 @@ type MainDataTable {
|
||||
|
||||
type Vm {
|
||||
id: ID
|
||||
status: String
|
||||
name: String
|
||||
state: String
|
||||
vmName: String
|
||||
ip: String
|
||||
power: Float
|
||||
calcOn: Boolean
|
||||
hostingPm: String
|
||||
host: String
|
||||
flavorName: String
|
||||
tag: String
|
||||
config: Config
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user