Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cleanup policies #416

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions files/groovy/create_cleanup_policies_from_list.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -46,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)
Expand All @@ -62,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()
Expand Down Expand Up @@ -91,24 +87,24 @@ return JsonOutput.toJson(scriptResults)
def Map<String, String> createCriteria(currentPolicy) {
Map<String, String> 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.preRelease == null) || (currentPolicy.criteria.preRelease == "")) {
criteriaMap.remove(IS_PRERELEASE_KEY)
if ((currentPolicy.criteria.isPrerelease == null) || (currentPolicy.criteria.isPrerelease == "")) {
criteriaMap.remove('isPrerelease')
} else {
criteriaMap.put(IS_PRERELEASE_KEY, Boolean.toString(currentPolicy.criteria.preRelease == "PRERELEASES"))
criteriaMap.put('isPrerelease', Boolean.toString(currentPolicy.criteria.isPrerelease == "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}")

Expand All @@ -123,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
}
Expand Down
160 changes: 157 additions & 3 deletions molecule/nexus_common_test_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
Expand Down