Search in sources :

Example 1 with DeploymentStatusKeeper

use of com.aws.greengrass.deployment.DeploymentStatusKeeper in project aws-greengrass-nucleus by aws-greengrass.

the class MultiGroupDeploymentTest method GIVEN_device_belongs_to_two_groups_WHEN_device_is_removed_from_one_group_THEN_next_deployment_removes_corresponding_component.

@Test
void GIVEN_device_belongs_to_two_groups_WHEN_device_is_removed_from_one_group_THEN_next_deployment_removes_corresponding_component() throws Exception {
    CountDownLatch firstGroupCDL = new CountDownLatch(1);
    CountDownLatch secondGroupCDL = new CountDownLatch(1);
    DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
    deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.IOT_JOBS, (status) -> {
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("firstGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
            firstGroupCDL.countDown();
        }
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("secondGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
            secondGroupCDL.countDown();
        }
        return true;
    }, "dummyValue");
    when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("firstGroup", "secondGroup"))));
    submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithRedSignalService.json").toURI(), "firstGroup", Deployment.DeploymentType.IOT_JOBS);
    assertTrue(firstGroupCDL.await(10, TimeUnit.SECONDS));
    when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("secondGroup"))));
    submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithSomeService.json").toURI(), "secondGroup", Deployment.DeploymentType.IOT_JOBS);
    assertTrue(secondGroupCDL.await(10, TimeUnit.SECONDS));
    Topics groupToRootTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, GROUP_TO_ROOT_COMPONENTS_TOPICS);
    List<String> groupNames = new ArrayList<>();
    groupToRootTopic.forEach(node -> groupNames.add(node.getName()));
    assertTrue(groupNames.containsAll(Arrays.asList("secondGroup")), "Device should belong to firstGroup and secondGroup");
    Map<GreengrassService, DependencyType> dependenciesAfter = kernel.getMain().getDependencies();
    List<String> serviceNames = dependenciesAfter.keySet().stream().map(service -> service.getName()).collect(Collectors.toList());
    assertTrue(serviceNames.containsAll(Arrays.asList("SomeService")));
    Topics componentsToGroupTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, COMPONENTS_TO_GROUPS_TOPICS);
    assertNotNull(componentsToGroupTopic.find("SomeService", "secondGroup"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Deployment(com.aws.greengrass.deployment.model.Deployment) GROUP_TO_ROOT_COMPONENTS_TOPICS(com.aws.greengrass.deployment.DeploymentService.GROUP_TO_ROOT_COMPONENTS_TOPICS) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) State(com.aws.greengrass.dependency.State) BaseITCase(com.aws.greengrass.integrationtests.BaseITCase) FleetStatusService(com.aws.greengrass.status.FleetStatusService) Map(java.util.Map) DeploymentStatusKeeper(com.aws.greengrass.deployment.DeploymentStatusKeeper) URI(java.net.URI) Path(java.nio.file.Path) DEPLOYMENT_SERVICE_TOPICS(com.aws.greengrass.deployment.DeploymentService.DEPLOYMENT_SERVICE_TOPICS) FLEET_STATUS_SERVICE_TOPICS(com.aws.greengrass.status.FleetStatusService.FLEET_STATUS_SERVICE_TOPICS) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) LocalOverrideRequest(com.aws.greengrass.deployment.model.LocalOverrideRequest) DEPLOYMENT_STATUS_KEY_NAME(com.aws.greengrass.deployment.DeploymentStatusKeeper.DEPLOYMENT_STATUS_KEY_NAME) Utils.copyFolderRecursively(com.aws.greengrass.util.Utils.copyFolderRecursively) UUID(java.util.UUID) COMPONENTS_TO_GROUPS_TOPICS(com.aws.greengrass.deployment.DeploymentService.COMPONENTS_TO_GROUPS_TOPICS) Collectors(java.util.stream.Collectors) ExceptionLogProtector.ignoreExceptionOfType(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) SERVICES_NAMESPACE_TOPIC(com.aws.greengrass.lifecyclemanager.GreengrassService.SERVICES_NAMESPACE_TOPIC) Test(org.junit.jupiter.api.Test) Topics(com.aws.greengrass.config.Topics) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) PreloadComponentStoreHelper(com.aws.greengrass.helper.PreloadComponentStoreHelper) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue) ConfigPlatformResolver(com.aws.greengrass.integrationtests.util.ConfigPlatformResolver) HashMap(java.util.HashMap) DEPLOYMENT_STATUS_DETAILS_KEY_NAME(com.aws.greengrass.deployment.DeploymentStatusKeeper.DEPLOYMENT_STATUS_DETAILS_KEY_NAME) Configuration(com.amazon.aws.iot.greengrass.configuration.common.Configuration) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Coerce(com.aws.greengrass.util.Coerce) ThingGroupHelper(com.aws.greengrass.deployment.ThingGroupHelper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) PackageDownloadException(com.aws.greengrass.componentmanager.exceptions.PackageDownloadException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) DEPLOYMENT_ID_KEY_NAME(com.aws.greengrass.deployment.DeploymentStatusKeeper.DEPLOYMENT_ID_KEY_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DependencyType(com.amazon.aws.iot.greengrass.component.common.DependencyType) File(java.io.File) ExceptionLogProtector.ignoreExceptionWithMessage(com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionWithMessage) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Topic(com.aws.greengrass.config.Topic) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) NoOpPathOwnershipHandler(com.aws.greengrass.testcommons.testutilities.NoOpPathOwnershipHandler) DeploymentStatus(com.aws.greengrass.deployment.model.DeploymentResult.DeploymentStatus) Topics(com.aws.greengrass.config.Topics) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) ArrayList(java.util.ArrayList) DependencyType(com.amazon.aws.iot.greengrass.component.common.DependencyType) DeploymentStatusKeeper(com.aws.greengrass.deployment.DeploymentStatusKeeper) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with DeploymentStatusKeeper

use of com.aws.greengrass.deployment.DeploymentStatusKeeper in project aws-greengrass-nucleus by aws-greengrass.

the class MultiGroupDeploymentTest method GIVEN_device_receives_deployment_from_multiple_groups_THEN_components_deployed_by_shadow_deployment_are_not_removed.

@Test
void GIVEN_device_receives_deployment_from_multiple_groups_THEN_components_deployed_by_shadow_deployment_are_not_removed() throws Exception {
    CountDownLatch firstGroupCDL = new CountDownLatch(1);
    CountDownLatch secondGroupCDL = new CountDownLatch(1);
    CountDownLatch shadowDeploymentCDL = new CountDownLatch(1);
    DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
    deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.IOT_JOBS, (status) -> {
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("thinggroup/firstGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
            firstGroupCDL.countDown();
        }
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("thinggroup/secondGroup") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
            secondGroupCDL.countDown();
        }
        return true;
    }, "dummyValueIotJobs");
    deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.SHADOW, (status) -> {
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("thing/thingname") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
            shadowDeploymentCDL.countDown();
        }
        return true;
    }, "dummyValueShadow");
    when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("thinggroup/firstGroup", "thinggroup/secondGroup"))));
    submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithRedSignalService.json").toURI(), "thinggroup/firstGroup", Deployment.DeploymentType.IOT_JOBS);
    assertTrue(firstGroupCDL.await(30, TimeUnit.SECONDS));
    submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithSomeService.json").toURI(), "thing/thingname", Deployment.DeploymentType.SHADOW);
    assertTrue(shadowDeploymentCDL.await(30, TimeUnit.SECONDS));
    when(thingGroupHelper.listThingGroupsForDevice(anyInt())).thenReturn(Optional.of(new HashSet<>(Arrays.asList("thinggroup/secondGroup"))));
    submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithYellowSignal.json").toURI(), "thinggroup/secondGroup", Deployment.DeploymentType.IOT_JOBS);
    assertTrue(secondGroupCDL.await(30, TimeUnit.SECONDS));
    Topics groupToRootTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, GROUP_TO_ROOT_COMPONENTS_TOPICS);
    List<String> groupNames = new ArrayList<>();
    groupToRootTopic.forEach(node -> groupNames.add(node.getName()));
    assertTrue(groupNames.containsAll(Arrays.asList("thinggroup/secondGroup", "thing/thingname")));
    assertFalse(groupNames.contains("thinggroup/firstGroup"));
    Topics componentsToGroupTopic = kernel.getConfig().lookupTopics(SERVICES_NAMESPACE_TOPIC, DEPLOYMENT_SERVICE_TOPICS, COMPONENTS_TO_GROUPS_TOPICS);
    assertNotNull(componentsToGroupTopic.find("YellowSignal", "thinggroup/secondGroup"));
    assertNotNull(componentsToGroupTopic.find("SomeService", "thing/thingname"));
}
Also used : Topics(com.aws.greengrass.config.Topics) ArrayList(java.util.ArrayList) DeploymentStatusKeeper(com.aws.greengrass.deployment.DeploymentStatusKeeper) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with DeploymentStatusKeeper

use of com.aws.greengrass.deployment.DeploymentStatusKeeper in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentServiceIntegrationTest method GIVEN_local_deployment_WHEN_required_capabilities_not_present_THEN_deployments_fails_with_appropriate_error.

@Test
void GIVEN_local_deployment_WHEN_required_capabilities_not_present_THEN_deployments_fails_with_appropriate_error() throws Exception {
    CountDownLatch deploymentCDL = new CountDownLatch(1);
    DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
    deploymentStatusKeeper.registerDeploymentStatusConsumer(DeploymentType.LOCAL, (status) -> {
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("requiredCapabilityNotPresent") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("FAILED")) {
            deploymentCDL.countDown();
            assertThat(((Map) status.get(DEPLOYMENT_STATUS_DETAILS_KEY_NAME)).get(DEPLOYMENT_FAILURE_CAUSE_KEY), equalTo("The current nucleus version doesn't support one or more capabilities that are " + "required by this deployment: NOT_SUPPORTED_1, NOT_SUPPORTED_2"));
        }
        return true;
    }, "DeploymentServiceIntegrationTest3");
    Map<String, String> componentsToMerge = new HashMap<>();
    componentsToMerge.put("YellowSignal", "1.0.0");
    LocalOverrideRequest request = LocalOverrideRequest.builder().requestId("requiredCapabilityNotPresent").componentsToMerge(componentsToMerge).requestTimestamp(System.currentTimeMillis()).requiredCapabilities(Arrays.asList("NOT_SUPPORTED_1", "NOT_SUPPORTED_2", "LARGE_CONFIGURATION")).build();
    submitLocalDocument(request);
    assertTrue(deploymentCDL.await(10, TimeUnit.SECONDS), "Deployment should fail with " + "requiredCapabilityNotPresent.");
}
Also used : LocalOverrideRequest(com.aws.greengrass.deployment.model.LocalOverrideRequest) HashMap(java.util.HashMap) DeploymentStatusKeeper(com.aws.greengrass.deployment.DeploymentStatusKeeper) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 4 with DeploymentStatusKeeper

use of com.aws.greengrass.deployment.DeploymentStatusKeeper in project aws-greengrass-nucleus by aws-greengrass.

the class IPCTestUtils method waitForDeploymentToBeSuccessful.

public static CountDownLatch waitForDeploymentToBeSuccessful(String deploymentId, Kernel kernel) {
    CountDownLatch deploymentLatch = new CountDownLatch(1);
    DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
    deploymentStatusKeeper.registerDeploymentStatusConsumer(Deployment.DeploymentType.LOCAL, (deploymentDetails) -> {
        String receivedDeploymentId = deploymentDetails.get(DEPLOYMENT_ID_KEY_NAME).toString();
        if (receivedDeploymentId.equals(deploymentId)) {
            DeploymentStatus status = DeploymentStatus.valueOf(deploymentDetails.get(DEPLOYMENT_STATUS_KEY_NAME).toString());
            if (status == DeploymentStatus.SUCCEEDED) {
                deploymentLatch.countDown();
            }
        }
        return true;
    }, deploymentId);
    return deploymentLatch;
}
Also used : DeploymentStatusKeeper(com.aws.greengrass.deployment.DeploymentStatusKeeper) CountDownLatch(java.util.concurrent.CountDownLatch) DeploymentStatus(software.amazon.awssdk.aws.greengrass.model.DeploymentStatus)

Example 5 with DeploymentStatusKeeper

use of com.aws.greengrass.deployment.DeploymentStatusKeeper in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentServiceIntegrationTest method GIVEN_deployment_with_large_config_WHEN_receives_deployment_THEN_deployment_succeeds.

@Test
void GIVEN_deployment_with_large_config_WHEN_receives_deployment_THEN_deployment_succeeds() throws Exception {
    CountDownLatch deploymentCDL = new CountDownLatch(1);
    DeploymentStatusKeeper deploymentStatusKeeper = kernel.getContext().get(DeploymentStatusKeeper.class);
    deploymentStatusKeeper.registerDeploymentStatusConsumer(DeploymentType.IOT_JOBS, (status) -> {
        if (status.get(DEPLOYMENT_ID_KEY_NAME).equals("ComponentConfig") && status.get(DEPLOYMENT_STATUS_KEY_NAME).equals("SUCCEEDED")) {
            deploymentCDL.countDown();
        }
        return true;
    }, "dummy");
    Configuration deployedConfiguration = OBJECT_MAPPER.readValue(new File(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithComponentConfigTestService.json").toURI()), Configuration.class);
    deployedConfiguration.setCreationTimestamp(System.currentTimeMillis());
    deployedConfiguration.setConfigurationArn("ComponentConfig");
    DeploymentDocument configurationDownloadedUsingDataPlaneAPI = convertFromDeploymentConfiguration(deployedConfiguration);
    // remove the configuration update section from deployedConfiguration after configurationDownloadedUsingDataPlaneAPI is created
    deployedConfiguration.getComponents().values().forEach(componentUpdate -> componentUpdate.setConfigurationUpdate(null));
    Deployment deployment = new Deployment(OBJECT_MAPPER.writeValueAsString(deployedConfiguration), DeploymentType.IOT_JOBS, deployedConfiguration.getConfigurationArn());
    when(deploymentDocumentDownloader.download(any())).thenReturn(configurationDownloadedUsingDataPlaneAPI);
    deploymentQueue.offer(deployment);
    assertTrue(deploymentCDL.await(10, TimeUnit.SECONDS));
    Map<String, Object> resultConfig = kernel.findServiceTopic("aws.iot.gg.test.integ.ComponentConfigTestService").findTopics(KernelConfigResolver.CONFIGURATION_CONFIG_KEY).toPOJO();
    assertThat(resultConfig, IsMapContaining.hasEntry("singleLevelKey", "updated value of singleLevelKey"));
    assertThat(resultConfig, IsMapContaining.hasEntry("listKey", Collections.singletonList("item3")));
    assertThat(resultConfig, IsMapContaining.hasEntry("emptyStringKey", ""));
    assertThat(resultConfig, IsMapContaining.hasEntry("emptyListKey", Collections.emptyList()));
    assertThat(resultConfig, IsMapContaining.hasEntry("emptyObjectKey", Collections.emptyMap()));
    assertThat(resultConfig, IsMapContaining.hasEntry("defaultIsNullKey", "updated value of defaultIsNullKey"));
    assertThat(resultConfig, IsMapContaining.hasEntry("willBeNullKey", null));
}
Also used : DeploymentDocumentConverter.convertFromDeploymentConfiguration(com.aws.greengrass.deployment.converter.DeploymentDocumentConverter.convertFromDeploymentConfiguration) Configuration(com.amazon.aws.iot.greengrass.configuration.common.Configuration) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) DeploymentStatusKeeper(com.aws.greengrass.deployment.DeploymentStatusKeeper) Deployment(com.aws.greengrass.deployment.model.Deployment) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentStatusKeeper (com.aws.greengrass.deployment.DeploymentStatusKeeper)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 Test (org.junit.jupiter.api.Test)13 Topics (com.aws.greengrass.config.Topics)8 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 LocalOverrideRequest (com.aws.greengrass.deployment.model.LocalOverrideRequest)7 Map (java.util.Map)6 Configuration (com.amazon.aws.iot.greengrass.configuration.common.Configuration)5 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)5 Deployment (com.aws.greengrass.deployment.model.Deployment)5 File (java.io.File)5 PackageDownloadException (com.aws.greengrass.componentmanager.exceptions.PackageDownloadException)4 Topic (com.aws.greengrass.config.Topic)4 State (com.aws.greengrass.dependency.State)4 DeploymentQueue (com.aws.greengrass.deployment.DeploymentQueue)4 DEPLOYMENT_SERVICE_TOPICS (com.aws.greengrass.deployment.DeploymentService.DEPLOYMENT_SERVICE_TOPICS)4 DEPLOYMENT_ID_KEY_NAME (com.aws.greengrass.deployment.DeploymentStatusKeeper.DEPLOYMENT_ID_KEY_NAME)4 DEPLOYMENT_STATUS_DETAILS_KEY_NAME (com.aws.greengrass.deployment.DeploymentStatusKeeper.DEPLOYMENT_STATUS_DETAILS_KEY_NAME)4