Rename LocalArtifactRepository to ArtifactRepository (#2643)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-09-03 08:53:11 +03:00
committed by GitHub
parent 01d3127cdc
commit 93f7e51565
9 changed files with 40 additions and 43 deletions

View File

@@ -538,25 +538,25 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
return metadata.entrySet().stream().map(md -> new DmfMetadata(md.getKey(), md.getValue())).toList();
}
private List<DmfArtifact> convertArtifacts(final Target target, final List<Artifact> localArtifacts) {
if (localArtifacts.isEmpty()) {
private List<DmfArtifact> convertArtifacts(final Target target, final List<Artifact> 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))

View File

@@ -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")

View File

@@ -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")

View File

@@ -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();

View File

@@ -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);

View File

@@ -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<ArtifactStorage> artifactRepository,
final ArtifactRepository artifactRepository,
final Optional<ArtifactStorage> 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);
}
}

View File

@@ -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;

View File

@@ -22,7 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
* {@link Artifact} repository.
*/
@Transactional(readOnly = true)
public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifact> {
public interface ArtifactRepository extends BaseEntityRepository<JpaArtifact> {
/**
* Counts artifacts size where the related software module is not deleted/archived.

View File

@@ -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