Search in sources :

Example 1 with ComponentIdentifier

use of com.aws.greengrass.componentmanager.models.ComponentIdentifier in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentTaskIntegrationTest method GIVEN_component_with_multiple_versions_WHEN_deploy_sequentially_THEN_stale_version_removed.

/**
 * Deploy versions 1.0.0 through 4.0.0 sequentially. Stale version should be removed. In this test we need to
 * preload recipe/artifact before a deployment so that it can be found locally, because unused local files are
 * removed by cleanup from previous deployment. After this we'll reload local files again so that the following
 * tests can proceed normally.
 */
@Test
@Order(1)
void GIVEN_component_with_multiple_versions_WHEN_deploy_sequentially_THEN_stale_version_removed() throws Exception {
    ComponentIdentifier simpleApp1 = new ComponentIdentifier(SIMPLE_APP_NAME, new Semver("1.0.0"));
    ComponentIdentifier simpleApp2 = new ComponentIdentifier(SIMPLE_APP_NAME, new Semver("2.0.0"));
    // deploy version 1
    Future<DeploymentResult> resultFuture1 = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("SimpleAppJobDoc1.json").toURI(), System.currentTimeMillis());
    DeploymentResult result1 = resultFuture1.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(DeploymentResult.DeploymentStatus.SUCCESSFUL, result1.getDeploymentStatus());
    // version 2 should not exist now. preload it before deployment. we'll do the same for later deployments
    assertRecipeArtifactNotExists(simpleApp2);
    preloadLocalStoreContent(SIMPLE_APP_NAME, "2.0.0");
    // deploy version 2
    Future<DeploymentResult> resultFuture2 = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("SimpleAppJobDoc2.json").toURI(), System.currentTimeMillis());
    DeploymentResult result2 = resultFuture2.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(DeploymentResult.DeploymentStatus.SUCCESSFUL, result2.getDeploymentStatus());
    // both 1 and 2 should exist in component store at this point
    assertRecipeArtifactExists(simpleApp1);
    assertRecipeArtifactExists(simpleApp2);
    // deploy version 3
    preloadLocalStoreContent(SIMPLE_APP_NAME, "3.0.0");
    Future<DeploymentResult> resultFuture3 = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("SimpleAppJobDoc3.json").toURI(), System.currentTimeMillis());
    DeploymentResult result3 = resultFuture3.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(DeploymentResult.DeploymentStatus.SUCCESSFUL, result3.getDeploymentStatus());
    // version 1 removed by preemptive cleanup
    assertRecipeArtifactNotExists(simpleApp1);
    // deploy version 4
    preloadLocalStoreContent(SIMPLE_APP_NAME, "4.0.0");
    Future<DeploymentResult> resultFuture4 = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("SimpleAppJobDoc4.json").toURI(), System.currentTimeMillis());
    DeploymentResult result4 = resultFuture4.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
    assertEquals(DeploymentResult.DeploymentStatus.SUCCESSFUL, result4.getDeploymentStatus());
    // version 2 removed by preemptive cleanup
    assertRecipeArtifactNotExists(simpleApp2);
}
Also used : ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) Semver(com.vdurmont.semver4j.Semver) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentIdentifier

use of com.aws.greengrass.componentmanager.models.ComponentIdentifier in project aws-greengrass-nucleus by aws-greengrass.

the class BaseE2ETestCase method draftComponent.

private static void draftComponent(ComponentIdentifier pkgIdCloud) throws IOException, PackageLoadingException {
    ComponentIdentifier pkgIdLocal = getLocalPackageIdentifier(pkgIdCloud);
    Path testRecipePath = e2eTestPkgStoreDir.resolve("recipes").resolve(getTestRecipeFileName(pkgIdLocal));
    // update recipe
    String content = new String(Files.readAllBytes(testRecipePath), StandardCharsets.UTF_8);
    Set<String> componentNameSet = Arrays.stream(componentsWithArtifactsInS3).map(ComponentIdentifier::getName).collect(Collectors.toSet());
    for (String cloudPkgName : componentNameSet) {
        String localPkgName = removeTestComponentNameCloudSuffix(cloudPkgName);
        content = content.replaceAll("\\{\\{" + localPkgName + "}}", cloudPkgName);
        content = content.replaceAll("\\{\\{" + TEST_COMPONENT_ARTIFACTS_S3_BUCKET_PREFIX + "}}", TEST_COMPONENT_ARTIFACTS_S3_BUCKET);
    }
    testRecipePath = e2eTestPkgStoreDir.resolve("recipes").resolve(getTestRecipeFileName(pkgIdCloud));
    Files.write(testRecipePath, content.getBytes(StandardCharsets.UTF_8));
    CreateComponentVersionResponse createComponentResult = ComponentServiceTestHelper.createComponent(greengrassClient, testRecipePath);
    componentArns.put(pkgIdCloud, createComponentResult.arn());
    assertEquals(pkgIdCloud.getName(), createComponentResult.componentName(), createComponentResult.toString());
    assertEquals(pkgIdCloud.getVersion().toString(), createComponentResult.componentVersion());
}
Also used : Path(java.nio.file.Path) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) CreateComponentVersionResponse(software.amazon.awssdk.services.greengrassv2.model.CreateComponentVersionResponse)

Example 3 with ComponentIdentifier

use of com.aws.greengrass.componentmanager.models.ComponentIdentifier in project aws-greengrass-nucleus by aws-greengrass.

the class BaseE2ETestCase method uploadComponentArtifactToS3.

private static void uploadComponentArtifactToS3(ComponentIdentifier... pkgIds) {
    for (ComponentIdentifier pkgId : pkgIds) {
        ComponentIdentifier pkgIdLocal = getLocalPackageIdentifier(pkgId);
        Path artifactDirPath = e2eTestPkgStoreDir.resolve("artifacts").resolve(pkgIdLocal.getName()).resolve(pkgIdLocal.getVersion().toString());
        File[] artifactFiles = artifactDirPath.toFile().listFiles();
        if (artifactFiles == null) {
            logger.atInfo().kv("component", pkgIdLocal).kv("artifactPath", artifactDirPath.toAbsolutePath()).log("Skip artifact upload. No artifacts found");
        } else {
            for (File artifact : artifactFiles) {
                try {
                    // Path is <bucket>/<component_name>-<component>_<component_version>/<filename>
                    s3Client.putObject(PutObjectRequest.builder().bucket(TEST_COMPONENT_ARTIFACTS_S3_BUCKET).key(pkgIdLocal.getName() + "-" + pkgIdLocal.getVersion().toString() + "/" + artifact.getName()).build(), RequestBody.fromFile(artifact));
                } catch (S3Exception e) {
                    logger.atError().setCause(e).log("Could not upload artifacts to S3");
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) ComponentIdentifier(com.aws.greengrass.componentmanager.models.ComponentIdentifier) File(java.io.File)

Example 4 with ComponentIdentifier

use of com.aws.greengrass.componentmanager.models.ComponentIdentifier 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 5 with ComponentIdentifier

use of com.aws.greengrass.componentmanager.models.ComponentIdentifier 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)

Aggregations

ComponentIdentifier (com.aws.greengrass.componentmanager.models.ComponentIdentifier)121 Test (org.junit.jupiter.api.Test)95 Semver (com.vdurmont.semver4j.Semver)91 ComponentRecipe (com.aws.greengrass.componentmanager.models.ComponentRecipe)38 HashMap (java.util.HashMap)37 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)32 DeploymentPackageConfiguration (com.aws.greengrass.deployment.model.DeploymentPackageConfiguration)32 Path (java.nio.file.Path)27 Map (java.util.Map)25 URI (java.net.URI)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 IOException (java.io.IOException)16 ComponentMetadata (com.aws.greengrass.componentmanager.models.ComponentMetadata)15 ComponentArtifact (com.aws.greengrass.componentmanager.models.ComponentArtifact)14 Topics (com.aws.greengrass.config.Topics)14 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)13 File (java.io.File)13 Topic (com.aws.greengrass.config.Topic)12 NoAvailableComponentVersionException (com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException)10 RecipeMetadata (com.aws.greengrass.componentmanager.models.RecipeMetadata)10