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);
}
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());
}
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);
}
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));
}
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());
}
Aggregations