use of com.aws.greengrass.mqttclient.PublishRequest in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusServiceTest method GIVEN_component_removed_WHEN_deployment_finishes_THEN_MQTT_Sent_with_fss_data_with_overall_healthy_state.
@Test
void GIVEN_component_removed_WHEN_deployment_finishes_THEN_MQTT_Sent_with_fss_data_with_overall_healthy_state() throws ServiceLoadException, IOException, InterruptedException {
// Set up all the topics
Topics statusConfigTopics = Topics.of(context, FLEET_STATUS_CONFIG_TOPICS, null);
statusConfigTopics.createLeafChild(FLEET_STATUS_PERIODIC_PUBLISH_INTERVAL_SEC).withValue("10000");
Topics allComponentToGroupsTopics = Topics.of(context, GROUP_TO_ROOT_COMPONENTS_TOPICS, null);
lenient().when(config.lookupTopics(COMPONENTS_TO_GROUPS_TOPICS)).thenReturn(allComponentToGroupsTopics);
// Set up all the mocks
when(mockDeploymentStatusKeeper.registerDeploymentStatusConsumer(any(), consumerArgumentCaptor.capture(), anyString())).thenReturn(true);
when(mockGreengrassService1.getName()).thenReturn("MockService");
when(mockGreengrassService1.getServiceConfig()).thenReturn(config);
when(mockGreengrassService1.getState()).thenReturn(State.RUNNING);
when(mockKernel.locate(DeploymentService.DEPLOYMENT_SERVICE_TOPICS)).thenReturn(mockDeploymentService);
when(mockKernel.locate("MockService")).thenReturn(mockGreengrassService1);
when(mockKernel.orderedDependencies()).thenReturn(Collections.singletonList(mockDeploymentService));
when(mockDeploymentService.getConfig()).thenReturn(config);
doNothing().when(context).addGlobalStateChangeListener(addGlobalStateChangeListenerArgumentCaptor.capture());
when(mockDeviceConfiguration.getStatusConfigurationTopics()).thenReturn(statusConfigTopics);
when(context.get(ScheduledExecutorService.class)).thenReturn(ses);
// Create the fleet status service instance
fleetStatusService = createFSS();
fleetStatusService.startup();
// Update the job status for an ongoing deployment to IN_PROGRESS.
Map<String, Object> map = new HashMap<>();
map.put(DEPLOYMENT_STATUS_KEY_NAME, JobStatus.IN_PROGRESS.toString());
map.put(DEPLOYMENT_ID_KEY_NAME, "testJob");
map.put(DEPLOYMENT_TYPE_KEY_NAME, IOT_JOBS);
consumerArgumentCaptor.getValue().apply(map);
// Update the state of an EG service.
addGlobalStateChangeListenerArgumentCaptor.getValue().globalServiceStateChanged(mockGreengrassService1, State.INSTALLED, State.RUNNING);
fleetStatusService.addServicesToPreviouslyKnownServicesList(Collections.singletonList(mockGreengrassService1), Instant.MIN);
map.put(DEPLOYMENT_STATUS_KEY_NAME, JobStatus.SUCCEEDED.toString());
Map<String, String> statusDetails = new HashMap<>();
statusDetails.put(DEPLOYMENT_DETAILED_STATUS_KEY, DeploymentResult.DeploymentStatus.SUCCESSFUL.toString());
map.put(DEPLOYMENT_STATUS_DETAILS_KEY_NAME, statusDetails);
consumerArgumentCaptor.getValue().apply(map);
// Verify that an MQTT message with the components' status is uploaded.
verify(mockMqttClient, times(1)).publish(publishRequestArgumentCaptor.capture());
PublishRequest publishRequest = publishRequestArgumentCaptor.getValue();
assertEquals(QualityOfService.AT_LEAST_ONCE, publishRequest.getQos());
assertEquals("$aws/things/testThing/greengrassv2/health/json", publishRequest.getTopic());
ObjectMapper mapper = new ObjectMapper();
FleetStatusDetails fleetStatusDetails = mapper.readValue(publishRequest.getPayload(), FleetStatusDetails.class);
assertEquals(VERSION, fleetStatusDetails.getGgcVersion());
assertEquals("testThing", fleetStatusDetails.getThing());
assertEquals(OverallStatus.HEALTHY, fleetStatusDetails.getOverallStatus());
assertEquals(JobStatus.SUCCEEDED.toString(), fleetStatusDetails.getDeploymentInformation().getStatus());
assertEquals(DeploymentResult.DeploymentStatus.SUCCESSFUL.toString(), fleetStatusDetails.getDeploymentInformation().getStatusDetails().getDetailedStatus());
assertNull(fleetStatusDetails.getDeploymentInformation().getStatusDetails().getFailureCause());
fleetStatusDetails.getComponentStatusDetails().forEach(System.out::println);
assertEquals(1, fleetStatusDetails.getComponentStatusDetails().size());
assertEquals("MockService", fleetStatusDetails.getComponentStatusDetails().get(0).getComponentName());
assertNull(fleetStatusDetails.getComponentStatusDetails().get(0).getStatusDetails());
assertEquals(State.RUNNING, fleetStatusDetails.getComponentStatusDetails().get(0).getState());
assertThat(fleetStatusDetails.getComponentStatusDetails().get(0).getFleetConfigArns(), is(IsEmptyCollection.empty()));
}
use of com.aws.greengrass.mqttclient.PublishRequest in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusServiceTest method GIVEN_component_status_changes_to_broken_WHEN_deployment_finishes_THEN_MQTT_Sent_with_fss_data_with_overall_unhealthy_state.
@Test
void GIVEN_component_status_changes_to_broken_WHEN_deployment_finishes_THEN_MQTT_Sent_with_fss_data_with_overall_unhealthy_state() throws ServiceLoadException, IOException, InterruptedException {
// Set up all the topics
Topics statusConfigTopics = Topics.of(context, FLEET_STATUS_CONFIG_TOPICS, null);
statusConfigTopics.createLeafChild(FLEET_STATUS_PERIODIC_PUBLISH_INTERVAL_SEC).withValue("10000");
Topics allComponentToGroupsTopics = Topics.of(context, GROUP_TO_ROOT_COMPONENTS_TOPICS, null);
Topics groupsTopics = Topics.of(context, "MockService", allComponentToGroupsTopics);
Topics groupsTopics2 = Topics.of(context, "MockService2", allComponentToGroupsTopics);
Topic groupTopic1 = Topic.of(context, "arn:aws:greengrass:testRegion:12345:configuration:testGroup:12", true);
groupsTopics.children.put(new CaseInsensitiveString("MockService"), groupTopic1);
groupsTopics2.children.put(new CaseInsensitiveString("MockService2"), groupTopic1);
allComponentToGroupsTopics.children.put(new CaseInsensitiveString("MockService"), groupsTopics);
allComponentToGroupsTopics.children.put(new CaseInsensitiveString("MockService2"), groupsTopics2);
lenient().when(config.lookupTopics(COMPONENTS_TO_GROUPS_TOPICS)).thenReturn(allComponentToGroupsTopics);
// Set up all the mocks
when(mockDeploymentStatusKeeper.registerDeploymentStatusConsumer(any(), consumerArgumentCaptor.capture(), anyString())).thenReturn(true);
when(mockGreengrassService1.getName()).thenReturn("MockService");
when(mockGreengrassService1.getServiceConfig()).thenReturn(config);
when(mockGreengrassService1.getState()).thenReturn(State.BROKEN);
when(mockKernel.locate(DeploymentService.DEPLOYMENT_SERVICE_TOPICS)).thenReturn(mockDeploymentService);
when(mockKernel.locate("MockService")).thenReturn(mockGreengrassService1);
when(mockKernel.orderedDependencies()).thenReturn(Collections.singleton(mockGreengrassService1));
when(mockDeploymentService.getConfig()).thenReturn(config);
doNothing().when(context).addGlobalStateChangeListener(addGlobalStateChangeListenerArgumentCaptor.capture());
when(mockDeviceConfiguration.getStatusConfigurationTopics()).thenReturn(statusConfigTopics);
when(context.get(ScheduledExecutorService.class)).thenReturn(ses);
// Create the fleet status service instance
fleetStatusService = createFSS();
fleetStatusService.startup();
// Update the job status for an ongoing deployment to IN_PROGRESS.
Map<String, Object> map = new HashMap<>();
map.put(DEPLOYMENT_STATUS_KEY_NAME, JobStatus.IN_PROGRESS.toString());
map.put(DEPLOYMENT_ID_KEY_NAME, "testJob");
map.put(DEPLOYMENT_TYPE_KEY_NAME, IOT_JOBS);
consumerArgumentCaptor.getValue().apply(map);
// Update the state of an EG service.
addGlobalStateChangeListenerArgumentCaptor.getValue().globalServiceStateChanged(mockGreengrassService1, State.INSTALLED, State.BROKEN);
// Update the job status for service broken after deployment
String failureCauseMessage = "Service in broken state after deployment";
map.put(DEPLOYMENT_STATUS_KEY_NAME, JobStatus.FAILED.toString());
Map<String, String> statusDetails = new HashMap<>();
statusDetails.put(DEPLOYMENT_DETAILED_STATUS_KEY, DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_NOT_REQUESTED.toString());
statusDetails.put(DEPLOYMENT_FAILURE_CAUSE_KEY, failureCauseMessage);
map.put(DEPLOYMENT_STATUS_DETAILS_KEY_NAME, statusDetails);
consumerArgumentCaptor.getValue().apply(map);
// Verify that an MQTT message with the components' status is uploaded.
verify(mockMqttClient, times(1)).publish(publishRequestArgumentCaptor.capture());
PublishRequest publishRequest = publishRequestArgumentCaptor.getValue();
assertEquals(QualityOfService.AT_LEAST_ONCE, publishRequest.getQos());
assertEquals("$aws/things/testThing/greengrassv2/health/json", publishRequest.getTopic());
ObjectMapper mapper = new ObjectMapper();
FleetStatusDetails fleetStatusDetails = mapper.readValue(publishRequest.getPayload(), FleetStatusDetails.class);
assertEquals(VERSION, fleetStatusDetails.getGgcVersion());
assertEquals("testThing", fleetStatusDetails.getThing());
assertEquals(OverallStatus.UNHEALTHY, fleetStatusDetails.getOverallStatus());
assertEquals(JobStatus.FAILED.toString(), fleetStatusDetails.getDeploymentInformation().getStatus());
assertEquals(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_NOT_REQUESTED.toString(), fleetStatusDetails.getDeploymentInformation().getStatusDetails().getDetailedStatus());
assertEquals(failureCauseMessage, fleetStatusDetails.getDeploymentInformation().getStatusDetails().getFailureCause());
assertEquals(1, fleetStatusDetails.getComponentStatusDetails().size());
assertEquals("MockService", fleetStatusDetails.getComponentStatusDetails().get(0).getComponentName());
assertNull(fleetStatusDetails.getComponentStatusDetails().get(0).getStatusDetails());
assertEquals(State.BROKEN, fleetStatusDetails.getComponentStatusDetails().get(0).getState());
assertEquals(Collections.singletonList("arn:aws:greengrass:testRegion:12345:configuration:testGroup:12"), fleetStatusDetails.getComponentStatusDetails().get(0).getFleetConfigArns());
}
use of com.aws.greengrass.mqttclient.PublishRequest in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusServiceTest method GIVEN_MQTT_connection_interrupted_WHEN_connection_resumes_THEN_MQTT_Sent_with_periodic_triggered_fss_data.
@Test
void GIVEN_MQTT_connection_interrupted_WHEN_connection_resumes_THEN_MQTT_Sent_with_periodic_triggered_fss_data() throws InterruptedException, ServiceLoadException, IOException {
// Set up all the topics
Topics statusConfigTopics = Topics.of(context, FLEET_STATUS_CONFIG_TOPICS, null);
statusConfigTopics.createLeafChild(FLEET_STATUS_PERIODIC_PUBLISH_INTERVAL_SEC).withValue("3");
Topics allComponentToGroupsTopics = Topics.of(context, GROUP_TO_ROOT_COMPONENTS_TOPICS, null);
Topics groupsTopics = Topics.of(context, "MockService", allComponentToGroupsTopics);
Topics groupsTopics2 = Topics.of(context, "MockService2", allComponentToGroupsTopics);
Topic groupTopic1 = Topic.of(context, "arn:aws:greengrass:testRegion:12345:configuration:testGroup:12", true);
groupsTopics.children.put(new CaseInsensitiveString("MockService"), groupTopic1);
groupsTopics2.children.put(new CaseInsensitiveString("MockService2"), groupTopic1);
allComponentToGroupsTopics.children.put(new CaseInsensitiveString("MockService"), groupsTopics);
allComponentToGroupsTopics.children.put(new CaseInsensitiveString("MockService2"), groupsTopics2);
lenient().when(config.lookupTopics(COMPONENTS_TO_GROUPS_TOPICS)).thenReturn(allComponentToGroupsTopics);
// Set up all the mocks
when(mockDeploymentStatusKeeper.registerDeploymentStatusConsumer(any(), consumerArgumentCaptor.capture(), anyString())).thenReturn(true);
when(mockGreengrassService1.getName()).thenReturn("MockService");
when(mockGreengrassService1.getServiceConfig()).thenReturn(config);
when(mockGreengrassService1.getState()).thenReturn(State.RUNNING);
when(mockKernel.locate(DeploymentService.DEPLOYMENT_SERVICE_TOPICS)).thenReturn(mockDeploymentService);
when(mockKernel.locate("MockService")).thenReturn(mockGreengrassService1);
when(mockKernel.orderedDependencies()).thenReturn(Collections.singleton(mockGreengrassService1));
when(mockDeploymentService.getConfig()).thenReturn(config);
doNothing().when(context).addGlobalStateChangeListener(addGlobalStateChangeListenerArgumentCaptor.capture());
when(mockDeviceConfiguration.getStatusConfigurationTopics()).thenReturn(statusConfigTopics);
when(context.get(ScheduledExecutorService.class)).thenReturn(ses);
doNothing().when(mockMqttClient).addToCallbackEvents(mqttClientConnectionEventsArgumentCaptor.capture());
// Create the fleet status service instance
fleetStatusService = createFSS(3);
fleetStatusService.startup();
mqttClientConnectionEventsArgumentCaptor.getValue().onConnectionInterrupted(500);
TimeUnit.SECONDS.sleep(4);
mqttClientConnectionEventsArgumentCaptor.getValue().onConnectionResumed(false);
TimeUnit.SECONDS.sleep(1);
// Verify that an MQTT message with the components' status is uploaded.
verify(mockMqttClient, atLeast(1)).publish(publishRequestArgumentCaptor.capture());
PublishRequest publishRequest = publishRequestArgumentCaptor.getValue();
assertEquals(QualityOfService.AT_LEAST_ONCE, publishRequest.getQos());
assertEquals("$aws/things/testThing/greengrassv2/health/json", publishRequest.getTopic());
ObjectMapper mapper = new ObjectMapper();
FleetStatusDetails fleetStatusDetails = mapper.readValue(publishRequest.getPayload(), FleetStatusDetails.class);
assertEquals(VERSION, fleetStatusDetails.getGgcVersion());
assertEquals("testThing", fleetStatusDetails.getThing());
assertEquals(OverallStatus.HEALTHY, fleetStatusDetails.getOverallStatus());
assertEquals(1, fleetStatusDetails.getComponentStatusDetails().size());
assertEquals("MockService", fleetStatusDetails.getComponentStatusDetails().get(0).getComponentName());
assertNull(fleetStatusDetails.getComponentStatusDetails().get(0).getStatusDetails());
assertEquals(State.RUNNING, fleetStatusDetails.getComponentStatusDetails().get(0).getState());
assertEquals(Collections.singletonList("arn:aws:greengrass:testRegion:12345:configuration:testGroup:12"), fleetStatusDetails.getComponentStatusDetails().get(0).getFleetConfigArns());
}
Aggregations