use of com.aws.greengrass.deployment.model.DeploymentTask in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentService method createNewDeployment.
private void createNewDeployment(Deployment deployment) {
logger.atInfo().kv(DEPLOYMENT_ID_LOG_KEY, deployment.getId()).kv("DeploymentType", deployment.getDeploymentType().toString()).log("Received deployment in the queue");
DeploymentTask deploymentTask;
boolean cancellable = true;
if (DEFAULT.equals(deployment.getDeploymentStage())) {
deploymentTask = createDefaultNewDeployment(deployment);
} else {
deploymentTask = createKernelUpdateDeployment(deployment);
cancellable = false;
if (DeploymentType.IOT_JOBS.equals(deployment.getDeploymentType())) {
// Keep track of IoT jobs for de-duplication
IotJobsHelper.getLatestQueuedJobs().addProcessedJob(deployment.getId());
}
}
if (deploymentTask == null) {
return;
}
deploymentStatusKeeper.persistAndPublishDeploymentStatus(deployment.getId(), deployment.getDeploymentType(), JobStatus.IN_PROGRESS.toString(), new HashMap<>());
if (DEFAULT.equals(deployment.getDeploymentStage())) {
try {
context.get(KernelAlternatives.class).cleanupLaunchDirectoryLinks();
deploymentDirectoryManager.createNewDeploymentDirectory(deployment.getDeploymentDocumentObj().getDeploymentId());
deploymentDirectoryManager.writeDeploymentMetadata(deployment);
} catch (IOException ioException) {
logger.atError().log("Unable to create deployment directory", ioException);
updateDeploymentResultAsFailed(deployment, deploymentTask, true, new DeploymentTaskFailureException(ioException));
return;
}
List<String> requiredCapabilities = deployment.getDeploymentDocumentObj().getRequiredCapabilities();
if (requiredCapabilities != null && !requiredCapabilities.isEmpty()) {
List<String> missingCapabilities = requiredCapabilities.stream().filter(reqCapabilities -> !kernel.getSupportedCapabilities().contains(reqCapabilities)).collect(Collectors.toList());
if (!missingCapabilities.isEmpty()) {
updateDeploymentResultAsFailed(deployment, deploymentTask, false, new MissingRequiredCapabilitiesException("The current nucleus version doesn't support one " + "or more capabilities that are required by this deployment: " + String.join(", ", missingCapabilities)));
return;
}
}
if (DeploymentType.LOCAL.equals(deployment.getDeploymentType())) {
try {
copyRecipesAndArtifacts(deployment);
} catch (InvalidRequestException | IOException e) {
logger.atError().log("Error copying recipes and artifacts", e);
updateDeploymentResultAsFailed(deployment, deploymentTask, false, e);
return;
}
}
}
Future<DeploymentResult> process = executorService.submit(deploymentTask);
logger.atInfo().kv("deployment", deployment.getId()).log("Started deployment execution");
currentDeploymentTaskMetadata = new DeploymentTaskMetadata(deploymentTask, process, deployment.getId(), deployment.getDeploymentType(), new AtomicInteger(1), deployment.getDeploymentDocumentObj(), cancellable);
}
Aggregations