@highstate/backend 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-I7NLZ54E.js → chunk-NMGIUI6X.js} +22 -7
- package/dist/chunk-NMGIUI6X.js.map +1 -0
- package/dist/highstate.manifest.json +3 -3
- package/dist/index.js +160 -92
- package/dist/index.js.map +1 -1
- package/dist/library/worker/main.js +19 -15
- package/dist/library/worker/main.js.map +1 -1
- package/dist/shared/index.js +3 -1
- package/package.json +3 -3
- package/src/library/local.ts +10 -2
- package/src/library/worker/evaluator.ts +14 -6
- package/src/library/worker/loader.ts +12 -9
- package/src/orchestrator/manager.ts +4 -2
- package/src/orchestrator/operation-workset.ts +132 -63
- package/src/orchestrator/operation.ts +49 -30
- package/src/project/manager.ts +8 -0
- package/src/shared/library.ts +3 -0
- package/src/shared/operation.ts +13 -2
- package/src/shared/resolvers/validation.ts +3 -3
- package/src/shared/state.ts +9 -1
- package/dist/chunk-I7NLZ54E.js.map +0 -1
package/dist/index.js
CHANGED
@@ -17,7 +17,7 @@ import {
|
|
17
17
|
isFinalOperationStatus,
|
18
18
|
projectOperationSchema,
|
19
19
|
terminalSessionSchema
|
20
|
-
} from "./chunk-
|
20
|
+
} from "./chunk-NMGIUI6X.js";
|
21
21
|
import {
|
22
22
|
LocalPulumiHost,
|
23
23
|
createAsyncBatcher,
|
@@ -229,7 +229,7 @@ var LocalLibraryBackend = class _LocalLibraryBackend {
|
|
229
229
|
async getResolvedUnitSources(unitTypes) {
|
230
230
|
return await this.lock.acquire(async () => {
|
231
231
|
const [library] = await this.getLibrary();
|
232
|
-
const units = unitTypes.map((type) => library.components[type]).filter(isUnitModel);
|
232
|
+
const units = unitTypes.map((type) => library.components[type]).filter(Boolean).filter(isUnitModel);
|
233
233
|
const packageNames = Object.keys(groupBy(units, (unit) => unit.source.package));
|
234
234
|
await this.ensureLibraryPackagesLoaded(packageNames, true);
|
235
235
|
const result = [];
|
@@ -302,10 +302,11 @@ var LocalLibraryBackend = class _LocalLibraryBackend {
|
|
302
302
|
}
|
303
303
|
async reloadLibrary() {
|
304
304
|
this.logger.info("reloading library");
|
305
|
+
this.eventEmitter.emit("library", [{ type: "reload-started" }]);
|
305
306
|
await this.ensureLibraryPackagesLoaded(this.libraryPackages, true);
|
306
307
|
this.worker = this.createLibraryWorker({
|
307
308
|
modulePaths: this.libraryPackages,
|
308
|
-
logLevel: "
|
309
|
+
logLevel: "warn"
|
309
310
|
});
|
310
311
|
for await (const [event] of on(this.worker, "message")) {
|
311
312
|
const eventData = event;
|
@@ -322,6 +323,7 @@ var LocalLibraryBackend = class _LocalLibraryBackend {
|
|
322
323
|
this.eventEmitter.emit("library", updates);
|
323
324
|
this.library = eventData.library;
|
324
325
|
this.logger.info("library reloaded");
|
326
|
+
this.eventEmitter.emit("library", [{ type: "reload-completed" }]);
|
325
327
|
return [this.library, this.worker];
|
326
328
|
}
|
327
329
|
throw new Error("Worker ended without sending library model");
|
@@ -989,6 +991,9 @@ var ProjectManager = class _ProjectManager {
|
|
989
991
|
async evaluateCompositeInstances(projectId, instanceIds) {
|
990
992
|
await this.projectLockManager.getLock(projectId).lockInstances(instanceIds, async () => {
|
991
993
|
this.logger.debug({ instanceIds }, "evaluating composite instances");
|
994
|
+
for (const instanceId of instanceIds) {
|
995
|
+
this.compositeInstanceEE.emit(projectId, { type: "evaluation-started", instanceId });
|
996
|
+
}
|
992
997
|
const [
|
993
998
|
{ instances, resolvedInputs, stateMap, resolveInputHash },
|
994
999
|
topLevelCompositeChildrenIds
|
@@ -2673,11 +2678,14 @@ import { EventEmitter as EventEmitter6, on as on6 } from "node:events";
|
|
2673
2678
|
import { uuidv7 as uuidv72 } from "uuidv7";
|
2674
2679
|
|
2675
2680
|
// src/orchestrator/operation.ts
|
2676
|
-
import { isUnitModel as isUnitModel4, parseInstanceId as
|
2681
|
+
import { isUnitModel as isUnitModel4, parseInstanceId as parseInstanceId3 } from "@highstate/contract";
|
2677
2682
|
import { mapValues as mapValues3 } from "remeda";
|
2678
2683
|
|
2679
2684
|
// src/orchestrator/operation-workset.ts
|
2680
|
-
import {
|
2685
|
+
import {
|
2686
|
+
isUnitModel as isUnitModel3,
|
2687
|
+
parseInstanceId as parseInstanceId2
|
2688
|
+
} from "@highstate/contract";
|
2681
2689
|
import { unique as unique2 } from "remeda";
|
2682
2690
|
var OperationWorkset = class _OperationWorkset {
|
2683
2691
|
constructor(operation, library, stateManager, logger) {
|
@@ -2686,7 +2694,8 @@ var OperationWorkset = class _OperationWorkset {
|
|
2686
2694
|
this.stateManager = stateManager;
|
2687
2695
|
this.logger = logger;
|
2688
2696
|
}
|
2689
|
-
|
2697
|
+
instanceIdsToUpdate = /* @__PURE__ */ new Set();
|
2698
|
+
instanceIdsToDestroy = /* @__PURE__ */ new Set();
|
2690
2699
|
instanceMap = /* @__PURE__ */ new Map();
|
2691
2700
|
instanceChildrenMap = /* @__PURE__ */ new Map();
|
2692
2701
|
initialStateMap = /* @__PURE__ */ new Map();
|
@@ -2708,14 +2717,26 @@ var OperationWorkset = class _OperationWorkset {
|
|
2708
2717
|
}
|
2709
2718
|
return instance;
|
2710
2719
|
}
|
2711
|
-
|
2712
|
-
|
2720
|
+
getAffectedInstanceIds(phase) {
|
2721
|
+
if (phase === "destroy") {
|
2722
|
+
return Array.from(this.instanceIdsToDestroy);
|
2723
|
+
}
|
2724
|
+
return Array.from(this.instanceIdsToUpdate);
|
2725
|
+
}
|
2726
|
+
getInstanceOrUndefined(instanceId) {
|
2727
|
+
return this.instanceMap.get(instanceId);
|
2728
|
+
}
|
2729
|
+
isAffected(instanceId, phase) {
|
2730
|
+
if (phase === "destroy") {
|
2731
|
+
return this.instanceIdsToDestroy.has(instanceId);
|
2732
|
+
}
|
2733
|
+
return this.instanceIdsToUpdate.has(instanceId);
|
2713
2734
|
}
|
2714
2735
|
updateState(update) {
|
2715
2736
|
const finalState = applyPartialInstanceState(this.stateMap, update);
|
2716
2737
|
this.stateManager.emitStatePatch(this.operation.projectId, createInstanceStatePatch(update));
|
2717
2738
|
if (finalState.parentId) {
|
2718
|
-
this.
|
2739
|
+
this.recalculateCompositeInstanceState(finalState.parentId);
|
2719
2740
|
}
|
2720
2741
|
return finalState;
|
2721
2742
|
}
|
@@ -2755,21 +2776,35 @@ var OperationWorkset = class _OperationWorkset {
|
|
2755
2776
|
}
|
2756
2777
|
emitAffectedInitialStates() {
|
2757
2778
|
for (const state of this.initialStateMap.values()) {
|
2758
|
-
if (this.
|
2779
|
+
if (this.instanceIdsToUpdate.has(state.id)) {
|
2759
2780
|
this.stateManager.emitStatePatch(this.operation.projectId, state);
|
2760
2781
|
}
|
2761
2782
|
}
|
2762
2783
|
}
|
2763
|
-
getAffectedCompositeChildren(instanceId) {
|
2784
|
+
getAffectedCompositeChildren(instanceId, phase) {
|
2764
2785
|
const children = this.instanceChildrenMap.get(instanceId);
|
2765
2786
|
if (!children) {
|
2766
2787
|
return [];
|
2767
2788
|
}
|
2768
|
-
|
2789
|
+
if (phase === "destroy") {
|
2790
|
+
return children.filter((child) => this.instanceIdsToDestroy.has(child.id));
|
2791
|
+
}
|
2792
|
+
return children.filter((child) => this.instanceIdsToUpdate.has(child.id));
|
2769
2793
|
}
|
2770
2794
|
getState(instanceId) {
|
2771
2795
|
return this.stateMap.get(instanceId);
|
2772
2796
|
}
|
2797
|
+
getParentId(instanceId, phase) {
|
2798
|
+
if (phase === "destroy") {
|
2799
|
+
const state = this.stateMap.get(instanceId);
|
2800
|
+
if (!state) {
|
2801
|
+
return null;
|
2802
|
+
}
|
2803
|
+
return state.parentId;
|
2804
|
+
}
|
2805
|
+
const instance = this.getInstance(instanceId);
|
2806
|
+
return instance.parentId ?? null;
|
2807
|
+
}
|
2773
2808
|
getDependentStates(instanceId) {
|
2774
2809
|
const dependentStateIds = this.dependentStateIdMap.get(instanceId);
|
2775
2810
|
if (!dependentStateIds) {
|
@@ -2777,7 +2812,7 @@ var OperationWorkset = class _OperationWorkset {
|
|
2777
2812
|
}
|
2778
2813
|
return Array.from(dependentStateIds).map((id) => this.stateMap.get(id)).filter((state) => !!state);
|
2779
2814
|
}
|
2780
|
-
|
2815
|
+
recalculateCompositeInstanceState(instanceId) {
|
2781
2816
|
const state = this.stateMap.get(instanceId) ?? createInstanceState(instanceId);
|
2782
2817
|
let currentResourceCount = 0;
|
2783
2818
|
let totalResourceCount = 0;
|
@@ -2799,7 +2834,7 @@ var OperationWorkset = class _OperationWorkset {
|
|
2799
2834
|
this.stateMap.set(instanceId, updatedState);
|
2800
2835
|
this.stateManager.emitStatePatch(this.operation.projectId, updatedState);
|
2801
2836
|
if (state.parentId) {
|
2802
|
-
this.
|
2837
|
+
this.recalculateCompositeInstanceState(state.parentId);
|
2803
2838
|
}
|
2804
2839
|
}
|
2805
2840
|
addInstance(instance) {
|
@@ -2822,9 +2857,9 @@ var OperationWorkset = class _OperationWorkset {
|
|
2822
2857
|
children.push(instance);
|
2823
2858
|
}
|
2824
2859
|
}
|
2825
|
-
async
|
2860
|
+
async calculateInstanceIdsToUpdate() {
|
2826
2861
|
const traverse = async (instanceId) => {
|
2827
|
-
if (this.
|
2862
|
+
if (this.instanceIdsToUpdate.has(instanceId)) {
|
2828
2863
|
return;
|
2829
2864
|
}
|
2830
2865
|
const instance = this.instanceMap.get(instanceId);
|
@@ -2840,40 +2875,48 @@ var OperationWorkset = class _OperationWorkset {
|
|
2840
2875
|
const state = this.stateMap.get(instance.id);
|
2841
2876
|
const { inputHash: expectedInputHash } = await this.inputHashResolver(instance.id);
|
2842
2877
|
if (this.operation.options.forceUpdateDependencies) {
|
2843
|
-
this.
|
2878
|
+
this.instanceIdsToUpdate.add(instanceId);
|
2844
2879
|
return;
|
2845
2880
|
}
|
2846
2881
|
if (state?.status !== "created" || state.inputHash !== expectedInputHash) {
|
2847
|
-
this.
|
2882
|
+
this.instanceIdsToUpdate.add(instanceId);
|
2848
2883
|
}
|
2849
2884
|
};
|
2850
|
-
for (const instanceId of this.operation.
|
2885
|
+
for (const instanceId of this.operation.requestedInstanceIds) {
|
2851
2886
|
if (this.operation.type === "update") {
|
2852
2887
|
await traverse(instanceId);
|
2853
2888
|
}
|
2854
|
-
this.
|
2889
|
+
this.instanceIdsToUpdate.add(instanceId);
|
2855
2890
|
}
|
2856
|
-
const compositeInstanceQueue = Array.from(this.
|
2891
|
+
const compositeInstanceQueue = Array.from(this.instanceIdsToUpdate);
|
2857
2892
|
while (compositeInstanceQueue.length > 0) {
|
2858
2893
|
const childId = compositeInstanceQueue.pop();
|
2859
2894
|
const children = this.instanceChildrenMap.get(childId) ?? [];
|
2860
2895
|
for (const child of children) {
|
2861
2896
|
compositeInstanceQueue.push(child.id);
|
2862
|
-
this.
|
2897
|
+
if (this.operation.options.forceUpdateChildren) {
|
2898
|
+
this.instanceIdsToUpdate.add(child.id);
|
2899
|
+
continue;
|
2900
|
+
}
|
2901
|
+
const state = this.stateMap.get(child.id);
|
2902
|
+
const { inputHash: expectedInputHash } = await this.inputHashResolver(child.id);
|
2903
|
+
if (state?.status !== "created" || state.inputHash !== expectedInputHash) {
|
2904
|
+
this.instanceIdsToUpdate.add(child.id);
|
2905
|
+
}
|
2863
2906
|
}
|
2864
2907
|
}
|
2865
|
-
for (const instanceId of this.
|
2908
|
+
for (const instanceId of this.instanceIdsToUpdate) {
|
2866
2909
|
let instance = this.instanceMap.get(instanceId);
|
2867
2910
|
while (instance?.parentId) {
|
2868
|
-
this.
|
2911
|
+
this.instanceIdsToUpdate.add(instance.parentId);
|
2869
2912
|
instance = this.instanceMap.get(instance.parentId);
|
2870
2913
|
}
|
2871
2914
|
}
|
2872
|
-
this.operation.
|
2915
|
+
this.operation.instanceIdsToUpdate = Array.from(this.instanceIdsToUpdate);
|
2873
2916
|
}
|
2874
|
-
|
2917
|
+
calculateInstanceIdsToDestroy() {
|
2875
2918
|
const traverse = (instanceKey) => {
|
2876
|
-
if (this.
|
2919
|
+
if (this.instanceIdsToDestroy.has(instanceKey)) {
|
2877
2920
|
return;
|
2878
2921
|
}
|
2879
2922
|
const state = this.stateMap.get(instanceKey);
|
@@ -2883,36 +2926,56 @@ var OperationWorkset = class _OperationWorkset {
|
|
2883
2926
|
const dependentIds = this.dependentStateIdMap.get(instanceKey) ?? [];
|
2884
2927
|
for (const dependentId of dependentIds) {
|
2885
2928
|
traverse(dependentId);
|
2886
|
-
this.
|
2929
|
+
this.instanceIdsToDestroy.add(dependentId);
|
2887
2930
|
}
|
2888
2931
|
};
|
2889
|
-
|
2890
|
-
const
|
2891
|
-
|
2892
|
-
|
2932
|
+
if (this.operation.type === "destroy" || this.operation.type === "recreate") {
|
2933
|
+
for (const instanceId of this.operation.requestedInstanceIds) {
|
2934
|
+
const instance = this.instanceMap.get(instanceId);
|
2935
|
+
if (!instance) {
|
2936
|
+
throw new Error(`Instance not found: ${instanceId}`);
|
2937
|
+
}
|
2938
|
+
if (this.operation.options.destroyDependentInstances) {
|
2939
|
+
traverse(instance.id);
|
2940
|
+
}
|
2941
|
+
this.instanceIdsToDestroy.add(instanceId);
|
2893
2942
|
}
|
2894
|
-
|
2895
|
-
|
2943
|
+
} else if (this.operation.type === "update") {
|
2944
|
+
for (const instanceId of this.operation.instanceIdsToUpdate) {
|
2945
|
+
const [type] = parseInstanceId2(instanceId);
|
2946
|
+
const component = this.library.components[type];
|
2947
|
+
if (!component || isUnitModel3(component)) {
|
2948
|
+
continue;
|
2949
|
+
}
|
2950
|
+
const childrenQueue = [...this.stateChildIdMap.get(instanceId) ?? []];
|
2951
|
+
while (childrenQueue.length > 0) {
|
2952
|
+
const childId = childrenQueue.pop();
|
2953
|
+
if (!this.instanceMap.has(childId)) {
|
2954
|
+
this.instanceIdsToDestroy.add(childId);
|
2955
|
+
}
|
2956
|
+
childrenQueue.push(...this.stateChildIdMap.get(childId) ?? []);
|
2957
|
+
}
|
2896
2958
|
}
|
2897
|
-
|
2959
|
+
} else {
|
2960
|
+
return;
|
2898
2961
|
}
|
2899
|
-
const compositeInstanceQueue = Array.from(this.
|
2962
|
+
const compositeInstanceQueue = Array.from(this.instanceIdsToDestroy);
|
2900
2963
|
while (compositeInstanceQueue.length > 0) {
|
2901
2964
|
const childId = compositeInstanceQueue.pop();
|
2902
2965
|
const children = this.stateChildIdMap.get(childId) ?? [];
|
2903
2966
|
for (const child of children) {
|
2904
2967
|
compositeInstanceQueue.push(child);
|
2905
|
-
this.
|
2968
|
+
this.instanceIdsToDestroy.add(child);
|
2906
2969
|
}
|
2907
2970
|
}
|
2908
|
-
for (const instanceId of this.
|
2971
|
+
for (const instanceId of this.instanceIdsToDestroy) {
|
2909
2972
|
let state = this.stateMap.get(instanceId);
|
2910
2973
|
while (state?.parentId) {
|
2911
|
-
this.
|
2974
|
+
this.instanceIdsToDestroy.add(state.parentId);
|
2912
2975
|
state = this.stateMap.get(state.parentId);
|
2913
2976
|
}
|
2914
2977
|
}
|
2915
|
-
this.operation.
|
2978
|
+
this.operation.instanceIdsToDestroy = Array.from(this.instanceIdsToDestroy);
|
2916
2979
|
}
|
2917
2980
|
getSourceHashIfApplicable(instance, component) {
|
2918
2981
|
if (isUnitModel3(component)) {
|
@@ -2934,14 +2997,7 @@ var OperationWorkset = class _OperationWorkset {
|
|
2934
2997
|
return inputHash;
|
2935
2998
|
}
|
2936
2999
|
getLockInstanceIds() {
|
2937
|
-
|
2938
|
-
for (const instanceId of this.operation.affectedInstanceIds) {
|
2939
|
-
const instance = this.getInstance(instanceId);
|
2940
|
-
if (instance.parentId) {
|
2941
|
-
instanceIds.add(instance.parentId);
|
2942
|
-
}
|
2943
|
-
}
|
2944
|
-
return Array.from(instanceIds);
|
3000
|
+
return Array.from(this.instanceIdsToUpdate.union(this.instanceIdsToDestroy));
|
2945
3001
|
}
|
2946
3002
|
static async load(operation, projectBackend, libraryBackend, stateBackend, stateManager, logger, signal) {
|
2947
3003
|
const [library, project, compositeInstances, states] = await Promise.all([
|
@@ -2970,8 +3026,13 @@ var OperationWorkset = class _OperationWorkset {
|
|
2970
3026
|
if (worksetInstance) {
|
2971
3027
|
worksetInstance.outputs = instance.instance.outputs;
|
2972
3028
|
worksetInstance.resolvedOutputs = instance.instance.resolvedOutputs;
|
2973
|
-
} else {
|
3029
|
+
} else if (instance.instance.parentId) {
|
2974
3030
|
workset.addInstance(instance.instance);
|
3031
|
+
} else {
|
3032
|
+
workset.logger.warn(
|
3033
|
+
`ignoring instance "${instance.instance.id}" from composite instance state because it is not in the project or is not a part of known composite instance`
|
3034
|
+
);
|
3035
|
+
continue;
|
2975
3036
|
}
|
2976
3037
|
for (const child of instance.children) {
|
2977
3038
|
if (!workset.instanceMap.has(child.id)) {
|
@@ -3025,19 +3086,10 @@ var OperationWorkset = class _OperationWorkset {
|
|
3025
3086
|
logger,
|
3026
3087
|
{ promiseCache: workset.inputHashResolverPromiseCache }
|
3027
3088
|
);
|
3028
|
-
|
3029
|
-
|
3030
|
-
case "preview":
|
3031
|
-
case "refresh":
|
3032
|
-
await workset.extendForUpdate();
|
3033
|
-
break;
|
3034
|
-
case "recreate":
|
3035
|
-
workset.extendForDestroy();
|
3036
|
-
break;
|
3037
|
-
case "destroy":
|
3038
|
-
workset.extendForDestroy();
|
3039
|
-
break;
|
3089
|
+
if (operation.type !== "destroy") {
|
3090
|
+
await workset.calculateInstanceIdsToUpdate();
|
3040
3091
|
}
|
3092
|
+
workset.calculateInstanceIdsToDestroy();
|
3041
3093
|
return workset;
|
3042
3094
|
}
|
3043
3095
|
};
|
@@ -3113,18 +3165,22 @@ var RuntimeOperation = class {
|
|
3113
3165
|
}
|
3114
3166
|
}
|
3115
3167
|
async processOperation() {
|
3116
|
-
this.operation.
|
3168
|
+
this.operation.instanceIdsToUpdate = this.workset.operation.instanceIdsToUpdate;
|
3169
|
+
this.operation.instanceIdsToDestroy = this.workset.operation.instanceIdsToDestroy;
|
3117
3170
|
this.logger.info(
|
3118
|
-
{
|
3171
|
+
{
|
3172
|
+
instanceIdsToUpdate: this.operation.instanceIdsToUpdate,
|
3173
|
+
instanceIdsToDestroy: this.operation.instanceIdsToDestroy
|
3174
|
+
},
|
3119
3175
|
"operation started"
|
3120
3176
|
);
|
3121
3177
|
const phases = this.getOperationPhases();
|
3122
3178
|
for (const phase of phases) {
|
3123
3179
|
this.currentPhase = phase;
|
3124
3180
|
const promises = [];
|
3125
|
-
for (const instanceId of this.
|
3126
|
-
const
|
3127
|
-
if (
|
3181
|
+
for (const instanceId of this.workset.getAffectedInstanceIds(phase)) {
|
3182
|
+
const parentId = this.workset.getParentId(instanceId, phase);
|
3183
|
+
if (parentId && this.workset.isAffected(parentId, phase)) {
|
3128
3184
|
continue;
|
3129
3185
|
}
|
3130
3186
|
promises.push(this.getInstancePromiseForOperation(instanceId));
|
@@ -3145,16 +3201,21 @@ var RuntimeOperation = class {
|
|
3145
3201
|
this.abortController.abort();
|
3146
3202
|
}
|
3147
3203
|
getInstancePromiseForOperation(instanceId) {
|
3148
|
-
const
|
3149
|
-
const component = this.workset.library.components[
|
3204
|
+
const [instanceType] = parseInstanceId3(instanceId);
|
3205
|
+
const component = this.workset.library.components[instanceType];
|
3150
3206
|
if (isUnitModel4(component)) {
|
3151
|
-
return this.getUnitPromise(
|
3207
|
+
return this.getUnitPromise(instanceId);
|
3152
3208
|
}
|
3153
|
-
return this.getCompositePromise(
|
3209
|
+
return this.getCompositePromise(instanceId);
|
3154
3210
|
}
|
3155
3211
|
getOperationPhases() {
|
3156
3212
|
switch (this.operation.type) {
|
3157
|
-
case "update":
|
3213
|
+
case "update": {
|
3214
|
+
if (this.operation.instanceIdsToDestroy.length > 0) {
|
3215
|
+
return ["destroy", "update"];
|
3216
|
+
}
|
3217
|
+
return ["update"];
|
3218
|
+
}
|
3158
3219
|
case "preview":
|
3159
3220
|
return ["update"];
|
3160
3221
|
case "recreate":
|
@@ -3165,31 +3226,32 @@ var RuntimeOperation = class {
|
|
3165
3226
|
return ["refresh"];
|
3166
3227
|
}
|
3167
3228
|
}
|
3168
|
-
async getUnitPromise(
|
3229
|
+
async getUnitPromise(instanceId) {
|
3169
3230
|
switch (this.currentPhase) {
|
3170
3231
|
case "update": {
|
3171
|
-
return this.updateUnit(
|
3232
|
+
return this.updateUnit(instanceId);
|
3172
3233
|
}
|
3173
3234
|
case "destroy": {
|
3174
|
-
return this.destroyUnit(
|
3235
|
+
return this.destroyUnit(instanceId);
|
3175
3236
|
}
|
3176
3237
|
case "refresh": {
|
3177
|
-
return this.refreshUnit(
|
3238
|
+
return this.refreshUnit(instanceId);
|
3178
3239
|
}
|
3179
3240
|
}
|
3180
3241
|
}
|
3181
|
-
async getCompositePromise(
|
3182
|
-
const logger = this.logger.child({ instanceId
|
3183
|
-
return this.getInstancePromise(
|
3184
|
-
const state = this.workset.getState(
|
3242
|
+
async getCompositePromise(instanceId) {
|
3243
|
+
const logger = this.logger.child({ instanceId });
|
3244
|
+
return this.getInstancePromise(instanceId, async () => {
|
3245
|
+
const state = this.workset.getState(instanceId) ?? createInstanceState(instanceId);
|
3246
|
+
const instance = this.workset.getInstanceOrUndefined(instanceId);
|
3185
3247
|
this.updateInstanceState({
|
3186
3248
|
...state,
|
3187
|
-
parentId: instance
|
3249
|
+
parentId: instance?.parentId,
|
3188
3250
|
latestOperationId: this.operation.id,
|
3189
3251
|
status: this.getStatusByOperationType(),
|
3190
3252
|
error: null
|
3191
3253
|
});
|
3192
|
-
const children = this.workset.getAffectedCompositeChildren(
|
3254
|
+
const children = this.workset.getAffectedCompositeChildren(instanceId, this.currentPhase);
|
3193
3255
|
const childPromises = [];
|
3194
3256
|
if (children.length) {
|
3195
3257
|
logger.info("running %s children", children.length);
|
@@ -3197,6 +3259,9 @@ var RuntimeOperation = class {
|
|
3197
3259
|
logger.warn("no affected children found for composite component");
|
3198
3260
|
}
|
3199
3261
|
for (const child of children) {
|
3262
|
+
if (!this.operation.options.forceUpdateChildren && !this.workset.isAffected(child.id, this.currentPhase)) {
|
3263
|
+
continue;
|
3264
|
+
}
|
3200
3265
|
logger.debug(`waiting for child: "%s"`, child.id);
|
3201
3266
|
childPromises.push(this.getInstancePromiseForOperation(child.id));
|
3202
3267
|
}
|
@@ -3206,25 +3271,26 @@ var RuntimeOperation = class {
|
|
3206
3271
|
logger.info("all children completed");
|
3207
3272
|
}
|
3208
3273
|
this.updateInstanceState({
|
3209
|
-
id:
|
3274
|
+
id: instanceId,
|
3210
3275
|
status: this.operation.type === "destroy" ? "not_created" : "created",
|
3211
|
-
inputHash: await this.workset.getUpToDateInputHash(instance)
|
3276
|
+
inputHash: instance ? await this.workset.getUpToDateInputHash(instance) : void 0
|
3212
3277
|
});
|
3213
3278
|
} catch (error) {
|
3214
3279
|
if (isAbortErrorLike(error)) {
|
3215
|
-
this.workset.restoreInitialStatus(
|
3280
|
+
this.workset.restoreInitialStatus(instanceId);
|
3216
3281
|
return;
|
3217
3282
|
}
|
3218
3283
|
this.updateInstanceState({
|
3219
|
-
id:
|
3284
|
+
id: instanceId,
|
3220
3285
|
status: "error",
|
3221
3286
|
error: errorToString(error)
|
3222
3287
|
});
|
3223
3288
|
}
|
3224
3289
|
});
|
3225
3290
|
}
|
3226
|
-
updateUnit(
|
3227
|
-
return this.getInstancePromise(
|
3291
|
+
updateUnit(instanceId) {
|
3292
|
+
return this.getInstancePromise(instanceId, async (logger) => {
|
3293
|
+
const instance = this.workset.getInstance(instanceId);
|
3228
3294
|
this.updateInstanceState({
|
3229
3295
|
id: instance.id,
|
3230
3296
|
parentId: instance.parentId,
|
@@ -3276,7 +3342,7 @@ var RuntimeOperation = class {
|
|
3276
3342
|
const dependencies = this.getInstanceDependencies(instance);
|
3277
3343
|
const dependencyPromises = [];
|
3278
3344
|
for (const dependency of dependencies) {
|
3279
|
-
if (!this.operation.
|
3345
|
+
if (!this.operation.instanceIdsToUpdate.includes(dependency.id)) {
|
3280
3346
|
continue;
|
3281
3347
|
}
|
3282
3348
|
logger.debug(`waiting for dependency: ${dependency.id}`);
|
@@ -3350,7 +3416,7 @@ var RuntimeOperation = class {
|
|
3350
3416
|
this.abortController.signal.throwIfAborted();
|
3351
3417
|
await this.processBeforeDestroyTriggers(state, logger);
|
3352
3418
|
logger.info("destroying unit...");
|
3353
|
-
const [type, name] =
|
3419
|
+
const [type, name] = parseInstanceId3(instanceId);
|
3354
3420
|
await this.runnerBackend.destroy({
|
3355
3421
|
projectId: this.operation.projectId,
|
3356
3422
|
instanceType: type,
|
@@ -3382,7 +3448,7 @@ var RuntimeOperation = class {
|
|
3382
3448
|
totalResourceCount: 0
|
3383
3449
|
});
|
3384
3450
|
logger.info("refreshing unit...");
|
3385
|
-
const [type, name] =
|
3451
|
+
const [type, name] = parseInstanceId3(instanceId);
|
3386
3452
|
await this.runnerBackend.refresh({
|
3387
3453
|
projectId: this.operation.projectId,
|
3388
3454
|
instanceType: type,
|
@@ -3565,11 +3631,13 @@ var OperationManager = class _OperationManager {
|
|
3565
3631
|
id: uuidv72(),
|
3566
3632
|
projectId: request.projectId,
|
3567
3633
|
type: request.type,
|
3568
|
-
|
3569
|
-
|
3634
|
+
requestedInstanceIds: request.instanceIds,
|
3635
|
+
instanceIdsToUpdate: [],
|
3636
|
+
instanceIdsToDestroy: [],
|
3570
3637
|
status: "pending",
|
3571
3638
|
options: {
|
3572
3639
|
forceUpdateDependencies: request.options?.forceUpdateDependencies ?? false,
|
3640
|
+
forceUpdateChildren: request.options?.forceUpdateChildren ?? false,
|
3573
3641
|
destroyDependentInstances: request.options?.destroyDependentInstances ?? true,
|
3574
3642
|
invokeDestroyTriggers: request.options?.invokeDestroyTriggers ?? false,
|
3575
3643
|
deleteUnreachableResources: request.options?.deleteUnreachableResources ?? false,
|