use of com.aws.greengrass.lifecyclemanager.KernelAlternatives in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfiguration method persistInitialLaunchParams.
/**
* Persist initial launch parameters of JVM options.
*
* @param kernelAlts KernelAlternatives instance
*/
void persistInitialLaunchParams(KernelAlternatives kernelAlts) {
if (Files.exists(kernelAlts.getLaunchParamsPath())) {
logger.atDebug().log("Nucleus launch parameters has already been set up");
return;
}
// Persist initial Nucleus launch parameters
try {
String jvmOptions = ManagementFactory.getRuntimeMXBean().getInputArguments().stream().sorted().filter(s -> !s.startsWith(JVM_OPTION_ROOT_PATH)).collect(Collectors.joining(" "));
kernel.getConfig().lookup(SERVICES_NAMESPACE_TOPIC, getNucleusComponentName(), CONFIGURATION_CONFIG_KEY, DEVICE_PARAM_JVM_OPTIONS).withNewerValue(DEFAULT_VALUE_TIMESTAMP + 1, jvmOptions);
kernelAlts.writeLaunchParamsToFile(jvmOptions);
logger.atInfo().log("Successfully setup Nucleus launch parameters");
} catch (IOException e) {
logger.atError().log("Unable to setup Nucleus launch parameters", e);
}
}
use of com.aws.greengrass.lifecyclemanager.KernelAlternatives in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfigurationTest method GIVEN_existing_launch_param_file_WHEN_persistInitialLaunchParams_THEN_skip.
@Test
void GIVEN_existing_launch_param_file_WHEN_persistInitialLaunchParams_THEN_skip(@TempDir Path tempDir) throws Exception {
deviceConfiguration = new DeviceConfiguration(mockKernel);
KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
Path tempFile = tempDir.resolve("testFile");
Files.createFile(tempFile);
doReturn(tempFile).when(kernelAlternatives).getLaunchParamsPath();
deviceConfiguration.persistInitialLaunchParams(kernelAlternatives);
verify(kernelAlternatives, times(0)).writeLaunchParamsToFile(anyString());
}
use of com.aws.greengrass.lifecyclemanager.KernelAlternatives in project aws-greengrass-nucleus by aws-greengrass.
the class BaseITCase method setup.
@BeforeAll
static void setup() throws IOException, InterruptedException {
if (!PlatformResolver.isWindows) {
return;
}
// To test runWith on Windows, need to prepare user and credential
createWindowsTestUser(WINDOWS_TEST_UESRNAME, WINDOWS_TEST_PASSWORD);
createWindowsTestUser(WINDOWS_TEST_UESRNAME_2, WINDOWS_TEST_PASSWORD);
WindowsCredUtils.add(WINDOWS_TEST_UESRNAME, WINDOWS_TEST_PASSWORD.getBytes(WindowsCredUtils.getCharsetForSystem()));
WindowsCredUtils.add(WINDOWS_TEST_UESRNAME_2, WINDOWS_TEST_PASSWORD.getBytes(WindowsCredUtils.getCharsetForSystem()));
// mock runas path
KernelAlternatives mockKernelAlts = mock(KernelAlternatives.class);
when(mockKernelAlts.getBinDir()).thenReturn(Paths.get("scripts").toAbsolutePath());
testContext = new Context();
testContext.put(KernelAlternatives.class, mockKernelAlts);
}
use of com.aws.greengrass.lifecyclemanager.KernelAlternatives in project aws-greengrass-nucleus by aws-greengrass.
the class DeviceConfigurationTest method GIVEN_no_launch_param_file_WHEN_persistInitialLaunchParams_THEN_write_jvm_args_to_file.
@Test
void GIVEN_no_launch_param_file_WHEN_persistInitialLaunchParams_THEN_write_jvm_args_to_file(@TempDir Path tempDir) throws Exception {
deviceConfiguration = new DeviceConfiguration(mockKernel);
KernelAlternatives kernelAlternatives = mock(KernelAlternatives.class);
Path tempFile = tempDir.resolve("testFile");
doReturn(tempFile).when(kernelAlternatives).getLaunchParamsPath();
deviceConfiguration.persistInitialLaunchParams(kernelAlternatives);
verify(kernelAlternatives).writeLaunchParamsToFile(anyString());
}
use of com.aws.greengrass.lifecyclemanager.KernelAlternatives in project aws-greengrass-nucleus by aws-greengrass.
the class PluginComponentTest method GIVEN_kernel_WHEN_deploy_updated_plugin_THEN_request_kernel_restart.
@Test
void GIVEN_kernel_WHEN_deploy_updated_plugin_THEN_request_kernel_restart(ExtensionContext context) throws Exception {
ignoreExceptionOfType(context, PackageDownloadException.class);
ignoreExceptionOfType(context, IOException.class);
ignoreExceptionOfType(context, SdkClientException.class);
Kernel kernelSpy = spy(kernel.parseArgs());
setupPackageStoreAndConfigWithDigest();
String deploymentId = "deployment1";
KernelAlternatives kernelAltsSpy = spy(kernelSpy.getContext().get(KernelAlternatives.class));
kernelSpy.getContext().put(KernelAlternatives.class, kernelAltsSpy);
// In actual workflow, DeploymentService will setup deployment artifacts directory per deployment before
// submitting task. Here in test, it's called explicitly because the directory is required by snapshot file.
kernelSpy.getContext().get(DeploymentDirectoryManager.class).createNewDeploymentDirectory(deploymentId);
kernelSpy.getContext().put(KernelUpdateActivator.class, new KernelUpdateActivator(kernelSpy, kernelSpy.getContext().get(BootstrapManager.class)));
// launch Nucleus
kernelSpy.launch();
// Ensure that the dependency isn't somehow in our class loader already
assertThrows(ClassNotFoundException.class, () -> Class.forName("com.aws.greengrass.integrationtests.lifecyclemanager.resource.PluginDependency"));
// First deployment to add plugin-1.0.0 to kernel
submitSampleJobDocument(getPluginDeploymentDocument(System.currentTimeMillis(), "1.0.0", deploymentId, FailureHandlingPolicy.DO_NOTHING, componentName), kernelSpy).get(30, TimeUnit.SECONDS);
GreengrassService eg = kernelSpy.locate(componentName);
assertEquals("com.aws.greengrass.integrationtests.lifecyclemanager.resource.APluginService", eg.getClass().getName());
assertEquals(componentId.getVersion().toString(), Coerce.toString(eg.getServiceConfig().findLeafChild(VERSION_CONFIG_KEY)));
kernelSpy.getContext().get(EZPlugins.class).forName("com.aws.greengrass.integrationtests.lifecyclemanager.resource.PluginDependency");
// setup again because local files removed by cleanup in the previous deployment
setupPackageStoreAndConfigWithDigest();
String deploymentId2 = "deployment2";
// No need to actually verify directory setup or make directory changes here.
doReturn(true).when(kernelAltsSpy).isLaunchDirSetup();
doNothing().when(kernelAltsSpy).prepareBootstrap(eq(deploymentId2));
doNothing().when(kernelSpy).shutdown(anyInt(), eq(REQUEST_RESTART));
// Second deployment to add plugin-1.1.0 to kernel which should enter kernel restart workflow
assertThrows(TimeoutException.class, () -> submitSampleJobDocument(getPluginDeploymentDocument(System.currentTimeMillis(), "1.1.0", deploymentId2, FailureHandlingPolicy.DO_NOTHING, componentName), kernelSpy).get(10, TimeUnit.SECONDS));
verify(kernelSpy).shutdown(eq(30), eq(REQUEST_RESTART));
}
Aggregations