Align DeploymentRequestBuilder with the rest of the builders (#2607)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -44,6 +44,7 @@ import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
|
|||||||
import org.eclipse.hawkbit.dmf.json.model.DmfTarget;
|
import org.eclipse.hawkbit.dmf.json.model.DmfTarget;
|
||||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||||
|
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||||
@@ -102,6 +103,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||||
private final DeploymentManagement deploymentManagement;
|
private final DeploymentManagement deploymentManagement;
|
||||||
private final TenantConfigurationManagement tenantConfigurationManagement;
|
private final TenantConfigurationManagement tenantConfigurationManagement;
|
||||||
|
private final RepositoryProperties repositoryProperties;
|
||||||
|
|
||||||
@SuppressWarnings("java:S107")
|
@SuppressWarnings("java:S107")
|
||||||
protected AmqpMessageDispatcherService(
|
protected AmqpMessageDispatcherService(
|
||||||
@@ -112,7 +114,8 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||||
final DeploymentManagement deploymentManagement,
|
final DeploymentManagement deploymentManagement,
|
||||||
final TenantConfigurationManagement tenantConfigurationManagement) {
|
final TenantConfigurationManagement tenantConfigurationManagement,
|
||||||
|
final RepositoryProperties repositoryProperties) {
|
||||||
super(rabbitTemplate);
|
super(rabbitTemplate);
|
||||||
this.artifactUrlHandler = artifactUrlHandler;
|
this.artifactUrlHandler = artifactUrlHandler;
|
||||||
this.amqpSenderService = amqpSenderService;
|
this.amqpSenderService = amqpSenderService;
|
||||||
@@ -123,6 +126,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
this.distributionSetManagement = distributionSetManagement;
|
this.distributionSetManagement = distributionSetManagement;
|
||||||
this.deploymentManagement = deploymentManagement;
|
this.deploymentManagement = deploymentManagement;
|
||||||
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
||||||
|
this.repositoryProperties = repositoryProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBatchAssignmentsEnabled() {
|
public boolean isBatchAssignmentsEnabled() {
|
||||||
@@ -281,7 +285,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
final Map<String, String> softwareModuleMetadata = getSoftwareModuleMetaData.apply(module);
|
final Map<String, String> softwareModuleMetadata = getSoftwareModuleMetaData.apply(module);
|
||||||
return softwareModuleMetadata == null ? Collections.emptyMap() : softwareModuleMetadata;
|
return softwareModuleMetadata == null ? Collections.emptyMap() : softwareModuleMetadata;
|
||||||
})));
|
})));
|
||||||
final int weight = deploymentManagement.getWeightConsideringDefault(action);
|
final int weight = getWeightConsideringDefault(action);
|
||||||
return new DmfMultiActionRequest.DmfMultiActionElement(getEventTypeForAction(action), actionRequest, weight);
|
return new DmfMultiActionRequest.DmfMultiActionElement(getEventTypeForAction(action), actionRequest, weight);
|
||||||
})
|
})
|
||||||
.toList());
|
.toList());
|
||||||
@@ -292,6 +296,10 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
amqpSenderService.sendMessage(message, targetAddress);
|
amqpSenderService.sendMessage(message, targetAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getWeightConsideringDefault(final Action action) {
|
||||||
|
return action.getWeight().orElse(repositoryProperties.getActionWeightIfAbsent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the type of event depending on whether the action is a DOWNLOAD_ONLY action or if it has a valid maintenance window
|
* Method to get the type of event depending on whether the action is a DOWNLOAD_ONLY action or if it has a valid maintenance window
|
||||||
* available or not based on defined maintenance schedule. In case of no maintenance schedule or if there is a valid window available,
|
* available or not based on defined maintenance schedule. In case of no maintenance schedule or if there is a valid window available,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
|
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
|
||||||
import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings;
|
import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings;
|
||||||
import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||||
@@ -268,10 +269,10 @@ public class DmfApiConfiguration {
|
|||||||
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
|
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
|
||||||
final TargetManagement<? extends Target> targetManagement, final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
final TargetManagement<? extends Target> targetManagement, final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement, final DeploymentManagement deploymentManagement,
|
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement, final DeploymentManagement deploymentManagement,
|
||||||
final TenantConfigurationManagement tenantConfigurationManagement) {
|
final TenantConfigurationManagement tenantConfigurationManagement, final RepositoryProperties repositoryProperties) {
|
||||||
return new AmqpMessageDispatcherService(rabbitTemplate, amqpSenderService, artifactUrlHandler,
|
return new AmqpMessageDispatcherService(rabbitTemplate, amqpSenderService, artifactUrlHandler,
|
||||||
systemSecurityContext, systemManagement, targetManagement, softwareModuleManagement, distributionSetManagement,
|
systemSecurityContext, systemManagement, targetManagement, softwareModuleManagement, distributionSetManagement,
|
||||||
deploymentManagement, tenantConfigurationManagement);
|
deploymentManagement, tenantConfigurationManagement, repositoryProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() {
|
private static Map<String, Object> getTTLMaxArgsAuthenticationQueue() {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||||
import org.eclipse.hawkbit.repository.artifact.ArtifactFilesystem;
|
import org.eclipse.hawkbit.repository.artifact.ArtifactFilesystem;
|
||||||
@@ -64,6 +65,7 @@ import org.springframework.amqp.core.MessageProperties;
|
|||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
|
import org.springframework.amqp.support.converter.AbstractJavaTypeMapper;
|
||||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
@@ -79,6 +81,9 @@ import org.springframework.test.context.TestPropertySource;
|
|||||||
"spring.main.allow-bean-definition-overriding=true" })
|
"spring.main.allow-bean-definition-overriding=true" })
|
||||||
class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
protected RepositoryProperties repositoryProperties;
|
||||||
|
|
||||||
private static final String TENANT = "DEFAULT";
|
private static final String TENANT = "DEFAULT";
|
||||||
private static final Long TENANT_ID = 4711L;
|
private static final Long TENANT_ID = 4711L;
|
||||||
|
|
||||||
@@ -115,7 +120,7 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
|||||||
|
|
||||||
amqpMessageDispatcherService = new AmqpMessageDispatcherService(rabbitTemplate, senderService,
|
amqpMessageDispatcherService = new AmqpMessageDispatcherService(rabbitTemplate, senderService,
|
||||||
artifactUrlHandlerMock, systemSecurityContext, systemManagement, targetManagement,
|
artifactUrlHandlerMock, systemSecurityContext, systemManagement, targetManagement,
|
||||||
softwareModuleManagement, distributionSetManagement, deploymentManagement, tenantConfigurationManagement);
|
softwareModuleManagement, distributionSetManagement, deploymentManagement, tenantConfigurationManagement, repositoryProperties);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import org.eclipse.hawkbit.dmf.json.model.DmfMultiActionRequest;
|
|||||||
import org.eclipse.hawkbit.dmf.json.model.DmfMultiActionRequest.DmfMultiActionElement;
|
import org.eclipse.hawkbit.dmf.json.model.DmfMultiActionRequest.DmfMultiActionElement;
|
||||||
import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
|
import org.eclipse.hawkbit.dmf.json.model.DmfSoftwareModule;
|
||||||
import org.eclipse.hawkbit.dmf.json.model.DmfTarget;
|
import org.eclipse.hawkbit.dmf.json.model.DmfTarget;
|
||||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
|
||||||
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
|
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.MultiActionAssignEvent;
|
import org.eclipse.hawkbit.repository.event.remote.MultiActionAssignEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.MultiActionCancelEvent;
|
import org.eclipse.hawkbit.repository.event.remote.MultiActionCancelEvent;
|
||||||
@@ -64,6 +63,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TenantConfigurationCre
|
|||||||
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValueChangeNotAllowedException;
|
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValueChangeNotAllowedException;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||||
|
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.RepositoryModelConstants;
|
import org.eclipse.hawkbit.repository.model.RepositoryModelConstants;
|
||||||
@@ -258,13 +258,13 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
|||||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||||
testdataFactory.addSoftwareModuleMetadata(ds);
|
testdataFactory.addSoftwareModuleMetadata(ds);
|
||||||
|
|
||||||
final Long installActionId = makeAssignment(DeploymentManagement.deploymentRequest(controllerId, ds.getId())
|
final Long installActionId = makeAssignment(DeploymentRequest.builder(controllerId, ds.getId())
|
||||||
.setActionType(ActionType.FORCED).build()).getAssignedEntity().get(0).getId();
|
.actionType(ActionType.FORCED).build()).getAssignedEntity().get(0).getId();
|
||||||
enableMultiAssignments();
|
enableMultiAssignments();
|
||||||
final Long downloadActionId = makeAssignment(DeploymentManagement.deploymentRequest(controllerId, ds.getId())
|
final Long downloadActionId = makeAssignment(DeploymentRequest.builder(controllerId, ds.getId())
|
||||||
.setActionType(ActionType.DOWNLOAD_ONLY).setWeight(weight1).build()).getAssignedEntity().get(0).getId();
|
.actionType(ActionType.DOWNLOAD_ONLY).weight(weight1).build()).getAssignedEntity().get(0).getId();
|
||||||
final Long cancelActionId = makeAssignment(
|
final Long cancelActionId = makeAssignment(
|
||||||
DeploymentManagement.deploymentRequest(controllerId, ds.getId()).setWeight(DEFAULT_TEST_WEIGHT).build())
|
DeploymentRequest.builder(controllerId, ds.getId()).weight(DEFAULT_TEST_WEIGHT).build())
|
||||||
.getAssignedEntity().get(0).getId();
|
.getAssignedEntity().get(0).getId();
|
||||||
// make sure the latest message in the queue is the one triggered by the
|
// make sure the latest message in the queue is the one triggered by the
|
||||||
// cancellation
|
// cancellation
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
|||||||
? tenantConfigHelper.isConfirmationFlowEnabled()
|
? tenantConfigHelper.isConfirmationFlowEnabled()
|
||||||
: dsAssignment.getConfirmationRequired();
|
: dsAssignment.getConfirmationRequired();
|
||||||
return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, distributionSetId)
|
return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, distributionSetId)
|
||||||
.setConfirmationRequired(isConfirmationRequired).build();
|
.confirmationRequired(isConfirmationRequired).build();
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final List<DistributionSetAssignmentResult> assignmentResults = deployManagement.assignDistributionSets(deploymentRequests);
|
final List<DistributionSetAssignmentResult> assignmentResults = deployManagement.assignDistributionSets(deploymentRequests);
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
|||||||
? tenantConfigHelper.isConfirmationFlowEnabled()
|
? tenantConfigHelper.isConfirmationFlowEnabled()
|
||||||
: dsAssignment.getConfirmationRequired();
|
: dsAssignment.getConfirmationRequired();
|
||||||
return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, targetId)
|
return MgmtDeploymentRequestMapper.createAssignmentRequestBuilder(dsAssignment, targetId)
|
||||||
.setConfirmationRequired(isConfirmationRequired).build();
|
.confirmationRequired(isConfirmationRequired).build();
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
|
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindowRequestBody;
|
|||||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
|
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentRequestBody;
|
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentRequestBody;
|
||||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtDistributionSetAssignment;
|
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtDistributionSetAssignment;
|
||||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
|
||||||
import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
|
import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
|
||||||
import org.eclipse.hawkbit.repository.model.DeploymentRequestBuilder;
|
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
||||||
|
import org.eclipse.hawkbit.repository.model.DeploymentRequest.DeploymentRequestBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapper for assignment requests
|
* A mapper for assignment requests
|
||||||
@@ -54,14 +54,14 @@ public final class MgmtDeploymentRequestMapper {
|
|||||||
private static DeploymentRequestBuilder createAssignmentRequestBuilder(final String targetId, final Long dsId,
|
private static DeploymentRequestBuilder createAssignmentRequestBuilder(final String targetId, final Long dsId,
|
||||||
final MgmtActionType type, final long forcetime, final Integer weight,
|
final MgmtActionType type, final long forcetime, final Integer weight,
|
||||||
final MgmtMaintenanceWindowRequestBody maintenanceWindow) {
|
final MgmtMaintenanceWindowRequestBody maintenanceWindow) {
|
||||||
final DeploymentRequestBuilder request = DeploymentManagement.deploymentRequest(targetId, dsId)
|
final DeploymentRequestBuilder request = DeploymentRequest.builder(targetId, dsId)
|
||||||
.setActionType(MgmtRestModelMapper.convertActionType(type)).setForceTime(forcetime).setWeight(weight);
|
.actionType(MgmtRestModelMapper.convertActionType(type)).forceTime(forcetime).weight(weight);
|
||||||
if (maintenanceWindow != null) {
|
if (maintenanceWindow != null) {
|
||||||
final String cronSchedule = maintenanceWindow.getSchedule();
|
final String cronSchedule = maintenanceWindow.getSchedule();
|
||||||
final String duration = maintenanceWindow.getDuration();
|
final String duration = maintenanceWindow.getDuration();
|
||||||
final String timezone = maintenanceWindow.getTimezone();
|
final String timezone = maintenanceWindow.getTimezone();
|
||||||
MaintenanceScheduleHelper.validateMaintenanceSchedule(cronSchedule, duration, timezone);
|
MaintenanceScheduleHelper.validateMaintenanceSchedule(cronSchedule, duration, timezone);
|
||||||
request.setMaintenance(cronSchedule, duration, timezone);
|
request.maintenance(cronSchedule, duration, timezone);
|
||||||
}
|
}
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.ActionCancellationType;
|
||||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
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.DistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
@@ -59,17 +58,6 @@ public interface DeploymentManagement extends PermissionSupport {
|
|||||||
return SpPermission.TARGET;
|
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}.
|
* 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)
|
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||||
List<Action> findActiveActionsWithHighestWeight(@NotEmpty String controllerId, int maxActionCount);
|
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
|
* 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.
|
* 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
|
* @param rolloutId rollout id
|
||||||
* @return <code>true</code> if rollout exists
|
* @return <code>true</code> if rollout exists
|
||||||
*/
|
*/
|
||||||
|
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
|
||||||
boolean exists(long rolloutId);
|
boolean exists(long rolloutId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public interface TargetFilterQueryManagement<T extends TargetFilterQuery>
|
|||||||
* @return the page with the found {@link TargetFilterQuery}s
|
* @return the page with the found {@link TargetFilterQuery}s
|
||||||
* @throws EntityNotFoundException if DS with given ID does not exist
|
* @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);
|
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 jakarta.validation.Valid;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
import org.eclipse.hawkbit.repository.exception.InvalidMaintenanceScheduleException;
|
import org.eclipse.hawkbit.repository.exception.InvalidMaintenanceScheduleException;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||||
|
|
||||||
@@ -69,4 +71,72 @@ public class DeploymentRequest {
|
|||||||
public String getControllerId() {
|
public String getControllerId() {
|
||||||
return targetWithActionType.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -169,10 +169,10 @@ public abstract class AbstractAutoAssignExecutor implements AutoAssignExecutor {
|
|||||||
: filterQuery.getAutoAssignActionType();
|
: filterQuery.getAutoAssignActionType();
|
||||||
|
|
||||||
return controllerIds.stream()
|
return controllerIds.stream()
|
||||||
.map(controllerId -> DeploymentManagement
|
.map(controllerId -> DeploymentRequest
|
||||||
.deploymentRequest(controllerId, filterQuery.getAutoAssignDistributionSet().getId())
|
.builder(controllerId, filterQuery.getAutoAssignDistributionSet().getId())
|
||||||
.setActionType(autoAssignActionType).setWeight(filterQuery.getAutoAssignWeight().orElse(null))
|
.actionType(autoAssignActionType).weight(filterQuery.getAutoAssignWeight().orElse(null))
|
||||||
.setConfirmationRequired(filterQuery.isConfirmationRequired()).build())
|
.confirmationRequired(filterQuery.isConfirmationRequired()).build())
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public class JpaActionManagement {
|
|||||||
this.repositoryProperties = repositoryProperties;
|
this.repositoryProperties = repositoryProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWeightConsideringDefault(final Action action) {
|
protected int getWeightConsideringDefault(final Action action) {
|
||||||
return action.getWeight().orElse(repositoryProperties.getActionWeightIfAbsent());
|
return action.getWeight().orElse(repositoryProperties.getActionWeightIfAbsent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
enforceMaxAssignmentsPerRequest(distinctAssignments.size());
|
enforceMaxAssignmentsPerRequest(distinctAssignments.size());
|
||||||
|
|
||||||
final List<DeploymentRequest> deploymentRequests = distinctAssignments.stream()
|
final List<DeploymentRequest> deploymentRequests = distinctAssignments.stream()
|
||||||
.map(entry -> DeploymentManagement.deploymentRequest(entry.getKey(), entry.getValue()).build()).toList();
|
.map(entry -> DeploymentRequest.builder(entry.getKey(), entry.getValue()).build()).toList();
|
||||||
|
|
||||||
return assignDistributionSets(
|
return assignDistributionSets(
|
||||||
auditorAware.getCurrentAuditor().orElse(tenantAware.getCurrentUsername()), deploymentRequests, null,
|
auditorAware.getCurrentAuditor().orElse(tenantAware.getCurrentUsername()), deploymentRequests, null,
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
|||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||||
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
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.DistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -326,7 +325,7 @@ class ConfirmationManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static DeploymentRequest toDeploymentRequest(final String controllerId, final Long distributionSetId) {
|
private static DeploymentRequest toDeploymentRequest(final String controllerId, final Long distributionSetId) {
|
||||||
return new DeploymentRequestBuilder(controllerId, distributionSetId).setConfirmationRequired(true).build();
|
return DeploymentRequest.builder(controllerId, distributionSetId).confirmationRequired(true).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyAutoConfirmationIsDisabled(final String controllerId) {
|
private void verifyAutoConfirmationIsDisabled(final String controllerId) {
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import jakarta.validation.ConstraintViolationException;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.assertj.core.api.Assertions;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
|
||||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
|
import org.eclipse.hawkbit.repository.event.remote.CancelTargetAssignmentEvent;
|
||||||
@@ -65,7 +64,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
|||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
|
||||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||||
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
|
||||||
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification;
|
||||||
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||||
import org.eclipse.hawkbit.repository.model.Action;
|
import org.eclipse.hawkbit.repository.model.Action;
|
||||||
@@ -74,7 +72,6 @@ import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
|||||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||||
import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
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.DistributionSet;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
@@ -747,11 +744,11 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final Target target = testdataFactory.createTarget();
|
final Target target = testdataFactory.createTarget();
|
||||||
final List<DistributionSet> distributionSets = testdataFactory.createDistributionSets(2);
|
final List<DistributionSet> distributionSets = testdataFactory.createDistributionSets(2);
|
||||||
|
|
||||||
final DeploymentRequest targetToDS0 = DeploymentManagement
|
final DeploymentRequest targetToDS0 = DeploymentRequest
|
||||||
.deploymentRequest(target.getControllerId(), distributionSets.get(0).getId()).setWeight(78).build();
|
.builder(target.getControllerId(), distributionSets.get(0).getId()).weight(78).build();
|
||||||
|
|
||||||
final DeploymentRequest targetToDS1 = DeploymentManagement
|
final DeploymentRequest targetToDS1 = DeploymentRequest
|
||||||
.deploymentRequest(target.getControllerId(), distributionSets.get(1).getId()).setWeight(565).build();
|
.builder(target.getControllerId(), distributionSets.get(1).getId()).weight(565).build();
|
||||||
|
|
||||||
final List<DeploymentRequest> deploymentRequests = List.of(targetToDS0, targetToDS1);
|
final List<DeploymentRequest> deploymentRequests = List.of(targetToDS0, targetToDS1);
|
||||||
Assertions.assertThatExceptionOfType(MultiAssignmentIsNotEnabledException.class)
|
Assertions.assertThatExceptionOfType(MultiAssignmentIsNotEnabledException.class)
|
||||||
@@ -835,8 +832,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
final DistributionSet distributionSet = testdataFactory.createDistributionSet();
|
||||||
|
|
||||||
assignDistributionSets(Collections
|
assignDistributionSets(Collections
|
||||||
.singletonList(new DeploymentRequestBuilder(target.getControllerId(), distributionSet.getId())
|
.singletonList(DeploymentRequest.builder(target.getControllerId(), distributionSet.getId())
|
||||||
.setConfirmationRequired(confirmationRequired).build()));
|
.confirmationRequired(confirmationRequired).build()));
|
||||||
|
|
||||||
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent()).hasSize(1)
|
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent()).hasSize(1)
|
||||||
.allSatisfy(action -> {
|
.allSatisfy(action -> {
|
||||||
@@ -952,14 +949,14 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||||
final List<DeploymentRequest> twoEqualAssignments = Collections.nCopies(2,
|
final List<DeploymentRequest> twoEqualAssignments = Collections.nCopies(2,
|
||||||
DeploymentManagement.deploymentRequest(targetId, dsId).build());
|
DeploymentRequest.builder(targetId, dsId).build());
|
||||||
|
|
||||||
assertThat(getResultingActionCount(deploymentManagement.assignDistributionSets(twoEqualAssignments)))
|
assertThat(getResultingActionCount(deploymentManagement.assignDistributionSets(twoEqualAssignments)))
|
||||||
.isEqualTo(1);
|
.isEqualTo(1);
|
||||||
|
|
||||||
enableMultiAssignments();
|
enableMultiAssignments();
|
||||||
final List<DeploymentRequest> twoEqualAssignmentsWithWeight = Collections.nCopies(2,
|
final List<DeploymentRequest> twoEqualAssignmentsWithWeight = Collections.nCopies(2,
|
||||||
DeploymentManagement.deploymentRequest(targetId, dsId).setWeight(555).build());
|
DeploymentRequest.builder(targetId, dsId).weight(555).build());
|
||||||
|
|
||||||
assertThat(getResultingActionCount(deploymentManagement.assignDistributionSets(twoEqualAssignmentsWithWeight)))
|
assertThat(getResultingActionCount(deploymentManagement.assignDistributionSets(twoEqualAssignmentsWithWeight)))
|
||||||
.isEqualTo(1);
|
.isEqualTo(1);
|
||||||
@@ -987,7 +984,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||||
deploymentRequests.add(
|
deploymentRequests.add(
|
||||||
DeploymentManagement.deploymentRequest(controllerId, dsId).setWeight(24).build());
|
DeploymentRequest.builder(controllerId, dsId).weight(24).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
enableMultiAssignments();
|
enableMultiAssignments();
|
||||||
@@ -1004,8 +1001,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||||
|
|
||||||
final DeploymentRequest assignWithoutWeight = DeploymentManagement.deploymentRequest(targetId, dsId).build();
|
final DeploymentRequest assignWithoutWeight = DeploymentRequest.builder(targetId, dsId).build();
|
||||||
final DeploymentRequest assignWithWeight = DeploymentManagement.deploymentRequest(targetId, dsId).setWeight(567).build();
|
final DeploymentRequest assignWithWeight = DeploymentRequest.builder(targetId, dsId).weight(567).build();
|
||||||
|
|
||||||
enableMultiAssignments();
|
enableMultiAssignments();
|
||||||
assertThat(deploymentManagement.assignDistributionSets(List.of(assignWithoutWeight, assignWithWeight))).isNotNull();
|
assertThat(deploymentManagement.assignDistributionSets(List.of(assignWithoutWeight, assignWithWeight))).isNotNull();
|
||||||
@@ -1019,7 +1016,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||||
|
|
||||||
final DeploymentRequest assignWithoutWeight = DeploymentManagement.deploymentRequest(targetId, dsId).setWeight(456).build();
|
final DeploymentRequest assignWithoutWeight = DeploymentRequest.builder(targetId, dsId).weight(456).build();
|
||||||
assertThat(deploymentManagement.assignDistributionSets(Collections.singletonList(assignWithoutWeight))).isNotNull().size().isEqualTo(1);
|
assertThat(deploymentManagement.assignDistributionSets(Collections.singletonList(assignWithoutWeight))).isNotNull().size().isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1040,14 +1037,10 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
void weightValidatedAndSaved() {
|
void weightValidatedAndSaved() {
|
||||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||||
final DeploymentRequest valideRequest1 = DeploymentManagement.deploymentRequest(targetId, dsId)
|
final DeploymentRequest valideRequest1 = DeploymentRequest.builder(targetId, dsId).weight(Action.WEIGHT_MAX).build();
|
||||||
.setWeight(Action.WEIGHT_MAX).build();
|
final DeploymentRequest valideRequest2 = DeploymentRequest.builder(targetId, dsId).weight(Action.WEIGHT_MIN).build();
|
||||||
final DeploymentRequest valideRequest2 = DeploymentManagement.deploymentRequest(targetId, dsId)
|
final DeploymentRequest weightTooLow = DeploymentRequest.builder(targetId, dsId).weight(Action.WEIGHT_MIN - 1).build();
|
||||||
.setWeight(Action.WEIGHT_MIN).build();
|
final DeploymentRequest weightTooHigh = DeploymentRequest.builder(targetId, dsId).weight(Action.WEIGHT_MAX + 1).build();
|
||||||
final DeploymentRequest weightTooLow = DeploymentManagement.deploymentRequest(targetId, dsId)
|
|
||||||
.setWeight(Action.WEIGHT_MIN - 1).build();
|
|
||||||
final DeploymentRequest weightTooHigh = DeploymentManagement.deploymentRequest(targetId, dsId)
|
|
||||||
.setWeight(Action.WEIGHT_MAX + 1).build();
|
|
||||||
enableMultiAssignments();
|
enableMultiAssignments();
|
||||||
final List<DeploymentRequest> deploymentRequestsTooLow = Collections.singletonList(weightTooLow);
|
final List<DeploymentRequest> deploymentRequestsTooLow = Collections.singletonList(weightTooLow);
|
||||||
Assertions.assertThatExceptionOfType(ConstraintViolationException.class)
|
Assertions.assertThatExceptionOfType(ConstraintViolationException.class)
|
||||||
@@ -1613,8 +1606,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
||||||
for (int i = 0; i < quotaManagement.getMaxTargetDistributionSetAssignmentsPerManualAssignment(); i++) {
|
for (int i = 0; i < quotaManagement.getMaxTargetDistributionSetAssignmentsPerManualAssignment(); i++) {
|
||||||
final Target target = testdataFactory.createTarget("test-target-" + i, "test-target-" + i, targetType);
|
final Target target = testdataFactory.createTarget("test-target-" + i, "test-target-" + i, targetType);
|
||||||
final DeploymentRequest deployment = DeploymentManagement
|
final DeploymentRequest deployment = DeploymentRequest
|
||||||
.deploymentRequest(target.getControllerId(), ds.getId()).build();
|
.builder(target.getControllerId(), ds.getId()).build();
|
||||||
deploymentRequests.add(deployment);
|
deploymentRequests.add(deployment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1637,8 +1630,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final Target target1 = testdataFactory.createTarget("test-target1", "test-target1", targetType1);
|
final Target target1 = testdataFactory.createTarget("test-target1", "test-target1", targetType1);
|
||||||
final Target target2 = testdataFactory.createTarget("test-target2", "test-target2", targetType2);
|
final Target target2 = testdataFactory.createTarget("test-target2", "test-target2", targetType2);
|
||||||
|
|
||||||
final DeploymentRequest deployment1 = DeploymentManagement.deploymentRequest(target1.getControllerId(), ds.getId()).build();
|
final DeploymentRequest deployment1 = DeploymentRequest.builder(target1.getControllerId(), ds.getId()).build();
|
||||||
final DeploymentRequest deployment2 = DeploymentManagement.deploymentRequest(target2.getControllerId(), ds.getId()).build();
|
final DeploymentRequest deployment2 = DeploymentRequest.builder(target2.getControllerId(), ds.getId()).build();
|
||||||
final List<DeploymentRequest> deploymentRequests = Arrays.asList(deployment1, deployment2);
|
final List<DeploymentRequest> deploymentRequests = Arrays.asList(deployment1, deployment2);
|
||||||
|
|
||||||
deploymentManagement.assignDistributionSets(deploymentRequests);
|
deploymentManagement.assignDistributionSets(deploymentRequests);
|
||||||
@@ -1663,7 +1656,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final TargetType targetType = testdataFactory.createTargetType("target-type", Set.of(dsType));
|
final TargetType targetType = testdataFactory.createTargetType("target-type", Set.of(dsType));
|
||||||
final Target target = testdataFactory.createTarget("test-target", "test-target", targetType);
|
final Target target = testdataFactory.createTarget("test-target", "test-target", targetType);
|
||||||
|
|
||||||
final DeploymentRequest deploymentRequest = DeploymentManagement.deploymentRequest(target.getControllerId(), ds.getId()).build();
|
final DeploymentRequest deploymentRequest = DeploymentRequest.builder(target.getControllerId(), ds.getId()).build();
|
||||||
final List<DeploymentRequest> deploymentRequests = List.of(deploymentRequest);
|
final List<DeploymentRequest> deploymentRequests = List.of(deploymentRequest);
|
||||||
|
|
||||||
assertThatExceptionOfType(IncompatibleTargetTypeException.class)
|
assertThatExceptionOfType(IncompatibleTargetTypeException.class)
|
||||||
@@ -1679,8 +1672,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final TargetType emptyTargetType = testdataFactory.createTargetType("target-type", Set.of());
|
final TargetType emptyTargetType = testdataFactory.createTargetType("target-type", Set.of());
|
||||||
final Target targetWithEmptyType = testdataFactory.createTarget("test-target", "test-target", emptyTargetType);
|
final Target targetWithEmptyType = testdataFactory.createTarget("test-target", "test-target", emptyTargetType);
|
||||||
|
|
||||||
final DeploymentRequest deploymentRequestWithEmptyType = DeploymentManagement
|
final DeploymentRequest deploymentRequestWithEmptyType = DeploymentRequest
|
||||||
.deploymentRequest(targetWithEmptyType.getControllerId(), ds.getId()).build();
|
.builder(targetWithEmptyType.getControllerId(), ds.getId()).build();
|
||||||
final List<DeploymentRequest> deploymentRequests = Collections.singletonList(deploymentRequestWithEmptyType);
|
final List<DeploymentRequest> deploymentRequests = Collections.singletonList(deploymentRequestWithEmptyType);
|
||||||
assertThatExceptionOfType(IncompatibleTargetTypeException.class)
|
assertThatExceptionOfType(IncompatibleTargetTypeException.class)
|
||||||
.isThrownBy(() -> deploymentManagement.assignDistributionSets(deploymentRequests));
|
.isThrownBy(() -> deploymentManagement.assignDistributionSets(deploymentRequests));
|
||||||
@@ -1695,8 +1688,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
final Collection<Target> targets, final int weight, final boolean confirmationRequired) {
|
final Collection<Target> targets, final int weight, final boolean confirmationRequired) {
|
||||||
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
||||||
distributionSets.forEach(ds -> targets.forEach(target -> deploymentRequests
|
distributionSets.forEach(ds -> targets.forEach(target -> deploymentRequests
|
||||||
.add(DeploymentManagement.deploymentRequest(target.getControllerId(), ds.getId()).setWeight(weight)
|
.add(DeploymentRequest.builder(target.getControllerId(), ds.getId())
|
||||||
.setConfirmationRequired(confirmationRequired).build())));
|
.weight(weight).confirmationRequired(confirmationRequired).build())));
|
||||||
return deploymentRequests;
|
return deploymentRequests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -340,8 +340,8 @@ public abstract class AbstractIntegrationTest {
|
|||||||
final boolean confirmationFlowActive = isConfirmationFlowActive();
|
final boolean confirmationFlowActive = isConfirmationFlowActive();
|
||||||
|
|
||||||
final List<DeploymentRequest> deploymentRequests = controllerIds.stream()
|
final List<DeploymentRequest> deploymentRequests = controllerIds.stream()
|
||||||
.map(id -> DeploymentManagement.deploymentRequest(id, dsId)
|
.map(id -> DeploymentRequest.builder(id, dsId)
|
||||||
.setActionType(actionType).setForceTime(forcedTime).setWeight(weight).setConfirmationRequired(confirmationFlowActive)
|
.actionType(actionType).forceTime(forcedTime).weight(weight).confirmationRequired(confirmationFlowActive)
|
||||||
.build())
|
.build())
|
||||||
.toList();
|
.toList();
|
||||||
final List<DistributionSetAssignmentResult> results = deploymentManagement.assignDistributionSets(deploymentRequests);
|
final List<DistributionSetAssignmentResult> results = deploymentManagement.assignDistributionSets(deploymentRequests);
|
||||||
@@ -393,9 +393,9 @@ public abstract class AbstractIntegrationTest {
|
|||||||
final String controllerId, final String maintenanceWindowSchedule, final String maintenanceWindowDuration,
|
final String controllerId, final String maintenanceWindowSchedule, final String maintenanceWindowDuration,
|
||||||
final String maintenanceWindowTimeZone) {
|
final String maintenanceWindowTimeZone) {
|
||||||
|
|
||||||
return makeAssignment(DeploymentManagement.deploymentRequest(controllerId, dsID)
|
return makeAssignment(DeploymentRequest.builder(controllerId, dsID)
|
||||||
.setMaintenance(maintenanceWindowSchedule, maintenanceWindowDuration, maintenanceWindowTimeZone)
|
.maintenance(maintenanceWindowSchedule, maintenanceWindowDuration, maintenanceWindowTimeZone)
|
||||||
.setConfirmationRequired(true).build());
|
.confirmationRequired(true).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet pset, final Target target) {
|
protected DistributionSetAssignmentResult assignDistributionSet(final DistributionSet pset, final Target target) {
|
||||||
|
|||||||
Reference in New Issue
Block a user