Search in sources :

Example 1 with DeploymentDocument

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()));
}
Also used : DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) Path(java.nio.file.Path) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) ArrayList(java.util.ArrayList) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 2 with DeploymentDocument

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());
}
Also used : DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) ArrayList(java.util.ArrayList) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) FileMatchers.anExistingFile(org.hamcrest.io.FileMatchers.anExistingFile) File(java.io.File) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 3 with DeploymentDocument

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);
    }
}
Also used : DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) DeploymentConfigMerger(com.aws.greengrass.deployment.DeploymentConfigMerger) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) ExecutionException(java.util.concurrent.ExecutionException) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)

Example 4 with DeploymentDocument

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;
}
Also used : UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) CompletableFuture(java.util.concurrent.CompletableFuture) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) UpdateAction(com.aws.greengrass.lifecyclemanager.UpdateAction) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) KernelUpdateActivator(com.aws.greengrass.deployment.activator.KernelUpdateActivator) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) DeploymentActivator(com.aws.greengrass.deployment.activator.DeploymentActivator)

Example 5 with DeploymentDocument

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;
}
Also used : DeploymentConfigurationValidationPolicy(software.amazon.awssdk.services.greengrassv2.model.DeploymentConfigurationValidationPolicy) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) Deployment(com.aws.greengrass.deployment.model.Deployment)

Aggregations

DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)55 Test (org.junit.jupiter.api.Test)47 HashMap (java.util.HashMap)35 DeploymentPackageConfiguration (com.aws.greengrass.deployment.model.DeploymentPackageConfiguration)34 ComponentIdentifier (com.aws.greengrass.componentmanager.models.ComponentIdentifier)31 ComponentRecipe (com.aws.greengrass.componentmanager.models.ComponentRecipe)20 Semver (com.vdurmont.semver4j.Semver)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 Map (java.util.Map)19 Path (java.nio.file.Path)12 ConfigurationUpdateOperation (com.aws.greengrass.deployment.model.ConfigurationUpdateOperation)10 ComponentMetadata (com.aws.greengrass.componentmanager.models.ComponentMetadata)8 Configuration (com.amazon.aws.iot.greengrass.configuration.common.Configuration)7 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)6 DeploymentActivatorFactory (com.aws.greengrass.deployment.activator.DeploymentActivatorFactory)5 ComponentUpdatePolicy (com.aws.greengrass.deployment.model.ComponentUpdatePolicy)5 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)5 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Requirement (com.vdurmont.semver4j.Requirement)5