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