|
|
@@ -48,8 +48,8 @@ export const SharedStatus: React.FC<{
|
|
|
for (let addedResource of addedResources) {
|
|
|
// if exists, update state to provisioned
|
|
|
if (resourceAddrMap.has(addedResource.addr)) {
|
|
|
- let currResource = resources[resourceAddrMap.get(addedResource.addr)]
|
|
|
- addedResource.errored = currResource.errored
|
|
|
+ let currResource = resources[resourceAddrMap.get(addedResource.addr)];
|
|
|
+ addedResource.errored = currResource.errored;
|
|
|
resources[resourceAddrMap.get(addedResource.addr)] = addedResource;
|
|
|
} else {
|
|
|
resources.push(addedResource);
|
|
|
@@ -132,6 +132,10 @@ export const SharedStatus: React.FC<{
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ case "change_summary":
|
|
|
+ if (streamValData.changes.add != 0) {
|
|
|
+ updateDesiredState(index, module);
|
|
|
+ }
|
|
|
default:
|
|
|
}
|
|
|
}
|
|
|
@@ -153,33 +157,95 @@ export const SharedStatus: React.FC<{
|
|
|
openWebsocket(websocketID);
|
|
|
};
|
|
|
|
|
|
+ const mergeCurrentAndDesired = (
|
|
|
+ index: number,
|
|
|
+ desired: any,
|
|
|
+ currentMap: Map<string, string>
|
|
|
+ ) => {
|
|
|
+ // map desired state to list of resources
|
|
|
+ var addedResources: TFResource[] = desired?.map((val: any) => {
|
|
|
+ return {
|
|
|
+ addr: val?.addr,
|
|
|
+ provisioned: currentMap.has(val?.addr),
|
|
|
+ errored: {
|
|
|
+ errored_out: val?.errored?.errored_out,
|
|
|
+ error_context: val?.errored?.error_context,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ });
|
|
|
+
|
|
|
+ updateTFModules(index, addedResources, [], []);
|
|
|
+ };
|
|
|
+
|
|
|
+ const updateDesiredState = (index: number, val: TFModule) => {
|
|
|
+ api
|
|
|
+ .getInfraDesired(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ { project_id: project_id, infra_id: val?.id }
|
|
|
+ )
|
|
|
+ .then((resDesired) => {
|
|
|
+ api
|
|
|
+ .getInfraCurrent(
|
|
|
+ "<token>",
|
|
|
+ {},
|
|
|
+ { project_id: project_id, infra_id: val?.id }
|
|
|
+ )
|
|
|
+ .then((resCurrent) => {
|
|
|
+ var desired = resDesired.data;
|
|
|
+ var current = resCurrent.data;
|
|
|
+
|
|
|
+ // convert current state to a lookup table
|
|
|
+ var currentMap: Map<string, string> = new Map();
|
|
|
+
|
|
|
+ current?.resources?.forEach((val: any) => {
|
|
|
+ currentMap.set(val?.type + "." + val?.name, "");
|
|
|
+ });
|
|
|
+
|
|
|
+ mergeCurrentAndDesired(index, desired, currentMap);
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ var desired = resDesired.data;
|
|
|
+ var currentMap: Map<string, string> = new Map();
|
|
|
+
|
|
|
+ // merge with empty current map
|
|
|
+ mergeCurrentAndDesired(index, desired, currentMap);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch((err) => console.log(err));
|
|
|
+ };
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
api.getInfra("<token>", {}, { project_id: project_id }).then((res) => {
|
|
|
- var matchedInfras : Map<string, any> = new Map()
|
|
|
- var numCreated = 0
|
|
|
-
|
|
|
- res.data.forEach((infra : any) => {
|
|
|
- // if filter list is empty, add infra automatically
|
|
|
- if (filter.length == 0) {
|
|
|
- matchedInfras.set(infra.kind + "-" + infra.id, infra)
|
|
|
- } else if (filter.includes(infra.kind) && matchedInfras.get(infra.Kind)?.id || 0 < infra.id) {
|
|
|
- matchedInfras.set(infra.kind, infra)
|
|
|
- }
|
|
|
-
|
|
|
- numCreated += infra?.status == "created" ? 1 : 0
|
|
|
- })
|
|
|
-
|
|
|
- // if all created, call next form step
|
|
|
- if (numCreated == res.data.length) {
|
|
|
- nextFormStep()
|
|
|
+ var matchedInfras: Map<string, any> = new Map();
|
|
|
+ var numCreated = 0;
|
|
|
+
|
|
|
+ res.data.forEach((infra: any) => {
|
|
|
+ // if filter list is empty, add infra automatically
|
|
|
+ if (filter.length == 0) {
|
|
|
+ matchedInfras.set(infra.kind + "-" + infra.id, infra);
|
|
|
+ } else if (
|
|
|
+ (filter.includes(infra.kind) && matchedInfras.get(infra.Kind)?.id) ||
|
|
|
+ 0 < infra.id
|
|
|
+ ) {
|
|
|
+ matchedInfras.set(infra.kind, infra);
|
|
|
}
|
|
|
|
|
|
+ numCreated += infra?.status == "created" ? 1 : 0;
|
|
|
+ });
|
|
|
+
|
|
|
+ // if all created, call next form step
|
|
|
+ if (numCreated == res.data.length) {
|
|
|
+ nextFormStep();
|
|
|
+ }
|
|
|
+
|
|
|
// query for desired and current state, and convert to tf module
|
|
|
matchedInfras.forEach((infra: any) => {
|
|
|
var module: TFModule = {
|
|
|
id: infra.id,
|
|
|
kind: infra.kind,
|
|
|
status: infra.status,
|
|
|
+ got_desired: false,
|
|
|
created_at: infra.created_at,
|
|
|
};
|
|
|
|
|
|
@@ -190,59 +256,18 @@ export const SharedStatus: React.FC<{
|
|
|
|
|
|
tfModules.forEach((val, index) => {
|
|
|
if (val?.status != "created" && val?.status != "destroyed") {
|
|
|
- api
|
|
|
- .getInfraDesired(
|
|
|
- "<token>",
|
|
|
- {},
|
|
|
- { project_id: project_id, infra_id: val?.id }
|
|
|
- )
|
|
|
- .then((resDesired) => {
|
|
|
- api
|
|
|
- .getInfraCurrent(
|
|
|
- "<token>",
|
|
|
- {},
|
|
|
- { project_id: project_id, infra_id: val?.id }
|
|
|
- )
|
|
|
- .then((resCurrent) => {
|
|
|
- var desired = resDesired.data;
|
|
|
- var current = resCurrent.data;
|
|
|
-
|
|
|
- // convert current state to a lookup table
|
|
|
- var currentMap: Map<string, string> = new Map();
|
|
|
-
|
|
|
- current?.resources?.forEach((val: any) => {
|
|
|
- currentMap.set(val?.type + "." + val?.name, "");
|
|
|
- });
|
|
|
-
|
|
|
- // map desired state to list of resources
|
|
|
- var addedResources: TFResource[] = desired?.map((val: any) => {
|
|
|
- return {
|
|
|
- addr: val?.addr,
|
|
|
- provisioned: currentMap.has(val?.addr),
|
|
|
- errored: {
|
|
|
- errored_out: val?.errored?.errored_out,
|
|
|
- error_context: val?.errored?.error_context,
|
|
|
- },
|
|
|
- };
|
|
|
- });
|
|
|
-
|
|
|
- updateTFModules(index, addedResources, [], [])
|
|
|
- })
|
|
|
- .catch((err) => console.log(err));
|
|
|
- })
|
|
|
- .catch((err) => console.log(err));
|
|
|
+ updateDesiredState(index, val);
|
|
|
+ setupInfraWebsocket(val.id + "", val, index);
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
- tfModules.forEach((val, index) => {
|
|
|
- setupInfraWebsocket(val.id + "", val, index);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return closeAllWebsockets;
|
|
|
}, []);
|
|
|
|
|
|
- let sortedModules = tfModules.sort((a, b) => b.id < a.id ? -1 : b.id > a.id ? 1 : 0)
|
|
|
+ let sortedModules = tfModules.sort((a, b) =>
|
|
|
+ b.id < a.id ? -1 : b.id > a.id ? 1 : 0
|
|
|
+ );
|
|
|
|
|
|
return (
|
|
|
<>
|