use of software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentE2ETest method GIVEN_target_service_has_dependencies_WHEN_deploys_target_service_THEN_service_and_dependencies_should_be_deployed.
@Timeout(value = 10, unit = TimeUnit.MINUTES)
@Test
void GIVEN_target_service_has_dependencies_WHEN_deploys_target_service_THEN_service_and_dependencies_should_be_deployed() throws Exception {
// Set up stdout listener to capture stdout for verify interpolation
List<String> stdouts = new CopyOnWriteArrayList<>();
Consumer<GreengrassLogMessage> listener = m -> {
String messageOnStdout = m.getMessage();
if (messageOnStdout != null && messageOnStdout.contains("CustomerApp output.")) {
stdouts.add(messageOnStdout);
// countdown when received output to verify
stdoutCountdown.countDown();
}
};
try (AutoCloseable l = TestUtils.createCloseableLogListener(listener)) {
stdoutCountdown = new CountDownLatch(1);
// 1st Deployment to have some services running in Kernel with default configuration
CreateDeploymentRequest createDeployment1 = CreateDeploymentRequest.builder().components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build())).build();
CreateDeploymentResponse createDeploymentResult1 = draftAndCreateDeployment(createDeployment1);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, createDeploymentResult1.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(2), s -> s.equals(JobExecutionStatus.SUCCEEDED));
assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("CustomerApp")::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("Mosquitto")::getState, eventuallyEval(is(State.RUNNING)));
assertThat(getCloudDeployedComponent("GreenSignal")::getState, eventuallyEval(is(State.FINISHED)));
// verify config in kernel
Map<String, Object> resultConfig = getCloudDeployedComponent("CustomerApp").getServiceConfig().findTopics(KernelConfigResolver.CONFIGURATION_CONFIG_KEY).toPOJO();
assertThat(resultConfig, IsMapWithSize.aMapWithSize(3));
assertThat(resultConfig, IsMapContaining.hasEntry("sampleText", "This is a test"));
assertThat(resultConfig, IsMapContaining.hasEntry("listKey", Arrays.asList("item1", "item2")));
assertThat(resultConfig, IsMapContaining.hasKey("path"));
assertThat((Map<String, String>) resultConfig.get("path"), IsMapContaining.hasEntry("leafKey", "default value of /path/leafKey"));
// verify stdout
assertThat("The stdout should be captured within seconds.", stdoutCountdown.await(5, TimeUnit.SECONDS));
String customerAppStdout = stdouts.get(0);
assertThat(customerAppStdout, containsString("This is a test"));
assertThat(customerAppStdout, containsString("Value for /path/leafKey: default value of /path/leafKey."));
assertThat(customerAppStdout, containsString("Value for /listKey/0: item1."));
assertThat(customerAppStdout, containsString("Value for /newKey: {configuration:/newKey}"));
// reset countdown and stdouts
stdoutCountdown = new CountDownLatch(1);
stdouts.clear();
// 2nd deployment to merge
/*
* {
* "MERGE": {
* "sampleText": "updated value for sampleText",
* "listKey": [
* "item3"
* ],
* "path": {
* "leafKey": "updated value of /path/leafKey"
* }
* }
* }
*/
ObjectMapper mapper = new ObjectMapper();
ObjectNode configUpdateInNode = mapper.createObjectNode();
ObjectNode mergeNode = configUpdateInNode.with("MERGE");
mergeNode.put("sampleText", "updated");
mergeNode.put("newKey", "updated");
mergeNode.withArray("listKey").add("item3");
mergeNode.with("path").put("leafKey", "updated");
CreateDeploymentRequest createDeployment2 = CreateDeploymentRequest.builder().targetArn(thingGroupArn).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").configurationUpdate(ComponentConfigurationUpdate.builder().merge(mapper.writeValueAsString(mergeNode)).build()).build())).build();
CreateDeploymentResponse createDeploymentResult2 = draftAndCreateDeployment(createDeployment2);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, createDeploymentResult2.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(2), s -> s.equals(JobExecutionStatus.SUCCEEDED));
assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("CustomerApp")::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("Mosquitto")::getState, eventuallyEval(is(State.RUNNING)));
assertThat(getCloudDeployedComponent("GreenSignal")::getState, eventuallyEval(is(State.FINISHED)));
// verify config in kernel
resultConfig = getCloudDeployedComponent("CustomerApp").getServiceConfig().findTopics(KernelConfigResolver.CONFIGURATION_CONFIG_KEY).toPOJO();
assertThat(resultConfig, IsMapWithSize.aMapWithSize(4));
assertThat(resultConfig, IsMapContaining.hasEntry("sampleText", "updated"));
assertThat(resultConfig, IsMapContaining.hasEntry("listKey", Collections.singletonList("item3")));
assertThat(resultConfig, IsMapContaining.hasKey("path"));
assertThat((Map<String, String>) resultConfig.get("path"), IsMapContaining.hasEntry("leafKey", "updated"));
// verify stdout
assertThat("The stdout should be captured within seconds.", stdoutCountdown.await(5, TimeUnit.SECONDS));
customerAppStdout = stdouts.get(0);
assertThat(customerAppStdout, containsString("Value for /sampleText: updated"));
assertThat(customerAppStdout, containsString("Value for /path/leafKey: updated"));
assertThat(customerAppStdout, containsString("Value for /listKey/0: item3."));
assertThat(customerAppStdout, containsString("Value for /newKey: updated"));
// reset countdown and stdouts
stdoutCountdown = new CountDownLatch(1);
stdouts.clear();
// 3rd deployment to reset
CreateDeploymentRequest createDeployment3 = CreateDeploymentRequest.builder().targetArn(thingGroupArn).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").configurationUpdate(ComponentConfigurationUpdate.builder().reset("/sampleText", "/path").build()).build())).build();
CreateDeploymentResponse createDeploymentResult = draftAndCreateDeployment(createDeployment3);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, createDeploymentResult.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(2), s -> s.equals(JobExecutionStatus.SUCCEEDED));
assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("CustomerApp")::getState, eventuallyEval(is(State.FINISHED)));
assertThat(getCloudDeployedComponent("Mosquitto")::getState, eventuallyEval(is(State.RUNNING)));
assertThat(getCloudDeployedComponent("GreenSignal")::getState, eventuallyEval(is(State.FINISHED)));
// verify config in kernel
resultConfig = getCloudDeployedComponent("CustomerApp").getServiceConfig().findTopics(KernelConfigResolver.CONFIGURATION_CONFIG_KEY).toPOJO();
assertThat(resultConfig, IsMapWithSize.aMapWithSize(4));
assertThat(resultConfig, IsMapContaining.hasEntry("sampleText", "This is a test"));
assertThat(resultConfig, IsMapContaining.hasEntry("listKey", Collections.singletonList("item3")));
assertThat(resultConfig, IsMapContaining.hasKey("path"));
assertThat((Map<String, String>) resultConfig.get("path"), IsMapContaining.hasEntry("leafKey", "default value of /path/leafKey"));
// verify stdout
assertThat("The stdout should be captured within seconds.", stdoutCountdown.await(5, TimeUnit.SECONDS));
customerAppStdout = stdouts.get(0);
assertThat(customerAppStdout, containsString("Value for /sampleText: This is a test"));
assertThat(customerAppStdout, containsString("Value for /path/leafKey: default value of /path/leafKey"));
assertThat(customerAppStdout, containsString("Value for /listKey/0: item3."));
assertThat(customerAppStdout, containsString("Value for /newKey: updated"));
}
}
use of software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse in project aws-greengrass-nucleus by aws-greengrass.
the class MultipleGroupsDeploymentE2ETest method GIVEN_deployment_to_2_groups_WHEN_remove_service_from_1_group_THEN_service_is_removed.
@Timeout(value = 10, unit = TimeUnit.MINUTES)
@Test
void GIVEN_deployment_to_2_groups_WHEN_remove_service_from_1_group_THEN_service_is_removed() throws Exception {
CreateDeploymentRequest createDeploymentRequest1 = CreateDeploymentRequest.builder().targetArn(thingGroupArn).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("0.9.1").configurationUpdate(ComponentConfigurationUpdate.builder().merge("{\"sampleText\":\"FCS integ test\"}").build()).build(), "SomeService", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build())).build();
CreateDeploymentResponse result1 = draftAndCreateDeployment(createDeploymentRequest1);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, result1.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.SUCCEEDED));
Topics groupToRootMapping = kernel.getConfig().lookupTopics(DEPLOYMENT_SERVICE_TOPICS, GROUP_TO_ROOT_COMPONENTS_TOPICS);
logger.atInfo().log("Group to root mapping is: " + groupToRootMapping.toString());
CreateDeploymentRequest createDeploymentRequest2 = CreateDeploymentRequest.builder().targetArn(secondThingGroupResponse.thingGroupArn()).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("0.9.1").configurationUpdate(ComponentConfigurationUpdate.builder().merge("{\"sampleText\":\"FCS integ test\"}").build()).build())).build();
CreateDeploymentResponse result2 = draftAndCreateDeployment(createDeploymentRequest2);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, result2.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.SUCCEEDED));
CreateDeploymentRequest createDeploymentRequest3 = CreateDeploymentRequest.builder().targetArn(thingGroupArn).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("0.9.1").configurationUpdate(ComponentConfigurationUpdate.builder().merge("{\"sampleText\":\"FCS integ test\"}").build()).build())).build();
CreateDeploymentResponse result3 = draftAndCreateDeployment(createDeploymentRequest3);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, result3.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.SUCCEEDED));
assertThat(kernel.getMain()::getState, eventuallyEval(is(State.FINISHED)));
assertThrows(ServiceLoadException.class, () -> {
GreengrassService service = getCloudDeployedComponent("SomeService");
logger.atInfo().log("Service is " + service.getName());
});
}
use of software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse in project aws-greengrass-nucleus by aws-greengrass.
the class MultipleGroupsDeploymentE2ETest method GIVEN_deployment_to_2_groups_WHEN_both_deployments_have_same_service_different_version_THEN_second_deployment_fails_due_to_conflict.
@Timeout(value = 10, unit = TimeUnit.MINUTES)
@Test
void GIVEN_deployment_to_2_groups_WHEN_both_deployments_have_same_service_different_version_THEN_second_deployment_fails_due_to_conflict(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, ExecutionException.class);
ignoreExceptionOfType(context, // Expect this to happen due to conflict
NoAvailableComponentVersionException.class);
CreateDeploymentRequest createDeploymentRequest1 = CreateDeploymentRequest.builder().targetArn(thingGroupArn).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("0.9.1").configurationUpdate(ComponentConfigurationUpdate.builder().merge("{\"sampleText\":\"FCS integ test\"}").build()).build())).build();
CreateDeploymentResponse result1 = draftAndCreateDeployment(createDeploymentRequest1);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, result1.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.SUCCEEDED));
Topics groupToRootMapping = kernel.getConfig().lookupTopics(DEPLOYMENT_SERVICE_TOPICS, GROUP_TO_ROOT_COMPONENTS_TOPICS);
logger.atInfo().log("Group to root mapping is: " + groupToRootMapping.toString());
CreateDeploymentRequest createDeploymentRequest2 = CreateDeploymentRequest.builder().targetArn(secondThingGroupResponse.thingGroupArn()).components(Utils.immutableMap("CustomerApp", ComponentDeploymentSpecification.builder().componentVersion("1.0.0").configurationUpdate(ComponentConfigurationUpdate.builder().merge("{\"sampleText\":\"FCS integ test\"}").build()).build())).build();
CreateDeploymentResponse result2 = draftAndCreateDeployment(createDeploymentRequest2);
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, result2.iotJobId(), thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.FAILED));
assertThat("Incorrect component version running", getCloudDeployedComponent("CustomerApp").getServiceConfig().find(VERSION_CONFIG_KEY).getOnce().toString(), is("0.9.1"));
}
use of software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse in project aws-greengrass-nucleus by aws-greengrass.
the class BaseE2ETestCase method draftAndCreateDeployment.
@SuppressWarnings("PMD.LinguisticNaming")
protected CreateDeploymentResponse draftAndCreateDeployment(CreateDeploymentRequest createDeploymentRequest) {
// update package name with random suffix to avoid conflict in cloud
Map<String, ComponentDeploymentSpecification> updatedPkgMetadata = new HashMap<>();
createDeploymentRequest.components().forEach((key, val) -> updatedPkgMetadata.put(getTestComponentNameInCloud(key), val));
createDeploymentRequest = createDeploymentRequest.toBuilder().components(updatedPkgMetadata).build();
// set default value
if (createDeploymentRequest.targetArn() == null) {
createDeploymentRequest = createDeploymentRequest.toBuilder().targetArn(thingGroupArn).build();
}
if (createDeploymentRequest.deploymentPolicies() == null) {
createDeploymentRequest = createDeploymentRequest.toBuilder().deploymentPolicies(DeploymentPolicies.builder().configurationValidationPolicy(DeploymentConfigurationValidationPolicy.builder().timeoutInSeconds(120).build()).componentUpdatePolicy(DeploymentComponentUpdatePolicy.builder().action(NOTIFY_COMPONENTS).timeoutInSeconds(120).build()).failureHandlingPolicy(DO_NOTHING).build()).build();
}
logger.atInfo().kv("CreateDeploymentRequest", createDeploymentRequest).log();
CreateDeploymentResponse createDeploymentResult = greengrassClient.createDeployment(createDeploymentRequest);
logger.atInfo().kv("CreateDeploymentResult", createDeploymentResult).log();
// Keep track of deployments to clean up
createdDeployments.add(CancelDeploymentRequest.builder().deploymentId(createDeploymentResult.deploymentId()).build());
return createDeploymentResult;
}
use of software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentE2ETest method GIVEN_blank_kernel_WHEN_deployment_has_components_that_dont_exist_THEN_job_should_fail_and_return_error.
@Test
void GIVEN_blank_kernel_WHEN_deployment_has_components_that_dont_exist_THEN_job_should_fail_and_return_error(ExtensionContext context) throws Exception {
ignoreExceptionUltimateCauseOfType(context, NoAvailableComponentVersionException.class);
// New deployment contains dependency conflicts
CreateDeploymentRequest createDeploymentRequest = CreateDeploymentRequest.builder().components(Utils.immutableMap("XYZPackage-" + UUID.randomUUID(), ComponentDeploymentSpecification.builder().componentVersion("1.0.0").build())).build();
CreateDeploymentResponse createDeploymentResult = draftAndCreateDeployment(createDeploymentRequest);
String jobId = createDeploymentResult.iotJobId();
IotJobsUtils.waitForJobExecutionStatusToSatisfy(iotClient, jobId, thingInfo.getThingName(), Duration.ofMinutes(5), s -> s.equals(JobExecutionStatus.FAILED));
// Make sure IoT Job was marked as failed and provided correct reason
String deploymentError = iotClient.describeJobExecution(DescribeJobExecutionRequest.builder().jobId(jobId).thingName(thingInfo.getThingName()).build()).execution().statusDetails().detailsMap().get(DeploymentService.DEPLOYMENT_FAILURE_CAUSE_KEY);
assertThat(deploymentError, containsString("satisfies the requirements"));
assertThat(deploymentError, containsString("XYZPackage"));
}
Aggregations