use of com.aws.greengrass.deployment.model.DeploymentResult in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_a_deployment_has_component_use_system_config_WHEN_submitted_THEN_system_configs_are_interpolated.
@Test
@Order(7)
void GIVEN_a_deployment_has_component_use_system_config_WHEN_submitted_THEN_system_configs_are_interpolated() throws Exception {
CountDownLatch stdoutLatch = new CountDownLatch(1);
// Set up stdout listener to capture stdout for verify #2 interpolation
List<String> stdouts = new CopyOnWriteArrayList<>();
Consumer<GreengrassLogMessage> listener = m -> {
String messageOnStdout = m.getMessage();
if (messageOnStdout != null && messageOnStdout.contains("aws.iot.gg.test.integ.SystemConfigTest output")) {
stdouts.add(messageOnStdout);
stdoutLatch.countDown();
}
};
Slf4jLogAdapter.addGlobalListener(listener);
try {
/*
* 1st deployment. Default Config.
*/
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("SystemConfigTest_DeployDocument.json").toURI(), System.currentTimeMillis());
resultFuture.get(10, TimeUnit.SECONDS);
// The main comes from SystemConfigTest_DeployDocument.json
String mainComponentName = "aws.iot.gg.test.integ.SystemConfigTest";
String mainComponentNameVer = "0.0.1";
// The dependency is specified in aws.iot.gg.test.integ.SystemConfigTest-0.1.1
String otherComponentName = "GreenSignal";
String otherComponentVer = "1.0.0";
assertThat("has output", stdoutLatch.await(STDOUT_TIMEOUT, TimeUnit.SECONDS), is(true));
// verify interpolation result
assertThat(stdouts.get(0), containsString("I'm kernel's root path: " + rootDir.toAbsolutePath()));
assertThat(stdouts.get(0), containsString("I'm my own artifact path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACT_DIRECTORY).resolve(mainComponentName).resolve(mainComponentNameVer).toAbsolutePath()));
assertTrue(stdouts.get(0).contains("I'm my own artifact decompressed path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACTS_DECOMPRESSED_DIRECTORY).resolve(mainComponentName).resolve(mainComponentNameVer).toAbsolutePath()));
assertThat(stdouts.get(0), containsString("I'm GreenSignal's artifact path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACT_DIRECTORY).resolve(otherComponentName).resolve(otherComponentVer).toAbsolutePath()));
assertThat(stdouts.get(0), containsString("I'm GreenSignal's artifact decompressed path: " + rootDir.resolve("packages").resolve(ComponentStore.ARTIFACTS_DECOMPRESSED_DIRECTORY).resolve(otherComponentName).resolve(otherComponentVer).toAbsolutePath()));
} finally {
Slf4jLogAdapter.removeGlobalListener(listener);
}
}
use of com.aws.greengrass.deployment.model.DeploymentResult in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_do_nothing_THEN_service_stays_broken.
/**
* First deployment starts some services. Second deployment tries to add a service that breaks and removes an
* existing service but the failure handling policy is to do nothing As a result, no corrective action will be taken
* on failure
*
* @throws Exception
*/
@Test
@Order(10)
void GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_do_nothing_THEN_service_stays_broken(ExtensionContext context) throws Exception {
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("YellowAndRedSignal.json").toURI(), System.currentTimeMillis());
resultFuture.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
List<String> services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, YellowSignal and RedSignal
assertEquals(4, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "YellowSignal", "RedSignal"));
groupToRootComponentsTopics.lookupTopics("RedSignal").replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
groupToRootComponentsTopics.lookupTopics("YellowSignal").replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
ignoreExceptionUltimateCauseOfType(context, ServiceUpdateException.class);
preloadLocalStoreContent();
resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("FailureDoNothingDeployment.json").toURI(), System.currentTimeMillis());
DeploymentResult result = resultFuture.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, RedSignal, BreakingService, Mosquitto and GreenSignal
assertEquals(6, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "RedSignal", "BreakingService", "Mosquitto", "GreenSignal"));
assertEquals(State.BROKEN, kernel.locate("BreakingService").getState());
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_NOT_REQUESTED, result.getDeploymentStatus());
}
use of com.aws.greengrass.deployment.model.DeploymentResult in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_a_deployment_with_dependency_has_config_WHEN_submitted_THEN_dependency_configs_are_interpolated.
@Test
@Order(5)
void GIVEN_a_deployment_with_dependency_has_config_WHEN_submitted_THEN_dependency_configs_are_interpolated() throws Exception {
// Set up stdout listener to capture stdout for verify #2 interpolation
countDownLatch = new CountDownLatch(1);
List<String> stdouts = new CopyOnWriteArrayList<>();
Consumer<GreengrassLogMessage> listener = m -> {
String messageOnStdout = m.getMessage();
if (messageOnStdout != null && messageOnStdout.contains("aws.iot.gg.test.integ.ComponentConfigTestMain output")) {
countDownLatch.countDown();
stdouts.add(messageOnStdout);
}
};
Slf4jLogAdapter.addGlobalListener(listener);
try {
/*
* 1st deployment. Default Config.
*/
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("CrossComponentConfigTest_DeployDocument.json").toURI(), System.currentTimeMillis());
resultFuture.get(10, TimeUnit.SECONDS);
// verify interpolation result
assertThat("The stdout should be captured within seconds.", countDownLatch.await(STDOUT_TIMEOUT, TimeUnit.SECONDS));
String stdout = stdouts.get(0);
assertThat(stdout, containsString("Value for /singleLevelKey: default value of singleLevelKey."));
assertThat(stdout, containsString("Value for /path/leafKey: default value of /path/leafKey."));
assertThat(stdout, containsString("Value for /listKey/0: item1."));
assertThat(stdout, containsString("Value for /emptyStringKey: ."));
} finally {
Slf4jLogAdapter.removeGlobalListener(listener);
}
}
use of com.aws.greengrass.deployment.model.DeploymentResult 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.deployment.model.DeploymentResult in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentTaskIntegrationTest method GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_rollback_THEN_services_are_rolled_back.
/**
* First deployment starts some services. Second deployment tries to add a service that breaks and removes an
* existing service and the failure handling policy is to rollback As a result, kernel should be reverted to the
* state before deployment
*
* @throws Exception
*/
@Test
@Order(11)
void GIVEN_services_running_WHEN_new_service_breaks_failure_handling_policy_rollback_THEN_services_are_rolled_back(ExtensionContext context) throws Exception {
Map<String, Object> pkgDetails = new HashMap<>();
pkgDetails.put(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0");
groupToRootComponentsTopics.lookupTopics("RedSignal").replaceAndWait(pkgDetails);
groupToRootComponentsTopics.lookupTopics("YellowSignal").replaceAndWait(pkgDetails);
Future<DeploymentResult> resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("YellowAndRedSignal.json").toURI(), System.currentTimeMillis());
resultFuture.get(DEPLOYMENT_TIMEOUT, TimeUnit.SECONDS);
List<String> services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, YellowSignal and RedSignal
assertEquals(4, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "YellowSignal", "RedSignal"));
ignoreExceptionUltimateCauseOfType(context, ServiceUpdateException.class);
groupToRootComponentsTopics.lookupTopics("YellowSignal").remove();
groupToRootComponentsTopics.lookupTopics("BreakingService").replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
preloadLocalStoreContent();
resultFuture = submitSampleJobDocument(DeploymentTaskIntegrationTest.class.getResource("FailureRollbackDeployment.json").toURI(), System.currentTimeMillis());
DeploymentResult result = resultFuture.get(60, TimeUnit.SECONDS);
services = kernel.orderedDependencies().stream().filter(greengrassService -> greengrassService instanceof GenericExternalService).map(GreengrassService::getName).collect(Collectors.toList());
// should contain main, Nucleus, YellowSignal, RedSignal
assertEquals(4, services.size());
assertThat(services, containsInAnyOrder("main", DEFAULT_NUCLEUS_COMPONENT_NAME, "YellowSignal", "RedSignal"));
assertThrows(ServiceLoadException.class, () -> kernel.locate("BreakingService"));
assertThrows(ServiceLoadException.class, () -> kernel.locate("Mosquitto"));
assertThrows(ServiceLoadException.class, () -> kernel.locate("GreenSignal"));
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_COMPLETE, result.getDeploymentStatus());
}
Aggregations