From 0f5c87a0c839f0d40fe62d121a8722b4918040dc Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Tue, 5 Nov 2024 11:27:41 +0200 Subject: [PATCH] Code format hawkbit-repository (#1939) Signed-off-by: Marinov Avgustin --- hawkbit-repository/README.md | 59 +++++++++++++----- .../model/AssignedSoftwareModule.java | 4 +- .../model/DistributionSetInvalidation.java | 1 + .../model/TotalTargetCountStatus.java | 1 + .../OfflineDsAssignmentStrategy.java | 38 ++++++------ .../OnlineDsAssignmentStrategy.java | 60 +++++++++---------- .../jpa/model/JpaTargetMetadata.java | 16 ++--- .../AbstractAccessControllerTest.java | 4 -- .../DistributionSetAccessControllerTest.java | 7 +-- .../TargetTypeAccessControllerTest.java | 7 +-- .../repository/jpa/rsql/RSQLToSQL.java | 11 ++-- hawkbit-repository/pom.xml | 34 +++++------ 12 files changed, 133 insertions(+), 109 deletions(-) diff --git a/hawkbit-repository/README.md b/hawkbit-repository/README.md index 2d68a4e73..2ee2fea11 100644 --- a/hawkbit-repository/README.md +++ b/hawkbit-repository/README.md @@ -1,12 +1,15 @@ # hawkBit metadata repository -The repository is in charge for managing the meta data of the update server, e.g. provisioning targets, distribution sets, software modules etc. +The repository is in charge for managing the meta data of the update server, e.g. provisioning targets, distribution +sets, software modules etc. # Build [indent=0] ---- + $ mvn clean install + ---- Note, in order to build correctly in your IDE, you have to add ./target/generated-sources/apt to your build path. @@ -14,34 +17,60 @@ Note, in order to build correctly in your IDE, you have to add ./target/generate #Concepts ## Rollout -A rollout consists of the distribution set and a target-query-filter which defines the targets to be updated in this rollout. The targets within this filter are split up in configured amount of _Deployment Groups_ at creation time. -When starting a rollout, for all targets within this rollout deployment actions will be created. The deployment actions of the first group will be started immediately all other deployment actions will be scheduled. +A rollout consists of the distribution set and a target-query-filter which defines the targets to be updated in this +rollout. The targets within this filter are split up in configured amount of _Deployment Groups_ at creation time. -> Due rollouts might include a large number of targets and deployment group, creation as well as starting a rollout might take some time and therefore the creation and starting of an rollout is executed asynchronously. The creation and starting progress is reflected by the rollout's status attribute +When starting a rollout, for all targets within this rollout deployment actions will be created. The deployment actions +of the first group will be started immediately all other deployment actions will be scheduled. + +> Due rollouts might include a large number of targets and deployment group, creation as well as starting a rollout +> might take some time and therefore the creation and starting of an rollout is executed asynchronously. The creation and +> starting progress is reflected by the rollout's status attribute ### Rollout Creation -The targets reflected by the target-query-filter is interpreted at creation time. Only targets which have been created at that time are included in the rollout. Targets which are created after the rollout creation will not be included. At rollout creation time all necessary deployment groups containing the targets will be created. Dynamically adding targets to a created or running rollout is currently not supported. + +The targets reflected by the target-query-filter is interpreted at creation time. Only targets which have been created +at that time are included in the rollout. Targets which are created after the rollout creation will not be included. At +rollout creation time all necessary deployment groups containing the targets will be created. Dynamically adding targets +to a created or running rollout is currently not supported. ### Rollout Starting -The rollout is using the same concept based on _deployment acionts_ per target. All necessary _deployment acionts_ will be created at starting point but not all _deployment acionts_ will be set to running. Only the _deployment acionts_ of the first _deployment group_ is set to running, all other actions are created in _scheduled_ state. -If targets having not finished _deployment actions_ at rollout starting time, these action are tried to cancel (state: canceling). Scheduled actions from another rollout are canceled directly on server side because they were never running before and can be safely canceled. ->Multiple rollouts can be running at the same time, but if the rollouts effect the same targets they will interfer the targets _deployment actions_ e.g. canceling/cancel already running/scheduled _deployment actions_. +The rollout is using the same concept based on _deployment acionts_ per target. All necessary _deployment acionts_ will +be created at starting point but not all _deployment acionts_ will be set to running. Only the _deployment acionts_ of +the first _deployment group_ is set to running, all other actions are created in _scheduled_ state. +If targets having not finished _deployment actions_ at rollout starting time, these action are tried to cancel (state: +canceling). Scheduled actions from another rollout are canceled directly on server side because they were never running +before and can be safely canceled. + +> Multiple rollouts can be running at the same time, but if the rollouts effect the same targets they will interfer the +> targets _deployment actions_ e.g. canceling/cancel already running/scheduled _deployment actions_. ### Deployment Group Condition/Action -#### Success Condition/Action -A _success condition_ defines when a deployment group is interpreted as success and triggers the _success action_. E.g. a threshold of successfully updated targets within the group. -The _success action_ is executed if the _success_condition_ is fullfilled. Currently only the _success action_ starting the next following deployment group is available. +#### Success Condition/Action + +A _success condition_ defines when a deployment group is interpreted as success and triggers the _success action_. E.g. +a threshold of successfully updated targets within the group. + +The _success action_ is executed if the _success_condition_ is fullfilled. Currently only the _success action_ starting +the next following deployment group is available. #### Error Condition/Action -A _error condition_ defines when a deployment group is interpreted as failure and triggers the _error action_. E.g. a threshold of update failures of targets within the group. -The _error action_ is executed if the _error condition_ is fullfilled. Currently only the _error action_ pausing the whole rollout is available, a paused rollout can be resumed by a user. +A _error condition_ defines when a deployment group is interpreted as failure and triggers the _error action_. E.g. a +threshold of update failures of targets within the group. + +The _error action_ is executed if the _error condition_ is fullfilled. Currently only the _error action_ pausing the +whole rollout is available, a paused rollout can be resumed by a user. ### Rollout Scheduler -The rollout is managed by a scheduler task which is checking for rollouts in _running_ state. This is done atomic by updating the row in the database, so only the rollouts are checked and processed for the current instance to avoid that multiple instances are processing a rollout. ->Due the scheduler, it might take some time until a rollouts is processed and switching is state or starting the next deployment group. +The rollout is managed by a scheduler task which is checking for rollouts in _running_ state. This is done atomic by +updating the row in the database, so only the rollouts are checked and processed for the current instance to avoid that +multiple instances are processing a rollout. + +> Due the scheduler, it might take some time until a rollouts is processed and switching is state or starting the next +> deployment group. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java index 59afca525..d94100cc9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java @@ -9,11 +9,11 @@ */ package org.eclipse.hawkbit.repository.model; +import java.io.Serializable; + import lombok.Data; import org.eclipse.hawkbit.repository.Identifiable; -import java.io.Serializable; - /** * Use to display software modules for the selected distribution. */ diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetInvalidation.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetInvalidation.java index 8316d41ba..e021452ab 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetInvalidation.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetInvalidation.java @@ -22,6 +22,7 @@ public class DistributionSetInvalidation { private Collection distributionSetIds; private CancelationType cancelationType; private boolean cancelRollouts; + /** * Parametric constructor * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java index c614128c3..4de878468 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java @@ -23,6 +23,7 @@ public class TotalTargetCountStatus { private final Map statusTotalCountMap = new EnumMap<>(Status.class); private final Long totalTargetCount; private final Action.ActionType rolloutType; + /** * Create a new states map with the target count for each state. * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OfflineDsAssignmentStrategy.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OfflineDsAssignmentStrategy.java index b41b16b79..beb1d9934 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OfflineDsAssignmentStrategy.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OfflineDsAssignmentStrategy.java @@ -56,6 +56,25 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy { quotaManagement, multiAssignmentsConfig, confirmationFlowConfig, repositoryProperties); } + @Override + public JpaAction createTargetAction(final String initiatedBy, final TargetWithActionType targetWithActionType, + final List targets, final JpaDistributionSet set) { + final JpaAction result = super.createTargetAction(initiatedBy, targetWithActionType, targets, set); + if (result != null) { + result.setStatus(Status.FINISHED); + result.setActive(Boolean.FALSE); + } + return result; + } + + @Override + public JpaActionStatus createActionStatus(final JpaAction action, final String actionMessage) { + final JpaActionStatus result = super.createActionStatus(action, actionMessage); + result.setStatus(Status.FINISHED); + result.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Action reported as offline deployment"); + return result; + } + @Override public List findTargetsForAssignment(final List controllerIDs, final long setId) { final Function, List> mapper; @@ -126,23 +145,4 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy { // no need to send deployment events in the offline case } - @Override - public JpaAction createTargetAction(final String initiatedBy, final TargetWithActionType targetWithActionType, - final List targets, final JpaDistributionSet set) { - final JpaAction result = super.createTargetAction(initiatedBy, targetWithActionType, targets, set); - if (result != null) { - result.setStatus(Status.FINISHED); - result.setActive(Boolean.FALSE); - } - return result; - } - - @Override - public JpaActionStatus createActionStatus(final JpaAction action, final String actionMessage) { - final JpaActionStatus result = super.createActionStatus(action, actionMessage); - result.setStatus(Status.FINISHED); - result.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Action reported as offline deployment"); - return result; - } - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java index 8acc2a8d5..9eaa65387 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/OnlineDsAssignmentStrategy.java @@ -72,6 +72,36 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy { sendTargetAssignDistributionSetEvent(filteredActions.get(0).getTenant(), distributionSetId, filteredActions); } + @Override + public JpaAction createTargetAction(final String initiatedBy, final TargetWithActionType targetWithActionType, + final List targets, final JpaDistributionSet set) { + final JpaAction result = super.createTargetAction(initiatedBy, targetWithActionType, targets, set); + if (result != null) { + final boolean confirmationRequired = targetWithActionType.isConfirmationRequired() + && result.getTarget().getAutoConfirmationStatus() == null; + if (isConfirmationFlowEnabled() && confirmationRequired) { + result.setStatus(Status.WAIT_FOR_CONFIRMATION); + } else { + result.setStatus(Status.RUNNING); + } + } + return result; + } + + /** + * Will be called to create the initial action status for an action + */ + @Override + public JpaActionStatus createActionStatus(final JpaAction action, final String actionMessage) { + final JpaActionStatus result = super.createActionStatus(action, actionMessage); + if (isConfirmationFlowEnabled()) { + result.setStatus(Status.WAIT_FOR_CONFIRMATION); + } else { + result.setStatus(Status.RUNNING); + } + return result; + } + @Override public List findTargetsForAssignment(final List controllerIDs, final long setId) { final Function, List> mapper; @@ -149,36 +179,6 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy { } } - @Override - public JpaAction createTargetAction(final String initiatedBy, final TargetWithActionType targetWithActionType, - final List targets, final JpaDistributionSet set) { - final JpaAction result = super.createTargetAction(initiatedBy, targetWithActionType, targets, set); - if (result != null) { - final boolean confirmationRequired = targetWithActionType.isConfirmationRequired() - && result.getTarget().getAutoConfirmationStatus() == null; - if (isConfirmationFlowEnabled() && confirmationRequired) { - result.setStatus(Status.WAIT_FOR_CONFIRMATION); - } else { - result.setStatus(Status.RUNNING); - } - } - return result; - } - - /** - * Will be called to create the initial action status for an action - */ - @Override - public JpaActionStatus createActionStatus(final JpaAction action, final String actionMessage) { - final JpaActionStatus result = super.createActionStatus(action, actionMessage); - if (isConfirmationFlowEnabled()) { - result.setStatus(Status.WAIT_FOR_CONFIRMATION); - } else { - result.setStatus(Status.RUNNING); - } - return result; - } - void cancelAssignment(final JpaAction action) { if (isMultiAssignmentsEnabled()) { sendMultiActionCancelEvent(action); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetMetadata.java index 6b6167b1c..754d632a9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetMetadata.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetMetadata.java @@ -77,6 +77,14 @@ public class JpaTargetMetadata extends AbstractJpaMetaData implements TargetMeta this.target = (JpaTarget) target; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((target == null) ? 0 : target.hashCode()); + return result; + } + @Override // exception squid:S2259 - obj is checked for null in super @SuppressWarnings("squid:S2259") @@ -94,12 +102,4 @@ public class JpaTargetMetadata extends AbstractJpaMetaData implements TargetMeta } return true; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((target == null) ? 0 : target.hashCode()); - return result; - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/AbstractAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/AbstractAccessControllerTest.java index 2d694c5ff..ce91fb24a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/AbstractAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/AbstractAccessControllerTest.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.jpa.acm.controller; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Optional; @@ -22,14 +21,11 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType; import org.eclipse.hawkbit.security.SecurityContextTenantAware; -import org.eclipse.hawkbit.tenancy.TenantAware; -import org.eclipse.hawkbit.tenancy.UserAuthoritiesResolver; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.domain.Specification; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(classes = { AbstractAccessControllerTest.AccessControlTestConfig.class }) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java index 07b4fe931..510d9d4e0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/DistributionSetAccessControllerTest.java @@ -16,6 +16,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import io.qameta.allure.Story; import org.eclipse.hawkbit.repository.Identifiable; import org.eclipse.hawkbit.repository.builder.AutoAssignDistributionSetUpdate; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -35,10 +38,6 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.junit.jupiter.api.Test; import org.springframework.data.domain.Pageable; -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Story; - @Feature("Component Tests - Access Control") @Story("Test Distribution Set Access Controller") class DistributionSetAccessControllerTest extends AbstractAccessControllerTest { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetTypeAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetTypeAccessControllerTest.java index 11e6ad6b0..e5cb50c5f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetTypeAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/controller/TargetTypeAccessControllerTest.java @@ -15,6 +15,9 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Arrays; import java.util.List; +import io.qameta.allure.Description; +import io.qameta.allure.Feature; +import io.qameta.allure.Story; import org.eclipse.hawkbit.repository.Identifiable; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; @@ -25,10 +28,6 @@ import org.eclipse.hawkbit.repository.model.TargetType; import org.junit.jupiter.api.Test; import org.springframework.data.domain.Pageable; -import io.qameta.allure.Description; -import io.qameta.allure.Feature; -import io.qameta.allure.Story; - @Feature("Component Tests - Access Control") @Story("Test Target Type Access Controller") class TargetTypeAccessControllerTest extends AbstractAccessControllerTest { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQL.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQL.java index 294eda33f..895ab02d7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQL.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLToSQL.java @@ -9,10 +9,7 @@ */ package org.eclipse.hawkbit.repository.jpa.rsql; -import cz.jirutka.rsql.parser.RSQLParser; -import cz.jirutka.rsql.parser.ast.Node; -import cz.jirutka.rsql.parser.ast.RSQLOperators; -import cz.jirutka.rsql.parser.ast.RSQLVisitor; +import java.util.List; import jakarta.persistence.EntityManager; import jakarta.persistence.TypedQuery; @@ -21,6 +18,10 @@ import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; +import cz.jirutka.rsql.parser.RSQLParser; +import cz.jirutka.rsql.parser.ast.Node; +import cz.jirutka.rsql.parser.ast.RSQLOperators; +import cz.jirutka.rsql.parser.ast.RSQLVisitor; import org.eclipse.hawkbit.repository.RsqlQueryField; import org.eclipse.hawkbit.repository.rsql.RsqlConfigHolder; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; @@ -30,8 +31,6 @@ import org.eclipse.persistence.queries.DatabaseQuery; import org.springframework.orm.jpa.vendor.Database; import org.springframework.util.CollectionUtils; -import java.util.List; - public class RSQLToSQL { private static final Database DATABASE = Database.H2; diff --git a/hawkbit-repository/pom.xml b/hawkbit-repository/pom.xml index ade71f6dc..e4a6d9ca1 100644 --- a/hawkbit-repository/pom.xml +++ b/hawkbit-repository/pom.xml @@ -9,23 +9,23 @@ SPDX-License-Identifier: EPL-2.0 --> - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-parent - ${revision} - - hawkbit-repository - hawkBit :: Repository - pom + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-parent + ${revision} + + hawkbit-repository + hawkBit :: Repository + pom - - hawkbit-repository-jpa - hawkbit-repository-api - hawkbit-repository-test - hawkbit-repository-core - + + hawkbit-repository-jpa + hawkbit-repository-api + hawkbit-repository-test + hawkbit-repository-core +