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