Search in sources :

Example 1 with FleetStatusService

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);
}
Also used : FleetStatusService(com.aws.greengrass.status.FleetStatusService) CountDownLatch(java.util.concurrent.CountDownLatch) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with FleetStatusService

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));
}
Also used : FleetStatusDetails(com.aws.greengrass.status.FleetStatusDetails) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) FleetStatusService(com.aws.greengrass.status.FleetStatusService) CountDownLatch(java.util.concurrent.CountDownLatch) PublishRequest(com.aws.greengrass.mqttclient.PublishRequest) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with FleetStatusService

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());
}
Also used : FleetStatusService(com.aws.greengrass.status.FleetStatusService) CountDownLatch(java.util.concurrent.CountDownLatch) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Kernel (com.aws.greengrass.lifecyclemanager.Kernel)3 FleetStatusService (com.aws.greengrass.status.FleetStatusService)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 DeploymentQueue (com.aws.greengrass.deployment.DeploymentQueue)2 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 PublishRequest (com.aws.greengrass.mqttclient.PublishRequest)1 FleetStatusDetails (com.aws.greengrass.status.FleetStatusDetails)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1