use of com.aws.greengrass.deployment.model.DeploymentDocument in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentManagerE2ETest method GIVEN_package_with_s3_artifacts_WHEN_deployed_THEN_download_artifacts_from_customer_s3_and_perform_integrity_check.
@Test
@Order(2)
void GIVEN_package_with_s3_artifacts_WHEN_deployed_THEN_download_artifacts_from_customer_s3_and_perform_integrity_check() throws Exception {
String appWithS3ArtifactsPackageName = getTestComponentNameInCloud("AppWithS3Artifacts");
List<String> rootPackageList = new ArrayList<>();
rootPackageList.add(appWithS3ArtifactsPackageName);
List<DeploymentPackageConfiguration> configList = new ArrayList<>();
configList.add(new DeploymentPackageConfiguration(appWithS3ArtifactsPackageName, true, "1.0.0"));
DeploymentDocument testDeploymentDocument = DeploymentDocument.builder().deploymentId("test").timestamp(12345678L).deploymentPackageConfigurationList(configList).failureHandlingPolicy(FailureHandlingPolicy.DO_NOTHING).groupName("mockGroup").build();
List<ComponentIdentifier> resolutionResult = dependencyResolver.resolveDependencies(testDeploymentDocument, new HashMap<>());
Future<Void> testFuture = componentManager.preparePackages(resolutionResult);
testFuture.get(10, TimeUnit.SECONDS);
// Validate artifact was downloaded and integrity check passed
assertThat(componentStorePath.toFile(), anExistingDirectory());
assertThat(componentStorePath.resolve(RECIPE_DIRECTORY).toFile(), anExistingDirectory());
assertThat(componentStorePath.resolve(ARTIFACT_DIRECTORY).toFile(), anExistingDirectory());
String testResourceRecipeFilename = getTestComponentNameInCloud(appWithS3ArtifactsPackageName) + "-1.0.0" + ".yaml";
assertThat(componentStorePath.resolve(RECIPE_DIRECTORY).resolve(PreloadComponentStoreHelper.getRecipeStorageFilenameFromTestSource(testResourceRecipeFilename)).toFile(), anExistingFile());
Path artifactTxt = componentStorePath.resolve(ARTIFACT_DIRECTORY).resolve(appWithS3ArtifactsPackageName).resolve("1.0.0").resolve("artifact.txt");
assertThat(artifactTxt.toFile(), anExistingFile());
assertThat(artifactTxt, hasPermission(FileSystemPermission.builder().ownerRead(true).groupRead(true).otherRead(true).ownerWrite(!SystemUtils.USER_NAME.equals(Platform.getInstance().getPrivilegedUser())).ownerExecute(true).groupExecute(true).build()));
}
use of com.aws.greengrass.deployment.model.DeploymentDocument in project aws-greengrass-nucleus by aws-greengrass.
the class ComponentManagerE2ETest method GIVEN_package_identifier_WHEN_resolve_dependencies_and_prepare_THEN_package_and_dependencies_downloaded_with_artifacts.
@Test
@Order(1)
void GIVEN_package_identifier_WHEN_resolve_dependencies_and_prepare_THEN_package_and_dependencies_downloaded_with_artifacts() throws Exception {
List<String> rootPackageList = new ArrayList<>();
rootPackageList.add(kernelIntegTestPkgName);
List<DeploymentPackageConfiguration> configList = new ArrayList<>();
configList.add(new DeploymentPackageConfiguration(kernelIntegTestPkgName, true, "1.0.0"));
DeploymentDocument testDeploymentDocument = DeploymentDocument.builder().deploymentId("test").timestamp(12345678L).deploymentPackageConfigurationList(configList).failureHandlingPolicy(FailureHandlingPolicy.DO_NOTHING).groupName("mockGroup").build();
List<ComponentIdentifier> resolutionResult = dependencyResolver.resolveDependencies(testDeploymentDocument, new HashMap<>());
Future<Void> testFuture = componentManager.preparePackages(resolutionResult);
testFuture.get(10, TimeUnit.SECONDS);
assertThat(componentStorePath.toFile(), anExistingDirectory());
assertThat(componentStorePath.resolve(RECIPE_DIRECTORY).toFile(), anExistingDirectory());
assertThat(componentStorePath.resolve(ARTIFACT_DIRECTORY).toFile(), anExistingDirectory());
File downloadedRecipe = componentStorePath.resolve(RECIPE_DIRECTORY).resolve(PreloadComponentStoreHelper.getRecipeStorageFilenameFromTestSource(getTestComponentNameInCloud("KernelIntegTestDependency") + "-1.0.0.yaml")).toFile();
assertThat(downloadedRecipe, anExistingFile());
assertThat(componentStorePath.resolve(componentStorePath.resolve(RECIPE_DIRECTORY).resolve(PreloadComponentStoreHelper.getRecipeStorageFilenameFromTestSource(getTestComponentNameInCloud("Log") + "-2.0.0" + ".yaml"))).toFile(), anExistingFile());
assertThat(componentStorePath.resolve(ARTIFACT_DIRECTORY).resolve(kernelIntegTestPkgName).resolve("1.0.0").resolve("kernel_integ_test_artifact.txt").toFile(), anExistingFile());
}
use of com.aws.greengrass.deployment.model.DeploymentDocument in project aws-greengrass-nucleus by aws-greengrass.
the class DefaultActivator method activate.
@Override
@SuppressWarnings("PMD.PrematureDeclaration")
public void activate(Map<String, Object> newConfig, Deployment deployment, CompletableFuture<DeploymentResult> totallyCompleteFuture) {
Map<String, Object> serviceConfig;
if (newConfig.containsKey(SERVICES_NAMESPACE_TOPIC)) {
serviceConfig = (Map<String, Object>) newConfig.get(SERVICES_NAMESPACE_TOPIC);
} else {
serviceConfig = new HashMap<>();
}
DeploymentDocument deploymentDocument = deployment.getDeploymentDocumentObj();
if (isAutoRollbackRequested(deploymentDocument) && !takeConfigSnapshot(totallyCompleteFuture)) {
return;
}
DeploymentConfigMerger.AggregateServicesChangeManager servicesChangeManager = new DeploymentConfigMerger.AggregateServicesChangeManager(kernel, serviceConfig);
// Get the timestamp before updateMap(). It will be used to check whether services have started.
long mergeTime = System.currentTimeMillis();
updateConfiguration(deploymentDocument.getTimestamp(), newConfig);
// wait until topic listeners finished processing mergeMap changes.
Throwable setDesiredStateFailureCause = kernel.getContext().runOnPublishQueueAndWait(() -> {
// polling to wait for all services to be started.
servicesChangeManager.startNewServices();
// Close unloadable service instances and initiate with new config
servicesChangeManager.replaceUnloadableService();
// Restart any services that may have been broken before this deployment
// This is added to allow deployments to fix broken services
servicesChangeManager.reinstallBrokenServices();
});
if (setDesiredStateFailureCause != null) {
handleFailure(servicesChangeManager, deploymentDocument, totallyCompleteFuture, setDesiredStateFailureCause);
return;
}
try {
Set<GreengrassService> servicesToTrack = servicesChangeManager.servicesToTrack();
logger.atDebug(MERGE_CONFIG_EVENT_KEY).kv("serviceToTrack", servicesToTrack).kv("mergeTime", mergeTime).log("Applied new service config. Waiting for services to complete update");
waitForServicesToStart(servicesToTrack, mergeTime);
logger.atDebug(MERGE_CONFIG_EVENT_KEY).log("new/updated services are running, will now remove old services");
servicesChangeManager.removeObsoleteServices();
logger.atInfo(MERGE_CONFIG_EVENT_KEY).kv(DEPLOYMENT_ID_LOG_KEY, deploymentDocument.getDeploymentId()).log("All services updated");
totallyCompleteFuture.complete(new DeploymentResult(DeploymentResult.DeploymentStatus.SUCCESSFUL, null));
} catch (InterruptedException | ExecutionException | ServiceUpdateException | ServiceLoadException e) {
handleFailure(servicesChangeManager, deploymentDocument, totallyCompleteFuture, e);
}
}
use of com.aws.greengrass.deployment.model.DeploymentDocument in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentConfigMerger method mergeInNewConfig.
/**
* Merge in new configuration values and new services.
*
* @param deployment deployment object
* @param newConfig the map of new configuration
* @return future which completes only once the config is merged and all the services in the config are running
*/
public Future<DeploymentResult> mergeInNewConfig(Deployment deployment, Map<String, Object> newConfig) {
CompletableFuture<DeploymentResult> totallyCompleteFuture = new CompletableFuture<>();
DeploymentActivator activator;
try {
activator = kernel.getContext().get(DeploymentActivatorFactory.class).getDeploymentActivator(newConfig);
} catch (ServiceUpdateException | ComponentConfigurationValidationException e) {
// Failed to pre-process new config, no rollback needed
logger.atError().setEventType(MERGE_ERROR_LOG_EVENT_KEY).setCause(e).log("Failed to process new configuration for activation");
totallyCompleteFuture.complete(new DeploymentResult(DeploymentResult.DeploymentStatus.FAILED_NO_STATE_CHANGE, e));
return totallyCompleteFuture;
}
boolean ggcRestart = false;
if (activator instanceof KernelUpdateActivator) {
ggcRestart = true;
}
DeploymentDocument deploymentDocument = deployment.getDeploymentDocumentObj();
if (DeploymentComponentUpdatePolicyAction.NOTIFY_COMPONENTS.equals(deploymentDocument.getComponentUpdatePolicy().getComponentUpdatePolicyAction())) {
kernel.getContext().get(UpdateSystemPolicyService.class).addUpdateAction(deploymentDocument.getDeploymentId(), new UpdateAction(deploymentDocument.getDeploymentId(), ggcRestart, deploymentDocument.getComponentUpdatePolicy().getTimeout(), () -> updateActionForDeployment(newConfig, deployment, activator, totallyCompleteFuture)));
} else {
logger.atInfo().log("Deployment is configured to skip update policy check," + " not waiting for disruptable time to update");
updateActionForDeployment(newConfig, deployment, activator, totallyCompleteFuture);
}
return totallyCompleteFuture;
}
use of com.aws.greengrass.deployment.model.DeploymentDocument in project aws-greengrass-nucleus by aws-greengrass.
the class DynamicComponentConfigurationValidatorTest method createTestDeployment.
private Deployment createTestDeployment() {
DeploymentDocument doc = new DeploymentDocument();
doc.setConfigurationArn("test_deployment_id");
doc.setTimestamp(DEFAULT_DEPLOYMENT_TIMESTAMP);
Deployment deployment = new Deployment();
DeploymentConfigurationValidationPolicy configurationValidationPolicy = DeploymentConfigurationValidationPolicy.builder().timeoutInSeconds(20).build();
doc.setConfigurationValidationPolicy(configurationValidationPolicy);
deployment.setDeploymentDocumentObj(doc);
return deployment;
}
Aggregations