From 93f7e515650b3e5ff1c372116934fd30241a4ca5 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Wed, 3 Sep 2025 08:53:11 +0300 Subject: [PATCH] Rename LocalArtifactRepository to ArtifactRepository (#2643) Signed-off-by: Avgustin Marinov --- .../amqp/AmqpMessageDispatcherService.java | 18 ++++---- .../rest/api/MgmtDownloadArtifactRestApi.java | 2 +- .../rest/api/MgmtSoftwareModuleRestApi.java | 2 +- .../MgmtSoftwareModuleResourceTest.java | 3 -- .../jpa/JpaRepositoryConfiguration.java | 4 +- .../jpa/management/JpaArtifactManagement.java | 42 +++++++++---------- .../management/JpaTenantStatsManagement.java | 6 +-- ...epository.java => ArtifactRepository.java} | 2 +- .../jpa/AbstractJpaIntegrationTest.java | 4 +- 9 files changed, 40 insertions(+), 43 deletions(-) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/{LocalArtifactRepository.java => ArtifactRepository.java} (96%) diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 55cd7b74d..75d81d05a 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -538,25 +538,25 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { return metadata.entrySet().stream().map(md -> new DmfMetadata(md.getKey(), md.getValue())).toList(); } - private List convertArtifacts(final Target target, final List localArtifacts) { - if (localArtifacts.isEmpty()) { + private List convertArtifacts(final Target target, final List artifacts) { + if (artifacts.isEmpty()) { return Collections.emptyList(); } - return localArtifacts.stream().map(localArtifact -> convertArtifact(target, localArtifact)).toList(); + return artifacts.stream().map(artifact -> convertArtifact(target, artifact)).toList(); } - private DmfArtifact convertArtifact(final Target target, final Artifact localArtifact) { + private DmfArtifact convertArtifact(final Target target, final Artifact artifact) { final TenantMetaData tenantMetadata = systemManagement.getTenantMetadataWithoutDetails(); return new DmfArtifact( - localArtifact.getFilename(), - new DmfArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()), - localArtifact.getSize(), - localArtifact.getLastModifiedAt(), + artifact.getFilename(), + new DmfArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()), + artifact.getSize(), + artifact.getLastModifiedAt(), artifactUrlHandler .getUrls(new DownloadDescriptor( tenantMetadata.getTenant(), target.getControllerId(), - localArtifact.getSoftwareModule().getId(), localArtifact.getFilename(), localArtifact.getSha1Hash()), + artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getSha1Hash()), ArtifactUrlResolver.ApiType.DMF) .stream() .collect(Collectors.toMap(ArtifactUrl::protocol, ArtifactUrl::ref)) diff --git a/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDownloadArtifactRestApi.java b/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDownloadArtifactRestApi.java index f3078123f..9777f9401 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDownloadArtifactRestApi.java +++ b/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDownloadArtifactRestApi.java @@ -36,7 +36,7 @@ public interface MgmtDownloadArtifactRestApi { * Handles the GET request for downloading an artifact. * * @param softwareModuleId of the parent SoftwareModule - * @param artifactId of the related LocalArtifact + * @param artifactId of the related repository Artifact * @return responseEntity with status ok if successful */ @GetMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}/download") diff --git a/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java b/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java index 4eaae9b04..cb5a2cf6b 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java +++ b/hawkbit-mgmt/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java @@ -142,7 +142,7 @@ public interface MgmtSoftwareModuleRestApi { * Handles the GET request of retrieving a single Artifact metadata request. * * @param softwareModuleId of the parent SoftwareModule - * @param artifactId of the related LocalArtifact + * @param artifactId of the related artifact * @return responseEntity with status ok if successful */ @Operation(summary = "Return single Artifact metadata", description = "Handles the GET request of retrieving a single Artifact metadata request. Required Permission: READ_REPOSITORY") diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 832952060..6fb3cdbbf 100644 --- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -52,7 +52,6 @@ import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.ArtifactUpload; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -93,8 +92,6 @@ import org.springframework.web.bind.annotation.RestController; "hawkbit.server.security.dos.maxArtifactStorage=500000" }) class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTest { - private LocalArtifactRepository localArtifactRepository; - @BeforeEach public void assertPreparationOfRepo() { assertThat(softwareModuleManagement.findAll(PAGE)).as("no softwaremodule should be founded").isEmpty(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java index 678960198..c0e6d0396 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRepositoryConfiguration.java @@ -70,7 +70,7 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder; import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetTypeRepository; -import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.repository.ArtifactRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutTargetGroupRepository; @@ -184,7 +184,7 @@ public class JpaRepositoryConfiguration { @Override public Object postProcessAfterInitialization(@NonNull final Object bean, @NonNull final String beanName) throws BeansException { - if (bean instanceof LocalArtifactRepository repo) { + if (bean instanceof ArtifactRepository repo) { return repo.withACM(artifactAccessController); } else if (bean instanceof SoftwareModuleTypeRepository repo) { return repo.withACM(softwareModuleTypeAccessController); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java index 3cc83a771..776d6482f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java @@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; -import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.repository.ArtifactRepository; import org.eclipse.hawkbit.repository.jpa.repository.SoftwareModuleRepository; import org.eclipse.hawkbit.repository.jpa.specifications.ArtifactSpecifications; import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper; @@ -67,8 +67,8 @@ import org.springframework.validation.annotation.Validated; @ConditionalOnBooleanProperty(prefix = "hawkbit.jpa", name = { "enabled", "artifact-management" }, matchIfMissing = true) public class JpaArtifactManagement implements ArtifactManagement { - private final LocalArtifactRepository localArtifactRepository; - private final ArtifactStorage artifactRepository; + private final ArtifactRepository artifactRepository; + private final ArtifactStorage artifactStorage; private final SoftwareModuleRepository softwareModuleRepository; private final EntityManager entityManager; private final PlatformTransactionManager txManager; @@ -76,15 +76,15 @@ public class JpaArtifactManagement implements ArtifactManagement { private final QuotaManagement quotaManagement; protected JpaArtifactManagement( - final LocalArtifactRepository localArtifactRepository, - final Optional artifactRepository, + final ArtifactRepository artifactRepository, + final Optional artifactStorage, final SoftwareModuleRepository softwareModuleRepository, final EntityManager entityManager, final PlatformTransactionManager txManager, final QuotaManagement quotaManagement, final TenantAware tenantAware) { - this.localArtifactRepository = localArtifactRepository; - this.artifactRepository = artifactRepository.orElse(null); + this.artifactRepository = artifactRepository; + this.artifactStorage = artifactStorage.orElse(null); this.softwareModuleRepository = softwareModuleRepository; this.entityManager = entityManager; this.txManager = txManager; @@ -97,7 +97,7 @@ public class JpaArtifactManagement implements ArtifactManagement { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public Artifact create(final ArtifactUpload artifactUpload) { - if (artifactRepository == null) { + if (artifactStorage == null) { throw new UnsupportedOperationException(); } @@ -106,7 +106,7 @@ public class JpaArtifactManagement implements ArtifactManagement { moduleId, 1, quotaManagement.getMaxArtifactsPerSoftwareModule(), Artifact.class, SoftwareModule.class, // get all artifacts without user context - softwareModuleId -> localArtifactRepository.count(null, ArtifactSpecifications.bySoftwareModuleId(softwareModuleId))); + softwareModuleId -> artifactRepository.count(null, ArtifactSpecifications.bySoftwareModuleId(softwareModuleId))); final JpaSoftwareModule softwareModule = softwareModuleRepository.getById(moduleId); @@ -127,7 +127,7 @@ public class JpaArtifactManagement implements ArtifactManagement { try { return storeArtifactMetadata(softwareModule, filename, artifact.getHashes(), artifact.getSize(), existing); } catch (final Exception e) { - artifactRepository.deleteBySha1(tenantAware.getCurrentTenant(), artifact.getHashes().sha1()); + artifactStorage.deleteBySha1(tenantAware.getCurrentTenant(), artifact.getHashes().sha1()); throw e; } } @@ -135,7 +135,7 @@ public class JpaArtifactManagement implements ArtifactManagement { @SuppressWarnings("java:S2201") // java:S2201 - the idea is to just check if the artifact exists @Override public ArtifactStream getArtifactStream(final String sha1Hash, final long softwareModuleId, final boolean isEncrypted) { - if (artifactRepository == null) { + if (artifactStorage == null) { throw new UnsupportedOperationException(); } @@ -146,11 +146,11 @@ public class JpaArtifactManagement implements ArtifactManagement { if (isEncrypted) { final ArtifactEncryptionService encryptionService = ArtifactEncryptionService.getInstance(); return new ArtifactStream( - encryptionService.decryptArtifact(softwareModuleId, artifactRepository.getBySha1(tenant, sha1Hash)), + encryptionService.decryptArtifact(softwareModuleId, artifactStorage.getBySha1(tenant, sha1Hash)), artifact.getSize() - encryptionService.encryptionSizeOverhead(), artifact.getSha1Hash()); } else { - return new ArtifactStream(artifactRepository.getBySha1(tenant, sha1Hash), artifact.getSize(), artifact.getSha1Hash()); + return new ArtifactStream(artifactStorage.getBySha1(tenant, sha1Hash), artifact.getSize(), artifact.getSha1Hash()); } } } @@ -162,11 +162,11 @@ public class JpaArtifactManagement implements ArtifactManagement { @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void delete(final long id) { - if (artifactRepository == null) { + if (artifactStorage == null) { throw new UnsupportedOperationException(); } - final JpaArtifact toDelete = localArtifactRepository.getById(id); + final JpaArtifact toDelete = artifactRepository.getById(id); final JpaSoftwareModule softwareModule = toDelete.getSoftwareModule(); // clearArtifactBinary checks (unconditionally) software module UPDATE access @@ -175,7 +175,7 @@ public class JpaArtifactManagement implements ArtifactManagement { softwareModule.removeArtifact(toDelete); softwareModuleRepository.save(softwareModule); - localArtifactRepository.deleteById(id); + artifactRepository.deleteById(id); final String sha1Hash = toDelete.getSha1Hash(); AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> clearArtifactBinary(sha1Hash)); @@ -195,14 +195,14 @@ public class JpaArtifactManagement implements ArtifactManagement { void clearArtifactBinary(final String sha1Hash) { DeploymentHelper.runInNewTransaction(txManager, "clearArtifactBinary", status -> { // countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse will skip ACM checks and will return total count as it should be - if (localArtifactRepository.countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(sha1Hash, + if (artifactRepository.countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(sha1Hash, tenantAware.getCurrentTenant()) <= 0) { // 1 artifact is the one being deleted! // removes the real artifact ONLY AFTER the delete of artifact or software module // in local history has passed successfully (caller has permission and no errors) AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> { try { log.debug("deleting artifact from repository {}", sha1Hash); - artifactRepository.deleteBySha1(tenantAware.getCurrentTenant(), sha1Hash); + artifactStorage.deleteBySha1(tenantAware.getCurrentTenant(), sha1Hash); } catch (final ArtifactStoreException e) { throw new ArtifactDeleteFailedException(e); } @@ -216,7 +216,7 @@ public class JpaArtifactManagement implements ArtifactManagement { final InputStream stream = artifactUpload.inputStream(); try (final InputStream wrappedStream = wrapInQuotaStream( isSmEncrypted ? wrapInEncryptionStream(artifactUpload.moduleId(), stream) : stream)) { - return artifactRepository.store( + return artifactStorage.store( tenantAware.getCurrentTenant(), wrappedStream, artifactUpload.filename(), artifactUpload.contentType(), artifactUpload.hash()); @@ -240,7 +240,7 @@ public class JpaArtifactManagement implements ArtifactManagement { private InputStream wrapInQuotaStream(final InputStream in) { final long maxArtifactSize = quotaManagement.getMaxArtifactSize(); - final long currentlyUsed = localArtifactRepository.sumOfNonDeletedArtifactSize().orElse(0L); + final long currentlyUsed = artifactRepository.sumOfNonDeletedArtifactSize().orElse(0L); final long maxArtifactSizeTotal = quotaManagement.getMaxArtifactStorage(); return new FileSizeAndStorageQuotaCheckingInputStream(in, maxArtifactSize, maxArtifactSizeTotal - currentlyUsed); @@ -262,6 +262,6 @@ public class JpaArtifactManagement implements ArtifactManagement { artifact.setFileSize(fileSize); log.debug("storing new artifact into repository {}", artifact); - return localArtifactRepository.save(AccessController.Operation.CREATE, artifact); + return artifactRepository.save(AccessController.Operation.CREATE, artifact); } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantStatsManagement.java index c6f3a52f0..cc94198ab 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantStatsManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTenantStatsManagement.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.management; import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository; -import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.repository.ArtifactRepository; import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository; import org.eclipse.hawkbit.repository.model.report.TenantUsage; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -30,12 +30,12 @@ import org.springframework.validation.annotation.Validated; public class JpaTenantStatsManagement implements TenantStatsManagement { private final TargetRepository targetRepository; - private final LocalArtifactRepository artifactRepository; + private final ArtifactRepository artifactRepository; private final ActionRepository actionRepository; private final TenantAware tenantAware; protected JpaTenantStatsManagement( - final TargetRepository targetRepository, final LocalArtifactRepository artifactRepository, final ActionRepository actionRepository, + final TargetRepository targetRepository, final ArtifactRepository artifactRepository, final ActionRepository actionRepository, final TenantAware tenantAware) { this.targetRepository = targetRepository; this.artifactRepository = artifactRepository; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ArtifactRepository.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ArtifactRepository.java index dc0f81d29..7d7ccd83b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/ArtifactRepository.java @@ -22,7 +22,7 @@ import org.springframework.transaction.annotation.Transactional; * {@link Artifact} repository. */ @Transactional(readOnly = true) -public interface LocalArtifactRepository extends BaseEntityRepository { +public interface ArtifactRepository extends BaseEntityRepository { /** * Counts artifacts size where the related software module is not deleted/archived. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index 9608a6703..6c535d05a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -32,7 +32,7 @@ import org.eclipse.hawkbit.repository.jpa.repository.ActionStatusRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetTagRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetTypeRepository; -import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.repository.ArtifactRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutRepository; import org.eclipse.hawkbit.repository.jpa.repository.RolloutTargetGroupRepository; @@ -98,7 +98,7 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest @Autowired protected ActionStatusRepository actionStatusRepository; @Autowired - protected LocalArtifactRepository artifactRepository; + protected ArtifactRepository artifactRepository; @Autowired protected RolloutGroupRepository rolloutGroupRepository; @Autowired