From 26b9f7155c65c503129f6c6fdf2610d21b8e80be Mon Sep 17 00:00:00 2001 From: Sonatype Zion Date: Fri, 8 Mar 2024 13:53:43 +0000 Subject: [PATCH] upstream: b=main,r=d55c5224aa2fb5615acba07367f7da5125d10003,t=2024-03-08-1342-44396 --- .../nexus/blobstore/api/BlobStore.java | 11 ++ .../api/metrics/BlobStoreMetricsService.java | 7 +- .../api/metrics/BlobStoreMetricsStore.java | 6 + .../nexus/blobstore/file/FileBlobStore.java | 43 +++-- .../internal/FileBlobStoreDescriptor.java | 2 - components/nexus-blobstore/pom.xml | 1 + .../nexus/blobstore/BlobStoreDescriptor.java | 1 - .../BlobStoreDescriptorProvider.java | 46 ----- .../BlobStoreMetricsStoreSupport.java | 6 + .../nexus/blobstore/group/BlobStoreGroup.java | 7 + .../internal/BlobStoreGroupDescriptor.java | 2 - ...tastoreBlobStoreMetricsServiceSupport.java | 5 + .../capability/CapabilityDescriptor.java | 1 - .../DefaultCapabilityDescriptorProvider.java | 46 ----- .../internal/task/CleanupTaskDescriptor.java | 2 - .../app/BaseUrlCapabilityDescriptor.java | 2 - .../orient/DatabaseBackupTaskDescriptor.java | 2 - .../DefaultCapabilityDescriptorRegistry.java | 15 +- .../node/IdentityCapabilityDescriptor.java | 2 - .../task/H2BackupTaskDescriptor.java | 2 - .../SchedulerCapabilityDescriptor.java | 2 - .../internal/script/ScriptTaskDescriptor.java | 2 - .../apikey/PurgeApiKeysTaskDescriptor.java | 2 - .../webhooks/GlobalWebhookCapability.groovy | 2 - .../SleeperCancelableTaskDescriptor.java | 2 - .../nexus/quartz/SleeperTaskDescriptor.java | 2 - .../nexus/quartz/TaskSchedulerHelper.java | 7 - .../BrandingCapabilityDescriptor.java | 2 - .../SettingsCapabilityDescriptor.java | 2 - .../sonatype/nexus/rapture/internal/index.vm | 50 +++-- .../static/rapture/NX/controller/User.js | 5 +- .../nexus/repository/RecipeSupport.java | 11 -- .../metrics/BlobStoreMetricsDAO.java | 5 + .../metrics/BlobStoreMetricsStoreImpl.java | 8 +- ...obStoreMetricsMigrationTaskDescriptor.java | 2 - .../AssetBlobCleanupTaskDescriptor.java | 2 - .../AssetBlobRefMigrationTaskDescriptor.java | 2 - ...rmalizeComponentVersionTaskDescriptor.java | 2 - .../blobstore/metrics/BlobStoreMetricsDAO.xml | 7 + .../RebuildBrowseNodesTaskDescriptor.java | 2 - .../StorageSettingsCapabilityDescriptor.java | 2 - .../nexus/repository}/db/DatabaseCheck.java | 9 +- .../db/datastore/DatabaseCheckImpl.java | 83 +------- .../db/orient/OrientDatabaseCheck.java | 7 +- .../task/SearchUpdateTaskDescriptor.java | 2 - .../purge/PurgeUnusedTaskDescriptor.java | 2 - .../rest/api/SimpleApiRepositoryAdapter.java | 2 +- .../index/RebuildIndexTaskDescriptor.java | 2 - .../RepositoryWebhookCapability.groovy | 2 - .../db/datastore/DatabaseCheckImplTest.java | 111 ----------- .../api/SimpleApiRepositoryAdapterTest.java | 2 +- ...uildAssetUploadMetadataTaskDescriptor.java | 2 - .../StorageFacetCleanupTaskDescriptor.java | 2 - .../scheduling/internal/TaskFactoryImpl.java | 35 +--- .../internal/TaskFactoryImplTest.groovy | 7 +- .../nexus/security/authc/AntiCsrfHelper.java | 16 +- .../nexus/security/authc/CsrfExemption.java} | 21 +-- .../security/authc/AntiCsrfHelperTest.java | 40 +++- .../nexus/audit/internal/AuditCapability.java | 2 - .../blobstore/s3/internal/S3BlobStore.java | 47 +++-- .../s3/internal/S3BlobStoreDescriptor.java | 2 - .../common/BlobStoreTaskSupport.java | 117 ++++++++++++ .../CompactBlobStoreTaskDescriptor.java | 2 - ...eleteBlobstoreTempFilesTaskDescriptor.java | 2 - .../RecalculateBlobStoreSizeTask.java | 92 +++++++++ ...ecalculateBlobStoreSizeTaskDescriptor.java | 52 +++++ .../RestoreMetadataTaskDescriptor.java | 2 - .../OrientRestoreMetadataTaskDescriptor.java | 2 - .../RecalculateBlobStoreSizeTaskTest.java | 177 ++++++++++++++++++ .../nexus/coreui/BlobStoreComponent.groovy | 27 ++- .../internal/DatastoreStateContributor.java | 2 +- .../blobstore/BlobStoreUIResource.java | 12 +- .../NX/coreui/controller/Repositories.js | 2 +- .../coreui/BlobStoreComponentTest.groovy | 9 +- .../DatastoreStateContributorTest.java | 2 +- .../blobstore/BlobStoreUIResourceTest.java | 7 +- .../DefaultRoleCapabilityDescriptor.java | 2 - .../internal/hosted/AptHostedRecipe.java | 2 - .../internal/proxy/AptProxyRecipe.java | 2 - .../RebuildAptMetadataTaskDescriptor.java | 2 - .../hosted/OrientAptHostedRecipe.java | 2 - .../internal/proxy/OrientAptProxyRecipe.java | 2 - .../legacy/LegacyUrlCapabilityDescriptor.java | 2 - .../internal/recipe/MavenGroupRecipe.groovy | 2 - .../internal/recipe/MavenHostedRecipe.groovy | 2 - .../internal/recipe/MavenProxyRecipe.java | 2 - .../orient/OrientMaven2GroupRecipe.groovy | 2 - .../orient/OrientMaven2HostedRecipe.groovy | 2 - .../orient/OrientMaven2ProxyRecipe.groovy | 2 - .../PublishMavenIndexTaskDescriptor.java | 2 - ...rgeMavenUnusedSnapshotsTaskDescriptor.java | 2 - .../RebuildMaven2MetadataTaskDescriptor.java | 2 - .../tasks/RemoveSnapshotsTaskDescriptor.java | 2 - .../UnpublishMavenIndexTaskDescriptor.java | 2 - .../raw/internal/recipe/RawGroupRecipe.groovy | 2 - .../internal/recipe/RawHostedRecipe.groovy | 2 - .../raw/internal/recipe/RawProxyRecipe.groovy | 2 - .../orient/raw/internal/RawGroupRecipe.groovy | 2 - .../raw/internal/RawHostedRecipe.groovy | 2 - .../tasklog/TaskLogCleanupTaskDescriptor.java | 2 - revision.txt | 2 +- 101 files changed, 701 insertions(+), 582 deletions(-) delete mode 100644 components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptorProvider.java delete mode 100644 components/nexus-capability/src/main/java/org/sonatype/nexus/capability/DefaultCapabilityDescriptorProvider.java rename components/{nexus-common/src/main/java/org/sonatype/nexus/common => nexus-repository-services/src/main/java/org/sonatype/nexus/repository}/db/DatabaseCheck.java (70%) delete mode 100644 components/nexus-repository-services/src/test/java/org/sonatype/nexus/repository/db/datastore/DatabaseCheckImplTest.java rename components/{nexus-common/src/main/java/org/sonatype/nexus/common/upgrade/AvailabilityVersion.java => nexus-security/src/main/java/org/sonatype/nexus/security/authc/CsrfExemption.java} (63%) create mode 100644 plugins/nexus-blobstore-tasks/src/main/java/org/sonatype/nexus/blobstore/common/BlobStoreTaskSupport.java create mode 100644 plugins/nexus-blobstore-tasks/src/main/java/org/sonatype/nexus/blobstore/metrics/reconcile/RecalculateBlobStoreSizeTask.java create mode 100644 plugins/nexus-blobstore-tasks/src/main/java/org/sonatype/nexus/blobstore/metrics/reconcile/RecalculateBlobStoreSizeTaskDescriptor.java create mode 100644 plugins/nexus-blobstore-tasks/src/test/java/org/sonatype/nexus/blobstore/metrics/reconcile/RecalculateBlobStoreSizeTaskTest.java diff --git a/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/BlobStore.java b/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/BlobStore.java index d30cd903ce..ad8649db36 100644 --- a/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/BlobStore.java +++ b/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/BlobStore.java @@ -22,6 +22,7 @@ import javax.annotation.Nullable; import org.sonatype.goodies.lifecycle.Lifecycle; +import org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsService; import org.sonatype.nexus.transaction.TransactionalStore; import com.google.common.annotations.VisibleForTesting; @@ -196,6 +197,15 @@ default Blob makeBlobPermanent(final BlobId blobId, final Map he */ boolean deleteHard(BlobId blobId); + /** + * Provides access to the blob store's metrics service instance + *

+ * Note: this method may not be available for all the blob store implementations + * and, if not supported, expect a {@link UnsupportedOperationException} + *

+ */ + BlobStoreMetricsService getMetricsService(); + /** * Provides an immutable snapshot of metrics about the BlobStore's usage. */ @@ -264,6 +274,7 @@ default Blob makeBlobPermanent(final BlobId blobId, final Map he /** * Get {@link BlobAttributes} for the {@link BlobId} provided. */ + @Nullable BlobAttributes getBlobAttributes(BlobId blobId); /** diff --git a/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsService.java b/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsService.java index 50b5aa10dc..a6fc560899 100644 --- a/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsService.java +++ b/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsService.java @@ -38,7 +38,7 @@ public interface BlobStoreMetricsService void setBlobStore(BlobStore blobStore); /** - * Record a new blob being added to the blobstore. + * Record a new blob being added to the blob store. * * @param size Size of the newly added blob in bytes. */ @@ -61,6 +61,11 @@ public interface BlobStoreMetricsService */ Map getOperationMetricsDelta(); + /** + * Reset the total metrics (blob count / size) + */ + void clearCountMetrics(); + /** * Reset the operational metrics. */ diff --git a/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsStore.java b/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsStore.java index b3869080c8..6facba6eca 100644 --- a/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsStore.java +++ b/components/nexus-blobstore-api/src/main/java/org/sonatype/nexus/blobstore/api/metrics/BlobStoreMetricsStore.java @@ -37,6 +37,12 @@ public interface BlobStoreMetricsStore */ void clearOperationMetrics(String blobStoreName); + /** + * Clear the summary metrics for the given blob store name. + * (total size , blob count) + */ + void clearCountMetrics(String blobStoreName); + /** * Initialize the metrics for the given blobstore. */ diff --git a/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/FileBlobStore.java b/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/FileBlobStore.java index a0db66727a..d9c1ec3488 100644 --- a/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/FileBlobStore.java +++ b/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/FileBlobStore.java @@ -61,6 +61,7 @@ import org.sonatype.nexus.blobstore.api.OperationMetrics; import org.sonatype.nexus.blobstore.api.OperationType; import org.sonatype.nexus.blobstore.api.RawObjectAccess; +import org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsService; import org.sonatype.nexus.blobstore.file.internal.BlobCollisionException; import org.sonatype.nexus.blobstore.file.internal.FileOperations; import org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics; @@ -165,7 +166,7 @@ public class FileBlobStore private Path basedir; - private FileBlobStoreMetricsService metricsStore; + private FileBlobStoreMetricsService metricsService; private LoadingCache liveBlobs; @@ -190,7 +191,7 @@ public FileBlobStore( final BlobIdLocationResolver blobIdLocationResolver, final FileOperations fileOperations, final ApplicationDirectories applicationDirectories, - final FileBlobStoreMetricsService metricsStore, + final FileBlobStoreMetricsService metricsService, final NodeAccess nodeAccess, final DryRunPrefix dryRunPrefix, final BlobStoreReconciliationLogger reconciliationLogger, @@ -201,7 +202,7 @@ public FileBlobStore( super(blobIdLocationResolver, dryRunPrefix); this.fileOperations = checkNotNull(fileOperations); this.applicationDirectories = checkNotNull(applicationDirectories); - this.metricsStore = checkNotNull(metricsStore); + this.metricsService = checkNotNull(metricsService); this.nodeAccess = checkNotNull(nodeAccess); this.supportsHardLinkCopy = true; this.supportsAtomicMove = true; @@ -216,7 +217,7 @@ public FileBlobStore( final Path contentDir, //NOSONAR final BlobIdLocationResolver blobIdLocationResolver, final FileOperations fileOperations, - final FileBlobStoreMetricsService metricsStore, + final FileBlobStoreMetricsService metricsService, final BlobStoreConfiguration configuration, final ApplicationDirectories directories, final NodeAccess nodeAccess, @@ -227,7 +228,7 @@ public FileBlobStore( final FileBlobDeletionIndex blobDeletionIndex) { - this(blobIdLocationResolver, fileOperations, directories, metricsStore, nodeAccess, dryRunPrefix, + this(blobIdLocationResolver, fileOperations, directories, metricsService, nodeAccess, dryRunPrefix, reconciliationLogger, pruneEmptyDirectoryAge, blobStoreQuotaUsageChecker, blobDeletionIndex); this.contentDir = checkNotNull(contentDir); this.blobStoreConfiguration = checkNotNull(configuration); @@ -251,9 +252,9 @@ protected void doStart() throws Exception { } liveBlobs = CacheBuilder.newBuilder().weakValues().build(from(FileBlob::new)); blobDeletionIndex.initIndex(metadata, this); - metricsStore.setStorageDir(storageDir); - metricsStore.setBlobStore(this); - metricsStore.start(); + metricsService.setStorageDir(storageDir); + metricsService.setBlobStore(this); + metricsService.start(); blobStoreQuotaUsageChecker.setBlobStore(this); blobStoreQuotaUsageChecker.start(); @@ -306,7 +307,7 @@ protected void doStop() throws Exception { blobDeletionIndex.stopIndex(); } finally { - metricsStore.stop(); + metricsService.stop(); blobStoreQuotaUsageChecker.stop(); } } @@ -425,14 +426,14 @@ private Blob tryCreate( if (existingSize != null) { overwrite(temporaryBlobPath, blobPath); overwrite(temporaryAttributePath, attributePath); - metricsStore.recordDeletion(existingSize); + metricsService.recordDeletion(existingSize); } else { move(temporaryBlobPath, blobPath); move(temporaryAttributePath, attributePath); } - metricsStore.recordAddition(blobAttributes.getMetrics().getContentSize()); + metricsService.recordAddition(blobAttributes.getMetrics().getContentSize()); return blob; } @@ -582,7 +583,7 @@ protected boolean doDeleteHard(final BlobId blobId) { delete(attributePath); if (blobDeleted && contentSize != null) { - metricsStore.recordDeletion(contentSize); + metricsService.recordDeletion(contentSize); } return blobDeleted; @@ -604,25 +605,31 @@ private Long getContentSizeForDeletion(final BlobId blobId) { .orElse(null); } + @Override + @Guarded(by = STARTED) + public BlobStoreMetricsService getMetricsService() { + return metricsService; + } + @Override @Guarded(by = STARTED) public BlobStoreMetrics getMetrics() { - return metricsStore.getMetrics(); + return metricsService.getMetrics(); } @Override public Map getOperationMetricsByType() { - return metricsStore.getOperationMetrics(); + return metricsService.getOperationMetrics(); } @Override public Map getOperationMetricsDelta() { - return metricsStore.getOperationMetricsDelta(); + return metricsService.getOperationMetricsDelta(); } @Override public void clearOperationMetrics() { - metricsStore.clearOperationMetrics(); + metricsService.clearOperationMetrics(); } @Override @@ -824,7 +831,7 @@ private Path getConfiguredBlobStorePath() { @Guarded(by = {NEW, STOPPED, FAILED, SHUTDOWN}) public void remove() { try { - metricsStore.remove(); + metricsService.remove(); Path blobDir = getAbsoluteBlobDir(); FileUtils.deleteDirectory(reconciliationLogDir.toFile()); @@ -1195,6 +1202,6 @@ public RawObjectAccess getRawObjectAccess() { @Override @VisibleForTesting public void flushMetrics() throws IOException { - metricsStore.flush(); + metricsService.flush(); } } diff --git a/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/internal/FileBlobStoreDescriptor.java b/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/internal/FileBlobStoreDescriptor.java index 0fd9009756..a02ddd1306 100644 --- a/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/internal/FileBlobStoreDescriptor.java +++ b/components/nexus-blobstore-file/src/main/java/org/sonatype/nexus/blobstore/file/internal/FileBlobStoreDescriptor.java @@ -31,7 +31,6 @@ import org.sonatype.nexus.blobstore.file.FileBlobStore; import org.sonatype.nexus.blobstore.quota.BlobStoreQuotaService; import org.sonatype.nexus.common.app.ApplicationDirectories; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.FormField; import org.sonatype.nexus.formfields.StringTextFormField; import org.sonatype.nexus.rest.ValidationErrorsException; @@ -49,7 +48,6 @@ * * @since 3.6 */ -@AvailabilityVersion(from = "1.0") @Named(FileBlobStore.TYPE) public class FileBlobStoreDescriptor extends BlobStoreDescriptorSupport diff --git a/components/nexus-blobstore/pom.xml b/components/nexus-blobstore/pom.xml index 070edabeb1..d099b33395 100644 --- a/components/nexus-blobstore/pom.xml +++ b/components/nexus-blobstore/pom.xml @@ -37,6 +37,7 @@ org.sonatype.nexus nexus-blobstore-api + org.sonatype.nexus nexus-thread diff --git a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptor.java b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptor.java index 817c58df1d..04c8400c43 100644 --- a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptor.java +++ b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptor.java @@ -22,7 +22,6 @@ /** * Describes a blob store. - * Note: Do not inject Map and instead opt to use BlobStoreDescriptorProvider * * @since 3.6 */ diff --git a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptorProvider.java b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptorProvider.java deleted file mode 100644 index 17322ac871..0000000000 --- a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreDescriptorProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Sonatype Nexus (TM) Open Source Version - * Copyright (c) 2008-present Sonatype, Inc. - * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, - * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks - * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the - * Eclipse Foundation. All other trademarks are the property of their respective owners. - */ -package org.sonatype.nexus.blobstore; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.sonatype.nexus.common.db.DatabaseCheck; - -@Named -@Singleton -public class BlobStoreDescriptorProvider -{ - private final Map blobStoreDescriptors; - - private final DatabaseCheck databaseCheck; - - @Inject - public BlobStoreDescriptorProvider( - final DatabaseCheck databaseCheck, - final Map blobStoreDescriptors) - { - this.databaseCheck = databaseCheck; - this.blobStoreDescriptors = blobStoreDescriptors; - } - - public Map get() { - return blobStoreDescriptors.entrySet().stream() - .filter(item -> databaseCheck.isAllowedByVersion(item.getValue().getClass())) - .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - } -} diff --git a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreMetricsStoreSupport.java b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreMetricsStoreSupport.java index f142be0d65..b6f0f85e08 100644 --- a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreMetricsStoreSupport.java +++ b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/BlobStoreMetricsStoreSupport.java @@ -287,6 +287,12 @@ private void readProperties() { } } + @Override + public void clearCountMetrics() { + totalSize.set(0L); + blobCount.set(0L); + } + @Override public void clearOperationMetrics() { getOperationMetricsDelta().values().forEach(OperationMetrics::clear); diff --git a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/BlobStoreGroup.java b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/BlobStoreGroup.java index 6ab0172289..0d89bf069d 100644 --- a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/BlobStoreGroup.java +++ b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/BlobStoreGroup.java @@ -48,6 +48,7 @@ import org.sonatype.nexus.blobstore.api.OperationType; import org.sonatype.nexus.blobstore.api.RawObjectAccess; import org.sonatype.nexus.blobstore.api.UnimplementedRawObjectAccess; +import org.sonatype.nexus.blobstore.api.metrics.BlobStoreMetricsService; import org.sonatype.nexus.blobstore.group.internal.BlobStoreGroupMetrics; import org.sonatype.nexus.blobstore.group.internal.WriteToFirstMemberFillPolicy; import org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics; @@ -277,6 +278,12 @@ public boolean deleteHard(final BlobId blobId) { } } + @Override + @Guarded(by = STARTED) + public BlobStoreMetricsService getMetricsService() { + throw new UnsupportedOperationException("metrics service is not available at a group level"); + } + @Override @Guarded(by = STARTED) public BlobStoreMetrics getMetrics() { diff --git a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/internal/BlobStoreGroupDescriptor.java b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/internal/BlobStoreGroupDescriptor.java index a89d3b9a0a..c77b4b9595 100644 --- a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/internal/BlobStoreGroupDescriptor.java +++ b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/group/internal/BlobStoreGroupDescriptor.java @@ -33,7 +33,6 @@ import org.sonatype.nexus.blobstore.group.BlobStoreGroupService; import org.sonatype.nexus.blobstore.group.FillPolicy; import org.sonatype.nexus.blobstore.quota.BlobStoreQuotaService; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.ComboboxFormField; import org.sonatype.nexus.formfields.FormField; import org.sonatype.nexus.formfields.ItemselectFormField; @@ -58,7 +57,6 @@ * * @since 3.14 */ -@AvailabilityVersion(from = "1.0") @Named(BlobStoreGroup.TYPE) public class BlobStoreGroupDescriptor extends BlobStoreDescriptorSupport diff --git a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/metrics/DatastoreBlobStoreMetricsServiceSupport.java b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/metrics/DatastoreBlobStoreMetricsServiceSupport.java index 8c99ab5df1..c08c227299 100644 --- a/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/metrics/DatastoreBlobStoreMetricsServiceSupport.java +++ b/components/nexus-blobstore/src/main/java/org/sonatype/nexus/blobstore/metrics/DatastoreBlobStoreMetricsServiceSupport.java @@ -158,6 +158,11 @@ public void flush() throws IOException { blobStoreMetricsStore.updateMetrics(blobStoreMetricsEntity); } + @Override + public void clearCountMetrics() { + blobStoreMetricsStore.clearCountMetrics(blobStore.getBlobStoreConfiguration().getName()); + } + @Override public void clearOperationMetrics() { datastoreBlobStoreMetricsContainer.getOperationMetricsDelta().values().forEach(OperationMetrics::clear); diff --git a/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/CapabilityDescriptor.java b/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/CapabilityDescriptor.java index 2765255383..6ad1c130ce 100644 --- a/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/CapabilityDescriptor.java +++ b/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/CapabilityDescriptor.java @@ -21,7 +21,6 @@ /** * Describes a capability (its type). - * Note: Do not inject List and instead opt to use DefaultCapabilityDescriptorProvider */ public interface CapabilityDescriptor { diff --git a/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/DefaultCapabilityDescriptorProvider.java b/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/DefaultCapabilityDescriptorProvider.java deleted file mode 100644 index 160d3b2fb8..0000000000 --- a/components/nexus-capability/src/main/java/org/sonatype/nexus/capability/DefaultCapabilityDescriptorProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Sonatype Nexus (TM) Open Source Version - * Copyright (c) 2008-present Sonatype, Inc. - * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. - * - * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, - * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks - * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the - * Eclipse Foundation. All other trademarks are the property of their respective owners. - */ -package org.sonatype.nexus.capability; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.sonatype.nexus.common.db.DatabaseCheck; - -import static com.google.common.base.Preconditions.checkNotNull; - -@Named -@Singleton -public class DefaultCapabilityDescriptorProvider -{ - private final Map descriptors; - - private final DatabaseCheck databaseCheck; - - @Inject - public DefaultCapabilityDescriptorProvider(final Map descriptors, - final DatabaseCheck databaseCheck) { - this.descriptors = checkNotNull(descriptors); - this.databaseCheck = checkNotNull(databaseCheck); - } - - public List get() { - return descriptors.values().stream() - .filter(capabilityDescriptor -> databaseCheck.isAllowedByVersion(capabilityDescriptor.getClass())) - .collect(Collectors.toList()); - } -} diff --git a/components/nexus-cleanup-config/src/main/java/org/sonatype/nexus/cleanup/internal/task/CleanupTaskDescriptor.java b/components/nexus-cleanup-config/src/main/java/org/sonatype/nexus/cleanup/internal/task/CleanupTaskDescriptor.java index 224b21a5e4..f06cac1fcc 100644 --- a/components/nexus-cleanup-config/src/main/java/org/sonatype/nexus/cleanup/internal/task/CleanupTaskDescriptor.java +++ b/components/nexus-cleanup-config/src/main/java/org/sonatype/nexus/cleanup/internal/task/CleanupTaskDescriptor.java @@ -15,7 +15,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** @@ -23,7 +22,6 @@ * * @since 3.14 */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class CleanupTaskDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/app/BaseUrlCapabilityDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/app/BaseUrlCapabilityDescriptor.java index da99f77d9d..cd7d4ceaf6 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/app/BaseUrlCapabilityDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/app/BaseUrlCapabilityDescriptor.java @@ -25,7 +25,6 @@ import org.sonatype.nexus.capability.CapabilityType; import org.sonatype.nexus.capability.Tag; import org.sonatype.nexus.capability.Taggable; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.FormField; import org.sonatype.nexus.formfields.UrlFormField; @@ -39,7 +38,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named(BaseUrlCapabilityDescriptor.TYPE_ID) @Singleton public class BaseUrlCapabilityDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/backup/orient/DatabaseBackupTaskDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/backup/orient/DatabaseBackupTaskDescriptor.java index ff9af176be..e654376693 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/backup/orient/DatabaseBackupTaskDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/backup/orient/DatabaseBackupTaskDescriptor.java @@ -19,7 +19,6 @@ import org.sonatype.goodies.i18n.I18N; import org.sonatype.goodies.i18n.MessageBundle; import org.sonatype.nexus.common.node.NodeAccess; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.StringTextFormField; import org.sonatype.nexus.scheduling.TaskConfiguration; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; @@ -31,7 +30,6 @@ * * @since 3.2 */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class DatabaseBackupTaskDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/DefaultCapabilityDescriptorRegistry.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/DefaultCapabilityDescriptorRegistry.java index 3f96d6e824..2ab45fb720 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/DefaultCapabilityDescriptorRegistry.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/DefaultCapabilityDescriptorRegistry.java @@ -13,8 +13,10 @@ package org.sonatype.nexus.internal.capability; import java.util.Collection; +import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; + import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -22,7 +24,6 @@ import org.sonatype.nexus.capability.CapabilityDescriptor; import org.sonatype.nexus.capability.CapabilityDescriptorRegistry; import org.sonatype.nexus.capability.CapabilityType; -import org.sonatype.nexus.capability.DefaultCapabilityDescriptorProvider; import com.google.common.collect.Lists; @@ -33,13 +34,14 @@ class DefaultCapabilityDescriptorRegistry implements CapabilityDescriptorRegistry { - private final DefaultCapabilityDescriptorProvider defaultCapabilityDescriptorProvider; + + private final List descriptors; private final Set dynamicDescriptors; @Inject - DefaultCapabilityDescriptorRegistry(final DefaultCapabilityDescriptorProvider defaultCapabilityDescriptorProvider) { - this.defaultCapabilityDescriptorProvider = checkNotNull(defaultCapabilityDescriptorProvider); + DefaultCapabilityDescriptorRegistry(final List descriptors) { + this.descriptors = checkNotNull(descriptors); this.dynamicDescriptors = new CopyOnWriteArraySet(); } @@ -57,7 +59,7 @@ public CapabilityDescriptorRegistry unregister(final CapabilityDescriptor capabi @Override public CapabilityDescriptor get(final CapabilityType capabilityType) { - final CapabilityDescriptor descriptor = get(defaultCapabilityDescriptorProvider.get(), capabilityType); + final CapabilityDescriptor descriptor = get(descriptors, capabilityType); if (descriptor == null) { return get(dynamicDescriptors, capabilityType); } @@ -67,7 +69,7 @@ public CapabilityDescriptor get(final CapabilityType capabilityType) { @Override public CapabilityDescriptor[] getAll() { final Collection all = Lists.newArrayList(); - all.addAll(defaultCapabilityDescriptorProvider.get()); + all.addAll(descriptors); all.addAll(dynamicDescriptors); return all.toArray(new CapabilityDescriptor[all.size()]); @@ -83,4 +85,5 @@ private CapabilityDescriptor get(final Collection descript } return null; } + } diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/node/IdentityCapabilityDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/node/IdentityCapabilityDescriptor.java index d1c38fa428..377dbfbf00 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/node/IdentityCapabilityDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/capability/node/IdentityCapabilityDescriptor.java @@ -25,7 +25,6 @@ import org.sonatype.nexus.capability.CapabilityType; import org.sonatype.nexus.capability.Tag; import org.sonatype.nexus.capability.Taggable; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.FormField; import static org.sonatype.nexus.capability.CapabilityType.capabilityType; @@ -37,7 +36,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named(IdentityCapabilityDescriptor.TYPE_ID) @Singleton public class IdentityCapabilityDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/datastore/task/H2BackupTaskDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/datastore/task/H2BackupTaskDescriptor.java index 33139d571a..0ea6269484 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/datastore/task/H2BackupTaskDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/datastore/task/H2BackupTaskDescriptor.java @@ -15,7 +15,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.StringTextFormField; import org.sonatype.nexus.scheduling.TaskDescriptor; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; @@ -27,7 +26,6 @@ * * @since 3.21 */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class H2BackupTaskDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/scheduling/SchedulerCapabilityDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/scheduling/SchedulerCapabilityDescriptor.java index 5051aa5e39..cae0b1ebaf 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/scheduling/SchedulerCapabilityDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/scheduling/SchedulerCapabilityDescriptor.java @@ -26,7 +26,6 @@ import org.sonatype.nexus.capability.CapabilityType; import org.sonatype.nexus.capability.Tag; import org.sonatype.nexus.capability.Taggable; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.FormField; import static org.sonatype.nexus.capability.CapabilityType.capabilityType; @@ -38,7 +37,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named(SchedulerCapabilityDescriptor.TYPE_ID) @Singleton public class SchedulerCapabilityDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/script/ScriptTaskDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/script/ScriptTaskDescriptor.java index 705d49d61a..e0255056a0 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/script/ScriptTaskDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/script/ScriptTaskDescriptor.java @@ -19,7 +19,6 @@ import org.sonatype.goodies.i18n.I18N; import org.sonatype.goodies.i18n.MessageBundle; import org.sonatype.nexus.common.node.NodeAccess; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.FormField; import org.sonatype.nexus.formfields.StringTextFormField; import org.sonatype.nexus.formfields.TextAreaFormField; @@ -30,7 +29,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class ScriptTaskDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/security/apikey/PurgeApiKeysTaskDescriptor.java b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/security/apikey/PurgeApiKeysTaskDescriptor.java index cb3c0c2c6a..10ad349685 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/security/apikey/PurgeApiKeysTaskDescriptor.java +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/security/apikey/PurgeApiKeysTaskDescriptor.java @@ -15,7 +15,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** @@ -23,7 +22,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class PurgeApiKeysTaskDescriptor diff --git a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/webhooks/GlobalWebhookCapability.groovy b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/webhooks/GlobalWebhookCapability.groovy index 60e50d58bc..83f44b326b 100644 --- a/components/nexus-core/src/main/java/org/sonatype/nexus/internal/webhooks/GlobalWebhookCapability.groovy +++ b/components/nexus-core/src/main/java/org/sonatype/nexus/internal/webhooks/GlobalWebhookCapability.groovy @@ -27,7 +27,6 @@ import org.sonatype.nexus.capability.CapabilityType import org.sonatype.nexus.capability.Condition import org.sonatype.nexus.capability.Tag import org.sonatype.nexus.capability.Taggable -import org.sonatype.nexus.common.upgrade.AvailabilityVersion import org.sonatype.nexus.formfields.FormField import org.sonatype.nexus.formfields.ItemselectFormField import org.sonatype.nexus.formfields.PasswordFormField @@ -173,7 +172,6 @@ class GlobalWebhookCapability // Descriptor // - @AvailabilityVersion(from = "1.0") @Named(GlobalWebhookCapability.TYPE_ID) @Singleton static public class Descriptor diff --git a/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperCancelableTaskDescriptor.java b/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperCancelableTaskDescriptor.java index 74d282c7fa..ef13f09b8b 100644 --- a/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperCancelableTaskDescriptor.java +++ b/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperCancelableTaskDescriptor.java @@ -15,13 +15,11 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** * Descriptor for {@link SleeperCancelableTask}. */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class SleeperCancelableTaskDescriptor diff --git a/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperTaskDescriptor.java b/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperTaskDescriptor.java index 12a81f31c0..78323a62a0 100644 --- a/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperTaskDescriptor.java +++ b/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/SleeperTaskDescriptor.java @@ -15,13 +15,11 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** * Descriptor for {@link SleeperTask}. */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class SleeperTaskDescriptor diff --git a/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/TaskSchedulerHelper.java b/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/TaskSchedulerHelper.java index 52f45a923c..69ab7effc1 100644 --- a/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/TaskSchedulerHelper.java +++ b/components/nexus-quartz/src/test/java/org/sonatype/nexus/quartz/TaskSchedulerHelper.java @@ -22,7 +22,6 @@ import org.sonatype.goodies.testsupport.TestUtil; import org.sonatype.nexus.common.app.ApplicationDirectories; import org.sonatype.nexus.common.app.BaseUrlManager; -import org.sonatype.nexus.common.db.DatabaseCheck; import org.sonatype.nexus.common.event.EventManager; import org.sonatype.nexus.common.log.LastShutdownTimeService; import org.sonatype.nexus.common.node.NodeAccess; @@ -95,8 +94,6 @@ public class TaskSchedulerHelper private DatabaseStatusDelayedExecutor statusDelayedExecutor; - private DatabaseCheck databaseCheck; - public TaskSchedulerHelper(final DatabaseInstance databaseInstance) { this.databaseInstance = checkNotNull(databaseInstance); } @@ -108,7 +105,6 @@ public void init(@Nullable final Integer poolSize, @Nullable final JobFactory fa nodeAccess = mock(NodeAccess.class); lastShutdownTimeService = mock(LastShutdownTimeService.class); statusDelayedExecutor = mock(DatabaseStatusDelayedExecutor.class); - databaseCheck = mock(DatabaseCheck.class); Module module = binder -> { Properties properties = new Properties(); @@ -153,9 +149,6 @@ public void init(@Nullable final Integer poolSize, @Nullable final JobFactory fa // filtering by feature flag is not supported here yet binder.bind(JobStore.class).to(JobStoreImpl.class); - - when(databaseCheck.isAllowedByVersion(any())).thenReturn(true); - binder.bind(DatabaseCheck.class).toInstance(databaseCheck); }; this.injector = Guice.createInjector(new WireModule( diff --git a/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/branding/BrandingCapabilityDescriptor.java b/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/branding/BrandingCapabilityDescriptor.java index a323006922..b68ceb4eb6 100644 --- a/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/branding/BrandingCapabilityDescriptor.java +++ b/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/branding/BrandingCapabilityDescriptor.java @@ -25,7 +25,6 @@ import org.sonatype.nexus.capability.CapabilityType; import org.sonatype.nexus.capability.Tag; import org.sonatype.nexus.capability.Taggable; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.CheckboxFormField; import org.sonatype.nexus.formfields.FormField; import org.sonatype.nexus.formfields.TextAreaFormField; @@ -37,7 +36,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named(BrandingCapabilityDescriptor.TYPE_ID) @Singleton public class BrandingCapabilityDescriptor diff --git a/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/settings/SettingsCapabilityDescriptor.java b/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/settings/SettingsCapabilityDescriptor.java index fafeb105a5..2f2cf2a75a 100644 --- a/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/settings/SettingsCapabilityDescriptor.java +++ b/components/nexus-rapture/src/main/java/org/sonatype/nexus/rapture/internal/settings/SettingsCapabilityDescriptor.java @@ -25,7 +25,6 @@ import org.sonatype.nexus.capability.CapabilityType; import org.sonatype.nexus.capability.Tag; import org.sonatype.nexus.capability.Taggable; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.CheckboxFormField; import org.sonatype.nexus.formfields.FormField; import org.sonatype.nexus.formfields.NumberTextFormField; @@ -39,7 +38,6 @@ * * @since 3.0 */ -@AvailabilityVersion(from = "1.0") @Named(SettingsCapabilityDescriptor.TYPE_ID) @Singleton public class SettingsCapabilityDescriptor diff --git a/components/nexus-rapture/src/main/resources/org/sonatype/nexus/rapture/internal/index.vm b/components/nexus-rapture/src/main/resources/org/sonatype/nexus/rapture/internal/index.vm index 801d66c09e..f7eba7e639 100644 --- a/components/nexus-rapture/src/main/resources/org/sonatype/nexus/rapture/internal/index.vm +++ b/components/nexus-rapture/src/main/resources/org/sonatype/nexus/rapture/internal/index.vm @@ -64,40 +64,28 @@ return window.location.origin + window.location.pathname + service; } - async function createWrapperScript() { - try { - const telemetryService = 'service/rest/v1/user-telemetry/javascript'; - const response = await fetch(servicePath(telemetryService)); - const jsContent = await response.text(); - if (jsContent.length > 0) { - log('Creating wrapper script'); - const scriptElement = document.createElement('script'); - scriptElement.type = 'text/javascript'; - scriptElement.text = jsContent; - scriptElement.style.display = 'none'; - document.head.appendChild(scriptElement); - } - else { - log('Invalid wrapper script'); - } - } catch (error) { - console.error('Error fetching or executing script:', error); - } - } + (function () { + const telemetryService = servicePath('service/rest/v1/user-telemetry/javascript'); + log('Creating wrapper script'); + const scriptElement = document.createElement('script'); + scriptElement.type = 'text/javascript'; + scriptElement.src = telemetryService; + scriptElement.async = true; + scriptElement.style.display = 'none'; + document.head.appendChild(scriptElement); + })(); + async function getTelemetryConfig() { try { const telemetryService = 'service/rest/v1/user-telemetry/config'; const response = await fetch(servicePath(telemetryService)); return await response.json(); } catch (error) { - console.error('Error fetching config:', error); + console.error('Error fetching telemetry config:', error); } } - async function initializeTelemetry(createWrapper = false) { - if (createWrapper) { - await createWrapperScript(); - } + async function initializeTelemetry() { if (window.userTelemetry) { log('Initializing telemetry'); const telemetryService = 'service/rest/v1/user-telemetry/events'; @@ -106,10 +94,14 @@ config.dataHost = config.contentHost; config.sanitizeUrl = sanitizeUrl; config.filterUrls = ['*/#admin*']; + config.usePOST = true; window.userTelemetry.initialize(config); + if (typeof window.initializeTelemetry != 'function') { + window.initializeTelemetry = initializeTelemetry; + } } else { - console.error('Error during telemetry initialization'); + log('Could not initialize telemetry'); } } @@ -118,13 +110,13 @@ const urlObject = new URL(url); return `${urlObject.pathname}${urlObject.hash}`; } catch (error) { - console.error("Invalid URL"); + log("Invalid URL"); return ''; } } - initializeTelemetry(true); - window.initializeTelemetry = initializeTelemetry; + setTimeout(initializeTelemetry, 1000); + #end #macro(message $text) diff --git a/components/nexus-rapture/src/main/resources/static/rapture/NX/controller/User.js b/components/nexus-rapture/src/main/resources/static/rapture/NX/controller/User.js index 28139d1f8b..1b985e3472 100644 --- a/components/nexus-rapture/src/main/resources/static/rapture/NX/controller/User.js +++ b/components/nexus-rapture/src/main/resources/static/rapture/NX/controller/User.js @@ -116,13 +116,16 @@ Ext.define('NX.controller.User', { if (user && !oldUser) { NX.Messages.info(NX.I18n.format('User_SignedIn_Message', user.id)); me.fireEvent('signin', user); - if (window.initializeTelemetry) { + if (typeof window.initializeTelemetry == 'function') { window.initializeTelemetry(); } } else if (!user && oldUser) { NX.Messages.info(NX.I18n.get('User_SignedOut_Message')); me.fireEvent('signout'); + if (typeof window.initializeTelemetry == 'function') { + window.initializeTelemetry(); + } } if (!user) { diff --git a/components/nexus-repository-config/src/main/java/org/sonatype/nexus/repository/RecipeSupport.java b/components/nexus-repository-config/src/main/java/org/sonatype/nexus/repository/RecipeSupport.java index 88d517f60c..9da0600af3 100644 --- a/components/nexus-repository-config/src/main/java/org/sonatype/nexus/repository/RecipeSupport.java +++ b/components/nexus-repository-config/src/main/java/org/sonatype/nexus/repository/RecipeSupport.java @@ -15,7 +15,6 @@ import javax.inject.Inject; import org.sonatype.goodies.common.ComponentSupport; -import org.sonatype.nexus.common.db.DatabaseCheck; import org.sonatype.nexus.repository.recipe.RouterBuilder; import static com.google.common.base.Preconditions.checkNotNull; @@ -37,8 +36,6 @@ public abstract class RecipeSupport private HighAvailabilitySupportChecker highAvailabilitySupportChecker; - private DatabaseCheck databaseCheck; - protected RecipeSupport(final Type type, final Format format) { this.type = checkNotNull(type); this.format = checkNotNull(format); @@ -72,11 +69,6 @@ public void setBrowseUnsupportedHandler(final BrowseUnsupportedHandler browseUns this.browseUnsupportedHandler = checkNotNull(browseUnsupportedHandler); } - @Inject - public void setDatabaseCheck(final DatabaseCheck databaseCheck) { - this.databaseCheck = databaseCheck; - } - /** * Adds route to redirect access directly with a browser to a handler with links to the repo's components and * assets. @@ -87,9 +79,6 @@ protected void addBrowseUnsupportedRoute(RouterBuilder builder) { @Override public boolean isFeatureEnabled() { - if (databaseCheck != null && !databaseCheck.isAllowedByVersion(getClass())) { - return false; - } if (highAvailabilitySupportChecker != null) { return highAvailabilitySupportChecker.isSupported(getFormat().getValue()); } diff --git a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.java b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.java index 014c5a88b5..d1b7ae4be3 100644 --- a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.java +++ b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.java @@ -45,4 +45,9 @@ public interface BlobStoreMetricsDAO * Clears the operational metrics associated with the blob store */ void clearOperationMetrics(String blobStoreName); + + /** + * Clears the summary metrics associated to the given blob store (total size , blob count). + */ + void clearCountMetrics(String blobStoreName); } diff --git a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsStoreImpl.java b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsStoreImpl.java index c16a4ff19c..e735656e7e 100644 --- a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsStoreImpl.java +++ b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsStoreImpl.java @@ -60,6 +60,12 @@ public void clearOperationMetrics(final String blobStoreName) { dao().clearOperationMetrics(blobStoreName); } + @Override + @Transactional + public void clearCountMetrics(final String blobStoreName) { + dao().clearCountMetrics(blobStoreName); + } + @Override @Transactional public void initializeMetrics(String blobStoreName) { @@ -73,4 +79,4 @@ public void initializeMetrics(String blobStoreName) { e); //this is likely an HA race condition between multiple nodes - this is not a problem } } -} \ No newline at end of file +} diff --git a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/migration/FileBlobStoreMetricsMigrationTaskDescriptor.java b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/migration/FileBlobStoreMetricsMigrationTaskDescriptor.java index 761bd9b6f3..130a3e3794 100644 --- a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/migration/FileBlobStoreMetricsMigrationTaskDescriptor.java +++ b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/blobstore/metrics/migration/FileBlobStoreMetricsMigrationTaskDescriptor.java @@ -16,13 +16,11 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** * {@link FileBlobStoreMetricsMigrationTask} descriptor. */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class FileBlobStoreMetricsMigrationTaskDescriptor diff --git a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/AssetBlobCleanupTaskDescriptor.java b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/AssetBlobCleanupTaskDescriptor.java index 66bc5a96db..20ddf7a688 100644 --- a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/AssetBlobCleanupTaskDescriptor.java +++ b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/AssetBlobCleanupTaskDescriptor.java @@ -15,13 +15,11 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** * @since 3.24 */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class AssetBlobCleanupTaskDescriptor diff --git a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/migration/AssetBlobRefMigrationTaskDescriptor.java b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/migration/AssetBlobRefMigrationTaskDescriptor.java index 7b58360af8..42ce07c5f9 100644 --- a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/migration/AssetBlobRefMigrationTaskDescriptor.java +++ b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/store/internal/migration/AssetBlobRefMigrationTaskDescriptor.java @@ -15,13 +15,11 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; /** * {@link AssetBlobRefMigrationTask} descriptor. */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class AssetBlobRefMigrationTaskDescriptor diff --git a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/tasks/normalize/NormalizeComponentVersionTaskDescriptor.java b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/tasks/normalize/NormalizeComponentVersionTaskDescriptor.java index 03a55f13b9..e373ce4cba 100644 --- a/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/tasks/normalize/NormalizeComponentVersionTaskDescriptor.java +++ b/components/nexus-repository-content/src/main/java/org/sonatype/nexus/repository/content/tasks/normalize/NormalizeComponentVersionTaskDescriptor.java @@ -16,7 +16,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import org.sonatype.nexus.common.upgrade.AvailabilityVersion; import org.sonatype.nexus.formfields.RepositoryCombobox; import org.sonatype.nexus.repository.RepositoryTaskSupport; import org.sonatype.nexus.scheduling.TaskDescriptorSupport; @@ -24,7 +23,6 @@ /** * Descriptor for {@link NormalizeComponentVersionTask} which populates the normalized_version column on the {format}_component tables */ -@AvailabilityVersion(from = "1.0") @Named @Singleton public class NormalizeComponentVersionTaskDescriptor diff --git a/components/nexus-repository-content/src/main/resources/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.xml b/components/nexus-repository-content/src/main/resources/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.xml index 5e5848ffbe..2552bdd15e 100644 --- a/components/nexus-repository-content/src/main/resources/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.xml +++ b/components/nexus-repository-content/src/main/resources/org/sonatype/nexus/repository/content/blobstore/metrics/BlobStoreMetricsDAO.xml @@ -74,6 +74,13 @@ WHERE blob_store_name = #{blobStoreName}; + + UPDATE blob_store_metrics + SET total_size = 0, + blob_count = 0 + WHERE blob_store_name = #{blobStoreName}; + +