From 6fc8a82c88f89f4907106ee70630d657562c9a85 Mon Sep 17 00:00:00 2001 From: Brian Veltman <2551674+brianveltman@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:00:26 +0200 Subject: [PATCH 1/3] Remove static import of cleanup policy criteriaSet --- files/groovy/create_cleanup_policies_from_list.groovy | 4 ---- 1 file changed, 4 deletions(-) diff --git a/files/groovy/create_cleanup_policies_from_list.groovy b/files/groovy/create_cleanup_policies_from_list.groovy index 391aa139..a77a4e3f 100644 --- a/files/groovy/create_cleanup_policies_from_list.groovy +++ b/files/groovy/create_cleanup_policies_from_list.groovy @@ -7,10 +7,6 @@ import java.util.concurrent.TimeUnit import org.sonatype.nexus.cleanup.storage.CleanupPolicy import org.sonatype.nexus.cleanup.storage.CleanupPolicyStorage -import static org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.IS_PRERELEASE_KEY -import static org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.LAST_BLOB_UPDATED_KEY -import static org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.LAST_DOWNLOADED_KEY -import static org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.REGEX_KEY; CleanupPolicyStorage cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.getName()) From b99237a036b52c3d296dfed3bb0f02064bfaf3d5 Mon Sep 17 00:00:00 2001 From: Brian Veltman <2551674+brianveltman@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:02:17 +0200 Subject: [PATCH 2/3] Disable prerelease criteria for cleanup policies --- .../create_cleanup_policies_from_list.groovy | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/files/groovy/create_cleanup_policies_from_list.groovy b/files/groovy/create_cleanup_policies_from_list.groovy index a77a4e3f..aecf1ad3 100644 --- a/files/groovy/create_cleanup_policies_from_list.groovy +++ b/files/groovy/create_cleanup_policies_from_list.groovy @@ -42,7 +42,7 @@ parsed_args.each { currentPolicy -> currentPolicy.format, currentPolicy.criteria.lastBlobUpdated, currentPolicy.criteria.lastDownloaded, - currentPolicy.criteria.preRelease, + // currentPolicy.criteria.preRelease, currentPolicy.criteria.regexKey) existingPolicy.setNotes(currentPolicy.notes) existingPolicy.setCriteria(criteriaMap) @@ -58,7 +58,7 @@ parsed_args.each { currentPolicy -> currentPolicy.format, currentPolicy.criteria.lastBlobUpdated, currentPolicy.criteria.lastDownloaded, - currentPolicy.criteria.preRelease, + // currentPolicy.criteria.preRelease, currentPolicy.criteria.regexKey) CleanupPolicy cleanupPolicy = cleanupPolicyStorage.newCleanupPolicy() @@ -96,11 +96,11 @@ def Map createCriteria(currentPolicy) { } else { criteriaMap.put(LAST_DOWNLOADED_KEY, asStringSeconds(currentPolicy.criteria.lastDownloaded)) } - if ((currentPolicy.criteria.preRelease == null) || (currentPolicy.criteria.preRelease == "")) { - criteriaMap.remove(IS_PRERELEASE_KEY) - } else { - criteriaMap.put(IS_PRERELEASE_KEY, Boolean.toString(currentPolicy.criteria.preRelease == "PRERELEASES")) - } + // if ((currentPolicy.criteria.preRelease == null) || (currentPolicy.criteria.preRelease == "")) { + // criteriaMap.remove(IS_PRERELEASE_KEY) + // } else { + // criteriaMap.put(IS_PRERELEASE_KEY, Boolean.toString(currentPolicy.criteria.preRelease == "PRERELEASES")) + // } if ((currentPolicy.criteria.regexKey == null) || (currentPolicy.criteria.regexKey == "")) { criteriaMap.remove(REGEX_KEY) } else { @@ -128,10 +128,10 @@ def Boolean isPolicyEqual(existingPolicy, currentPolicy) { && currentCriteria.containsKey(LAST_DOWNLOADED_KEY) && existingPolicy.getCriteria()[LAST_DOWNLOADED_KEY] == currentCriteria[LAST_DOWNLOADED_KEY])) - isequal &= (((! existingPolicy.getCriteria().containsKey(IS_PRERELEASE_KEY)) && (! currentCriteria.containsKey(IS_PRERELEASE_KEY))) - || (existingPolicy.getCriteria().containsKey(IS_PRERELEASE_KEY) - && currentCriteria.containsKey(IS_PRERELEASE_KEY) - && existingPolicy.getCriteria()[IS_PRERELEASE_KEY] == currentCriteria[IS_PRERELEASE_KEY])) + // isequal &= (((! existingPolicy.getCriteria().containsKey(IS_PRERELEASE_KEY)) && (! currentCriteria.containsKey(IS_PRERELEASE_KEY))) + // || (existingPolicy.getCriteria().containsKey(IS_PRERELEASE_KEY) + // && currentCriteria.containsKey(IS_PRERELEASE_KEY) + // && existingPolicy.getCriteria()[IS_PRERELEASE_KEY] == currentCriteria[IS_PRERELEASE_KEY])) isequal &= (((! existingPolicy.getCriteria().containsKey(REGEX_KEY)) && (! currentCriteria.containsKey(REGEX_KEY))) || (existingPolicy.getCriteria().containsKey(REGEX_KEY) From 5a1031b879c4c5a4a92ded6f97445b2467b1d6a9 Mon Sep 17 00:00:00 2001 From: Brian Veltman <2551674+brianveltman@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:05:44 +0200 Subject: [PATCH 3/3] use criteriaSet attributes for cleanup policies --- .../create_cleanup_policies_from_list.groovy | 62 +++---- molecule/nexus_common_test_vars.yml | 160 +++++++++++++++++- 2 files changed, 188 insertions(+), 34 deletions(-) diff --git a/files/groovy/create_cleanup_policies_from_list.groovy b/files/groovy/create_cleanup_policies_from_list.groovy index aecf1ad3..172fc79b 100644 --- a/files/groovy/create_cleanup_policies_from_list.groovy +++ b/files/groovy/create_cleanup_policies_from_list.groovy @@ -42,7 +42,7 @@ parsed_args.each { currentPolicy -> currentPolicy.format, currentPolicy.criteria.lastBlobUpdated, currentPolicy.criteria.lastDownloaded, - // currentPolicy.criteria.preRelease, + currentPolicy.criteria.isPrerelease, currentPolicy.criteria.regexKey) existingPolicy.setNotes(currentPolicy.notes) existingPolicy.setCriteria(criteriaMap) @@ -58,7 +58,7 @@ parsed_args.each { currentPolicy -> currentPolicy.format, currentPolicy.criteria.lastBlobUpdated, currentPolicy.criteria.lastDownloaded, - // currentPolicy.criteria.preRelease, + currentPolicy.criteria.isPrerelease, currentPolicy.criteria.regexKey) CleanupPolicy cleanupPolicy = cleanupPolicyStorage.newCleanupPolicy() @@ -87,24 +87,24 @@ return JsonOutput.toJson(scriptResults) def Map createCriteria(currentPolicy) { Map criteriaMap = Maps.newHashMap() if (currentPolicy.criteria.lastBlobUpdated == null) { - criteriaMap.remove(LAST_BLOB_UPDATED_KEY) + criteriaMap.remove('lastBlobUpdated') } else { - criteriaMap.put(LAST_BLOB_UPDATED_KEY, asStringSeconds(currentPolicy.criteria.lastBlobUpdated)) + criteriaMap.put('lastBlobUpdated', asStringSeconds(currentPolicy.criteria.lastBlobUpdated)) } if (currentPolicy.criteria.lastDownloaded == null) { - criteriaMap.remove(LAST_DOWNLOADED_KEY) + criteriaMap.remove('lastDownloaded') } else { - criteriaMap.put(LAST_DOWNLOADED_KEY, asStringSeconds(currentPolicy.criteria.lastDownloaded)) + criteriaMap.put('lastDownloaded', asStringSeconds(currentPolicy.criteria.lastDownloaded)) + } + if ((currentPolicy.criteria.isPrerelease == null) || (currentPolicy.criteria.isPrerelease == "")) { + criteriaMap.remove('isPrerelease') + } else { + criteriaMap.put('isPrerelease', Boolean.toString(currentPolicy.criteria.isPrerelease == "PRERELEASES")) } - // if ((currentPolicy.criteria.preRelease == null) || (currentPolicy.criteria.preRelease == "")) { - // criteriaMap.remove(IS_PRERELEASE_KEY) - // } else { - // criteriaMap.put(IS_PRERELEASE_KEY, Boolean.toString(currentPolicy.criteria.preRelease == "PRERELEASES")) - // } if ((currentPolicy.criteria.regexKey == null) || (currentPolicy.criteria.regexKey == "")) { - criteriaMap.remove(REGEX_KEY) + criteriaMap.remove('regex') } else { - criteriaMap.put(REGEX_KEY, String.valueOf(currentPolicy.criteria.regexKey)) + criteriaMap.put('regex', String.valueOf(currentPolicy.criteria.regexKey)) } log.info("Using criteriaMap: ${criteriaMap}") @@ -119,24 +119,24 @@ def Boolean isPolicyEqual(existingPolicy, currentPolicy) { isequal &= existingPolicy.getNotes() == currentPolicy.notes isequal &= existingPolicy.getFormat() == currentPolicy.format - isequal &= (((! existingPolicy.getCriteria().containsKey(LAST_BLOB_UPDATED_KEY)) && (! currentCriteria.containsKey(LAST_BLOB_UPDATED_KEY))) - || (existingPolicy.getCriteria().containsKey(LAST_BLOB_UPDATED_KEY) - && currentCriteria.containsKey(LAST_BLOB_UPDATED_KEY) - && existingPolicy.getCriteria()[LAST_BLOB_UPDATED_KEY] == currentCriteria[LAST_BLOB_UPDATED_KEY])) - isequal &= ((! (existingPolicy.getCriteria().containsKey(LAST_DOWNLOADED_KEY)) && (! currentCriteria.containsKey(LAST_DOWNLOADED_KEY))) - || (existingPolicy.getCriteria().containsKey(LAST_DOWNLOADED_KEY) - && currentCriteria.containsKey(LAST_DOWNLOADED_KEY) - && existingPolicy.getCriteria()[LAST_DOWNLOADED_KEY] == currentCriteria[LAST_DOWNLOADED_KEY])) - - // isequal &= (((! existingPolicy.getCriteria().containsKey(IS_PRERELEASE_KEY)) && (! currentCriteria.containsKey(IS_PRERELEASE_KEY))) - // || (existingPolicy.getCriteria().containsKey(IS_PRERELEASE_KEY) - // && currentCriteria.containsKey(IS_PRERELEASE_KEY) - // && existingPolicy.getCriteria()[IS_PRERELEASE_KEY] == currentCriteria[IS_PRERELEASE_KEY])) - - isequal &= (((! existingPolicy.getCriteria().containsKey(REGEX_KEY)) && (! currentCriteria.containsKey(REGEX_KEY))) - || (existingPolicy.getCriteria().containsKey(REGEX_KEY) - && currentCriteria.containsKey(REGEX_KEY) - && existingPolicy.getCriteria()[REGEX_KEY] == currentCriteria[REGEX_KEY])) + isequal &= (((! existingPolicy.getCriteria().containsKey('lastBlobUpdated')) && (! currentCriteria.containsKey('lastBlobUpdated'))) + || (existingPolicy.getCriteria().containsKey('lastBlobUpdated') + && currentCriteria.containsKey('lastBlobUpdated') + && existingPolicy.getCriteria()['lastBlobUpdated'] == currentCriteria['lastBlobUpdated'])) + isequal &= ((! (existingPolicy.getCriteria().containsKey('lastDownloaded')) && (! currentCriteria.containsKey('lastDownloaded'))) + || (existingPolicy.getCriteria().containsKey('lastDownloaded') + && currentCriteria.containsKey('lastDownloaded') + && existingPolicy.getCriteria()['lastDownloaded'] == currentCriteria['lastDownloaded'])) + + isequal &= (((! existingPolicy.getCriteria().containsKey('isPrerelease')) && (! currentCriteria.containsKey('isPrerelease'))) + || (existingPolicy.getCriteria().containsKey('isPrerelease') + && currentCriteria.containsKey('isPrerelease') + && existingPolicy.getCriteria()['isPrerelease'] == currentCriteria['isPrerelease'])) + + isequal &= (((! existingPolicy.getCriteria().containsKey('regex')) && (! currentCriteria.containsKey('regex'))) + || (existingPolicy.getCriteria().containsKey('regex') + && currentCriteria.containsKey('regex') + && existingPolicy.getCriteria()['regex'] == currentCriteria['regex'])) return isequal } diff --git a/molecule/nexus_common_test_vars.yml b/molecule/nexus_common_test_vars.yml index e6a9e328..9bb32686 100644 --- a/molecule/nexus_common_test_vars.yml +++ b/molecule/nexus_common_test_vars.yml @@ -28,7 +28,6 @@ nexus_config_pypi: true nexus_config_docker: true nexus_config_raw: true nexus_config_rubygems: true -nexus_config_bower: true nexus_config_npm: true nexus_config_nuget: true nexus_config_gitlfs: true @@ -47,14 +46,169 @@ nexus_rut_auth_realm: false nexus_rut_auth_header: CUSTOM_RUT_HEADER nexus_repos_cleanup_policies: + - name: all_cleanup + format: all + notes: "All" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 - name: mvn_cleanup format: maven2 - mode: + notes: "mvn" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + - name: mvn_releases_cleanup + format: maven2 + notes: "mvn RELEASES" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + isPrerelease: RELEASES + - name: mvn_prereleases_cleanup + format: maven2 + notes: "mvn PRERELEASES" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + isPrerelease: PRERELEASES + - name: python_cleanup + format: pypi + notes: "Python pip" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: docker_cleanup + format: docker + notes: "Docker" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: raw_cleanup + format: raw + notes: "Raw" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: rubygems_cleanup + format: rubygems + notes: "Rubygems" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: npm_cleanup + format: npm notes: "" + criteria: + regexKey: 'beta-*' + - name: npm_releases_cleanup + format: npm + notes: "npm RELEASES" + criteria: + regexKey: 'beta-*' + isPrerelease: RELEASES + - name: npm_prereleases_cleanup + format: npm + notes: "npm PRERELEASES" + criteria: + regexKey: 'beta-*' + isPrerelease: PRERELEASES + - name: nuget_cleanup + format: nuget + notes: "NuGet" criteria: lastBlobUpdated: 60 lastDownloaded: 120 - + regexKey: 'beta-*' + - name: gitlfs_cleanup + format: gitlfs + notes: "gitlfs" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + - name: yum_prerelease_cleanup + format: yum + notes: "yum PRERELEASES" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + isPrerelease: PRERELEASES + - name: yum_release_cleanup + format: yum + notes: "yum RELEASES" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + isPrerelease: RELEASES + - name: yum_cleanup + format: yum + notes: "yum" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: apt_cleanup + format: apt + notes: "apt" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: helm_cleanup + format: helm + notes: "Helm" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: r_cleanup + format: r + notes: "r" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: conda_cleanup + format: conda + notes: "conda" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: go_cleanup + format: go + notes: "go" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: cocoapods_cleanup + format: cocoapods + notes: "cocoapods" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: conan_cleanup + format: conan + notes: "conan" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' + - name: p2_cleanup + format: p2 + notes: "p2" + criteria: + lastBlobUpdated: 60 + lastDownloaded: 120 + regexKey: 'beta-*' nexus_repos_maven_proxy: - name: central remote_url: https://repo1.maven.org/maven2/