use of com.aws.greengrass.status.FleetStatusDetails in project aws-greengrass-nucleus by aws-greengrass.
the class FleetStatusServiceSetupTest method setupKernel.
@BeforeEach
void setupKernel() throws Exception {
fleetStatusDetails = new AtomicReference<>();
kernel = new Kernel();
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, FleetStatusServiceSetupTest.class.getResource("onlyMain.yaml"));
kernel.getContext().put(MqttClient.class, mqttClient);
when(mqttClient.publish(any(PublishRequest.class))).thenAnswer(i -> {
Object argument = i.getArgument(0);
PublishRequest publishRequest = (PublishRequest) argument;
try {
fleetStatusDetails.set(OBJECT_MAPPER.readValue(publishRequest.getPayload(), FleetStatusDetails.class));
} catch (JsonMappingException ignored) {
}
return CompletableFuture.completedFuture(0);
});
}
use of com.aws.greengrass.status.FleetStatusDetails in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsFleetStatusServiceTest method WHEN_deployment_bumps_up_component_version_THEN_status_of_new_version_is_updated_to_cloud.
@Test
void WHEN_deployment_bumps_up_component_version_THEN_status_of_new_version_is_updated_to_cloud() throws Exception {
((Map) kernel.getContext().getvIfExists(Kernel.SERVICE_TYPE_TO_CLASS_MAP_KEY).get()).put("plugin", GreengrassService.class.getName());
assertNotNull(deviceConfiguration.getThingName());
CountDownLatch jobsDeploymentLatch = new CountDownLatch(1);
CountDownLatch fssPublishLatch = new CountDownLatch(1);
logListener = eslm -> {
if (eslm.getMessage() != null && eslm.getMessage().equals(UPDATE_DEPLOYMENT_STATUS_ACCEPTED) && eslm.getContexts().get("JobId").equals("simpleApp2")) {
jobsDeploymentLatch.countDown();
}
if (jobsDeploymentLatch.getCount() == 0 && eslm.getEventType() != null && eslm.getEventType().equals("fss-status-update-published") && eslm.getMessage().equals("Status update published to FSS")) {
fssPublishLatch.countDown();
}
};
Slf4jLogAdapter.addGlobalListener(logListener);
// First local deployment adds SimpleApp v1
Map<String, String> componentsToMerge = new HashMap<>();
componentsToMerge.put("SimpleApp", "1.0.0");
LocalOverrideRequest request = LocalOverrideRequest.builder().requestId("SimpleApp1").componentsToMerge(componentsToMerge).requestTimestamp(System.currentTimeMillis()).build();
submitLocalDocument(request);
// Second local deployment removes SimpleApp v1
request = LocalOverrideRequest.builder().requestId("removeSimpleApp").componentsToRemove(Arrays.asList("SimpleApp")).requestTimestamp(System.currentTimeMillis()).build();
submitLocalDocument(request);
// Cloud deployment adds SimpleApp v2. First two deployments are local because this edge case is hit when device is
// offline after receiving the deployment and cannot emit FSS update. Since local deployment do not emit FSS update,
// this test simulates the device being offline by using local deployments.
offerSampleIoTJobsDeployment("FleetConfigSimpleApp2.json", "simpleApp2");
assertTrue(fssPublishLatch.await(180, TimeUnit.SECONDS));
verify(mqttClient, atLeastOnce()).publish(captor.capture());
List<PublishRequest> prs = captor.getAllValues();
// Get the last FSS publish request which should have component info of simpleApp v2 and other built in services
PublishRequest pr = prs.get(prs.size() - 1);
try {
FleetStatusDetails fleetStatusDetails = OBJECT_MAPPER.readValue(pr.getPayload(), FleetStatusDetails.class);
assertEquals("ThingName", fleetStatusDetails.getThing());
assertEquals(OverallStatus.HEALTHY, fleetStatusDetails.getOverallStatus());
assertNotNull(fleetStatusDetails.getComponentStatusDetails());
assertEquals(componentNamesToCheck.size(), fleetStatusDetails.getComponentStatusDetails().size());
fleetStatusDetails.getComponentStatusDetails().forEach(componentStatusDetails -> {
componentNamesToCheck.remove(componentStatusDetails.getComponentName());
if (componentStatusDetails.getComponentName().equals("SimpleApp")) {
assertEquals("2.0.0", componentStatusDetails.getVersion());
assertEquals(1, componentStatusDetails.getFleetConfigArns().size());
assertEquals(MOCK_FLEET_CONFIG_ARN, componentStatusDetails.getFleetConfigArns().get(0));
assertEquals(State.FINISHED, componentStatusDetails.getState());
assertTrue(componentStatusDetails.isRoot());
} else {
assertFalse(componentStatusDetails.isRoot());
}
});
} catch (UnrecognizedPropertyException ignored) {
}
assertEquals(0, componentNamesToCheck.size());
Slf4jLogAdapter.removeGlobalListener(logListener);
}
use of com.aws.greengrass.status.FleetStatusDetails in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsFleetStatusServiceTest method GIVEN_jobs_deployment_WHEN_deployment_finishes_THEN_status_is_uploaded_to_cloud.
@Test
void GIVEN_jobs_deployment_WHEN_deployment_finishes_THEN_status_is_uploaded_to_cloud(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, InvocationTargetException.class);
((Map) kernel.getContext().getvIfExists(Kernel.SERVICE_TYPE_TO_CLASS_MAP_KEY).get()).put("plugin", GreengrassService.class.getName());
assertNotNull(deviceConfiguration.getThingName());
CountDownLatch fssPublishLatch = new CountDownLatch(1);
logListener = eslm -> {
if (eslm.getEventType() != null && eslm.getEventType().equals("fss-status-update-published") && eslm.getMessage().equals("Status update published to FSS")) {
fssPublishLatch.countDown();
}
};
Slf4jLogAdapter.addGlobalListener(logListener);
offerSampleIoTJobsDeployment("FleetStatusServiceConfig.json", TEST_JOB_ID_1);
assertTrue(fssPublishLatch.await(60, TimeUnit.SECONDS));
verify(mqttClient, atLeastOnce()).publish(captor.capture());
List<PublishRequest> prs = captor.getAllValues();
// Get the last FSS publish request which should have all the components information.
PublishRequest pr = prs.get(prs.size() - 1);
try {
FleetStatusDetails fleetStatusDetails = OBJECT_MAPPER.readValue(pr.getPayload(), FleetStatusDetails.class);
assertEquals("ThingName", fleetStatusDetails.getThing());
assertEquals(OverallStatus.HEALTHY, fleetStatusDetails.getOverallStatus());
assertNotNull(fleetStatusDetails.getComponentStatusDetails());
assertEquals(componentNamesToCheck.size(), fleetStatusDetails.getComponentStatusDetails().size());
fleetStatusDetails.getComponentStatusDetails().forEach(componentStatusDetails -> {
componentNamesToCheck.remove(componentStatusDetails.getComponentName());
if (componentStatusDetails.getComponentName().equals("CustomerApp")) {
assertEquals("1.0.0", componentStatusDetails.getVersion());
assertEquals(1, componentStatusDetails.getFleetConfigArns().size());
assertEquals(MOCK_FLEET_CONFIG_ARN, componentStatusDetails.getFleetConfigArns().get(0));
assertEquals(State.FINISHED, componentStatusDetails.getState());
assertTrue(componentStatusDetails.isRoot());
} else if (componentStatusDetails.getComponentName().equals("Mosquitto")) {
assertEquals("1.0.0", componentStatusDetails.getVersion());
assertEquals(1, componentStatusDetails.getFleetConfigArns().size());
assertEquals(MOCK_FLEET_CONFIG_ARN, componentStatusDetails.getFleetConfigArns().get(0));
assertEquals(State.RUNNING, componentStatusDetails.getState());
assertFalse(componentStatusDetails.isRoot());
} else {
assertFalse(componentStatusDetails.isRoot());
}
});
} catch (UnrecognizedPropertyException ignored) {
}
assertEquals(0, componentNamesToCheck.size());
Slf4jLogAdapter.removeGlobalListener(logListener);
}
use of com.aws.greengrass.status.FleetStatusDetails in project aws-greengrass-nucleus by aws-greengrass.
the class PeriodicFleetStatusServiceTest method setupKernel.
@BeforeEach
void setupKernel(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, TLSAuthException.class);
CountDownLatch fssRunning = new CountDownLatch(1);
CountDownLatch deploymentServiceRunning = new CountDownLatch(1);
AtomicBoolean mainServiceFinished = new AtomicBoolean();
allComponentsInFssUpdate = new CountDownLatch(1);
fleetStatusDetails = new AtomicReference<>();
CompletableFuture cf = new CompletableFuture();
cf.complete(null);
kernel = new Kernel();
when(DEFAULT_HANDLER.retrieveWithDefault(any(), eq(TELEMETRY_TEST_PERIODIC_AGGREGATE_INTERVAL_SEC), any())).thenReturn(DEFAULT_PERIODIC_AGGREGATE_INTERVAL_SEC);
when(DEFAULT_HANDLER.retrieveWithDefault(any(), eq(TELEMETRY_TEST_PERIODIC_PUBLISH_INTERVAL_SEC), any())).thenReturn(DEFAULT_PERIODIC_PUBLISH_INTERVAL_SEC);
when(DEFAULT_HANDLER.retrieveWithDefault(any(), eq(FLEET_STATUS_TEST_PERIODIC_UPDATE_INTERVAL_SEC), any())).thenReturn(FSS_UPDATE_INTERVAL);
TestFeatureParameters.internalEnableTestingFeatureParameters(DEFAULT_HANDLER);
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, IotJobsFleetStatusServiceTest.class.getResource("onlyMain.yaml"));
kernel.getContext().put(MqttClient.class, mqttClient);
when(mqttClient.publish(any(PublishRequest.class))).thenAnswer(i -> {
Object argument = i.getArgument(0);
PublishRequest publishRequest = (PublishRequest) argument;
try {
fleetStatusDetails.set(OBJECT_MAPPER.readValue(publishRequest.getPayload(), FleetStatusDetails.class));
if (mainServiceFinished.get() && kernel.orderedDependencies().size() == fleetStatusDetails.get().getComponentStatusDetails().size()) {
allComponentsInFssUpdate.countDown();
}
} catch (JsonMappingException ignored) {
}
return CompletableFuture.completedFuture(0);
});
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals(FleetStatusService.FLEET_STATUS_SERVICE_TOPICS)) {
if (newState.equals(State.RUNNING)) {
fssRunning.countDown();
}
FleetStatusService fleetStatusService = (FleetStatusService) service;
fleetStatusService.setPeriodicPublishIntervalSec(FSS_UPDATE_INTERVAL);
fleetStatusService.schedulePeriodicFleetStatusDataUpdate(false);
}
if (service.getName().equals(DeploymentService.DEPLOYMENT_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
deploymentServiceRunning.countDown();
}
if (service.getName().equals(KernelCommandLine.MAIN_SERVICE_NAME) && newState.equals(State.FINISHED)) {
mainServiceFinished.set(true);
}
});
// set required instances from context
deviceConfiguration = new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath", "certFilePath", "caFilePath", "us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
kernel.launch();
assertTrue(deploymentServiceRunning.await(10, TimeUnit.SECONDS));
assertTrue(fssRunning.await(10, TimeUnit.SECONDS));
}
Aggregations