Code format hawkbit-repository (#1939)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-11-05 11:27:41 +02:00
committed by GitHub
parent 7161b8803a
commit 0f5c87a0c8
12 changed files with 133 additions and 109 deletions

View File

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

View File

@@ -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.
*/

View File

@@ -22,6 +22,7 @@ public class DistributionSetInvalidation {
private Collection<Long> distributionSetIds;
private CancelationType cancelationType;
private boolean cancelRollouts;
/**
* Parametric constructor
*

View File

@@ -23,6 +23,7 @@ public class TotalTargetCountStatus {
private final Map<Status, Long> 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.
*

View File

@@ -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<JpaTarget> 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<JpaTarget> findTargetsForAssignment(final List<String> controllerIDs, final long setId) {
final Function<List<String>, List<JpaTarget>> 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<JpaTarget> 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;
}
}

View File

@@ -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<JpaTarget> 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<JpaTarget> findTargetsForAssignment(final List<String> controllerIDs, final long setId) {
final Function<List<String>, List<JpaTarget>> mapper;
@@ -149,36 +179,6 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
}
}
@Override
public JpaAction createTargetAction(final String initiatedBy, final TargetWithActionType targetWithActionType,
final List<JpaTarget> 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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,23 +9,23 @@
SPDX-License-Identifier: EPL-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-parent</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hawkbit-repository</artifactId>
<name>hawkBit :: Repository</name>
<packaging>pom</packaging>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-parent</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hawkbit-repository</artifactId>
<name>hawkBit :: Repository</name>
<packaging>pom</packaging>
<modules>
<module>hawkbit-repository-jpa</module>
<module>hawkbit-repository-api</module>
<module>hawkbit-repository-test</module>
<module>hawkbit-repository-core</module>
</modules>
<modules>
<module>hawkbit-repository-jpa</module>
<module>hawkbit-repository-api</module>
<module>hawkbit-repository-test</module>
<module>hawkbit-repository-core</module>
</modules>
</project>