Align DeploymentRequestBuilder with the rest of the builders (#2607)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -34,7 +34,6 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionCancellationType;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
||||
import org.eclipse.hawkbit.repository.model.DeploymentRequestBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
@@ -59,17 +58,6 @@ public interface DeploymentManagement extends PermissionSupport {
|
||||
return SpPermission.TARGET;
|
||||
}
|
||||
|
||||
/**
|
||||
* build a {@link DeploymentRequest} for a target distribution set assignment
|
||||
*
|
||||
* @param controllerId ID of target
|
||||
* @param distributionSetId ID of distribution set
|
||||
* @return the builder
|
||||
*/
|
||||
static DeploymentRequestBuilder deploymentRequest(final String controllerId, final long distributionSetId) {
|
||||
return new DeploymentRequestBuilder(controllerId, distributionSetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns {@link DistributionSet}s to {@link Target}s according to the {@link DeploymentRequest}.
|
||||
*
|
||||
@@ -316,14 +304,6 @@ public interface DeploymentManagement extends PermissionSupport {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||
List<Action> findActiveActionsWithHighestWeight(@NotEmpty String controllerId, int maxActionCount);
|
||||
|
||||
/**
|
||||
* Get weight of an Action. Returns the default value if the weight is null according to the properties.
|
||||
*
|
||||
* @param action to extract the weight from
|
||||
* @return weight of the action
|
||||
*/
|
||||
int getWeightConsideringDefault(final Action action);
|
||||
|
||||
/**
|
||||
* Force cancels given {@link Action} for given {@link Target}. Force canceling means that the action is marked as canceled on the SP server
|
||||
* and a cancel request is sent to the target. But however it's not tracked, if the targets handles the cancel request or not.
|
||||
|
||||
@@ -266,6 +266,7 @@ public interface RolloutManagement extends PermissionSupport {
|
||||
* @param rolloutId rollout id
|
||||
* @return <code>true</code> if rollout exists
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||
boolean exists(long rolloutId);
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,7 +85,7 @@ public interface TargetFilterQueryManagement<T extends TargetFilterQuery>
|
||||
* @return the page with the found {@link TargetFilterQuery}s
|
||||
* @throws EntityNotFoundException if DS with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY + " and " + "hasAuthority('READ_" + SpPermission.DISTRIBUTION_SET + "')")
|
||||
Page<TargetFilterQuery> findByAutoAssignDSAndRsql(long setId, String rsql, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@ package org.eclipse.hawkbit.repository.model;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidMaintenanceScheduleException;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
|
||||
@@ -69,4 +71,72 @@ public class DeploymentRequest {
|
||||
public String getControllerId() {
|
||||
return targetWithActionType.getControllerId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link DeploymentRequest} for a target distribution set assignment
|
||||
*
|
||||
* @param controllerId ID of target
|
||||
* @param distributionSetId ID of distribution set
|
||||
* @return the builder
|
||||
*/
|
||||
public static DeploymentRequestBuilder builder(final String controllerId, final long distributionSetId) {
|
||||
return new DeploymentRequestBuilder(controllerId, distributionSetId);
|
||||
}
|
||||
|
||||
@Accessors(fluent = true)
|
||||
public static class DeploymentRequestBuilder {
|
||||
|
||||
private final String controllerId;
|
||||
private final Long distributionSetId;
|
||||
@Setter
|
||||
private Integer weight;
|
||||
@Setter
|
||||
private long forceTime = RepositoryModelConstants.NO_FORCE_TIME;
|
||||
@Setter
|
||||
private ActionType actionType = ActionType.FORCED;
|
||||
private String maintenanceSchedule;
|
||||
private String maintenanceWindowDuration;
|
||||
private String maintenanceWindowTimeZone;
|
||||
@Setter
|
||||
private boolean confirmationRequired;
|
||||
|
||||
/**
|
||||
* Create a builder for a target distribution set assignment with the
|
||||
* mandatory fields
|
||||
*
|
||||
* @param controllerId ID of the target
|
||||
* @param distributionSetId ID of the distribution set
|
||||
*/
|
||||
private DeploymentRequestBuilder(final String controllerId, final Long distributionSetId) {
|
||||
this.controllerId = controllerId;
|
||||
this.distributionSetId = distributionSetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a maintenanceWindow
|
||||
*
|
||||
* @param maintenanceSchedule is the cron expression to be used for scheduling maintenance
|
||||
* windows. Expression has 6 mandatory fields and 1 last optional
|
||||
* field: "second minute hour dayofmonth month weekday year"
|
||||
* @param maintenanceWindowDuration in HH:mm:ss format specifying the duration of a maintenance
|
||||
* window, for example 00:30:00 for 30 minutes
|
||||
* @param maintenanceWindowTimeZone is the time zone specified as +/-hh:mm offset from UTC, for
|
||||
* example +02:00 for CET summer time and +00:00 for UTC. The
|
||||
* start time of a maintenance window calculated based on the
|
||||
* cron expression is relative to this time zone.
|
||||
* @return builder
|
||||
*/
|
||||
public DeploymentRequestBuilder maintenance(
|
||||
final String maintenanceSchedule, final String maintenanceWindowDuration, final String maintenanceWindowTimeZone) {
|
||||
this.maintenanceSchedule = maintenanceSchedule;
|
||||
this.maintenanceWindowDuration = maintenanceWindowDuration;
|
||||
this.maintenanceWindowTimeZone = maintenanceWindowTimeZone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRequest build() {
|
||||
return new DeploymentRequest(controllerId, distributionSetId, actionType, forceTime, weight,
|
||||
maintenanceSchedule, maintenanceWindowDuration, maintenanceWindowTimeZone, confirmationRequired);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2019 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
|
||||
/**
|
||||
* Builder for {@link DeploymentRequest}
|
||||
*/
|
||||
public class DeploymentRequestBuilder {
|
||||
|
||||
private final String controllerId;
|
||||
private final Long distributionSetId;
|
||||
private Integer weight;
|
||||
private long forceTime = RepositoryModelConstants.NO_FORCE_TIME;
|
||||
private ActionType actionType = ActionType.FORCED;
|
||||
private String maintenanceSchedule;
|
||||
private String maintenanceWindowDuration;
|
||||
private String maintenanceWindowTimeZone;
|
||||
private boolean confirmationRequired;
|
||||
|
||||
/**
|
||||
* Create a builder for a target distribution set assignment with the
|
||||
* mandatory fields
|
||||
*
|
||||
* @param controllerId ID of the target
|
||||
* @param distributionSetId ID of the distribution set
|
||||
*/
|
||||
public DeploymentRequestBuilder(final String controllerId, final Long distributionSetId) {
|
||||
this.controllerId = controllerId;
|
||||
this.distributionSetId = distributionSetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an other {@link ActionType} than {@link ActionType#FORCED}
|
||||
*
|
||||
* @param actionType type to used
|
||||
* @return builder
|
||||
*/
|
||||
public DeploymentRequestBuilder setActionType(final ActionType actionType) {
|
||||
this.actionType = actionType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a forceTime other than the default one.
|
||||
*
|
||||
* @param forceTime at what time the type soft turns into forced.
|
||||
* @return builder
|
||||
*/
|
||||
public DeploymentRequestBuilder setForceTime(final long forceTime) {
|
||||
this.forceTime = forceTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the weight of the action.
|
||||
*
|
||||
* @param weight the priority given to the action.
|
||||
* @return builder
|
||||
*/
|
||||
public DeploymentRequestBuilder setWeight(final Integer weight) {
|
||||
this.weight = weight;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a maintenanceWindow
|
||||
*
|
||||
* @param maintenanceSchedule is the cron expression to be used for scheduling maintenance
|
||||
* windows. Expression has 6 mandatory fields and 1 last optional
|
||||
* field: "second minute hour dayofmonth month weekday year"
|
||||
* @param maintenanceWindowDuration in HH:mm:ss format specifying the duration of a maintenance
|
||||
* window, for example 00:30:00 for 30 minutes
|
||||
* @param maintenanceWindowTimeZone is the time zone specified as +/-hh:mm offset from UTC, for
|
||||
* example +02:00 for CET summer time and +00:00 for UTC. The
|
||||
* start time of a maintenance window calculated based on the
|
||||
* cron expression is relative to this time zone.
|
||||
* @return builder
|
||||
*/
|
||||
public DeploymentRequestBuilder setMaintenance(final String maintenanceSchedule,
|
||||
final String maintenanceWindowDuration, final String maintenanceWindowTimeZone) {
|
||||
this.maintenanceSchedule = maintenanceSchedule;
|
||||
this.maintenanceWindowDuration = maintenanceWindowDuration;
|
||||
this.maintenanceWindowTimeZone = maintenanceWindowTimeZone;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if a confirmation is required.
|
||||
*
|
||||
* @param confirmationRequired if a confirmation is required for the {@link Action}
|
||||
* @return builder
|
||||
*/
|
||||
public DeploymentRequestBuilder setConfirmationRequired(final boolean confirmationRequired) {
|
||||
this.confirmationRequired = confirmationRequired;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* build the request
|
||||
*
|
||||
* @return the request object
|
||||
*/
|
||||
public DeploymentRequest build() {
|
||||
return new DeploymentRequest(controllerId, distributionSetId, actionType, forceTime, weight,
|
||||
maintenanceSchedule, maintenanceWindowDuration, maintenanceWindowTimeZone, confirmationRequired);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user