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 (#2020)

* 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 authored Nov 12, 2024
1 parent 714eb8b commit 17248a1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 38 deletions.
53 changes: 29 additions & 24 deletions hawkbit-ddi/hawkbit-ddi-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,37 @@
</parent>

<artifactId>hawkbit-ddi-starter</artifactId>
<name>hawkBit :: Spring Boot Starter DDI API</name>
<name>hawkBit :: DDI API :: Spring Boot Starter</name>

<dependencies>
<!-- hawkBit - START -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-security-controller</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.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-ddi-resource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<!-- hawkBit - END -->

<!-- Spring - START -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -44,28 +72,5 @@
<artifactId>spring-security-aspects</artifactId>
</dependency>
<!-- Spring - END -->

<!-- hawkBit - START -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-ddi-resource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-security-controller</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<!-- hawkBit - END -->
</dependencies>
</project>
11 changes: 8 additions & 3 deletions hawkbit-mgmt/hawkbit-mgmt-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@
</parent>

<artifactId>hawkbit-mgmt-starter</artifactId>
<name>hawkBit :: Spring Boot Starter Management API</name>
<name>hawkBit :: Management API :: Spring Boot Starter</name>

<dependencies>
<!-- hawkBit - START -->
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-mgmt-resource</artifactId>
<artifactId>hawkbit-security-controller</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-security-controller</artifactId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-jpa</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-mgmt-resource</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-autoconfigure</artifactId>
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 17248a1

Please sign in to comment.