Search in sources :

Example 1 with BootstrapManager

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

use of com.aws.greengrass.deployment.bootstrap.BootstrapManager 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 3 with BootstrapManager

use of com.aws.greengrass.deployment.bootstrap.BootstrapManager 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 4 with BootstrapManager

use of com.aws.greengrass.deployment.bootstrap.BootstrapManager 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)

Example 5 with BootstrapManager

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

the class KernelTest method GIVEN_kernel_launch_WHEN_bootstrap_task_requires_reboot_THEN_prepare_reboot.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
@Test
void GIVEN_kernel_launch_WHEN_bootstrap_task_requires_reboot_THEN_prepare_reboot() 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(REQUEST_REBOOT).when(bootstrapManager).executeAllBootstrapTasksSequentially(any());
    doReturn(true).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_REBOOT));
}
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)

Aggregations

BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)10 DeploymentDirectoryManager (com.aws.greengrass.deployment.DeploymentDirectoryManager)7 Test (org.junit.jupiter.api.Test)7 Path (java.nio.file.Path)5 IOException (java.io.IOException)4 DefaultActivator (com.aws.greengrass.deployment.activator.DefaultActivator)3 DeploymentActivatorFactory (com.aws.greengrass.deployment.activator.DeploymentActivatorFactory)3 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)3 ComponentUpdatePolicy (com.aws.greengrass.deployment.model.ComponentUpdatePolicy)3 Deployment (com.aws.greengrass.deployment.model.Deployment)3 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)3 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)3 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)3 Topic (com.aws.greengrass.config.Topic)2 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)2 HashMap (java.util.HashMap)2 DeploymentQueue (com.aws.greengrass.deployment.DeploymentQueue)1 DeviceConfigurationException (com.aws.greengrass.deployment.exceptions.DeviceConfigurationException)1 DeploymentStage (com.aws.greengrass.deployment.model.Deployment.DeploymentStage)1