use of com.aws.greengrass.deployment.model.Deployment.DeploymentType in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentStatusKeeper method publishPersistedStatusUpdates.
/**
* Invokes the call-backs with persisted deployment status updates for deployments with specified type.
* This is called by IotJobsHelper/MqttJobsHelper when connection is re-established to update cloud of all
* all deployments the device performed when offline
*
* @param type deployment type
*/
public void publishPersistedStatusUpdates(DeploymentType type) {
synchronized (type) {
Topics processedDeployments = getProcessedDeployments();
ArrayList<Topics> deployments = new ArrayList<>();
processedDeployments.forEach(node -> {
Topics deploymentDetails = (Topics) node;
DeploymentType deploymentType = Coerce.toEnum(DeploymentType.class, deploymentDetails.find(DEPLOYMENT_TYPE_KEY_NAME));
if (Objects.equals(deploymentType, type)) {
deployments.add(deploymentDetails);
}
});
// Topics are stored as ConcurrentHashMaps which do not guarantee ordering of elements
// We want the statuses to be updated in the cloud in the order in which they were processed on the device.
// This will be accurate representation of what happened on the device, especially when deployment service
// processes multiple deployments in the order in which they come. Additionally, a customer workflow can
// depend on this order. If Group2 gets successfully updated before Group1 then customer workflow may
// error out.
List<Topics> sortedByTimestamp = deployments.stream().sorted((o1, o2) -> {
if (o1.getModtime() > o2.getModtime()) {
return 1;
}
return -1;
}).collect(Collectors.toList());
List<Function<Map<String, Object>, Boolean>> consumers = getConsumersForDeploymentType(type);
logger.atDebug().kv("deploymentType", type).kv("numberOfSubscribers", consumers.size()).log("Updating status of persisted deployments to subscribers");
for (Topics topics : sortedByTimestamp) {
boolean allConsumersUpdated = consumers.stream().allMatch(consumer -> consumer.apply(topics.toPOJO()));
if (!allConsumersUpdated) {
// If one deployment update fails, exit the loop to ensure the update order.
logger.atDebug().log("Unable to update status of persisted deployments. Retry later");
break;
}
processedDeployments.remove(topics);
}
}
}
use of com.aws.greengrass.deployment.model.Deployment.DeploymentType in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusService method deploymentStatusChanged.
private Boolean deploymentStatusChanged(Map<String, Object> deploymentDetails) {
DeploymentType type = Coerce.toEnum(DeploymentType.class, deploymentDetails.get(DEPLOYMENT_TYPE_KEY_NAME));
if (type == IOT_JOBS || type == SHADOW) {
String status = deploymentDetails.get(DEPLOYMENT_STATUS_KEY_NAME).toString();
if (JobStatus.IN_PROGRESS.toString().equals(status)) {
isDeploymentInProgress.set(true);
return true;
}
logger.atDebug().log("Updating Fleet Status service for deployment with ID: {}", deploymentDetails.get(DEPLOYMENT_ID_KEY_NAME));
isDeploymentInProgress.set(false);
DeploymentInformation deploymentInformation = getDeploymentInformation(deploymentDetails);
updateEventTriggeredFleetStatusData(deploymentInformation);
}
// TODO: [P41214799] Handle local deployment update for FSS
return true;
}
use of com.aws.greengrass.deployment.model.Deployment.DeploymentType 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