Search in sources :

Example 1 with CreateDeploymentResponse

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"));
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ComponentDeploymentSpecification(software.amazon.awssdk.services.greengrassv2.model.ComponentDeploymentSpecification) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) NoAvailableComponentVersionException(com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException) ComponentUpdatePolicyEvents(software.amazon.awssdk.aws.greengrass.model.ComponentUpdatePolicyEvents) IPCTestUtils(com.aws.greengrass.integrationtests.ipc.IPCTestUtils) SERVICE_LIFECYCLE_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICE_LIFECYCLE_NAMESPACE_TOPIC) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) State(com.aws.greengrass.dependency.State) Duration(java.time.Duration) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) StreamResponseHandler(software.amazon.awssdk.eventstreamrpc.StreamResponseHandler) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) DeploymentPolicies(software.amazon.awssdk.services.greengrassv2.model.DeploymentPolicies) GreengrassCoreIPCClient(software.amazon.awssdk.aws.greengrass.GreengrassCoreIPCClient) Set(java.util.Set) TestUtils(com.aws.greengrass.testcommons.testutilities.TestUtils) UUID(java.util.UUID) EventuallyLambdaMatcher.eventuallyEval(com.github.grantwest.eventually.EventuallyLambdaMatcher.eventuallyEval) ROLLBACK(software.amazon.awssdk.services.greengrassv2.model.DeploymentFailureHandlingPolicy.ROLLBACK) DeferComponentUpdateRequest(software.amazon.awssdk.aws.greengrass.model.DeferComponentUpdateRequest) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) CreateDeploymentRequest(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) DeploymentService(com.aws.greengrass.deployment.DeploymentService) IotJobsUtils(com.aws.greengrass.integrationtests.e2e.util.IotJobsUtils) DEPLOYMENT_DETAILED_STATUS_KEY(com.aws.greengrass.deployment.DeploymentService.DEPLOYMENT_DETAILED_STATUS_KEY) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) JobExecutionStatus(software.amazon.awssdk.services.iot.model.JobExecutionStatus) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ExceptionLogProtector.ignoreExceptionUltimateCauseWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseWithMessage) DeploymentConfigurationValidationPolicy(software.amazon.awssdk.services.greengrassv2.model.DeploymentConfigurationValidationPolicy) UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) BaseE2ETestCase(com.aws.greengrass.integrationtests.e2e.BaseE2ETestCase) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SKIP_NOTIFY_COMPONENTS(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicyAction.SKIP_NOTIFY_COMPONENTS) CreateDeploymentResponse(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse) StringContains.containsString(org.hamcrest.core.StringContains.containsString) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) GGExtension(com.aws.greengrass.testcommons.testutilities.GGExtension) IsCollectionWithSize(org.hamcrest.collection.IsCollectionWithSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException) DO_NOTHING(software.amazon.awssdk.services.greengrassv2.model.DeploymentFailureHandlingPolicy.DO_NOTHING) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ComponentConfigurationUpdate(software.amazon.awssdk.services.greengrassv2.model.ComponentConfigurationUpdate) ExceptionLogProtector.ignoreExceptionUltimateCauseOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionUltimateCauseOfType) EventStreamRPCConnection(software.amazon.awssdk.eventstreamrpc.EventStreamRPCConnection) NOTIFY_COMPONENTS(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicyAction.NOTIFY_COMPONENTS) SubscribeToComponentUpdatesRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToComponentUpdatesRequest) IsMapContaining(org.hamcrest.collection.IsMapContaining) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Slf4jLogAdapter(com.aws.greengrass.logging.impl.Slf4jLogAdapter) AfterEach(org.junit.jupiter.api.AfterEach) DescribeJobExecutionRequest(software.amazon.awssdk.services.iot.model.DescribeJobExecutionRequest) Utils(com.aws.greengrass.util.Utils) KernelConfigResolver(com.aws.greengrass.componentmanager.KernelConfigResolver) DeploymentComponentUpdatePolicy(software.amazon.awssdk.services.greengrassv2.model.DeploymentComponentUpdatePolicy) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) IsMapWithSize(org.hamcrest.collection.IsMapWithSize) Timeout(org.junit.jupiter.api.Timeout) Collections(java.util.Collections) CreateDeploymentResponse(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GreengrassLogMessage(com.aws.greengrass.logging.impl.GreengrassLogMessage) CreateDeploymentRequest(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with CreateDeploymentResponse

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());
    });
}
Also used : CreateDeploymentResponse(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse) Topics(com.aws.greengrass.config.Topics) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) CreateDeploymentRequest(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 3 with CreateDeploymentResponse

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"));
}
Also used : CreateDeploymentResponse(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse) Topics(com.aws.greengrass.config.Topics) CreateDeploymentRequest(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 4 with CreateDeploymentResponse

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;
}
Also used : CreateDeploymentResponse(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse) HashMap(java.util.HashMap) ComponentDeploymentSpecification(software.amazon.awssdk.services.greengrassv2.model.ComponentDeploymentSpecification)

Example 5 with CreateDeploymentResponse

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"));
}
Also used : CreateDeploymentResponse(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse) CreateDeploymentRequest(software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

CreateDeploymentResponse (software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentResponse)18 Test (org.junit.jupiter.api.Test)17 CreateDeploymentRequest (software.amazon.awssdk.services.greengrassv2.model.CreateDeploymentRequest)17 Timeout (org.junit.jupiter.api.Timeout)15 StringContains.containsString (org.hamcrest.core.StringContains.containsString)6 Topics (com.aws.greengrass.config.Topics)5 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)5 GreengrassLogMessage (com.aws.greengrass.logging.impl.GreengrassLogMessage)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ComponentDeploymentSpecification (software.amazon.awssdk.services.greengrassv2.model.ComponentDeploymentSpecification)5 BaseE2ETestCase (com.aws.greengrass.integrationtests.e2e.BaseE2ETestCase)4 IotJobsUtils (com.aws.greengrass.integrationtests.e2e.util.IotJobsUtils)4 GGExtension (com.aws.greengrass.testcommons.testutilities.GGExtension)4 Utils (com.aws.greengrass.util.Utils)4 Duration (java.time.Duration)4 Map (java.util.Map)4 NoAvailableComponentVersionException (com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException)3 State (com.aws.greengrass.dependency.State)3 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)3 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)3