Skip to content

GPII-3759: Bodge quality fix to allow language solution to have its settings applied last #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 54 additions & 26 deletions gpii/node_modules/lifecycleManager/src/LifecycleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,30 @@ var gpii = fluid.registerNamespace("gpii");
return restorePromise;
};

/** Iterates through a block of lifecycleInstructions in an order induced by their "settingsApplicationPriority"
* fields. This ensures that solutions' settingsHandlers are invoked in an appropriate order for the terms of
* GPII-3759.
* @param {Object} lifecycleInstructions - The `lifecycleInstructions` member of a configuration's worth of payloads
* @param {Object} solutionsRegistryEntries - The `solutionsRegistryEntries' block of the final payload
* @param {Function} solutionFunc - A function with signature (solution, solutionId) that will be executed
* for each solution in the sorted payload
*/
gpii.lifecycleManager.lifecycleInstructionsByPriority = function (lifecycleInstructions, solutionsRegistryEntries,
solutionFunc) {
var priorityRecords = [];
fluid.each(lifecycleInstructions, function (solution, solutionId) {
priorityRecords.push({
priority: fluid.parsePriority(solution.settingsApplicationPriority, 0, false, "solutions registry entry"),
namespace: solutionId
});
});
fluid.sortByPriority(priorityRecords);
priorityRecords.forEach(function (sortedRecord) {
var solutionId = sortedRecord.namespace;
solutionFunc(lifecycleInstructions[solutionId], solutionId);
});
};

/**
* Apply lifecycle instructions to the local computer.
* @param {Component} that - A instance of gpii.lifecycleManager.
Expand All @@ -1199,14 +1223,16 @@ var gpii = fluid.registerNamespace("gpii");
var appliedSolutions = userSession.model.appliedSolutions;

var promises = [];
fluid.each(lifecycleInstructions, function (solution, solutionId) {
var sol = fluid.copy(solution);
if (appliedSolutions[solutionId]) {
// merge already applied settings with the updates
sol = fluid.extend(true, {}, appliedSolutions[solutionId], sol);
gpii.lifecycleManager.lifecycleInstructionsByPriority(lifecycleInstructions,
finalPayload.solutionsRegistryEntries, function (solution, solutionId) {
var sol = fluid.copy(solution);
if (appliedSolutions[solutionId]) {
// merge already applied settings with the updates
sol = fluid.extend(true, {}, appliedSolutions[solutionId], sol);
}
promises.push(that.applySolution(solutionId, sol, userSession, [ "update" ], "update"));
}
promises.push(that.applySolution(solutionId, sol, userSession, [ "update" ], "update"));
});
);
return fluid.promise.sequence(promises);
};

Expand All @@ -1230,25 +1256,27 @@ var gpii = fluid.registerNamespace("gpii");
// When "stop" is called this payload will be used to restore the settings back to their
// original state.
var tasks = [];
fluid.each(lifecycleInstructions, function (solution, solutionId) {
tasks.push(function () {
if (!fluid.isDestroyed(that)) { // See above comment for GPII-580
// check the current state of the solution to decide whether we should run the
// "update", "start" or "stop" directive
return that.getSolutionRunningState(solutionId, solution, userSession);
}
});
tasks.push(function () {
if (!fluid.isDestroyed(that)) { // See above comment for GPII-580
// if solution is already running, call "update" directive - else use "start" directive
var isRunning = userSession.model.runningOnLogin[solutionId];
var actions = gpii.lifecycleManager.calculateLifecycleActions(isRunning, solution.active);

// build structure for returned values (for later reset)
return that.applySolution(solutionId, solution, userSession, actions, "start");
}
});
});
gpii.lifecycleManager.lifecycleInstructionsByPriority(lifecycleInstructions,
finalPayload.solutionsRegistryEntries, function (solution, solutionId) {
tasks.push(function () {
if (!fluid.isDestroyed(that)) { // See above comment for GPII-580
// check the current state of the solution to decide whether we should run the
// "update", "start" or "stop" directive
return that.getSolutionRunningState(solutionId, solution, userSession);
}
});
tasks.push(function () {
if (!fluid.isDestroyed(that)) { // See above comment for GPII-580
// if solution is already running, call "update" directive - else use "start" directive
var isRunning = userSession.model.runningOnLogin[solutionId];
var actions = gpii.lifecycleManager.calculateLifecycleActions(isRunning, solution.active);

// build structure for returned values (for later reset)
return that.applySolution(solutionId, solution, userSession, actions, "start");
}
});
}
);
// Note that these promises are only sequenced for their side-effects (the ones on user session state within applySolution and on the system at large
// via the settings handlers)
return fluid.promise.sequence(tasks);
Expand Down
1 change: 1 addition & 0 deletions testData/solutions/win32.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6549,6 +6549,7 @@
}
]
},
"settingsApplicationPriority": "last",
"settingsHandlers": {
"configure1": {
"type": "gpii.windows.registrySettingsHandler",
Expand Down