Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ public void activate(Map<String, Object> newConfig, Deployment deployment,
kernelAlternatives.prepareBootstrap(deploymentDocument.getDeploymentId());
} catch (IOException e) {
// TODO: better handling of error codes for different IO operations
rollback(deployment, e);
rollback(deployment, e, false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops :(

lifecycle.startupAllServices();

totallyCompleteFuture.complete(
new DeploymentResult(DeploymentResult.DeploymentStatus.FAILED_NO_STATE_CHANGE,
new DeploymentException("Unable to process deployment. Greengrass could not prepare for"
+ " bootstrap.", e)));
return;
}

Expand All @@ -105,11 +111,11 @@ public void activate(Map<String, Object> newConfig, Deployment deployment,

kernel.shutdown(30, exitCode == REQUEST_REBOOT ? REQUEST_REBOOT : REQUEST_RESTART);
} catch (ServiceUpdateException | IOException e) {
rollback(deployment, e);
rollback(deployment, e, true);
}
}

void rollback(Deployment deployment, Throwable failureCause) {
void rollback(Deployment deployment, Throwable failureCause, boolean requiresRestart) {
logger.atInfo(MERGE_CONFIG_EVENT_KEY, failureCause)
.kv(DEPLOYMENT_ID_LOG_KEY, deployment.getGreengrassDeploymentId())
.log("Rolling back failed deployment");
Expand All @@ -120,10 +126,13 @@ void rollback(Deployment deployment, Throwable failureCause) {
deployment.setErrorTypes(errorReport.getRight());
deployment.setStageDetails(Utils.generateFailureMessage(failureCause));

final boolean bootstrapOnRollbackRequired = kernelAlternatives.prepareBootstrapOnRollbackIfNeeded(
kernel.getContext(), deploymentDirectoryManager, bootstrapManager);
// Persist deployment metadata only if restart is required
if (requiresRestart) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: when bootstrap prepared failed, and we don't persist the deployment metadata, if we use systemctl to restart Nucleus, would it still look for deployment metadata when restarting?

Copy link
Copy Markdown
Member Author

@alter-mage alter-mage Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will still persist deployment metadata but only in the launch directory of the deployment that failed. After rollback, the launch directory will revert back to previous one (before current deployment was received). So after restart, yes, Nucleus will still look for deployment metadata but its fine if it does not find it and will launch in default mode.

final boolean bootstrapOnRollbackRequired = kernelAlternatives.prepareBootstrapOnRollbackIfNeeded(
kernel.getContext(), deploymentDirectoryManager, bootstrapManager);

deployment.setDeploymentStage(bootstrapOnRollbackRequired ? ROLLBACK_BOOTSTRAP : KERNEL_ROLLBACK);
deployment.setDeploymentStage(bootstrapOnRollbackRequired ? ROLLBACK_BOOTSTRAP : KERNEL_ROLLBACK);
}

try {
deploymentDirectoryManager.writeDeploymentMetadata(deployment);
Expand All @@ -135,7 +144,10 @@ void rollback(Deployment deployment, Throwable failureCause) {
} catch (IOException e) {
logger.atError().setCause(e).log("Failed to set up rollback directory");
}

// Restart Kernel regardless and rely on loader orchestration
kernel.shutdown(30, REQUEST_RESTART);
if (requiresRestart) {
kernel.shutdown(30, REQUEST_RESTART);
}
}
}