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.domain.ActivitySubUnit;
|
||||||
import com.sgs.graphql.activitySubUnit.repo.criteria.ActivitySubUnitCriteria;
|
import com.sgs.graphql.activitySubUnit.repo.criteria.ActivitySubUnitCriteria;
|
||||||
import com.sgs.graphql.activitySubUnit.service.ActivitySubUnitService;
|
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.pagination.Pagination;
|
||||||
import com.sgs.lib.dao.query.sort.SortBy;
|
import com.sgs.lib.dao.query.sort.SortBy;
|
||||||
import graphql.kickstart.tools.GraphQLQueryResolver;
|
import graphql.kickstart.tools.GraphQLQueryResolver;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -33,7 +31,6 @@ public class ActivitySubUnitQueryResolver implements GraphQLQueryResolver {
|
|||||||
return activitySubUnitService.findById(id).orElse(null);
|
return activitySubUnitService.findById(id).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority('" + PermissionName.ACTIVITY_SUB_UNITS_GET + "')")
|
|
||||||
public List<ActivitySubUnit> activitySubUnits(ActivitySubUnitCriteria criteria, List<SortBy> sortBy) {
|
public List<ActivitySubUnit> activitySubUnits(ActivitySubUnitCriteria criteria, List<SortBy> sortBy) {
|
||||||
return activitySubUnitService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new ActivitySubUnitCriteria()),
|
return activitySubUnitService.filterWithSort(ObjectUtils.defaultIfNull(criteria, new ActivitySubUnitCriteria()),
|
||||||
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
Sort.by(ObjectUtils.defaultIfNull(sortBy, new ArrayList<SortBy>())
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ public class DataCenter extends BaseDomain {
|
|||||||
private Double consuptionAmount;
|
private Double consuptionAmount;
|
||||||
private ConsuptionUnit consuptionUnit;
|
private ConsuptionUnit consuptionUnit;
|
||||||
private ActivitySubUnit activitySubUnit;
|
private ActivitySubUnit activitySubUnit;
|
||||||
|
|
||||||
|
// New attributes
|
||||||
|
private String ayposURL;
|
||||||
|
private String address;
|
||||||
|
private Double latitude;
|
||||||
|
private Double longitude;
|
||||||
|
|
||||||
|
|
||||||
@Column(name = "data_center_name")
|
@Column(name = "data_center_name")
|
||||||
@@ -118,13 +124,8 @@ public class DataCenter extends BaseDomain {
|
|||||||
this.consuptionUnit = consuptionUnit;
|
this.consuptionUnit = consuptionUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ManyToOne(cascade = CascadeType.ALL)
|
@ManyToOne(fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "area_id")
|
@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() {
|
public Area getArea() {
|
||||||
return area;
|
return area;
|
||||||
}
|
}
|
||||||
@@ -162,4 +163,41 @@ public class DataCenter extends BaseDomain {
|
|||||||
public void setActivitySubUnit(ActivitySubUnit activitySubUnit) {
|
public void setActivitySubUnit(ActivitySubUnit activitySubUnit) {
|
||||||
this.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 com.sgs.lib.dao.domain.BaseDomain;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "physical_machine")
|
@Table(name = "physical_machine")
|
||||||
public class PhysicalMachine extends BaseDomain {
|
public class PhysicalMachine extends BaseDomain {
|
||||||
private String status;
|
|
||||||
private String name;
|
private String name;
|
||||||
private Double powerConsumption;
|
private String ip;
|
||||||
private Vms vms;
|
private String tag;
|
||||||
|
private Double power;
|
||||||
|
private List<VM> vms = new ArrayList<>();
|
||||||
private Project project;
|
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")
|
@Column(name = "name")
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -36,23 +27,40 @@ public class PhysicalMachine extends BaseDomain {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(name = "power_consumption", nullable = false)
|
@Column(name = "ip")
|
||||||
public Double getPowerConsumption() {
|
public String getIp() {
|
||||||
return powerConsumption;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPowerConsumption(Double powerConsumption) {
|
public void setIp(String ip) {
|
||||||
this.powerConsumption = powerConsumption;
|
this.ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@Column(name = "tag")
|
||||||
@JoinColumn(name = "vms_id")
|
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
|
@JsonManagedReference
|
||||||
public Vms getVms() {
|
public List<VM> getVms() {
|
||||||
return vms;
|
return vms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVms(Vms vms) {
|
public void setVms(List<VM> vms) {
|
||||||
this.vms = vms;
|
this.vms = vms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,6 +74,4 @@ public class PhysicalMachine extends BaseDomain {
|
|||||||
public void setProject(Project project) {
|
public void setProject(Project project) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,30 +9,34 @@ import javax.persistence.*;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "vm")
|
@Table(name = "vm")
|
||||||
public class VM extends BaseDomain {
|
public class VM extends BaseDomain {
|
||||||
private String status;
|
private String state;
|
||||||
private String name;
|
private String vmName;
|
||||||
|
private String ip;
|
||||||
private Double power;
|
private Double power;
|
||||||
private Boolean calcOn = false;
|
private Boolean calcOn = false;
|
||||||
|
private String hostingPm;
|
||||||
|
private String host;
|
||||||
|
private String flavorName;
|
||||||
|
private String tag;
|
||||||
private Config config;
|
private Config config;
|
||||||
private Vms activeVms;
|
private PhysicalMachine physicalMachine;
|
||||||
private Vms inactiveVms;
|
|
||||||
|
|
||||||
@Column(name = "status")
|
@Column(name = "state")
|
||||||
public String getStatus() {
|
public String getState() {
|
||||||
return status;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(String status) {
|
public void setState(String state) {
|
||||||
this.status = status;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(name = "name")
|
@Column(name = "vm_name")
|
||||||
public String getName() {
|
public String getVmName() {
|
||||||
return name;
|
return vmName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setVmName(String vmName) {
|
||||||
this.name = name;
|
this.vmName = vmName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(name = "power", nullable = false)
|
@Column(name = "power", nullable = false)
|
||||||
@@ -53,6 +57,51 @@ public class VM extends BaseDomain {
|
|||||||
this.calcOn = calcOn;
|
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")
|
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "vm")
|
||||||
@JsonManagedReference
|
@JsonManagedReference
|
||||||
public Config getConfig() {
|
public Config getConfig() {
|
||||||
@@ -63,28 +112,15 @@ public class VM extends BaseDomain {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@ManyToOne
|
@JoinColumn(name = "physical_machine_id")
|
||||||
@JoinColumn(name = "active_vms_id")
|
|
||||||
@JsonBackReference
|
@JsonBackReference
|
||||||
public Vms getActiveVms() {
|
public PhysicalMachine getPhysicalMachine() {
|
||||||
return activeVms;
|
return physicalMachine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActiveVms(Vms activeVms) {
|
public void setPhysicalMachine(PhysicalMachine physicalMachine) {
|
||||||
this.activeVms = activeVms;
|
this.physicalMachine = physicalMachine;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "inactive_vms_id")
|
|
||||||
@JsonBackReference
|
|
||||||
public Vms getInactiveVms() {
|
|
||||||
return inactiveVms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInactiveVms(Vms inactiveVms) {
|
|
||||||
this.inactiveVms = inactiveVms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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.consuptionUnit.dto.ConsuptionUnitDto;
|
||||||
import com.sgs.graphql.activitySubUnit.dto.ActivitySubUnitDto;
|
import com.sgs.graphql.activitySubUnit.dto.ActivitySubUnitDto;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DataCenterDto {
|
public class DataCenterDto {
|
||||||
@JsonProperty("data_center")
|
@JsonProperty("data_center")
|
||||||
@@ -16,9 +16,8 @@ public class DataCenterDto {
|
|||||||
private int id;
|
private int id;
|
||||||
private Integer externalId;
|
private Integer externalId;
|
||||||
private Integer number;
|
private Integer number;
|
||||||
|
|
||||||
private AreaDto area;
|
private AreaDto area;
|
||||||
private List<ProjectDto> projects;
|
private Map<String, ProjectDto> projects;
|
||||||
|
|
||||||
// Emission calculation fields
|
// Emission calculation fields
|
||||||
private SectorDto sector;
|
private SectorDto sector;
|
||||||
@@ -69,11 +68,11 @@ public class DataCenterDto {
|
|||||||
this.area = area;
|
this.area = area;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProjectDto> getProjects() {
|
public Map<String, ProjectDto> getProjects() {
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjects(List<ProjectDto> projects) {
|
public void setProjects(Map<String, ProjectDto> projects) {
|
||||||
this.projects = 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;
|
package com.sgs.graphql.dataCenter.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PhysicalMachineDto {
|
public class PhysicalMachineDto {
|
||||||
private String status;
|
@JsonProperty("name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@JsonProperty("tag")
|
||||||
|
private String tag;
|
||||||
|
|
||||||
|
@JsonProperty("power")
|
||||||
|
private double power;
|
||||||
|
|
||||||
|
@JsonProperty("confg") // Note: keeping the typo from JSON
|
||||||
|
private List<Object> confg;
|
||||||
|
|
||||||
@JsonProperty("power_consumption")
|
private String ip; // IP address from the message key
|
||||||
private double powerConsumption;
|
|
||||||
|
|
||||||
private VmsDto vms;
|
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -27,19 +26,35 @@ public class PhysicalMachineDto {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPowerConsumption() {
|
public String getTag() {
|
||||||
return powerConsumption;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPowerConsumption(double powerConsumption) {
|
public void setTag(String tag) {
|
||||||
this.powerConsumption = powerConsumption;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VmsDto getVms() {
|
public double getPower() {
|
||||||
return vms;
|
return power;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVms(VmsDto vms) {
|
public void setPower(double power) {
|
||||||
this.vms = vms;
|
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;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto {
|
||||||
private int id;
|
@JsonProperty("main_optimization_space")
|
||||||
private String name;
|
private MainOptimizationSpaceDto mainOptimizationSpace;
|
||||||
|
|
||||||
|
@JsonProperty("sub_optimization_space")
|
||||||
|
private SubOptimizationSpaceDto subOptimizationSpace;
|
||||||
|
|
||||||
|
// Legacy field - kept for backward compatibility with older message formats
|
||||||
@JsonProperty("physical_machines")
|
@JsonProperty("physical_machines")
|
||||||
private List<PhysicalMachineDto> physicalMachines;
|
private List<PhysicalMachineDto> physicalMachines;
|
||||||
|
|
||||||
|
// These fields are derived from the map key and entity relationships, not from the message
|
||||||
|
private String id; // This will be set from the map key
|
||||||
|
private String name; // This will be derived or set separately
|
||||||
|
|
||||||
public int getId() {
|
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;
|
return id;
|
||||||
}
|
}
|
||||||
public void setId(int id) {
|
|
||||||
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = 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,53 +1,131 @@
|
|||||||
package com.sgs.graphql.dataCenter.dto;
|
package com.sgs.graphql.dataCenter.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import java.util.List;
|
||||||
public class VMDto {
|
|
||||||
private String status;
|
public class VMDto {
|
||||||
private String name;
|
@JsonProperty("vm_name")
|
||||||
private double power;
|
private String vmName;
|
||||||
private boolean calcOn;
|
|
||||||
|
@JsonProperty("power")
|
||||||
@JsonProperty("config")
|
private double power;
|
||||||
private ConfigDto config;
|
|
||||||
|
@JsonProperty("state")
|
||||||
public String getStatus() {
|
private String state;
|
||||||
return status;
|
|
||||||
}
|
@JsonProperty("hosting_pm")
|
||||||
|
private String hostingPm;
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
@JsonProperty("host")
|
||||||
}
|
private String host;
|
||||||
|
|
||||||
public String getName() {
|
@JsonProperty("flavor_name")
|
||||||
return name;
|
private String flavorName;
|
||||||
}
|
|
||||||
|
@JsonProperty("tag")
|
||||||
public void setName(String name) {
|
private String tag;
|
||||||
this.name = name;
|
|
||||||
}
|
@JsonProperty("confg") // Note: keeping the typo from JSON
|
||||||
|
private List<Object> confg;
|
||||||
public double getPower() {
|
|
||||||
return power;
|
private String ip; // IP address from the message key
|
||||||
}
|
private boolean calcOn = false; // Derived from state: active = true, inactive = false
|
||||||
|
|
||||||
public void setPower(double power) {
|
public String getVmName() {
|
||||||
this.power = power;
|
return vmName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigDto getConfig() {
|
public void setVmName(String vmName) {
|
||||||
return config;
|
this.vmName = vmName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfig(ConfigDto config) {
|
public String getIp() {
|
||||||
this.config = config;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCalcOn() {
|
public void setIp(String ip) {
|
||||||
return calcOn;
|
this.ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCalcOn(boolean calcOn) {
|
public String getState() {
|
||||||
this.calcOn = calcOn;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void setState(String state) {
|
||||||
|
this.state = state;
|
||||||
|
// Automatically set calcOn based on state
|
||||||
|
this.calcOn = "active".equalsIgnoreCase(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPower() {
|
||||||
|
return power;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPower(double power) {
|
||||||
|
this.power = power;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostingPm() {
|
||||||
|
return hostingPm;
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
return calcOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,5 +18,7 @@ public interface DataCenterRepo extends BaseRepo<DataCenter> {
|
|||||||
Optional<DataCenter> findByNumber(@Param("number") Integer number);
|
Optional<DataCenter> findByNumber(@Param("number") Integer number);
|
||||||
|
|
||||||
Optional<DataCenter> findByExternalId(Integer externalId);
|
Optional<DataCenter> findByExternalId(Integer externalId);
|
||||||
|
|
||||||
|
boolean existsByExternalId(Integer externalId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,16 @@ public interface VMRepo extends BaseRepo<VM> {
|
|||||||
Optional<VM> findById(UUID id);
|
Optional<VM> findById(UUID id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all VMs by name (handles duplicates)
|
* Find all VMs by vmName
|
||||||
* @param name VM name
|
* @param vmName VM name
|
||||||
* @return List of VMs with the given 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)
|
* Find first VM by vmName ordered by ID (most recent first)
|
||||||
* @param name VM name
|
* @param vmName VM name
|
||||||
* @return Optional VM
|
* @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) {
|
public DataCenterService(DataCenterRepo repository, DataCenterCriteriaSpec criteriaSpec) {
|
||||||
super(repository, 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.domain.*;
|
||||||
|
|
||||||
import com.sgs.graphql.dataCenter.dto.*;
|
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.DataCenterRepo;
|
||||||
import com.sgs.graphql.dataCenter.repo.VMRepo;
|
import com.sgs.graphql.dataCenter.repo.VMRepo;
|
||||||
import com.sgs.graphql.dataCenter.service.DataCenterService;
|
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.domain.EmissionSource;
|
||||||
import com.sgs.graphql.emissionSource.repo.EmissionSourceRepo;
|
import com.sgs.graphql.emissionSource.repo.EmissionSourceRepo;
|
||||||
import com.sgs.graphql.mainDataTable.mutation.MainDataTableMutation;
|
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.enums.LogType;
|
||||||
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
import com.sgs.graphql.systemHistory.mutation.SystemLogger;
|
||||||
import com.sgs.graphql.organization.domain.Organization;
|
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.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Component;
|
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.domain.MainDataTable;
|
||||||
import com.sgs.graphql.mainDataTable.mutation.input.MainDataTableCreateInput;
|
import com.sgs.graphql.mainDataTable.mutation.input.MainDataTableCreateInput;
|
||||||
@@ -51,7 +29,8 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import java.util.List;
|
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.core.context.SecurityContextHolder;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
@@ -66,40 +45,21 @@ public class MessageListener {
|
|||||||
private final DataCenterService dataCenterService;
|
private final DataCenterService dataCenterService;
|
||||||
private final DataCenterRepo dataCenterRepo;
|
private final DataCenterRepo dataCenterRepo;
|
||||||
private final VMRepo vmRepo;
|
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 EmissionSourceRepo emissionSourceRepo;
|
||||||
private final EmissionScopeRepo emissionScopeRepo;
|
|
||||||
private final ConsuptionUnitRepo consuptionUnitRepo;
|
|
||||||
private final ActivitySubUnitRepo activitySubUnitRepo;
|
|
||||||
private final OrganizationRepo organizationRepo;
|
private final OrganizationRepo organizationRepo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MainDataTableMutation mainDataTableMutation;
|
private MainDataTableMutation mainDataTableMutation;
|
||||||
|
|
||||||
public MessageListener(@Qualifier("singleQuoteObjectMapper") ObjectMapper objectMapper, SystemLogger systemLogger,
|
public MessageListener(@Qualifier("singleQuoteObjectMapper") ObjectMapper objectMapper, SystemLogger systemLogger,
|
||||||
DataCenterService dataCenterService, DataCenterRepo dataCenterRepo, VMRepo vmRepo, AreaRepo areaRepo,
|
DataCenterService dataCenterService, DataCenterRepo dataCenterRepo, VMRepo vmRepo,
|
||||||
DistrictRepo districtRepo, CityRepo cityRepo, SectorRepo sectorRepo,
|
EmissionSourceRepo emissionSourceRepo, OrganizationRepo organizationRepo) {
|
||||||
SubSectorRepo subSectorRepo, EmissionSourceRepo emissionSourceRepo,
|
|
||||||
EmissionScopeRepo emissionScopeRepo, ConsuptionUnitRepo consuptionUnitRepo,
|
|
||||||
ActivitySubUnitRepo activitySubUnitRepo, OrganizationRepo organizationRepo) {
|
|
||||||
this.objectMapper = objectMapper;
|
this.objectMapper = objectMapper;
|
||||||
this.systemLogger = systemLogger;
|
this.systemLogger = systemLogger;
|
||||||
this.dataCenterService = dataCenterService;
|
this.dataCenterService = dataCenterService;
|
||||||
this.dataCenterRepo = dataCenterRepo;
|
this.dataCenterRepo = dataCenterRepo;
|
||||||
this.vmRepo = vmRepo;
|
this.vmRepo = vmRepo;
|
||||||
this.areaRepo = areaRepo;
|
|
||||||
this.districtRepo = districtRepo;
|
|
||||||
this.cityRepo = cityRepo;
|
|
||||||
this.sectorRepo = sectorRepo;
|
|
||||||
this.subSectorRepo = subSectorRepo;
|
|
||||||
this.emissionSourceRepo = emissionSourceRepo;
|
this.emissionSourceRepo = emissionSourceRepo;
|
||||||
this.emissionScopeRepo = emissionScopeRepo;
|
|
||||||
this.consuptionUnitRepo = consuptionUnitRepo;
|
|
||||||
this.activitySubUnitRepo = activitySubUnitRepo;
|
|
||||||
this.organizationRepo = organizationRepo;
|
this.organizationRepo = organizationRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,14 +69,26 @@ public class MessageListener {
|
|||||||
try {
|
try {
|
||||||
DataCenterDto dto = objectMapper.readValue(message, DataCenterDto.class);
|
DataCenterDto dto = objectMapper.readValue(message, DataCenterDto.class);
|
||||||
|
|
||||||
// 🔍 Log emission-related fields to verify only tags are received
|
// 🔍 Log basic fields received
|
||||||
System.out.println("🔍 EMISSION FIELDS RECEIVED:");
|
System.out.println("🔍 MESSAGE RECEIVED:");
|
||||||
System.out.println(" Sector: " + (dto.getSector() != null ? dto.getSector().getTag() : "null"));
|
System.out.println(" External ID: " + dto.getId());
|
||||||
System.out.println(" SubSector: " + (dto.getSubSector() != null ? dto.getSubSector().getTag() : "null"));
|
System.out.println(" Number: " + dto.getNumber());
|
||||||
System.out.println(" EmissionSource: " + (dto.getEmissionSource() != null ? dto.getEmissionSource().getTag() : "null"));
|
System.out.println(" Consumption Amount: " + dto.getConsuptionAmount());
|
||||||
System.out.println(" EmissionScope: " + (dto.getEmissionScope() != null ? dto.getEmissionScope().getTag() : "null"));
|
System.out.println(" Projects Count: " + (dto.getProjects() != null ? dto.getProjects().size() : 0));
|
||||||
System.out.println(" ConsuptionUnit: " + (dto.getConsuptionUnit() != null ? dto.getConsuptionUnit().getTag() : "null"));
|
|
||||||
System.out.println(" ActivitySubUnit: " + (dto.getActivitySubUnit() != null ? dto.getActivitySubUnit().getTag() : "null"));
|
// 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 entity = toDataCenterEntity(dto);
|
||||||
DataCenter dataCenter = createDataCenter(entity);
|
DataCenter dataCenter = createDataCenter(entity);
|
||||||
@@ -127,12 +99,23 @@ public class MessageListener {
|
|||||||
System.out.println("✅ DTO parsed:\n" + objectMapper.writeValueAsString(dto));
|
System.out.println("✅ DTO parsed:\n" + objectMapper.writeValueAsString(dto));
|
||||||
//System.out.println("✅ Entity:\n" + objectMapper.writeValueAsString(entity));
|
//System.out.println("✅ Entity:\n" + objectMapper.writeValueAsString(entity));
|
||||||
System.out.println("🚨 DataCenter name: " + dataCenter.getDataCenter());
|
System.out.println("🚨 DataCenter name: " + dataCenter.getDataCenter());
|
||||||
System.out.println("🚨 Area: " + dataCenter.getArea()); // could be null
|
System.out.println("🚨 External ID: " + dataCenter.getExternalId());
|
||||||
System.out.println("PMs in first project: " + dataCenter.getProjects().get(0).getPhysicalMachines().size());
|
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));
|
//System.out.println("✅ Saved DataCenter:\n" + objectMapper.writeValueAsString(dataCenter));
|
||||||
|
|
||||||
// Perform emission calculations
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Mesaj işlenirken hata oluştu: " + e.getMessage());
|
System.err.println("Mesaj işlenirken hata oluştu: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -154,140 +137,76 @@ public class MessageListener {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
VM entity = new VM();
|
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.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()));
|
entity.setConfig(toConfigEntity(dto.getConfig()));
|
||||||
|
|
||||||
// Debug logging
|
// Debug logging
|
||||||
System.out.println("🔍 VM Entity Created: " + dto.getName() + " - calcOn = " + dto.isCalcOn());
|
System.out.println("🔍 VM Entity Created: " + dto.getVmName() + " - state = " + dto.getState() + " - calcOn = " + dto.isCalcOn());
|
||||||
|
|
||||||
return entity;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PhysicalMachine toPhysicalMachineEntity(PhysicalMachineDto dto) {
|
public PhysicalMachine toPhysicalMachineEntity(PhysicalMachineDto dto) {
|
||||||
if (dto == null)
|
if (dto == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
PhysicalMachine entity = new PhysicalMachine();
|
PhysicalMachine entity = new PhysicalMachine();
|
||||||
entity.setStatus(dto.getStatus());
|
|
||||||
entity.setName(dto.getName());
|
entity.setName(dto.getName());
|
||||||
entity.setPowerConsumption(dto.getPowerConsumption());
|
entity.setIp(dto.getIp());
|
||||||
|
entity.setTag(dto.getTag());
|
||||||
Vms vms = toVmsEntity(dto.getVms());
|
entity.setPower(dto.getPower());
|
||||||
if (vms != null) {
|
|
||||||
entity.setVms(vms);
|
// VMs are now processed separately from the new message format
|
||||||
vms.setPhysicalMachine(entity);
|
entity.setVms(new ArrayList<>());
|
||||||
}
|
|
||||||
|
|
||||||
return entity;
|
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) {
|
public DataCenter toDataCenterEntity(DataCenterDto dto) {
|
||||||
if (dto == null)
|
if (dto == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
DataCenter entity = new DataCenter();
|
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.setExternalId(dto.getId());
|
||||||
entity.setNumber(dto.getNumber());
|
entity.setNumber(dto.getNumber());
|
||||||
entity.setConsuptionAmount(dto.getConsuptionAmount());
|
entity.setConsuptionAmount(dto.getConsuptionAmount());
|
||||||
|
|
||||||
// Convert Area
|
// Note: Area, Sector, SubSector, EmissionSource, EmissionScope,
|
||||||
Area area = toAreaEntity(dto.getArea());
|
// ConsuptionUnit, and ActivitySubUnit are no longer received in the message
|
||||||
entity.setArea(area);
|
// These will need to be set via the DataCenter CRUD operations
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Convert Projects
|
// Convert Projects
|
||||||
if (dto.getProjects() != null) {
|
if (dto.getProjects() != null) {
|
||||||
List<Project> projects = dto.getProjects().stream()
|
List<Project> projects = new ArrayList<>();
|
||||||
.map(this::toProjectEntity)
|
for (Map.Entry<String, ProjectDto> projectEntry : dto.getProjects().entrySet()) {
|
||||||
.peek(proj -> proj.setDataCenter(entity))
|
String projectId = projectEntry.getKey();
|
||||||
.collect(Collectors.toList());
|
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);
|
entity.setProjects(projects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,147 +220,105 @@ public class MessageListener {
|
|||||||
Project entity = new Project();
|
Project entity = new Project();
|
||||||
entity.setName(dto.getName());
|
entity.setName(dto.getName());
|
||||||
|
|
||||||
if (dto.getPhysicalMachines() != null) {
|
// Process MainOptimizationSpace instead of physical machines list
|
||||||
List<PhysicalMachine> physicalMachines = dto.getPhysicalMachines().stream()
|
if (dto.getMainOptimizationSpace() != null) {
|
||||||
.map(this::toPhysicalMachineEntity)
|
List<PhysicalMachine> physicalMachines = processMainOptimizationSpace(dto.getMainOptimizationSpace());
|
||||||
.peek(pm -> pm.setProject(entity))
|
// Set project reference for each PM
|
||||||
.collect(Collectors.toList());
|
physicalMachines.forEach(pm -> pm.setProject(entity));
|
||||||
entity.setPhysicalMachines(physicalMachines);
|
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;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
// public Aggregate toAggregateEntity(AggregateDto dto){
|
* Process MainOptimizationSpaceDto and assign VMs to their hosting PMs
|
||||||
// if (dto == null)
|
*/
|
||||||
// return null;
|
private List<PhysicalMachine> processMainOptimizationSpace(MainOptimizationSpaceDto mainOptSpace) {
|
||||||
|
List<PhysicalMachine> physicalMachines = new ArrayList<>();
|
||||||
// Aggregate entity = new Aggregate();
|
|
||||||
// entity.setStatus(dto.getStatus());
|
if (mainOptSpace.getPms() == null || mainOptSpace.getVms() == null) {
|
||||||
// entity.setName(dto.getName());
|
System.out.println("⚠️ MainOptimizationSpace has null PMs or VMs");
|
||||||
|
return physicalMachines;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("✅ Found Sector: tag=" + sector.getTag());
|
System.out.println("🔍 Processing MainOptimizationSpace with " +
|
||||||
return sector;
|
mainOptSpace.getPms().size() + " PMs and " +
|
||||||
}
|
mainOptSpace.getVms().size() + " VMs");
|
||||||
|
|
||||||
public EmissionScope toEmissionScopeEntity(EmissionScopeDto dto) {
|
// Convert PMs from DTO to Entity
|
||||||
if (dto == null) return null;
|
for (Map.Entry<String, PhysicalMachineDto> pmEntry : mainOptSpace.getPms().entrySet()) {
|
||||||
|
String pmIp = pmEntry.getKey();
|
||||||
EmissionScope emissionScope = emissionScopeRepo.findByTag(dto.getTag());
|
PhysicalMachineDto pmDto = pmEntry.getValue();
|
||||||
if (emissionScope == null) {
|
|
||||||
System.err.println("❌ EmissionScope not found with tag: " + dto.getTag());
|
// Set the IP from the map key
|
||||||
return null;
|
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());
|
// Assign VMs to their hosting PMs
|
||||||
return emissionScope;
|
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()) {
|
VM vm = toVMEntity(vmDto);
|
||||||
System.err.println("❌ ConsuptionUnit not found with tag: " + dto.getTag());
|
|
||||||
return null;
|
// 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
|
return physicalMachines;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public DataCenter createDataCenter(DataCenter newDc) {
|
public DataCenter createDataCenter(DataCenter newDc) {
|
||||||
try {
|
try {
|
||||||
|
// First, validate that a DataCenter with this external ID exists
|
||||||
Optional<DataCenter> existingDcOpt = dataCenterRepo.findByExternalId(newDc.getExternalId());
|
Optional<DataCenter> existingDcOpt = dataCenterRepo.findByExternalId(newDc.getExternalId());
|
||||||
DataCenter dc;
|
|
||||||
|
if (!existingDcOpt.isPresent()) {
|
||||||
if (existingDcOpt.isPresent()) {
|
String errorMessage = "❌ No DataCenter found with external ID: " + newDc.getExternalId() +
|
||||||
dc = existingDcOpt.get();
|
". DataCenter must be created via CRUD operations before receiving VM data.";
|
||||||
dc.setDataCenter(newDc.getDataCenter());
|
System.err.println(errorMessage);
|
||||||
dc.setArea(newDc.getArea());
|
systemLogger.createSystemLog(LogType.ERROR, errorMessage);
|
||||||
|
throw new RuntimeException(errorMessage);
|
||||||
// Update emission-related fields
|
}
|
||||||
dc.setSector(newDc.getSector());
|
|
||||||
dc.setSubSector(newDc.getSubSector());
|
System.out.println("✅ Found existing DataCenter with external ID: " + newDc.getExternalId());
|
||||||
dc.setEmissionSource(newDc.getEmissionSource());
|
|
||||||
dc.setEmissionScope(newDc.getEmissionScope());
|
DataCenter dc = existingDcOpt.get();
|
||||||
dc.setConsuptionAmount(newDc.getConsuptionAmount());
|
|
||||||
dc.setConsuptionUnit(newDc.getConsuptionUnit());
|
// Note: DataCenter name and emission-related fields are no longer updated from the message
|
||||||
dc.setActivitySubUnit(newDc.getActivitySubUnit());
|
// These are now managed via DataCenter CRUD operations
|
||||||
|
|
||||||
for (Project newProject : newDc.getProjects()) {
|
for (Project newProject : newDc.getProjects()) {
|
||||||
Optional<Project> existingProjOpt = dc.getProjects().stream()
|
Optional<Project> existingProjOpt = dc.getProjects().stream()
|
||||||
.filter(p -> p.getName().equalsIgnoreCase(newProject.getName()))
|
.filter(p -> p.getName().equalsIgnoreCase(newProject.getName()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
@@ -450,134 +327,102 @@ public class MessageListener {
|
|||||||
if (existingProjOpt.isPresent()) {
|
if (existingProjOpt.isPresent()) {
|
||||||
project = existingProjOpt.get();
|
project = existingProjOpt.get();
|
||||||
project.setName(newProject.getName());
|
project.setName(newProject.getName());
|
||||||
|
System.out.println("✅ Updated existing project: " + project.getName());
|
||||||
} else {
|
} else {
|
||||||
project = newProject;
|
project = newProject;
|
||||||
project.setDataCenter(dc);
|
project.setDataCenter(dc);
|
||||||
dc.getProjects().add(project);
|
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()) {
|
for (PhysicalMachine newPm : newProject.getPhysicalMachines()) {
|
||||||
Optional<PhysicalMachine> existingPmOpt = project.getPhysicalMachines().stream()
|
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();
|
.findFirst();
|
||||||
|
|
||||||
PhysicalMachine pm;
|
PhysicalMachine pm;
|
||||||
if (existingPmOpt.isPresent()) {
|
if (existingPmOpt.isPresent()) {
|
||||||
|
// Update existing PM
|
||||||
pm = existingPmOpt.get();
|
pm = existingPmOpt.get();
|
||||||
pm.setStatus(newPm.getStatus());
|
pm.setName(newPm.getName());
|
||||||
pm.setPowerConsumption(newPm.getPowerConsumption());
|
pm.setIp(newPm.getIp());
|
||||||
|
pm.setTag(newPm.getTag());
|
||||||
|
pm.setPower(newPm.getPower());
|
||||||
|
|
||||||
|
System.out.println("✅ Updated existing PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
||||||
} else {
|
} else {
|
||||||
|
// Create new PM
|
||||||
pm = newPm;
|
pm = newPm;
|
||||||
pm.setProject(project); // Set project directly
|
pm.setProject(project);
|
||||||
project.getPhysicalMachines().add(pm);
|
project.getPhysicalMachines().add(pm);
|
||||||
|
|
||||||
|
System.out.println("✅ Created new PM: " + pm.getName() + " (IP: " + pm.getIp() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ FIXED: VM upsert logic with global VM lookup
|
// Process VMs that are already assigned to this PM
|
||||||
if (newPm.getVms() != null) {
|
if (newPm.getVms() != null && !newPm.getVms().isEmpty()) {
|
||||||
System.out.println("🔍 Processing VMs for PM: " + newPm.getName());
|
System.out.println("🔍 Processing " + newPm.getVms().size() + " VMs for PM: " + newPm.getName());
|
||||||
|
|
||||||
|
// Ensure PM has VM list initialized
|
||||||
if (pm.getVms() == null) {
|
if (pm.getVms() == null) {
|
||||||
pm.setVms(new Vms());
|
pm.setVms(new ArrayList<>());
|
||||||
pm.getVms().setPhysicalMachine(pm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active VMs - Use global VM lookup to avoid duplicates
|
// Clear existing VMs to replace with new ones
|
||||||
if (newPm.getVms().getActive() != null) {
|
pm.getVms().clear();
|
||||||
for (VM newVm : newPm.getVms().getActive()) {
|
|
||||||
// First, try to find existing VM globally by name, most recent first
|
// Process each VM that's already assigned to this PM
|
||||||
Optional<VM> existingVmOpt = vmRepo.findFirstByNameOrderByIdDesc(newVm.getName());
|
for (VM newVm : newPm.getVms()) {
|
||||||
|
if (newVm == null) continue;
|
||||||
VM vm;
|
|
||||||
if (existingVmOpt.isPresent()) {
|
// Find existing VM by vmName
|
||||||
// Update existing VM
|
Optional<VM> existingVmOpt = Optional.empty();
|
||||||
vm = existingVmOpt.get();
|
String vmLookupName = newVm.getVmName();
|
||||||
vm.setStatus(newVm.getStatus());
|
if (vmLookupName != null) {
|
||||||
vm.setPower(newVm.getPower());
|
existingVmOpt = vmRepo.findFirstByVmNameOrderByIdDesc(vmLookupName);
|
||||||
vm.setCalcOn(newVm.getCalcOn());
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
VM vm;
|
||||||
// Inactive VMs - Use global VM lookup to avoid duplicates
|
if (existingVmOpt.isPresent()) {
|
||||||
if (newPm.getVms().getInactive() != null) {
|
// Update existing VM
|
||||||
for (VM newVm : newPm.getVms().getInactive()) {
|
vm = existingVmOpt.get();
|
||||||
// First, try to find existing VM globally by name, most recent first
|
vm.setState(newVm.getState());
|
||||||
Optional<VM> existingVmOpt = vmRepo.findFirstByNameOrderByIdDesc(newVm.getName());
|
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;
|
System.out.println("✅ Updated existing VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
||||||
if (existingVmOpt.isPresent()) {
|
} else {
|
||||||
// Update existing VM
|
// Use new VM
|
||||||
vm = existingVmOpt.get();
|
vm = newVm;
|
||||||
vm.setStatus(newVm.getStatus());
|
|
||||||
vm.setPower(newVm.getPower());
|
System.out.println("✅ Created new VM: " + vm.getVmName() + " (IP: " + vm.getIp() + ") - calcOn = " + vm.getCalcOn());
|
||||||
vm.setCalcOn(newVm.getCalcOn());
|
}
|
||||||
|
|
||||||
// Ensure it's in the correct parent collection
|
// Set physical machine relationship
|
||||||
if (pm.getVms().getInactive() == null) {
|
vm.setPhysicalMachine(pm);
|
||||||
pm.getVms().setInactive(new java.util.ArrayList<>());
|
pm.getVms().add(vm);
|
||||||
}
|
|
||||||
if (!pm.getVms().getInactive().contains(vm)) {
|
|
||||||
pm.getVms().getInactive().add(vm);
|
|
||||||
}
|
|
||||||
vm.setInactiveVms(pm.getVms());
|
|
||||||
|
|
||||||
System.out.println("✅ Updated existing inactive VM: " + vm.getName() + " (ID: " + vm.getId() + ") - calcOn = " + vm.getCalcOn());
|
|
||||||
} 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
|
// Update config
|
||||||
if (newVm.getConfig() != null) {
|
if (newVm.getConfig() != null) {
|
||||||
if (vm.getConfig() == null) {
|
if (vm.getConfig() == null) {
|
||||||
vm.setConfig(newVm.getConfig());
|
vm.setConfig(newVm.getConfig());
|
||||||
vm.getConfig().setVm(vm);
|
vm.getConfig().setVm(vm);
|
||||||
} else {
|
} else {
|
||||||
vm.getConfig().setCpu(newVm.getConfig().getCpu());
|
vm.getConfig().setCpu(newVm.getConfig().getCpu());
|
||||||
vm.getConfig().setRam(newVm.getConfig().getRam());
|
vm.getConfig().setRam(newVm.getConfig().getRam());
|
||||||
vm.getConfig().setDisk(newVm.getConfig().getDisk());
|
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("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));
|
System.out.println("Projects=" + (dc.getProjects() != null ? dc.getProjects().size() : 0));
|
||||||
|
|
||||||
DataCenter saved = dataCenterService.save(dc);
|
DataCenter saved = dataCenterService.save(dc);
|
||||||
@@ -611,20 +451,17 @@ public class MessageListener {
|
|||||||
|
|
||||||
|
|
||||||
public void processEmissionCalculations(DataCenter dataCenter) {
|
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 {
|
try {
|
||||||
setupSecurityContext();
|
setupSecurityContext();
|
||||||
|
|
||||||
// Check if this is Sabit Enerji sector
|
// Note: Sector information is no longer received in the message
|
||||||
if (dataCenter.getSector() != null && dataCenter.getSector().getTag().equals("Sabit Enerji")) {
|
// 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) {
|
} catch (Exception e) {
|
||||||
System.err.println("❌ Error during emission calculations: " + e.getMessage());
|
System.err.println("❌ Error during emission calculations: " + e.getMessage());
|
||||||
System.err.println("❌ Exception type: " + e.getClass().getSimpleName());
|
System.err.println("❌ Exception type: " + e.getClass().getSimpleName());
|
||||||
@@ -635,29 +472,29 @@ public class MessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void calculateVMEmissions(DataCenter dataCenter) {
|
private void calculateVMEmissions(DataCenter dataCenter) {
|
||||||
System.out.println("🔍 Calculating emissions for active VMs with calcOn=true in DataCenter: " + dataCenter.getDataCenter());
|
System.out.println("🔍 Calculating emissions for VMs with calcOn=true in DataCenter ID: " + dataCenter.getId() +
|
||||||
int totalActiveVMs = 0;
|
" (Name: " + dataCenter.getDataCenter() + ")");
|
||||||
|
int totalVMs = 0;
|
||||||
int eligibleVMs = 0;
|
int eligibleVMs = 0;
|
||||||
int successfulCalculations = 0;
|
int successfulCalculations = 0;
|
||||||
|
|
||||||
for (Project project : dataCenter.getProjects()) {
|
for (Project project : dataCenter.getProjects()) {
|
||||||
for (PhysicalMachine pm : project.getPhysicalMachines()) {
|
for (PhysicalMachine pm : project.getPhysicalMachines()) {
|
||||||
if (pm.getVms() != null) {
|
if (pm.getVms() != null) {
|
||||||
|
// Calculate for all VMs (only those with calcOn = true)
|
||||||
// Calculate for Active VMs only (only those with calcOn = true)
|
for (VM vm : pm.getVms()) {
|
||||||
for (VM vm : pm.getVms().getActive()) {
|
totalVMs++;
|
||||||
totalActiveVMs++;
|
|
||||||
if (vm.getCalcOn() != null && vm.getCalcOn()) {
|
if (vm.getCalcOn() != null && vm.getCalcOn()) {
|
||||||
eligibleVMs++;
|
eligibleVMs++;
|
||||||
if (vm.getPower() != null && vm.getPower() > 0) {
|
if (vm.getPower() != null && vm.getPower() > 0) {
|
||||||
System.out.println("✅ Processing VM " + vm.getName() + " (calcOn = true)");
|
System.out.println("✅ Processing VM " + vm.getVmName() + " (calcOn = true)");
|
||||||
boolean success = createVMEmissionRecord(dataCenter, vm, project, pm);
|
boolean success = createVMEmissionRecord(dataCenter, vm, project, pm);
|
||||||
if (success) successfulCalculations++;
|
if (success) successfulCalculations++;
|
||||||
} else {
|
} 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 {
|
} 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("🎯 VM Emission Calculation Summary:");
|
||||||
System.out.println(" Total active VMs found: " + totalActiveVMs);
|
System.out.println(" Total VMs found: " + totalVMs);
|
||||||
System.out.println(" Active VMs with calcOn = true: " + eligibleVMs);
|
System.out.println(" VMs with calcOn = true: " + eligibleVMs);
|
||||||
System.out.println(" Active VMs skipped (calcOn = false or null): " + (totalActiveVMs - eligibleVMs));
|
System.out.println(" VMs skipped (calcOn = false or null): " + (totalVMs - eligibleVMs));
|
||||||
System.out.println(" Successful emission calculations: " + successfulCalculations);
|
System.out.println(" Successful emission calculations: " + successfulCalculations);
|
||||||
System.out.println(" Failed calculations: " + (eligibleVMs - 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) {
|
private boolean createVMEmissionRecord(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
||||||
try {
|
try {
|
||||||
MainDataTableCreateInput input = createVMMainDataTableInput(dataCenter, vm, project, pm);
|
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);
|
MainDataTable result = callMainDataTableMutation(input);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
System.out.println("✅ VM Emission calculation completed:");
|
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(" - Power: " + vm.getPower() + "W");
|
||||||
System.out.println(" - CO2: " + result.getCo2());
|
System.out.println(" - CO2: " + result.getCo2());
|
||||||
System.out.println(" - Total Emission: " + result.getTotalEmission());
|
System.out.println(" - Total Emission: " + result.getTotalEmission());
|
||||||
System.out.println(" - Record ID: " + result.getId());
|
System.out.println(" - Record ID: " + result.getId());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -701,10 +538,12 @@ public class MessageListener {
|
|||||||
private MainDataTableCreateInput createVMMainDataTableInput(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
private MainDataTableCreateInput createVMMainDataTableInput(DataCenter dataCenter, VM vm, Project project, PhysicalMachine pm) {
|
||||||
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
MainDataTableCreateInput input = new MainDataTableCreateInput();
|
||||||
|
|
||||||
// Copy datacenter-level information
|
// Copy datacenter-level information (if available)
|
||||||
input.setYear("2025");
|
input.setYear("2025");
|
||||||
input.setMonth("07");
|
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()) {
|
if (dataCenter.getArea() != null && !dataCenter.getArea().getCities().isEmpty()) {
|
||||||
input.setCity(dataCenter.getArea().getCities().get(0).getId());
|
input.setCity(dataCenter.getArea().getCities().get(0).getId());
|
||||||
}
|
}
|
||||||
@@ -715,6 +554,8 @@ public class MessageListener {
|
|||||||
|
|
||||||
if (dataCenter.getSector() != null) {
|
if (dataCenter.getSector() != null) {
|
||||||
input.setSector(dataCenter.getSector().getId());
|
input.setSector(dataCenter.getSector().getId());
|
||||||
|
} else {
|
||||||
|
System.out.println("⚠️ Warning: DataCenter has no sector set - emission calculation may fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataCenter.getSubSector() != null) {
|
if (dataCenter.getSubSector() != null) {
|
||||||
@@ -724,11 +565,12 @@ public class MessageListener {
|
|||||||
if (dataCenter.getEmissionSource() != null) {
|
if (dataCenter.getEmissionSource() != null) {
|
||||||
input.setEmissionSource(dataCenter.getEmissionSource().getId());
|
input.setEmissionSource(dataCenter.getEmissionSource().getId());
|
||||||
} else {
|
} else {
|
||||||
// Fallback to default emission source for Sabit Enerji
|
// Fallback to default emission source for electricity
|
||||||
try {
|
try {
|
||||||
List<EmissionSource> elektrikSources = emissionSourceRepo.findByTag("Doğalgaz(Elektrik Üretimi)");
|
List<EmissionSource> elektrikSources = emissionSourceRepo.findByTag("Doğalgaz(Elektrik Üretimi)");
|
||||||
if (!elektrikSources.isEmpty()) {
|
if (!elektrikSources.isEmpty()) {
|
||||||
input.setEmissionSource(elektrikSources.get(0).getId());
|
input.setEmissionSource(elektrikSources.get(0).getId());
|
||||||
|
System.out.println("⚠️ Using default emission source: Doğalgaz(Elektrik Üretimi)");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("❌ Error finding default emission source: " + e.getMessage());
|
System.err.println("❌ Error finding default emission source: " + e.getMessage());
|
||||||
@@ -743,7 +585,9 @@ public class MessageListener {
|
|||||||
input.setConsuptionUnit(dataCenter.getConsuptionUnit().getId());
|
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 {
|
try {
|
||||||
List<Organization> organizations = organizationRepo.findAll();
|
List<Organization> organizations = organizationRepo.findAll();
|
||||||
@@ -762,10 +606,11 @@ public class MessageListener {
|
|||||||
|
|
||||||
System.out.println("🔍 VM Emission Input:");
|
System.out.println("🔍 VM Emission Input:");
|
||||||
System.out.println(" VM ID: " + vm.getId());
|
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(" Power: " + vm.getPower() + "W");
|
||||||
System.out.println(" Physical Machine: " + pm.getName());
|
System.out.println(" Physical Machine: " + pm.getName());
|
||||||
System.out.println(" Project: " + project.getName());
|
System.out.println(" Project: " + project.getName());
|
||||||
|
System.out.println(" DataCenter Sector: " + (dataCenter.getSector() != null ? dataCenter.getSector().getTag() : "NOT SET"));
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,10 @@ security.jwt.token.secret-key=secret
|
|||||||
|
|
||||||
app.survey.base-url=http://localhost.com
|
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.host=localhost
|
||||||
spring.rabbitmq.port=5672
|
spring.rabbitmq.port=5672
|
||||||
spring.rabbitmq.username=guest
|
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]
|
projects: [Project]
|
||||||
area: Area
|
area: Area
|
||||||
number:Int
|
number: Int
|
||||||
}
|
|
||||||
|
ayposURL: String
|
||||||
type EmissionScope{
|
address: String
|
||||||
tag: String
|
latitude: Float
|
||||||
}
|
longitude: Float
|
||||||
|
|
||||||
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]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Project {
|
type Project {
|
||||||
@@ -55,24 +29,24 @@ type Project {
|
|||||||
|
|
||||||
type PhysicalMachine {
|
type PhysicalMachine {
|
||||||
id: ID
|
id: ID
|
||||||
status: String
|
|
||||||
name: String
|
name: String
|
||||||
powerConsumption: Float
|
ip: String
|
||||||
vms: Vms
|
tag: String
|
||||||
}
|
power: Float
|
||||||
|
vms: [Vm]
|
||||||
type Vms {
|
|
||||||
id: ID
|
|
||||||
active: [Vm]
|
|
||||||
inactive: [Vm]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vm {
|
type Vm {
|
||||||
id: ID
|
id: ID
|
||||||
status: String
|
state: String
|
||||||
name: String
|
vmName: String
|
||||||
|
ip: String
|
||||||
power: Float
|
power: Float
|
||||||
calcOn: Boolean
|
calcOn: Boolean
|
||||||
|
hostingPm: String
|
||||||
|
host: String
|
||||||
|
flavorName: String
|
||||||
|
tag: String
|
||||||
config: Config
|
config: Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,15 @@ type MainDataTable {
|
|||||||
|
|
||||||
type Vm {
|
type Vm {
|
||||||
id: ID
|
id: ID
|
||||||
status: String
|
state: String
|
||||||
name: String
|
vmName: String
|
||||||
|
ip: String
|
||||||
power: Float
|
power: Float
|
||||||
calcOn: Boolean
|
calcOn: Boolean
|
||||||
|
hostingPm: String
|
||||||
|
host: String
|
||||||
|
flavorName: String
|
||||||
|
tag: String
|
||||||
config: Config
|
config: Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user