From e570039c6a38034d58552e871e3e694b05b52e63 Mon Sep 17 00:00:00 2001 From: Siddhant Srivastava Date: Mon, 2 Dec 2024 17:52:34 -0800 Subject: [PATCH] fix: link launch dir with existing nucleus package if does not exist --- .../errorcode/DeploymentErrorCode.java | 2 +- .../lifecyclemanager/KernelAlternatives.java | 18 +++++++++++++++--- .../DirectoryValidationException.java | 5 +++++ .../activator/KernelUpdateActivatorTest.java | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/aws/greengrass/deployment/errorcode/DeploymentErrorCode.java b/src/main/java/com/aws/greengrass/deployment/errorcode/DeploymentErrorCode.java index ec604e9b33..4ee20370d4 100644 --- a/src/main/java/com/aws/greengrass/deployment/errorcode/DeploymentErrorCode.java +++ b/src/main/java/com/aws/greengrass/deployment/errorcode/DeploymentErrorCode.java @@ -64,7 +64,7 @@ public enum DeploymentErrorCode { // JVM hashing issue HASHING_ALGORITHM_UNAVAILABLE(DeploymentErrorType.DEVICE_ERROR), // Could be a local file issue or a Nucleus issue; we will categorize as the latter for visibility - LAUNCH_DIRECTORY_CORRUPTED(DeploymentErrorType.NUCLEUS_ERROR), + LAUNCH_DIRECTORY_CORRUPTED(DeploymentErrorType.DEVICE_ERROR), /* Component recipe errors */ RECIPE_PARSE_ERROR(DeploymentErrorType.COMPONENT_RECIPE_ERROR), diff --git a/src/main/java/com/aws/greengrass/lifecyclemanager/KernelAlternatives.java b/src/main/java/com/aws/greengrass/lifecyclemanager/KernelAlternatives.java index 3bffaaa754..baa8130272 100644 --- a/src/main/java/com/aws/greengrass/lifecyclemanager/KernelAlternatives.java +++ b/src/main/java/com/aws/greengrass/lifecyclemanager/KernelAlternatives.java @@ -169,10 +169,22 @@ public boolean isLaunchDirSetup() { * @throws DeploymentException when user is not allowed to change file permission */ public void validateLaunchDirSetupVerbose() throws DirectoryValidationException, DeploymentException { - Path currentDir = getCurrentDir(); - if (!Files.isSymbolicLink(currentDir)) { - throw new DirectoryValidationException("Missing symlink to current nucleus launch directory"); + if (!Files.isSymbolicLink(getCurrentDir())) { + try { + /* + Simply recreating a new init dir and relinking the current Nucleus jar path to it should be + sufficient as the kernel update workflow will create the new launch dir and its links anyway + */ + relinkInitLaunchDir(locateCurrentKernelUnpackDir(), true); + } catch (IOException ex) { + throw new DirectoryValidationException("Unable to relink init launch directory", ex); + } catch (URISyntaxException ex) { + // TODO: Fix usage of root path with spaces on linux + throw new DeploymentException("Unable to relink init launch directory", ex); + } } + + Path currentDir = getCurrentDir(); Path loaderPath = getLoaderPathFromLaunchDir(currentDir); if (Files.exists(loaderPath)) { if (!loaderPath.toFile().canExecute()) { diff --git a/src/main/java/com/aws/greengrass/lifecyclemanager/exceptions/DirectoryValidationException.java b/src/main/java/com/aws/greengrass/lifecyclemanager/exceptions/DirectoryValidationException.java index b4efa72735..8450719474 100644 --- a/src/main/java/com/aws/greengrass/lifecyclemanager/exceptions/DirectoryValidationException.java +++ b/src/main/java/com/aws/greengrass/lifecyclemanager/exceptions/DirectoryValidationException.java @@ -15,4 +15,9 @@ public DirectoryValidationException(String message) { super(message); super.addErrorCode(DeploymentErrorCode.LAUNCH_DIRECTORY_CORRUPTED); } + + public DirectoryValidationException(String message, Throwable throwable) { + super(message, throwable); + super.addErrorCode(DeploymentErrorCode.LAUNCH_DIRECTORY_CORRUPTED); + } } \ No newline at end of file diff --git a/src/test/java/com/aws/greengrass/deployment/activator/KernelUpdateActivatorTest.java b/src/test/java/com/aws/greengrass/deployment/activator/KernelUpdateActivatorTest.java index 3922d5e79f..e62fb994f3 100644 --- a/src/test/java/com/aws/greengrass/deployment/activator/KernelUpdateActivatorTest.java +++ b/src/test/java/com/aws/greengrass/deployment/activator/KernelUpdateActivatorTest.java @@ -227,7 +227,7 @@ void GIVEN_launch_dir_corrupted_WHEN_deployment_activate_THEN_deployment_fail(Ex assertEquals(mockException, result.getFailureCause().getCause()); List expectedStack = Arrays.asList("DEPLOYMENT_FAILURE", "LAUNCH_DIRECTORY_CORRUPTED"); - List expectedTypes = Collections.singletonList("NUCLEUS_ERROR"); + List expectedTypes = Collections.singletonList("DEVICE_ERROR"); TestUtils.validateGenerateErrorReport(result.getFailureCause(), expectedStack, expectedTypes); }