forked from BLC/sgeUpdated
Fix the datacenter query according to the changes in backend
This commit is contained in:
@@ -58,41 +58,42 @@ export const getDataCenters = () => {
|
||||
id
|
||||
tag
|
||||
}
|
||||
emissionSource {
|
||||
dataCenterEmissionSources {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
description
|
||||
emissionSource {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
description
|
||||
}
|
||||
isDefault
|
||||
percentage
|
||||
}
|
||||
activitySubUnit {
|
||||
id
|
||||
tag
|
||||
}
|
||||
projects {
|
||||
physicalMachines {
|
||||
id
|
||||
name
|
||||
physicalMachines {
|
||||
vms {
|
||||
id
|
||||
name
|
||||
vms {
|
||||
id
|
||||
vmName
|
||||
state
|
||||
power
|
||||
calcOn
|
||||
hostingPm
|
||||
host
|
||||
flavorName
|
||||
tag
|
||||
config {
|
||||
id
|
||||
cpu
|
||||
ram
|
||||
disk
|
||||
}
|
||||
}
|
||||
vmName
|
||||
state
|
||||
power
|
||||
calcOn
|
||||
hostingPm
|
||||
host
|
||||
flavorName
|
||||
tag
|
||||
config {
|
||||
id
|
||||
cpu
|
||||
ram
|
||||
disk
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +112,7 @@ export const getDataCenters = () => {
|
||||
console.log("GraphQL Response:", {
|
||||
status: response.status,
|
||||
data: response.data,
|
||||
errors: response.data?.errors
|
||||
errors: response.data?.errors,
|
||||
});
|
||||
|
||||
// Check for GraphQL errors
|
||||
@@ -144,7 +145,7 @@ export const getDataCenters = () => {
|
||||
message: error.message,
|
||||
response: error.response?.data,
|
||||
status: error.response?.status,
|
||||
stack: error.stack
|
||||
stack: error.stack,
|
||||
});
|
||||
|
||||
// Check for specific error types
|
||||
@@ -213,13 +214,18 @@ export const createDataCenter = (dataCenterData) => {
|
||||
id
|
||||
tag
|
||||
}
|
||||
emissionSource {
|
||||
dataCenterEmissionSources {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
description
|
||||
emissionSource {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
description
|
||||
}
|
||||
isDefault
|
||||
percentage
|
||||
}
|
||||
activitySubUnit {
|
||||
id
|
||||
@@ -236,16 +242,20 @@ export const createDataCenter = (dataCenterData) => {
|
||||
number: parseInt(dataCenterData.number) || 1,
|
||||
areaId: dataCenterData.areaId || null,
|
||||
address: dataCenterData.address || "",
|
||||
latitude: dataCenterData.latitude ? parseFloat(dataCenterData.latitude) : null,
|
||||
longitude: dataCenterData.longitude ? parseFloat(dataCenterData.longitude) : null,
|
||||
latitude: dataCenterData.latitude
|
||||
? parseFloat(dataCenterData.latitude)
|
||||
: null,
|
||||
longitude: dataCenterData.longitude
|
||||
? parseFloat(dataCenterData.longitude)
|
||||
: null,
|
||||
emissionScopeId: dataCenterData.emissionScopeId || null,
|
||||
sectorId: dataCenterData.sectorId || null,
|
||||
subSectorId: dataCenterData.subSectorId || null,
|
||||
emissionSourceId: dataCenterData.emissionSourceId || null,
|
||||
consuptionUnitId: dataCenterData.consuptionUnitId || null,
|
||||
activitySubUnitId: dataCenterData.activitySubUnitId || null
|
||||
}
|
||||
}
|
||||
activitySubUnitId: dataCenterData.activitySubUnitId || null,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -258,7 +268,7 @@ export const createDataCenter = (dataCenterData) => {
|
||||
console.log("Create Response:", {
|
||||
status: response.status,
|
||||
data: response.data,
|
||||
errors: response.data?.errors
|
||||
errors: response.data?.errors,
|
||||
});
|
||||
|
||||
if (response.data?.errors) {
|
||||
@@ -334,13 +344,18 @@ export const updateDataCenter = (id, dataCenterData) => {
|
||||
id
|
||||
tag
|
||||
}
|
||||
emissionSource {
|
||||
dataCenterEmissionSources {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
description
|
||||
emissionSource {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
description
|
||||
}
|
||||
isDefault
|
||||
percentage
|
||||
}
|
||||
activitySubUnit {
|
||||
id
|
||||
@@ -358,16 +373,20 @@ export const updateDataCenter = (id, dataCenterData) => {
|
||||
number: parseInt(dataCenterData.number) || 1,
|
||||
areaId: dataCenterData.areaId || null,
|
||||
address: dataCenterData.address || "",
|
||||
latitude: dataCenterData.latitude ? parseFloat(dataCenterData.latitude) : null,
|
||||
longitude: dataCenterData.longitude ? parseFloat(dataCenterData.longitude) : null,
|
||||
latitude: dataCenterData.latitude
|
||||
? parseFloat(dataCenterData.latitude)
|
||||
: null,
|
||||
longitude: dataCenterData.longitude
|
||||
? parseFloat(dataCenterData.longitude)
|
||||
: null,
|
||||
emissionScopeId: dataCenterData.emissionScopeId || null,
|
||||
sectorId: dataCenterData.sectorId || null,
|
||||
subSectorId: dataCenterData.subSectorId || null,
|
||||
emissionSourceId: dataCenterData.emissionSourceId || null,
|
||||
consuptionUnitId: dataCenterData.consuptionUnitId || null,
|
||||
activitySubUnitId: dataCenterData.activitySubUnitId || null
|
||||
}
|
||||
}
|
||||
activitySubUnitId: dataCenterData.activitySubUnitId || null,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -382,7 +401,7 @@ export const updateDataCenter = (id, dataCenterData) => {
|
||||
|
||||
dispatch({
|
||||
type: "UPDATE_DATA_CENTER_SUCCESS",
|
||||
payload: response.data.data.updateDataCenter
|
||||
payload: response.data.data.updateDataCenter,
|
||||
});
|
||||
|
||||
return response.data.data.updateDataCenter;
|
||||
@@ -415,8 +434,8 @@ export const deleteDataCenter = (id) => {
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: id
|
||||
}
|
||||
id: id,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -431,7 +450,7 @@ export const deleteDataCenter = (id) => {
|
||||
|
||||
dispatch({
|
||||
type: "DELETE_DATA_CENTER_SUCCESS",
|
||||
payload: id
|
||||
payload: id,
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -466,7 +485,7 @@ export const getEmissionScopes = () => {
|
||||
description
|
||||
}
|
||||
}
|
||||
`
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -481,7 +500,7 @@ export const getEmissionScopes = () => {
|
||||
|
||||
dispatch({
|
||||
type: "GET_EMISSION_SCOPES_SUCCESS",
|
||||
payload: response.data.data.emissionScopes
|
||||
payload: response.data.data.emissionScopes,
|
||||
});
|
||||
|
||||
return response.data.data.emissionScopes;
|
||||
@@ -502,65 +521,59 @@ export const getDataCenterVMs = (dataCenterId) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// Don't make the request if dataCenterId is undefined, null, or empty
|
||||
if (!dataCenterId || dataCenterId === "undefined") {
|
||||
console.log('getDataCenterVMs: No dataCenterId provided');
|
||||
console.log("getDataCenterVMs: No dataCenterId provided");
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('getDataCenterVMs: Fetching VMs for data center:', dataCenterId);
|
||||
const response = await ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
console.log(
|
||||
"getDataCenterVMs: Fetching VMs for data center:",
|
||||
dataCenterId
|
||||
);
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
dataCenter(id: "${dataCenterId}") {
|
||||
id
|
||||
dataCenter
|
||||
projects {
|
||||
physicalMachines {
|
||||
id
|
||||
name
|
||||
physicalMachines {
|
||||
vms {
|
||||
id
|
||||
name
|
||||
vms {
|
||||
id
|
||||
name
|
||||
status
|
||||
power
|
||||
}
|
||||
vmName
|
||||
state
|
||||
power
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
const dataCenter = response?.data?.data?.dataCenter;
|
||||
console.log('getDataCenterVMs: Data center response:', dataCenter);
|
||||
console.log("getDataCenterVMs: Data center response:", dataCenter);
|
||||
|
||||
let allVMs = [];
|
||||
|
||||
if (dataCenter && dataCenter.projects) {
|
||||
dataCenter.projects.forEach(project => {
|
||||
if (project.physicalMachines) {
|
||||
project.physicalMachines.forEach(pm => {
|
||||
if (pm.vms) {
|
||||
allVMs = allVMs.concat(pm.vms);
|
||||
}
|
||||
});
|
||||
if (dataCenter && dataCenter.physicalMachines) {
|
||||
dataCenter.physicalMachines.forEach((pm) => {
|
||||
if (pm.vms) {
|
||||
allVMs = allVMs.concat(pm.vms);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('getDataCenterVMs: Found VMs:', allVMs);
|
||||
console.log("getDataCenterVMs: Found VMs:", allVMs);
|
||||
resolve(allVMs);
|
||||
} catch (error) {
|
||||
console.error("Error fetching VMs by data center:", error);
|
||||
|
||||
Reference in New Issue
Block a user