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);
}
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());
}
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");
}
}
}
}
}
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()));
}
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());
}
Aggregations