Skip to content

Commit dfac9c9

Browse files
fix: we skip download if the same version of nucleus is being deployed (#1717)
* fix: we skip download if the same version of nucleus is being deployed During installation the gg nucleus zip is not copied into the artifacts dir, as the installer is contained in the zip file. Even if the zip file is copied, it does not match the expected checksum, as there is some code signature added in the zip file provided by the zip file coming from cloudfront. This is now using the version that is provided by the localCandidate.getVersion() function to determine if a download is necessary. So the nucleus component is treated special. Signed-off-by: Thomas Roos <[email protected]> * chore: improve logging --------- Signed-off-by: Thomas Roos <[email protected]> Co-authored-by: Siddhant Srivastava <[email protected]>
1 parent 74f83ff commit dfac9c9

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/main/java/com/aws/greengrass/componentmanager/ComponentManager.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.aws.greengrass.util.NucleusPaths;
4040
import com.aws.greengrass.util.Permissions;
4141
import com.aws.greengrass.util.RetryUtils;
42+
import com.aws.greengrass.util.Utils;
4243
import com.vdurmont.semver4j.Requirement;
4344
import com.vdurmont.semver4j.Semver;
4445
import com.vdurmont.semver4j.SemverException;
@@ -203,8 +204,19 @@ private ComponentIdentifier negotiateVersionWithCloud(String componentName,
203204
Map<String, Requirement> versionRequirements,
204205
ComponentIdentifier localCandidate)
205206
throws PackagingException, InterruptedException {
206-
ResolvedComponentVersion resolvedComponentVersion;
207207

208+
// Special handling for Nucleus component - skip download if same version
209+
if (DEFAULT_NUCLEUS_COMPONENT_NAME.equals(componentName) && localCandidate != null) {
210+
String currentNucleusVersion = deviceConfiguration.getNucleusVersion();
211+
if (localCandidate.getVersion().toString().equals(currentNucleusVersion)) {
212+
logger.atInfo().kv(COMPONENT_NAME, componentName)
213+
.kv("version", currentNucleusVersion)
214+
.log("Skipping Nucleus download as the same version is already installed");
215+
return localCandidate;
216+
}
217+
}
218+
219+
ResolvedComponentVersion resolvedComponentVersion;
208220
if (localCandidate == null) {
209221
try {
210222
resolvedComponentVersion = RetryUtils.runWithRetry(clientExceptionRetryConfig,
@@ -441,9 +453,14 @@ private void preparePackage(ComponentIdentifier componentIdentifier)
441453
void prepareArtifacts(ComponentIdentifier componentIdentifier, List<ComponentArtifact> artifacts)
442454
throws PackageLoadingException, PackageDownloadException, InvalidArtifactUriException,
443455
InterruptedException {
444-
if (artifacts == null) {
445-
logger.atWarn().kv(PACKAGE_IDENTIFIER, componentIdentifier)
446-
.log("Artifact list was null, expected non-null and non-empty");
456+
if (Utils.isEmpty(artifacts)) {
457+
if (DEFAULT_NUCLEUS_COMPONENT_NAME.equals(componentIdentifier.getName())) {
458+
logger.atDebug().kv(PACKAGE_IDENTIFIER, componentIdentifier).log("Skipping Nucleus artifact"
459+
+ " download as version to be deployed is already running");
460+
} else {
461+
logger.atWarn().kv(PACKAGE_IDENTIFIER, componentIdentifier)
462+
.log("Artifact list was null, expected non-null and non-empty");
463+
}
447464
return;
448465
}
449466
Path packageArtifactDirectory = componentStore.resolveArtifactDirectoryPath(componentIdentifier);

src/test/java/com/aws/greengrass/componentmanager/ComponentManagerTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ void after() throws Exception {
182182
void GIVEN_artifact_list_empty_WHEN_attempt_download_artifact_THEN_do_nothing() throws Exception {
183183
ComponentIdentifier pkgId = new ComponentIdentifier("CoolService", new Semver("1.0.0"));
184184

185-
when(componentStore.resolveArtifactDirectoryPath(pkgId)).thenReturn(tempDir);
186-
187185
componentManager.prepareArtifacts(pkgId, Collections.emptyList());
188186

189187
verify(artifactDownloader, never()).download();
@@ -221,8 +219,6 @@ void GIVEN_artifact_from_gg_repo_WHEN_download_artifact_with_unarchive_THEN_call
221219
@Test
222220
void GIVEN_package_identifier_WHEN_request_to_prepare_package_THEN_task_succeed() throws Exception {
223221
ComponentIdentifier pkgId = new ComponentIdentifier("MonitoringService", new Semver("1.0.0"));
224-
when(componentStore.resolveArtifactDirectoryPath(pkgId)).thenReturn(tempDir);
225-
226222
String fileName = "MonitoringService-1.0.0.yaml";
227223
Path sourceRecipe = RECIPE_RESOURCE_PATH.resolve(fileName);
228224

0 commit comments

Comments
 (0)