use of com.aws.greengrass.status.FleetStatusService in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentServiceIntegrationTest method before.
@BeforeEach
void before(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, PackageDownloadException.class);
ignoreExceptionOfType(context, SdkClientException.class);
kernel = new Kernel();
kernel.getContext().put(DeploymentDocumentDownloader.class, deploymentDocumentDownloader);
NoOpPathOwnershipHandler.register(kernel);
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, DeploymentServiceIntegrationTest.class.getResource("onlyMain.yaml"));
// ensure deployment service starts
CountDownLatch deploymentServiceLatch = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals(DEPLOYMENT_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
deploymentServiceLatch.countDown();
}
});
setDeviceConfig(kernel, DeviceConfiguration.DEPLOYMENT_POLLING_FREQUENCY_SECONDS, 1L);
kernel.launch();
assertTrue(deploymentServiceLatch.await(10, TimeUnit.SECONDS));
deploymentQueue = kernel.getContext().get(DeploymentQueue.class);
FleetStatusService fleetStatusService = (FleetStatusService) kernel.locate(FLEET_STATUS_SERVICE_TOPICS);
fleetStatusService.getIsConnected().set(false);
// pre-load contents to package store
localStoreContentPath = Paths.get(DeploymentTaskIntegrationTest.class.getResource("local_store_content").toURI());
PreloadComponentStoreHelper.preloadRecipesFromTestResourceDir(localStoreContentPath.resolve("recipes"), kernel.getNucleusPaths().recipePath());
copyFolderRecursively(localStoreContentPath.resolve("artifacts"), kernel.getNucleusPaths().artifactPath(), REPLACE_EXISTING);
}
use of com.aws.greengrass.status.FleetStatusService 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));
}
use of com.aws.greengrass.status.FleetStatusService in project aws-greengrass-nucleus by aws-greengrass.
the class MultiGroupDeploymentTest method before.
@BeforeEach
void before(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, PackageDownloadException.class);
ignoreExceptionOfType(context, SdkClientException.class);
kernel = new Kernel();
kernel.getContext().put(ThingGroupHelper.class, thingGroupHelper);
NoOpPathOwnershipHandler.register(kernel);
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, DeploymentServiceIntegrationTest.class.getResource("onlyMain.yaml"));
// ensure deployment service starts
CountDownLatch deploymentServiceLatch = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals(DEPLOYMENT_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
deploymentServiceLatch.countDown();
}
});
setDeviceConfig(kernel, DeviceConfiguration.DEPLOYMENT_POLLING_FREQUENCY_SECONDS, 1L);
kernel.launch();
assertTrue(deploymentServiceLatch.await(10, TimeUnit.SECONDS));
deploymentQueue = kernel.getContext().get(DeploymentQueue.class);
FleetStatusService fleetStatusService = (FleetStatusService) kernel.locate(FLEET_STATUS_SERVICE_TOPICS);
fleetStatusService.getIsConnected().set(false);
localStoreContentPath = Paths.get(DeploymentTaskIntegrationTest.class.getResource("local_store_content").toURI());
}
Aggregations