From 23ad6a140fd34bfae73a626619df0dd1c9c574e5 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 15 Feb 2024 09:20:48 +0200 Subject: [PATCH] [#1580] Software Module & Distribution Set lock: add lock at mgmt level (#1644) Additionally, * removed DistributionSet.getAutoAssignFilters and * removed SoftwareModule.getAssignedTo both are not used and exposed via Mgmt API. Maybe, if needed, they could be returned back along with exposing them via Mgmt API. Signed-off-by: Marinov Avgustin --- .../repository/model/DistributionSet.java | 64 ++++++++--------- .../repository/model/SoftwareModule.java | 70 +++++++++---------- .../jpa/model/JpaDistributionSet.java | 1 + .../jpa/model/JpaSoftwareModule.java | 15 +--- 4 files changed, 71 insertions(+), 79 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index 8a98f2760..dd6ca94df 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -26,11 +26,41 @@ import java.util.Set; public interface DistributionSet extends NamedVersionedEntity { /** - * @return true if the set is deleted and only kept for history + * @return type of the {@link DistributionSet}. + */ + DistributionSetType getType(); + + /** + * + * @return unmodifiableSet of {@link SoftwareModule}. + */ + Set getModules(); + + /** + * @return true if all defined + * {@link DistributionSetType#getMandatoryModuleTypes()} of + * {@link #getType()} are present in this {@link DistributionSet}. + */ + boolean isComplete(); + + /** + * @return true if this {@link DistributionSet} is locked. If so it's 'functional' + * properties (e.g. software modules) could not be modified anymore. + */ + boolean isLocked(); + + /** + * @return true if this {@link DistributionSet} is deleted and only kept for history * purposes. */ boolean isDeleted(); + /** + * @return false if this {@link DistributionSet} is + * invalidated. + */ + boolean isValid(); + /** * @return true if {@link DistributionSet} contains a mandatory * migration step, i.e. unfinished {@link Action}s will kept active @@ -38,17 +68,6 @@ public interface DistributionSet extends NamedVersionedEntity { */ boolean isRequiredMigrationStep(); - /** - * @return the auto assign target filters - */ - List getAutoAssignFilters(); - - /** - * - * @return unmodifiableSet of {@link SoftwareModule}. - */ - Set getModules(); - /** * Searches through modules for the given type. * @@ -59,23 +78,4 @@ public interface DistributionSet extends NamedVersionedEntity { default Optional findFirstModuleByType(final SoftwareModuleType type) { return getModules().stream().filter(module -> module.getType().equals(type)).findAny(); } - - /** - * @return type of the {@link DistributionSet}. - */ - DistributionSetType getType(); - - /** - * @return true if all defined - * {@link DistributionSetType#getMandatoryModuleTypes()} of - * {@link #getType()} are present in this {@link DistributionSet}. - */ - boolean isComplete(); - - /** - * @return false if this {@link DistributionSet} is - * invalidated. - */ - boolean isValid(); - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index 4cae47e43..411bab43a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -14,14 +14,47 @@ import java.util.Optional; /** * Software package as sub element of a {@link DistributionSet}. - * */ public interface SoftwareModule extends NamedVersionedEntity { + /** * Maximum length of software vendor. */ int VENDOR_MAX_SIZE = 256; + /** + * @return the type of the software module + */ + SoftwareModuleType getType(); + + /** + * @return immutable list of all artifacts + */ + List getArtifacts(); + + /** + * @return the vendor of this {@link SoftwareModule}. + */ + String getVendor(); + + /** + * @return {@code true} if this software module is marked as encrypted + * otherwise {@code false} + */ + boolean isEncrypted(); + + /** + * @return true if this {@link SoftwareModule} is locked. If so it's 'functional' + * properties (e.g. software modules) could not be modified anymore. + */ + boolean isLocked(); + + /** + * @return {@code true} if this {@link SoftwareModule} is marked as deleted + * otherwise {@code false} + */ + boolean isDeleted(); + /** * @param artifactId * to look for @@ -40,37 +73,4 @@ public interface SoftwareModule extends NamedVersionedEntity { return getArtifacts().stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim())) .findAny(); } - - /** - * @return immutable list of all artifacts - */ - List getArtifacts(); - - /** - * @return the vendor of this software module - */ - String getVendor(); - - /** - * @return the type of the software module - */ - SoftwareModuleType getType(); - - /** - * @return {@code true} if this software module is marked as deleted - * otherwise {@code false} - */ - boolean isDeleted(); - - /** - * @return immutable list of {@link DistributionSet}s the module is assigned - * to - */ - List getAssignedTo(); - - /** - * @return {@code true} if this software module is marked as encrypted - * otherwise {@code false} - */ - boolean isEncrypted(); -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java index 48f246fbd..11b4af8b8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -123,6 +123,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen private boolean requiredMigrationStep; @ToString.Exclude + @Getter(AccessLevel.NONE) @OneToMany(mappedBy = "autoAssignDistributionSet", targetEntity = JpaTargetFilterQuery.class, fetch = FetchType.LAZY) private List autoAssignFilters; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java index 188b59890..efa9931ea 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java @@ -88,6 +88,9 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement @Size(max = SoftwareModule.VENDOR_MAX_SIZE) private String vendor; + @Column(name = "encrypted") + private boolean encrypted; + @ToString.Exclude @CascadeOnDelete @OneToMany(mappedBy = "softwareModule", fetch = FetchType.LAZY, targetEntity = JpaSoftwareModuleMetadata.class) @@ -99,9 +102,6 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement @Column(name = "deleted") private boolean deleted; - @Column(name = "encrypted") - private boolean encrypted; - @ToString.Exclude @Getter(AccessLevel.NONE) @CascadeOnDelete @@ -190,15 +190,6 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement this.encrypted = encrypted; } - @Override - public List getAssignedTo() { - if (assignedTo == null) { - return Collections.emptyList(); - } - - return Collections.unmodifiableList(assignedTo); - } - @Override public void fireCreateEvent(final DescriptorEvent descriptorEvent) { EventPublisherHolder.getInstance().getEventPublisher().publishEvent(