use of com.aws.greengrass.deployment.model.DeploymentResult.DeploymentStatus in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentService method finishCurrentDeployment.
@SuppressWarnings("PMD.NullAssignment")
private void finishCurrentDeployment() throws InterruptedException {
logger.atInfo().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId()).log("Current deployment finished");
try {
// No timeout is set here. Detection of error is delegated to downstream components like
// dependency resolver, package downloader, kernel which will have more visibility
// if something is going wrong
DeploymentResult result = currentDeploymentTaskMetadata.getDeploymentResultFuture().get();
if (result != null) {
DeploymentStatus deploymentStatus = result.getDeploymentStatus();
Map<String, String> statusDetails = new HashMap<>();
statusDetails.put(DEPLOYMENT_DETAILED_STATUS_KEY, deploymentStatus.name());
if (DeploymentStatus.SUCCESSFUL.equals(deploymentStatus)) {
// Add the root packages of successful deployment to the configuration
persistGroupToRootComponents(currentDeploymentTaskMetadata.getDeploymentDocument());
deploymentStatusKeeper.persistAndPublishDeploymentStatus(currentDeploymentTaskMetadata.getDeploymentId(), currentDeploymentTaskMetadata.getDeploymentType(), JobStatus.SUCCEEDED.toString(), statusDetails);
if (currentDeploymentTaskMetadata.getDeploymentTask() instanceof KernelUpdateDeploymentTask) {
try {
kernel.getContext().get(KernelAlternatives.class).activationSucceeds();
} catch (IOException e) {
logger.atError().log("Failed to reset Nucleus activate directory", e);
}
}
deploymentDirectoryManager.persistLastSuccessfulDeployment();
} else {
if (result.getFailureCause() != null) {
statusDetails.put(DEPLOYMENT_FAILURE_CAUSE_KEY, result.getFailureCause().getMessage());
}
if (FAILED_ROLLBACK_NOT_REQUESTED.equals(result.getDeploymentStatus())) {
// Update the groupToRootComponents mapping in config for the case where there is no rollback
// and now the components deployed for the current group are not the same as before deployment
persistGroupToRootComponents(currentDeploymentTaskMetadata.getDeploymentDocument());
}
deploymentStatusKeeper.persistAndPublishDeploymentStatus(currentDeploymentTaskMetadata.getDeploymentId(), currentDeploymentTaskMetadata.getDeploymentType(), JobStatus.FAILED.toString(), statusDetails);
if (currentDeploymentTaskMetadata.getDeploymentTask() instanceof KernelUpdateDeploymentTask) {
try {
kernel.getContext().get(KernelAlternatives.class).rollbackCompletes();
} catch (IOException e) {
logger.atError().log("Failed to reset Nucleus rollback directory", e);
}
}
deploymentDirectoryManager.persistLastFailedDeployment();
}
}
} catch (ExecutionException e) {
Throwable t = e.getCause();
if (t instanceof InterruptedException) {
logger.atInfo().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId()).log("Deployment task is interrupted");
} else {
// This code path can only occur when DeploymentTask throws unchecked exception.
logger.atError().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId()).setCause(t).log("Deployment task throws unknown exception");
HashMap<String, String> statusDetails = new HashMap<>();
statusDetails.put("error", t.getMessage());
deploymentStatusKeeper.persistAndPublishDeploymentStatus(currentDeploymentTaskMetadata.getDeploymentId(), currentDeploymentTaskMetadata.getDeploymentType(), JobStatus.FAILED.toString(), statusDetails);
deploymentDirectoryManager.persistLastFailedDeployment();
}
} catch (CancellationException e) {
logger.atInfo().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId()).log("Deployment task is cancelled");
}
// Setting this to null to indicate there is not current deployment being processed
// Did not use optionals over null due to performance
currentDeploymentTaskMetadata = null;
}
Aggregations