Skip to content

Commit

Permalink
FileSystem implementation of ArtifiactRepository moved in mgmt and dd…
Browse files Browse the repository at this point in the history
…i starters only

* it's not needed for dmf
* also made optional when not needed (e.g. some JpaArtifactManagement)

_release_notes_

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Nov 12, 2024
1 parent 714eb8b commit 13955c8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
5 changes: 5 additions & 0 deletions hawkbit-ddi/hawkbit-ddi-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>hawkbit-ddi-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down
5 changes: 5 additions & 0 deletions hawkbit-mgmt/hawkbit-mgmt-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>hawkbit-mgmt-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
Expand Down
5 changes: 5 additions & 0 deletions hawkbit-monolith/hawkbit-update-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>hawkbit-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
Expand Down
5 changes: 0 additions & 5 deletions hawkbit-repository/hawkbit-repository-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<artifactId>hawkbit-repository-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;

import javax.sql.DataSource;
Expand Down Expand Up @@ -173,6 +174,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan;
Expand All @@ -181,6 +183,7 @@
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
Expand Down Expand Up @@ -872,9 +875,9 @@ ControllerManagement controllerManagement(final ScheduledExecutorService executo
@ConditionalOnMissingBean
ArtifactManagement artifactManagement(
final EntityManager entityManager, final LocalArtifactRepository localArtifactRepository,
final SoftwareModuleRepository softwareModuleRepository, final ArtifactRepository artifactRepository,
final SoftwareModuleRepository softwareModuleRepository, final Optional<ArtifactRepository> artifactRepository,
final QuotaManagement quotaManagement, final TenantAware tenantAware) {
return new JpaArtifactManagement(entityManager, localArtifactRepository, softwareModuleRepository, artifactRepository,
return new JpaArtifactManagement(entityManager, localArtifactRepository, softwareModuleRepository, artifactRepository.orElse(null),
quotaManagement, tenantAware);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;

import jakarta.annotation.Nullable;
import jakarta.persistence.EntityManager;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -74,6 +76,7 @@ public class JpaArtifactManagement implements ArtifactManagement {

private final SoftwareModuleRepository softwareModuleRepository;

@Nullable
private final ArtifactRepository artifactRepository;

private final TenantAware tenantAware;
Expand All @@ -82,7 +85,7 @@ public class JpaArtifactManagement implements ArtifactManagement {

public JpaArtifactManagement(final EntityManager entityManager,
final LocalArtifactRepository localArtifactRepository,
final SoftwareModuleRepository softwareModuleRepository, final ArtifactRepository artifactRepository,
final SoftwareModuleRepository softwareModuleRepository, @Nullable final ArtifactRepository artifactRepository,
final QuotaManagement quotaManagement, final TenantAware tenantAware) {
this.entityManager = entityManager;
this.localArtifactRepository = localArtifactRepository;
Expand All @@ -102,6 +105,10 @@ public long count() {
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact create(final ArtifactUpload artifactUpload) {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}

final long moduleId = artifactUpload.getModuleId();
assertArtifactQuota(moduleId, 1);
final JpaSoftwareModule softwareModule =
Expand Down Expand Up @@ -190,8 +197,11 @@ public long countBySoftwareModule(final long softwareModuleId) {
}

@Override
public Optional<DbArtifact> loadArtifactBinary(final String sha1Hash, final long softwareModuleId,
final boolean isEncrypted) {
public Optional<DbArtifact> loadArtifactBinary(final String sha1Hash, final long softwareModuleId, final boolean isEncrypted) {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}

assertSoftwareModuleExists(softwareModuleId);

final String tenant = tenantAware.getCurrentTenant();
Expand All @@ -217,10 +227,13 @@ public Optional<DbArtifact> loadArtifactBinary(final String sha1Hash, final long
* Software module related UPDATE permission shall be checked by the callers!
*
* @param sha1Hash no longer needed
* @param softwareModuleId the garbage collection call is made for
*/
@PreAuthorize(SpPermission.SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void clearArtifactBinary(final String sha1Hash) {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}

// countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse will skip ACM checks and
// will return total count as it should be
final long count = localArtifactRepository.countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(
Expand Down

0 comments on commit 13955c8

Please sign in to comment.