Search in sources :

Example 1 with IotJobsHelper

use of com.aws.greengrass.deployment.IotJobsHelper in project aws-greengrass-nucleus by aws-greengrass.

the class IotJobsFleetStatusServiceTest method setupKernel.

@SuppressWarnings("PMD.CloseResource")
@BeforeEach
void setupKernel(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, TLSAuthException.class);
    ignoreExceptionOfType(context, PackageDownloadException.class);
    ignoreExceptionUltimateCauseOfType(context, EOFException.class);
    ignoreExceptionUltimateCauseOfType(context, ResourceNotFoundException.class);
    CountDownLatch fssRunning = new CountDownLatch(1);
    CountDownLatch deploymentServiceRunning = new CountDownLatch(1);
    CompletableFuture<Void> cf = new CompletableFuture<>();
    cf.complete(null);
    lenient().when(mockIotJobsClientWrapper.PublishUpdateJobExecution(any(UpdateJobExecutionRequest.class), any(QualityOfService.class))).thenAnswer(invocationOnMock -> {
        verify(mockIotJobsClientWrapper, atLeastOnce()).SubscribeToUpdateJobExecutionAccepted(any(), eq(QualityOfService.AT_LEAST_ONCE), jobsAcceptedHandlerCaptor.capture());
        Consumer<UpdateJobExecutionResponse> jobResponseConsumer = jobsAcceptedHandlerCaptor.getValue();
        UpdateJobExecutionResponse mockJobExecutionResponse = mock(UpdateJobExecutionResponse.class);
        jobResponseConsumer.accept(mockJobExecutionResponse);
        return cf;
    });
    lenient().when(mqttClient.publish(any())).thenReturn(CompletableFuture.completedFuture(0));
    kernel = new Kernel();
    NoOpPathOwnershipHandler.register(kernel);
    ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, IotJobsFleetStatusServiceTest.class.getResource("onlyMain.yaml"));
    kernel.getContext().put(MqttClient.class, mqttClient);
    kernel.getContext().put(ThingGroupHelper.class, thingGroupHelper);
    // Mock out cloud communication
    GreengrassServiceClientFactory mgscf = mock(GreengrassServiceClientFactory.class);
    GreengrassV2DataClient mcf = mock(GreengrassV2DataClient.class);
    lenient().when(mcf.resolveComponentCandidates(any(ResolveComponentCandidatesRequest.class))).thenThrow(ResourceNotFoundException.class);
    lenient().when(mgscf.getGreengrassV2DataClient()).thenReturn(mcf);
    kernel.getContext().put(GreengrassServiceClientFactory.class, mgscf);
    componentNamesToCheck.clear();
    kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
        if (service.getName().equals(FleetStatusService.FLEET_STATUS_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
            fssRunning.countDown();
        }
        if (service.getName().equals(DeploymentService.DEPLOYMENT_SERVICE_TOPICS) && newState.equals(State.RUNNING)) {
            deploymentServiceRunning.countDown();
            deploymentService = (DeploymentService) service;
            IotJobsHelper iotJobsHelper = deploymentService.getContext().get(IotJobsHelper.class);
            iotJobsHelper.setIotJobsClientWrapper(mockIotJobsClientWrapper);
        }
        componentNamesToCheck.add(service.getName());
    });
    // 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);
    // pre-load contents to package store
    Path localStoreContentPath = Paths.get(IotJobsFleetStatusServiceTest.class.getResource("local_store_content").toURI());
    PreloadComponentStoreHelper.preloadRecipesFromTestResourceDir(localStoreContentPath.resolve("recipes"), kernel.getNucleusPaths().recipePath());
    copyFolderRecursively(localStoreContentPath.resolve("artifacts"), kernel.getNucleusPaths().artifactPath(), REPLACE_EXISTING);
    kernel.launch();
    assertTrue(fssRunning.await(10, TimeUnit.SECONDS));
    assertTrue(deploymentServiceRunning.await(10, TimeUnit.SECONDS));
}
Also used : Path(java.nio.file.Path) UpdateJobExecutionResponse(software.amazon.awssdk.iot.iotjobs.model.UpdateJobExecutionResponse) GreengrassServiceClientFactory(com.aws.greengrass.util.GreengrassServiceClientFactory) CountDownLatch(java.util.concurrent.CountDownLatch) GreengrassV2DataClient(software.amazon.awssdk.services.greengrassv2data.GreengrassV2DataClient) CompletableFuture(java.util.concurrent.CompletableFuture) IotJobsHelper(com.aws.greengrass.deployment.IotJobsHelper) UpdateJobExecutionRequest(software.amazon.awssdk.iot.iotjobs.model.UpdateJobExecutionRequest) QualityOfService(software.amazon.awssdk.crt.mqtt.QualityOfService) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) ResolveComponentCandidatesRequest(software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 IotJobsHelper (com.aws.greengrass.deployment.IotJobsHelper)1 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)1 GreengrassServiceClientFactory (com.aws.greengrass.util.GreengrassServiceClientFactory)1 Path (java.nio.file.Path)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 QualityOfService (software.amazon.awssdk.crt.mqtt.QualityOfService)1 UpdateJobExecutionRequest (software.amazon.awssdk.iot.iotjobs.model.UpdateJobExecutionRequest)1 UpdateJobExecutionResponse (software.amazon.awssdk.iot.iotjobs.model.UpdateJobExecutionResponse)1 GreengrassV2DataClient (software.amazon.awssdk.services.greengrassv2data.GreengrassV2DataClient)1 ResolveComponentCandidatesRequest (software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesRequest)1