Search in sources :

Example 1 with DeploymentQueue

use of com.aws.greengrass.deployment.DeploymentQueue 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 DeploymentQueue

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

the class KernelTest method GIVEN_kernel_launch_WHEN_deployment_rollback_cannot_reload_deployment_THEN_proceed_as_default.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_launch_WHEN_deployment_rollback_cannot_reload_deployment_THEN_proceed_as_default(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, IOException.class);
    KernelLifecycle kernelLifecycle = mock(KernelLifecycle.class);
    doNothing().when(kernelLifecycle).initConfigAndTlog(any());
    doNothing().when(kernelLifecycle).launch();
    kernel.setKernelLifecycle(kernelLifecycle);
    KernelCommandLine kernelCommandLine = mock(KernelCommandLine.class);
    KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
    doReturn(KERNEL_ROLLBACK).when(kernelAlternatives).determineDeploymentStage(any(), any());
    kernel.getContext().put(KernelAlternatives.class, kernelAlternatives);
    DeploymentDirectoryManager deploymentDirectoryManager = mock(DeploymentDirectoryManager.class);
    doThrow(new IOException()).when(deploymentDirectoryManager).readDeploymentMetadata();
    doReturn(mockFile).when(deploymentDirectoryManager).getSnapshotFilePath();
    doReturn(deploymentDirectoryManager).when(kernelCommandLine).getDeploymentDirectoryManager();
    doReturn(mock(BootstrapManager.class)).when(kernelCommandLine).getBootstrapManager();
    kernel.setKernelCommandLine(kernelCommandLine);
    try {
        kernel.parseArgs().launch();
    } catch (RuntimeException ignored) {
    }
    DeploymentQueue deployments = kernel.getContext().get(DeploymentQueue.class);
    assertNull(deployments.peek());
}
Also used : BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) IOException(java.io.IOException) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue) Test(org.junit.jupiter.api.Test)

Example 3 with DeploymentQueue

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

the class IotJobsFleetStatusServiceTest method submitLocalDocument.

private void submitLocalDocument(LocalOverrideRequest request) throws Exception {
    DeploymentQueue deploymentQueue = (DeploymentQueue) kernel.getContext().getvIfExists(DeploymentQueue.class).get();
    Deployment deployment = new Deployment(OBJECT_MAPPER.writeValueAsString(request), DeploymentType.LOCAL, request.getRequestId());
    deploymentQueue.offer(deployment);
}
Also used : Deployment(com.aws.greengrass.deployment.model.Deployment) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue)

Example 4 with DeploymentQueue

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

the class IotJobsFleetStatusServiceTest method offerSampleIoTJobsDeployment.

private void offerSampleIoTJobsDeployment(String fileName, String deploymentId) throws Exception {
    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);
    DeploymentQueue deploymentQueue = (DeploymentQueue) kernel.getContext().getvIfExists(DeploymentQueue.class).get();
    Configuration deploymentConfiguration = OBJECT_MAPPER.readValue(new File(getClass().getResource(fileName).toURI()), Configuration.class);
    deploymentQueue.offer(new Deployment(OBJECT_MAPPER.writeValueAsString(deploymentConfiguration), DeploymentType.IOT_JOBS, deploymentId));
}
Also used : Path(java.nio.file.Path) Configuration(com.amazon.aws.iot.greengrass.configuration.common.Configuration) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) Deployment(com.aws.greengrass.deployment.model.Deployment) File(java.io.File) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue)

Example 5 with DeploymentQueue

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

the class KernelTest method GIVEN_kernel_launch_WHEN_deployment_activation_happy_path_THEN_inject_deployment.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_launch_WHEN_deployment_activation_happy_path_THEN_inject_deployment() throws Exception {
    KernelLifecycle kernelLifecycle = mock(KernelLifecycle.class);
    doNothing().when(kernelLifecycle).launch();
    doNothing().when(kernelLifecycle).initConfigAndTlog(any());
    kernel.setKernelLifecycle(kernelLifecycle);
    KernelCommandLine kernelCommandLine = mock(KernelCommandLine.class);
    KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
    doReturn(KERNEL_ACTIVATION).when(kernelAlternatives).determineDeploymentStage(any(), any());
    kernel.getContext().put(KernelAlternatives.class, kernelAlternatives);
    DeploymentDirectoryManager deploymentDirectoryManager = mock(DeploymentDirectoryManager.class);
    doReturn(mock(Deployment.class)).when(deploymentDirectoryManager).readDeploymentMetadata();
    doReturn(mockFile).when(deploymentDirectoryManager).getTargetConfigFilePath();
    doReturn(deploymentDirectoryManager).when(kernelCommandLine).getDeploymentDirectoryManager();
    doReturn(mock(BootstrapManager.class)).when(kernelCommandLine).getBootstrapManager();
    kernel.setKernelCommandLine(kernelCommandLine);
    try {
        kernel.parseArgs().launch();
    } catch (RuntimeException ignored) {
    }
    DeploymentQueue deployments = kernel.getContext().get(DeploymentQueue.class);
    assertNotNull(deployments.peek());
    deployments.remove();
    assertTrue(deployments.isEmpty());
}
Also used : BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) Deployment(com.aws.greengrass.deployment.model.Deployment) DeploymentQueue(com.aws.greengrass.deployment.DeploymentQueue) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentQueue (com.aws.greengrass.deployment.DeploymentQueue)7 Deployment (com.aws.greengrass.deployment.model.Deployment)4 DeploymentDirectoryManager (com.aws.greengrass.deployment.DeploymentDirectoryManager)3 BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)3 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)2 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)2 FleetStatusService (com.aws.greengrass.status.FleetStatusService)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 Configuration (com.amazon.aws.iot.greengrass.configuration.common.Configuration)1 DeviceConfigurationException (com.aws.greengrass.deployment.exceptions.DeviceConfigurationException)1 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)1 File (java.io.File)1 Path (java.nio.file.Path)1