Search in sources :

Example 1 with DeploymentDirectoryManager

use of com.aws.greengrass.deployment.DeploymentDirectoryManager 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 2 with DeploymentDirectoryManager

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

the class KernelTest method GIVEN_kernel_launch_WHEN_bootstrap_task_fails_and_prepare_rollback_fails_THEN_continue.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_launch_WHEN_bootstrap_task_fails_and_prepare_rollback_fails_THEN_continue(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, ServiceUpdateException.class);
    ignoreExceptionOfType(context, IOException.class);
    KernelLifecycle kernelLifecycle = mock(KernelLifecycle.class);
    kernel.setKernelLifecycle(kernelLifecycle);
    KernelCommandLine kernelCommandLine = mock(KernelCommandLine.class);
    KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
    doReturn(BOOTSTRAP).when(kernelAlternatives).determineDeploymentStage(any(), any());
    doThrow(new IOException()).when(kernelAlternatives).prepareRollback();
    kernel.getContext().put(KernelAlternatives.class, kernelAlternatives);
    Deployment deployment = mock(Deployment.class);
    DeploymentDirectoryManager deploymentDirectoryManager = mock(DeploymentDirectoryManager.class);
    doReturn(mock(Path.class)).when(deploymentDirectoryManager).getBootstrapTaskFilePath();
    doReturn(mockFile).when(deploymentDirectoryManager).getTargetConfigFilePath();
    doReturn(deployment).when(deploymentDirectoryManager).readDeploymentMetadata();
    doNothing().when(deploymentDirectoryManager).writeDeploymentMetadata(any());
    doReturn(deploymentDirectoryManager).when(kernelCommandLine).getDeploymentDirectoryManager();
    BootstrapManager bootstrapManager = mock(BootstrapManager.class);
    doThrow(new ServiceUpdateException("mock error")).when(bootstrapManager).executeAllBootstrapTasksSequentially(any());
    doReturn(bootstrapManager).when(kernelCommandLine).getBootstrapManager();
    kernel.setKernelCommandLine(kernelCommandLine);
    try {
        kernel.parseArgs().launch();
    } catch (RuntimeException ignored) {
    }
    verify(kernelAlternatives).prepareRollback();
    verify(kernelLifecycle).shutdown(eq(30), eq(REQUEST_RESTART));
}
Also used : Path(java.nio.file.Path) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) Deployment(com.aws.greengrass.deployment.model.Deployment) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) IOException(java.io.IOException) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) Test(org.junit.jupiter.api.Test)

Example 3 with DeploymentDirectoryManager

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

the class KernelTest method GIVEN_kernel_launch_WHEN_bootstrap_task_finishes_THEN_prepare_restart_into_activation.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_launch_WHEN_bootstrap_task_finishes_THEN_prepare_restart_into_activation() throws Exception {
    KernelLifecycle kernelLifecycle = mock(KernelLifecycle.class);
    kernel.setKernelLifecycle(kernelLifecycle);
    KernelCommandLine kernelCommandLine = mock(KernelCommandLine.class);
    KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
    doReturn(BOOTSTRAP).when(kernelAlternatives).determineDeploymentStage(any(), any());
    kernel.getContext().put(KernelAlternatives.class, kernelAlternatives);
    DeploymentDirectoryManager deploymentDirectoryManager = mock(DeploymentDirectoryManager.class);
    doReturn(mock(Path.class)).when(deploymentDirectoryManager).getBootstrapTaskFilePath();
    doReturn(mockFile).when(deploymentDirectoryManager).getTargetConfigFilePath();
    doReturn(deploymentDirectoryManager).when(kernelCommandLine).getDeploymentDirectoryManager();
    BootstrapManager bootstrapManager = mock(BootstrapManager.class);
    doReturn(NO_OP).when(bootstrapManager).executeAllBootstrapTasksSequentially(any());
    doReturn(false).when(bootstrapManager).hasNext();
    doReturn(bootstrapManager).when(kernelCommandLine).getBootstrapManager();
    kernel.setKernelCommandLine(kernelCommandLine);
    try {
        kernel.parseArgs().launch();
    } catch (RuntimeException ignored) {
    }
    verify(kernelLifecycle).shutdown(eq(30), eq(REQUEST_RESTART));
}
Also used : Path(java.nio.file.Path) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) Test(org.junit.jupiter.api.Test)

Example 4 with DeploymentDirectoryManager

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

the class KernelCommandLine method initPaths.

private void initPaths(String rootAbsolutePath) {
    // init all paths
    try {
        // Set root path first, so that deTilde works on the subsequent calls
        nucleusPaths.setRootPath(Paths.get(rootAbsolutePath).toAbsolutePath());
        // set root path for the telemetry logger
        TelemetryConfig.getInstance().setRoot(Paths.get(deTilde(ROOT_DIR_PREFIX)));
        LogManager.setRoot(Paths.get(deTilde(ROOT_DIR_PREFIX)));
        nucleusPaths.setTelemetryPath(TelemetryConfig.getInstance().getStoreDirectory());
        String storeDirectory = LogManager.getRootLogConfiguration().getStoreDirectory().toAbsolutePath().toString();
        nucleusPaths.setLoggerPath(Paths.get(storeDirectory));
        nucleusPaths.initPaths(Paths.get(rootAbsolutePath).toAbsolutePath(), Paths.get(deTilde(workPathName)).toAbsolutePath(), Paths.get(deTilde(packageStorePathName)).toAbsolutePath(), Paths.get(deTilde(configPathName)).toAbsolutePath(), Paths.get(deTilde(kernelAltsPathName)).toAbsolutePath(), Paths.get(deTilde(deploymentsPathName)).toAbsolutePath(), Paths.get(deTilde(cliIpcInfoPathName)).toAbsolutePath(), Paths.get(deTilde(binPathName)).toAbsolutePath());
        // Initialize file and directory managers after kernel root directory is set up
        deploymentDirectoryManager = new DeploymentDirectoryManager(kernel, nucleusPaths);
        kernel.getContext().put(DeploymentDirectoryManager.class, deploymentDirectoryManager);
    } catch (IOException e) {
        RuntimeException rte = new RuntimeException("Cannot create all required directories", e);
        logger.atError("system-boot-error", rte).log();
        throw rte;
    }
    // GG_NEEDS_REVIEW (Hui): TODO: Add current kernel to local component store, if not exits.
    // Add symlinks for current Kernel alt, if not exits
    // Register Kernel Loader as system service (platform-specific), if not exits
    bootstrapManager = new BootstrapManager(kernel);
    kernel.getContext().put(BootstrapManager.class, bootstrapManager);
    kernel.getContext().get(KernelAlternatives.class);
}
Also used : BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) IOException(java.io.IOException)

Example 5 with DeploymentDirectoryManager

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

the class KernelTest method GIVEN_kernel_launch_WHEN_bootstrap_task_fails_THEN_prepare_rollback.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_launch_WHEN_bootstrap_task_fails_THEN_prepare_rollback(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, ServiceUpdateException.class);
    KernelLifecycle kernelLifecycle = mock(KernelLifecycle.class);
    kernel.setKernelLifecycle(kernelLifecycle);
    KernelCommandLine kernelCommandLine = mock(KernelCommandLine.class);
    KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
    doReturn(BOOTSTRAP).when(kernelAlternatives).determineDeploymentStage(any(), any());
    kernel.getContext().put(KernelAlternatives.class, kernelAlternatives);
    Deployment deployment = mock(Deployment.class);
    DeploymentDirectoryManager deploymentDirectoryManager = mock(DeploymentDirectoryManager.class);
    doReturn(mock(Path.class)).when(deploymentDirectoryManager).getBootstrapTaskFilePath();
    doReturn(mockFile).when(deploymentDirectoryManager).getTargetConfigFilePath();
    doReturn(deployment).when(deploymentDirectoryManager).readDeploymentMetadata();
    doReturn(deploymentDirectoryManager).when(kernelCommandLine).getDeploymentDirectoryManager();
    BootstrapManager bootstrapManager = mock(BootstrapManager.class);
    doThrow(new ServiceUpdateException("mock error")).when(bootstrapManager).executeAllBootstrapTasksSequentially(any());
    doReturn(bootstrapManager).when(kernelCommandLine).getBootstrapManager();
    kernel.setKernelCommandLine(kernelCommandLine);
    try {
        kernel.parseArgs().launch();
    } catch (RuntimeException ignored) {
    }
    verify(kernelAlternatives).prepareRollback();
    verify(deploymentDirectoryManager).writeDeploymentMetadata(eq(deployment));
    verify(kernelLifecycle).shutdown(eq(30), eq(REQUEST_RESTART));
}
Also used : Path(java.nio.file.Path) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) Deployment(com.aws.greengrass.deployment.model.Deployment) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentDirectoryManager (com.aws.greengrass.deployment.DeploymentDirectoryManager)9 BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)9 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 Deployment (com.aws.greengrass.deployment.model.Deployment)4 DeploymentQueue (com.aws.greengrass.deployment.DeploymentQueue)3 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)3 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)2 DeviceConfigurationException (com.aws.greengrass.deployment.exceptions.DeviceConfigurationException)1 DeploymentStage (com.aws.greengrass.deployment.model.Deployment.DeploymentStage)1