Search in sources :

Example 1 with DeploymentPackageConfiguration

use of com.aws.greengrass.deployment.model.DeploymentPackageConfiguration 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 DeploymentPackageConfiguration

use of com.aws.greengrass.deployment.model.DeploymentPackageConfiguration 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 DeploymentPackageConfiguration

use of com.aws.greengrass.deployment.model.DeploymentPackageConfiguration in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentDocumentConverter method buildDeploymentPackageConfigurations.

private static List<DeploymentPackageConfiguration> buildDeploymentPackageConfigurations(LocalOverrideRequest localOverrideRequest, Map<String, String> newRootComponents) {
    Map<String, DeploymentPackageConfiguration> packageConfigurations = new HashMap<>();
    if (localOverrideRequest.getConfigurationUpdate() != null) {
        localOverrideRequest.getConfigurationUpdate().forEach((componentName, configUpdate) -> {
            packageConfigurations.computeIfAbsent(componentName, DeploymentPackageConfiguration::new);
            packageConfigurations.get(componentName).setConfigurationUpdateOperation(configUpdate);
            packageConfigurations.get(componentName).setResolvedVersion(ANY_VERSION);
        });
    }
    // Add to or update root component with version in the configuration lists
    newRootComponents.forEach((rootComponentName, version) -> {
        DeploymentPackageConfiguration pkg = packageConfigurations.computeIfAbsent(rootComponentName, DeploymentPackageConfiguration::new);
        pkg.setResolvedVersion(version);
        pkg.setRootComponent(true);
    });
    if (localOverrideRequest.getComponentToRunWithInfo() != null) {
        localOverrideRequest.getComponentToRunWithInfo().forEach((componentName, runWithInfo) -> {
            if (runWithInfo != null) {
                packageConfigurations.computeIfAbsent(componentName, DeploymentPackageConfiguration::new);
                RunWith runWith = RunWith.builder().posixUser(runWithInfo.getPosixUser()).windowsUser(runWithInfo.getWindowsUser()).systemResourceLimits(convertSystemResourceLimits(runWithInfo.getSystemResourceLimits())).build();
                packageConfigurations.get(componentName).setRunWith(runWith);
            }
        });
    }
    return new ArrayList<>(packageConfigurations.values());
}
Also used : DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RunWith(com.aws.greengrass.deployment.model.RunWith)

Example 4 with DeploymentPackageConfiguration

use of com.aws.greengrass.deployment.model.DeploymentPackageConfiguration in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentDocumentConverterTest method GIVEN_FCS_Deployment_Config_Missing_Fields_When_convert_Then_all_fields_are_converted_with_defaults.

@Test
void GIVEN_FCS_Deployment_Config_Missing_Fields_When_convert_Then_all_fields_are_converted_with_defaults() throws Exception {
    // GIVEN
    String filename = "FcsDeploymentConfig_Missing_Fields.json";
    String json = new String(Files.readAllBytes(Paths.get(getClass().getResource(filename).toURI())));
    Configuration resultConfig = mapper.readValue(json, Configuration.class);
    // WHEN
    DeploymentDocument deploymentDocument = DeploymentDocumentConverter.convertFromDeploymentConfiguration(resultConfig);
    // THEN
    // The following values are from FcsDeploymentConfig_Missing_Fields.json
    assertThat(deploymentDocument.getTimestamp(), is(1604067741583L));
    assertThat(deploymentDocument.getConfigurationArn(), is("arn:aws:greengrass:us-east-1:698947471564:configuration:thinggroup/SampleGroup:2"));
    assertThat(deploymentDocument.getGroupName(), is("thinggroup/SampleGroup"));
    assertThat(deploymentDocument.getRequiredCapabilities(), is(empty()));
    assertThat(deploymentDocument.getDeploymentPackageConfigurationList(), hasSize(1));
    DeploymentPackageConfiguration componentConfiguration = deploymentDocument.getDeploymentPackageConfigurationList().get(0);
    assertThat(componentConfiguration.getPackageName(), equalTo("CustomerApp"));
    assertThat(componentConfiguration.getResolvedVersion(), equalTo("1.0.0"));
    assertNull(componentConfiguration.getConfigurationUpdateOperation());
    // The following fields are not provided in the json so default values should be used.
    // Default for FailureHandlingPolicy should be ROLLBACK
    assertThat(deploymentDocument.getFailureHandlingPolicy(), is(FailureHandlingPolicy.ROLLBACK));
    // Default for ComponentUpdatePolicy is NOTIFY_COMPONENTS with 60 sec as timeout
    assertThat(deploymentDocument.getComponentUpdatePolicy().getComponentUpdatePolicyAction(), is(NOTIFY_COMPONENTS));
    assertThat(deploymentDocument.getComponentUpdatePolicy().getTimeout(), is(60));
}
Also used : DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) Configuration(com.amazon.aws.iot.greengrass.configuration.common.Configuration) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) Test(org.junit.jupiter.api.Test)

Example 5 with DeploymentPackageConfiguration

use of com.aws.greengrass.deployment.model.DeploymentPackageConfiguration in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentDocumentConverterTest method GIVEN_Full_Local_Override_Request_config_update_And_Current_Root_WHEN_convert_THEN_Return_expected_Deployment_Document.

// Existing: ROOT_COMPONENT_TO_REMOVE_1-1.0.0, ROOT_COMPONENT_TO_REMOVE_2-2.0.0, EXISTING_ROOT_COMPONENT-2.0.0
// To Remove: ROOT_COMPONENT_TO_REMOVE_1, ROOT_COMPONENT_TO_REMOVE_2
// To Add: NEW_ROOT_COMPONENT-2.0.0
// To Update: EXISTING_ROOT_COMPONENT-1.0.0 -> 2.0.0
// Result roots: NEW_ROOT_COMPONENT-2.0.0, EXISTING_ROOT_COMPONENT-2.0.0
@Test
void GIVEN_Full_Local_Override_Request_config_update_And_Current_Root_WHEN_convert_THEN_Return_expected_Deployment_Document() throws Exception {
    String dependencyUpdateConfigString = "{ \"MERGE\": { \"Company\": { \"Office\": { \"temperature\": 22 } }, \"path1\": { \"Object2\": { \"key2\": \"val2\" } } }, \"RESET\": [ \"/secret/first\" ] }";
    Map<String, ConfigurationUpdateOperation> updateConfig = new HashMap<>();
    updateConfig.put(DEPENDENCY_COMPONENT, mapper.readValue(dependencyUpdateConfigString, ConfigurationUpdateOperation.class));
    String existingUpdateConfigString = "{ \"MERGE\": {\"foo\": \"bar\"}}";
    updateConfig.put(EXISTING_ROOT_COMPONENT, mapper.readValue(existingUpdateConfigString, ConfigurationUpdateOperation.class));
    Map<String, RunWithInfo> componentToRunWithInfo = new HashMap<>();
    RunWithInfo runWithInfo = new RunWithInfo();
    runWithInfo.setPosixUser("foo:bar");
    runWithInfo.setWindowsUser("testWindowsUser");
    SystemResourceLimits limits = new SystemResourceLimits();
    limits.setMemory(102400L);
    limits.setCpus(1.5);
    runWithInfo.setSystemResourceLimits(limits);
    componentToRunWithInfo.put(NEW_ROOT_COMPONENT, runWithInfo);
    runWithInfo = new RunWithInfo();
    runWithInfo.setPosixUser("1234");
    runWithInfo.setWindowsUser("testWindowsUser2");
    componentToRunWithInfo.put(DEPENDENCY_COMPONENT, runWithInfo);
    // Existing: ROOT_COMPONENT_TO_REMOVE_1-1.0.0, ROOT_COMPONENT_TO_REMOVE_2-2.0.0, EXISTING_ROOT_COMPONENT-2.0.0
    // To Remove: ROOT_COMPONENT_TO_REMOVE_1, ROOT_COMPONENT_TO_REMOVE_2
    // To Add: NEW_ROOT_COMPONENT-2.0.0
    // To Update: EXISTING_ROOT_COMPONENT-1.0.0 -> 2.0.0
    // Result roots: NEW_ROOT_COMPONENT-2.0.0, EXISTING_ROOT_COMPONENT-2.0.0
    LocalOverrideRequest testRequest = LocalOverrideRequest.builder().requestId(REQUEST_ID).requestTimestamp(REQUEST_TIMESTAMP).componentsToMerge(ROOT_COMPONENTS_TO_MERGE).componentsToRemove(Arrays.asList(ROOT_COMPONENT_TO_REMOVE_1, ROOT_COMPONENT_TO_REMOVE_2)).configurationUpdate(updateConfig).componentToRunWithInfo(componentToRunWithInfo).build();
    DeploymentDocument deploymentDocument = DeploymentDocumentConverter.convertFromLocalOverrideRequestAndRoot(testRequest, CURRENT_ROOT_COMPONENTS);
    assertThat(deploymentDocument.getFailureHandlingPolicy(), is(FailureHandlingPolicy.DO_NOTHING));
    assertThat(deploymentDocument.getDeploymentId(), is(REQUEST_ID));
    assertThat(deploymentDocument.getTimestamp(), is(REQUEST_TIMESTAMP));
    assertThat(deploymentDocument.getRootPackages(), is(Arrays.asList(EXISTING_ROOT_COMPONENT, NEW_ROOT_COMPONENT)));
    List<DeploymentPackageConfiguration> deploymentPackageConfigurations = deploymentDocument.getDeploymentPackageConfigurationList();
    assertThat(deploymentPackageConfigurations.size(), is(3));
    // verify deploymentConfigs
    DeploymentPackageConfiguration existingRootComponentConfig = deploymentPackageConfigurations.stream().filter(e -> e.getPackageName().equals(EXISTING_ROOT_COMPONENT)).findAny().get();
    assertThat(existingRootComponentConfig.getResolvedVersion(), is("2.0.0"));
    assertThat(existingRootComponentConfig.getConfigurationUpdateOperation(), is(mapper.readValue(existingUpdateConfigString, ConfigurationUpdateOperation.class)));
    DeploymentPackageConfiguration newRootComponentConfig = deploymentPackageConfigurations.stream().filter(e -> e.getPackageName().equals(NEW_ROOT_COMPONENT)).findAny().get();
    assertThat(newRootComponentConfig.getResolvedVersion(), is("2.0.0"));
    assertNull(newRootComponentConfig.getConfigurationUpdateOperation());
    assertEquals("foo:bar", newRootComponentConfig.getRunWith().getPosixUser());
    assertEquals("testWindowsUser", newRootComponentConfig.getRunWith().getWindowsUser());
    assertEquals(1.5, newRootComponentConfig.getRunWith().getSystemResourceLimits().getCpus());
    assertEquals(102400L, newRootComponentConfig.getRunWith().getSystemResourceLimits().getMemory());
    DeploymentPackageConfiguration DependencyComponentConfig = deploymentPackageConfigurations.stream().filter(e -> e.getPackageName().equals(DEPENDENCY_COMPONENT)).findAny().get();
    assertEquals(DependencyComponentConfig.getConfigurationUpdateOperation(), mapper.readValue(dependencyUpdateConfigString, ConfigurationUpdateOperation.class));
    assertThat(DependencyComponentConfig.getResolvedVersion(), is("*"));
}
Also used : ConfigurationUpdateOperation(com.aws.greengrass.deployment.model.ConfigurationUpdateOperation) DeploymentPackageConfiguration(com.aws.greengrass.deployment.model.DeploymentPackageConfiguration) RunWithInfo(software.amazon.awssdk.aws.greengrass.model.RunWithInfo) LocalOverrideRequest(com.aws.greengrass.deployment.model.LocalOverrideRequest) HashMap(java.util.HashMap) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) SystemResourceLimits(software.amazon.awssdk.aws.greengrass.model.SystemResourceLimits) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentPackageConfiguration (com.aws.greengrass.deployment.model.DeploymentPackageConfiguration)37 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)33 HashMap (java.util.HashMap)33 Test (org.junit.jupiter.api.Test)32 ComponentIdentifier (com.aws.greengrass.componentmanager.models.ComponentIdentifier)31 ComponentRecipe (com.aws.greengrass.componentmanager.models.ComponentRecipe)21 Semver (com.vdurmont.semver4j.Semver)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 Map (java.util.Map)19 ConfigurationUpdateOperation (com.aws.greengrass.deployment.model.ConfigurationUpdateOperation)11 ComponentMetadata (com.aws.greengrass.componentmanager.models.ComponentMetadata)8 Path (java.nio.file.Path)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Requirement (com.vdurmont.semver4j.Requirement)5 UpdateBehaviorTree (com.aws.greengrass.config.UpdateBehaviorTree)4 ArrayList (java.util.ArrayList)4 DependencyProperties (com.amazon.aws.iot.greengrass.component.common.DependencyProperties)2 Configuration (com.amazon.aws.iot.greengrass.configuration.common.Configuration)2 NoAvailableComponentVersionException (com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException)2 PackagingException (com.aws.greengrass.componentmanager.exceptions.PackagingException)2