Remove Rollout(Group) builders (#2603)
* Fix entityManager.merge for ds and sm Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Remove Rollout(Group) builders Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Remove EntityFactory Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> --------- Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -32,13 +32,12 @@ import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRolloutMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.GroupCreate;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -67,20 +66,18 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
private final RolloutGroupManagement rolloutGroupManagement;
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final TenantConfigHelper tenantConfigHelper;
|
||||
|
||||
MgmtRolloutResource(
|
||||
final RolloutManagement rolloutManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement, final EntityFactory entityFactory,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final SystemSecurityContext systemSecurityContext,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement) {
|
||||
this.rolloutManagement = rolloutManagement;
|
||||
this.rolloutGroupManagement = rolloutGroupManagement;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.targetFilterQueryManagement = targetFilterQueryManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
this.tenantConfigHelper = TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement);
|
||||
}
|
||||
|
||||
@@ -99,7 +96,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
: rolloutManagement.findByRsqlWithDetailedStatus(rsqlParam, false, pageable);
|
||||
rest = MgmtRolloutMapper.toResponseRolloutWithDetails(rollouts.getContent());
|
||||
} else {
|
||||
rollouts = rsqlParam == null
|
||||
rollouts = rsqlParam == null
|
||||
? rolloutManagement.findAll(false, pageable)
|
||||
: rolloutManagement.findByRsql(rsqlParam, false, pageable);
|
||||
rest = MgmtRolloutMapper.toResponseRollout(rollouts.getContent());
|
||||
@@ -124,10 +121,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
throw new RSQLParameterSyntaxException("Cannot create a Rollout with an empty target query filter!");
|
||||
}
|
||||
targetFilterQueryManagement.verifyTargetFilterQuerySyntax(targetFilterQuery);
|
||||
final DistributionSet distributionSet = distributionSetManagement
|
||||
.getValidAndComplete(rolloutRequestBody.getDistributionSetId());
|
||||
final DistributionSet distributionSet = distributionSetManagement.getValidAndComplete(rolloutRequestBody.getDistributionSetId());
|
||||
final RolloutGroupConditions rolloutGroupConditions = MgmtRolloutMapper.fromRequest(rolloutRequestBody, true);
|
||||
final RolloutCreate create = MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet);
|
||||
final Create create = MgmtRolloutMapper.fromRequest(rolloutRequestBody, distributionSet);
|
||||
final boolean confirmationFlowActive = tenantConfigHelper.isConfirmationFlowEnabled();
|
||||
|
||||
final Rollout rollout;
|
||||
@@ -138,13 +134,11 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
if (rolloutRequestBody.getAmountGroups() != null) {
|
||||
throw new ValidationException("Either 'amountGroups' or 'groups' must be defined in the request");
|
||||
}
|
||||
final List<RolloutGroupCreate> rolloutGroups = rolloutRequestBody.getGroups().stream()
|
||||
.map(mgmtRolloutGroup -> {
|
||||
final boolean confirmationRequired = isConfirmationRequiredForGroup(mgmtRolloutGroup,
|
||||
rolloutRequestBody).orElse(confirmationFlowActive);
|
||||
return MgmtRolloutMapper.fromRequest(entityFactory, mgmtRolloutGroup)
|
||||
.confirmationRequired(confirmationRequired);
|
||||
}).toList();
|
||||
final List<GroupCreate> rolloutGroups = rolloutRequestBody.getGroups().stream()
|
||||
.map(mgmtRolloutGroup -> MgmtRolloutMapper.fromRequest(
|
||||
mgmtRolloutGroup,
|
||||
isConfirmationRequiredForGroup(mgmtRolloutGroup, rolloutRequestBody).orElse(confirmationFlowActive)))
|
||||
.toList();
|
||||
rollout = rolloutManagement.create(create, rolloutGroups, rolloutGroupConditions);
|
||||
} else if (rolloutRequestBody.getAmountGroups() != null) {
|
||||
final boolean confirmationRequired = rolloutRequestBody.getConfirmationRequired() == null
|
||||
@@ -161,7 +155,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtRolloutResponseBody> update(final Long rolloutId, final MgmtRolloutRestRequestBodyPut rolloutUpdateBody) {
|
||||
final Rollout updated = rolloutManagement.update(MgmtRolloutMapper.fromRequest(entityFactory, rolloutUpdateBody, rolloutId));
|
||||
final Rollout updated = rolloutManagement.update(MgmtRolloutMapper.fromRequest(rolloutUpdateBody, rolloutId));
|
||||
return ResponseEntity.ok(MgmtRolloutMapper.toResponseRollout(updated, true));
|
||||
}
|
||||
|
||||
@@ -282,7 +276,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
|
||||
throw new ValidationException("Rollout must be finished in order to be retried!");
|
||||
}
|
||||
|
||||
final RolloutCreate create = MgmtRolloutMapper.fromRetriedRollout(entityFactory, rolloutForRetry);
|
||||
final Create create = MgmtRolloutMapper.fromRetriedRollout(rolloutForRetry);
|
||||
final RolloutGroupConditions groupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
final Rollout retriedRollout = rolloutManagement.create(create, 1, false, groupConditions, null);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetFilterQueryMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.AutoAssignDistributionSetUpdate;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
@@ -36,7 +35,6 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.utils.TenantConfigHelper;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTagMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
@@ -38,7 +37,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -35,11 +35,11 @@ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroup;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.DynamicRolloutGroupTemplate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutUpdate;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.GroupCreate;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
@@ -125,49 +125,54 @@ public final class MgmtRolloutMapper {
|
||||
return body;
|
||||
}
|
||||
|
||||
public static RolloutCreate fromRequest(
|
||||
final EntityFactory entityFactory, final MgmtRolloutRestRequestBodyPost restRequest, final DistributionSet distributionSet) {
|
||||
return entityFactory.rollout().create()
|
||||
public static Create fromRequest(final MgmtRolloutRestRequestBodyPost restRequest, final DistributionSet distributionSet) {
|
||||
return Create.builder()
|
||||
.name(restRequest.getName())
|
||||
.description(restRequest.getDescription())
|
||||
.distributionSetId(distributionSet)
|
||||
.distributionSet(distributionSet)
|
||||
.targetFilterQuery(restRequest.getTargetFilterQuery())
|
||||
.actionType(MgmtRestModelMapper.convertActionType(restRequest.getType()))
|
||||
.actionType(Optional.ofNullable(MgmtRestModelMapper.convertActionType(restRequest.getType())).orElse(Action.ActionType.FORCED))
|
||||
.forcedTime(restRequest.getForcetime()).startAt(restRequest.getStartAt())
|
||||
.weight(restRequest.getWeight())
|
||||
.dynamic(restRequest.isDynamic());
|
||||
.dynamic(restRequest.isDynamic())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static RolloutUpdate fromRequest(
|
||||
final EntityFactory entityFactory, final MgmtRolloutRestRequestBodyPut restRequest, final long rolloutId) {
|
||||
return entityFactory.rollout().update(rolloutId)
|
||||
public static Update fromRequest(final MgmtRolloutRestRequestBodyPut restRequest, final long rolloutId) {
|
||||
return Update.builder().id(rolloutId)
|
||||
.name(restRequest.getName())
|
||||
.description(restRequest.getDescription());
|
||||
.description(restRequest.getDescription())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static RolloutCreate fromRetriedRollout(final EntityFactory entityFactory, final Rollout rollout) {
|
||||
return entityFactory.rollout().create()
|
||||
public static Create fromRetriedRollout(final Rollout rollout) {
|
||||
return Create.builder()
|
||||
.name(rollout.getName().concat("_retry"))
|
||||
.description(rollout.getDescription())
|
||||
.distributionSetId(rollout.getDistributionSet())
|
||||
.distributionSet(rollout.getDistributionSet())
|
||||
.targetFilterQuery("failedrollout==".concat(String.valueOf(rollout.getId())))
|
||||
.actionType(rollout.getActionType())
|
||||
.forcedTime(rollout.getForcedTime())
|
||||
.startAt(rollout.getStartAt())
|
||||
.weight(null);
|
||||
.weight(null)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static RolloutGroupCreate fromRequest(final EntityFactory entityFactory, final MgmtRolloutGroup restRequest) {
|
||||
return entityFactory.rolloutGroup().create().name(restRequest.getName())
|
||||
public static GroupCreate fromRequest(final MgmtRolloutGroup restRequest, final boolean confirmationRequired) {
|
||||
return GroupCreate.builder()
|
||||
.name(restRequest.getName())
|
||||
.description(restRequest.getDescription()).targetFilterQuery(restRequest.getTargetFilterQuery())
|
||||
.targetPercentage(restRequest.getTargetPercentage()).conditions(fromRequest(restRequest, false));
|
||||
.targetPercentage(restRequest.getTargetPercentage())
|
||||
.conditions(fromRequest((AbstractMgmtRolloutConditionsEntity)restRequest, false))
|
||||
.confirmationRequired(confirmationRequired)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static DynamicRolloutGroupTemplate fromRequest(final MgmtDynamicRolloutGroupTemplate restRequest) {
|
||||
public static RolloutManagement.DynamicRolloutGroupTemplate fromRequest(final MgmtDynamicRolloutGroupTemplate restRequest) {
|
||||
if (restRequest == null) {
|
||||
return null;
|
||||
}
|
||||
return DynamicRolloutGroupTemplate.builder()
|
||||
return RolloutManagement.DynamicRolloutGroupTemplate.builder()
|
||||
.nameSuffix(Optional.ofNullable(restRequest.getNameSuffix()).orElse(""))
|
||||
.targetCount(restRequest.getTargetCount())
|
||||
.build();
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
|
||||
@@ -23,8 +23,6 @@ import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQueryReq
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.AutoAssignDistributionSetUpdate;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
|
||||
@@ -17,12 +17,11 @@ import java.util.Map;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.GroupCreate;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -93,14 +92,14 @@ class JsonBuilder {
|
||||
|
||||
static String rolloutWithGroups(final String name, final String description, final Integer groupSize,
|
||||
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
|
||||
final List<RolloutGroup> groups) {
|
||||
final List<GroupCreate> groups) {
|
||||
return rolloutWithGroups(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, groups,
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
static String rolloutWithGroups(final String name, final String description, final Integer groupSize,
|
||||
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
|
||||
final List<RolloutGroup> groups, final String type, final Integer weight,
|
||||
final List<GroupCreate> groups, final String type, final Integer weight,
|
||||
final Boolean confirmationRequired) {
|
||||
final List<String> rolloutGroupsJson = groups.stream().map(JsonBuilder::rolloutGroup).toList();
|
||||
return rollout(
|
||||
@@ -198,10 +197,14 @@ class JsonBuilder {
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
static String rolloutGroup(final RolloutGroup rolloutGroup) {
|
||||
static String rolloutGroup(final GroupCreate create) {
|
||||
return rolloutGroup(create, null);
|
||||
}
|
||||
|
||||
static String rolloutGroup(final GroupCreate create, final RolloutGroup rolloutGroup) {
|
||||
final RolloutGroupConditions conditions = getConditions(rolloutGroup);
|
||||
return rolloutGroup(rolloutGroup.getName(), rolloutGroup.getDescription(), rolloutGroup.getTargetFilterQuery(),
|
||||
rolloutGroup.getTargetPercentage(), rolloutGroup.isConfirmationRequired(), conditions);
|
||||
return rolloutGroup(create.getName(), create.getDescription(), create.getTargetFilterQuery(),
|
||||
create.getTargetPercentage(), create.isConfirmationRequired(), conditions);
|
||||
|
||||
}
|
||||
|
||||
@@ -278,10 +281,14 @@ class JsonBuilder {
|
||||
}
|
||||
|
||||
private static RolloutGroupConditions getConditions(final RolloutGroup rolloutGroup) {
|
||||
return new RolloutGroupConditionBuilder()
|
||||
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())
|
||||
.errorAction(rolloutGroup.getErrorAction(), rolloutGroup.getErrorActionExp())
|
||||
.successAction(rolloutGroup.getSuccessAction(), rolloutGroup.getSuccessActionExp())
|
||||
.successCondition(rolloutGroup.getSuccessCondition(), rolloutGroup.getSuccessConditionExp()).build();
|
||||
if (rolloutGroup == null) {
|
||||
return new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
} else {
|
||||
return new RolloutGroupConditionBuilder()
|
||||
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())
|
||||
.errorAction(rolloutGroup.getErrorAction(), rolloutGroup.getErrorActionExp())
|
||||
.successAction(rolloutGroup.getSuccessAction(), rolloutGroup.getSuccessActionExp())
|
||||
.successCondition(rolloutGroup.getSuccessCondition(), rolloutGroup.getSuccessConditionExp()).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,8 +210,8 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
// then simulate a status update with code 200 for the first action
|
||||
final Action action = actions.get(0);
|
||||
controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).code(200)
|
||||
.message("Update succeeded").status(Status.FINISHED));
|
||||
controllerManagement.addUpdateActionStatus(Action.ActionStatusCreate.builder()
|
||||
.actionId(action.getId()).code(200).messages(List.of("Update succeeded")).status(Status.FINISHED).build());
|
||||
|
||||
// verify that one result is returned if the actions are filtered for status code 200
|
||||
final String rsqlStatusCode = "lastStatusCode==200";
|
||||
@@ -284,7 +284,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void filterActionsByRollout() throws Exception {
|
||||
// prepare test
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||
final DistributionSet ds = testdataFactory.createDistributionSetLocked();
|
||||
final Target target0 = testdataFactory.createTarget("t0");
|
||||
|
||||
// manual assignment
|
||||
|
||||
@@ -38,10 +38,14 @@ import org.awaitility.core.ConditionFactory;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtRestModelMapper;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.RolloutManagement.GroupCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
@@ -90,6 +94,8 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
private RolloutGroupManagement rolloutGroupManagement;
|
||||
@Autowired
|
||||
private RolloutTestApprovalStrategy approvalStrategy;
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving a single rollout.
|
||||
@@ -105,12 +111,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
// create a running rollout for the created targets
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory
|
||||
.rollout()
|
||||
.create()
|
||||
Create.builder()
|
||||
.name("rollout1")
|
||||
.distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
.distributionSet(dsA)
|
||||
.targetFilterQuery("controllerId==rollout*")
|
||||
.build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -135,7 +140,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
void getRolloutDeployGroupTargetsWithParameters() throws Exception {
|
||||
testdataFactory.createTargets(4, "rollout", "description");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA, "controllerId==rollout*");
|
||||
final RolloutGroup firstRolloutGroup = rolloutGroupManagement
|
||||
.findByRollout(rollout.getId(), PageRequest.of(0, 1)).getContent().get(0);
|
||||
|
||||
@@ -157,7 +162,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
try {
|
||||
testdataFactory.createTargets(4, "rollout", "description");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA.getId(), "controllerId==rollout*", false);
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA, "controllerId==rollout*", false);
|
||||
mvc.perform(post(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/approve", rollout.getId())
|
||||
.accept(MediaTypes.HAL_JSON_VALUE))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -176,7 +181,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
try {
|
||||
testdataFactory.createTargets(4, "rollout", "description");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA.getId(), "controllerId==rollout*", false);
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA, "controllerId==rollout*", false);
|
||||
mvc.perform(post(MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING + "/{rolloutId}/deny", rollout.getId())
|
||||
.accept(MediaTypes.HAL_JSON_VALUE))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -197,7 +202,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String remark = "Some remark";
|
||||
testdataFactory.createTargets(amountTargets, "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA.getId(), "controllerId==rollout*", false);
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA, "controllerId==rollout*", false);
|
||||
|
||||
rolloutHandler.handleAll();
|
||||
|
||||
@@ -459,11 +464,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final float percentTargetsInGroup1 = 20;
|
||||
final float percentTargetsInGroup2 = 100;
|
||||
|
||||
final List<RolloutGroup> rolloutGroups = Arrays.asList(
|
||||
entityFactory.rolloutGroup().create().name("Group1").description("Group1desc")
|
||||
.targetPercentage(percentTargetsInGroup1).build(),
|
||||
entityFactory.rolloutGroup().create().name("Group2").description("Group2desc")
|
||||
.targetPercentage(percentTargetsInGroup2).build());
|
||||
final List<GroupCreate> rolloutGroups = List.of(
|
||||
GroupCreate.builder().name("Group1").description("Group1desc").targetPercentage(percentTargetsInGroup1).build(),
|
||||
GroupCreate.builder().name("Group2").description("Group2desc").targetPercentage(percentTargetsInGroup2).build());
|
||||
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
@@ -572,11 +575,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final int amountTargets = 10;
|
||||
testdataFactory.createTargets(amountTargets, "ro-target", "rollout");
|
||||
|
||||
final List<RolloutGroup> rolloutGroups = Arrays.asList(
|
||||
entityFactory.rolloutGroup().create().name("Group1").description("Group1desc").targetPercentage(0F)
|
||||
.build(),
|
||||
entityFactory.rolloutGroup().create().name("Group2").description("Group2desc").targetPercentage(100F)
|
||||
.build());
|
||||
final List<GroupCreate> rolloutGroups = List.of(
|
||||
GroupCreate.builder().name("Group1").description("Group1desc").targetPercentage(0F).build(),
|
||||
GroupCreate.builder().name("Group2").description("Group2desc").targetPercentage(100F).build());
|
||||
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
@@ -600,11 +601,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final int amountTargets = 10;
|
||||
testdataFactory.createTargets(amountTargets, "ro-target", "rollout");
|
||||
|
||||
final List<RolloutGroup> rolloutGroups = Arrays.asList(
|
||||
entityFactory.rolloutGroup().create().name("Group1").description("Group1desc").targetPercentage(1F)
|
||||
.build(),
|
||||
entityFactory.rolloutGroup().create().name("Group2").description("Group2desc").targetPercentage(101F)
|
||||
.build());
|
||||
final List<GroupCreate> rolloutGroups = List.of(
|
||||
GroupCreate.builder().name("Group1").description("Group1desc").targetPercentage(1F).build(),
|
||||
GroupCreate.builder().name("Group2").description("Group2desc").targetPercentage(101F).build());
|
||||
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
@@ -627,12 +626,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
// create a running rollout for the created targets
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory
|
||||
.rollout()
|
||||
.create()
|
||||
Create.builder()
|
||||
.name("rollout1")
|
||||
.distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
.distributionSet(dsA)
|
||||
.targetFilterQuery("controllerId==rollout*")
|
||||
.build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -669,8 +667,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout1").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout1").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -690,8 +687,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
// create a running rollout for the created targets
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout1").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout1").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -730,18 +726,16 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
@Test
|
||||
void retrieveRolloutListFullRepresentationWithFilter() throws Exception {
|
||||
testdataFactory.createTargets(20, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSetLocked("");
|
||||
|
||||
// create a running rollout for the created targets
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout1").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout1").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout2").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout2").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -789,8 +783,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout1").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout1").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -887,11 +880,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build();
|
||||
|
||||
final List<String> rolloutGroups = Arrays.asList(
|
||||
JsonBuilder.rolloutGroup("Group1", "Group1desc", null, percentTargetsInGroup1, false,
|
||||
rolloutGroupConditions),
|
||||
JsonBuilder.rolloutGroup("Group2", "Group1desc", null, percentTargetsInGroup2, null,
|
||||
rolloutGroupConditions));
|
||||
final List<String> rolloutGroups = List.of(
|
||||
JsonBuilder.rolloutGroup("Group1", "Group1desc", null, percentTargetsInGroup1, false, rolloutGroupConditions),
|
||||
JsonBuilder.rolloutGroup("Group2", "Group1desc", null, percentTargetsInGroup2, null, rolloutGroupConditions));
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts")
|
||||
.content(JsonBuilder.rollout("rollout2", "desc", null, dsA.getId(), "id==ro-target*",
|
||||
@@ -1040,7 +1031,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
}
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*",
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*",
|
||||
confirmationRequired);
|
||||
|
||||
// retrieve rollout groups from created rollout
|
||||
@@ -1077,14 +1068,11 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
// setup
|
||||
final int amountTargets = 8;
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSetLocked("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout1 = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*",
|
||||
false);
|
||||
|
||||
final Rollout rollout2 = createRollout("rollout2", 1, dsA.getId(), "controllerId==rollout*",
|
||||
false);
|
||||
final Rollout rollout1 = createRollout("rollout1", 4, dsA, "controllerId==rollout*",false);
|
||||
final Rollout rollout2 = createRollout("rollout2", 1, dsA, "controllerId==rollout*", false);
|
||||
|
||||
rolloutManagement.start(rollout1.getId());
|
||||
rolloutManagement.start(rollout2.getId());
|
||||
@@ -1111,7 +1099,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// starting rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
|
||||
@@ -1149,7 +1137,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// starting rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
|
||||
@@ -1184,7 +1172,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// starting rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
|
||||
@@ -1224,7 +1212,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// starting rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
|
||||
@@ -1252,7 +1240,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// resume not yet started rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/resume", rollout.getId()))
|
||||
@@ -1272,7 +1260,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA, "controllerId==rollout*");
|
||||
|
||||
// starting rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
|
||||
@@ -1313,8 +1301,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout1").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout1").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, confirmationRequired, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -1339,7 +1326,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA, "controllerId==rollout*");
|
||||
|
||||
final RolloutGroup firstGroup = rolloutGroupManagement
|
||||
.findByRollout(rollout.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
|
||||
@@ -1366,7 +1353,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA, "controllerId==rollout*");
|
||||
|
||||
final RolloutGroup firstGroup = rolloutGroupManagement
|
||||
.findByRollout(rollout.getId(), PageRequest.of(0, 1, Direction.ASC, "id")).getContent().get(0);
|
||||
@@ -1396,7 +1383,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 2, dsA, "controllerId==rollout*");
|
||||
|
||||
rolloutManagement.start(rollout.getId());
|
||||
|
||||
@@ -1428,7 +1415,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// starting rollout
|
||||
mvc.perform(post("/rest/v1/rollouts/{rolloutId}/start", rollout.getId()))
|
||||
@@ -1452,7 +1439,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rolloutDelete", 4, dsA.getId(), "controllerId==rolloutDelete*");
|
||||
final Rollout rollout = createRollout("rolloutDelete", 4, dsA, "controllerId==rolloutDelete*");
|
||||
|
||||
mvc.perform(delete("/rest/v1/rollouts/{rolloutid}", rollout.getId()))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -1481,7 +1468,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void getRolloutWithRSQLParam() throws Exception {
|
||||
|
||||
final int amountTargetsRollout1 = 25;
|
||||
final int amountTargetsRollout2 = 25;
|
||||
final int amountTargetsRollout3 = 25;
|
||||
@@ -1490,12 +1476,12 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
testdataFactory.createTargets(amountTargetsRollout2, "rollout2", "rollout2");
|
||||
testdataFactory.createTargets(amountTargetsRollout3, "rollout3", "rollout3");
|
||||
testdataFactory.createTargets(amountTargetsOther, "other1", "other1");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSetLocked("");
|
||||
|
||||
createRollout("rollout1", 5, dsA.getId(), "controllerId==rollout1*");
|
||||
final Rollout rollout2 = createRollout("rollout2", 5, dsA.getId(), "controllerId==rollout2*");
|
||||
createRollout("rollout3", 5, dsA.getId(), "controllerId==rollout3*");
|
||||
createRollout("other1", 5, dsA.getId(), "controllerId==other1*");
|
||||
createRollout("rollout1", 5, dsA, "controllerId==rollout1*");
|
||||
final Rollout rollout2 = createRollout("rollout2", 5, dsA, "controllerId==rollout2*");
|
||||
createRollout("rollout3", 5, dsA, "controllerId==rollout3*");
|
||||
createRollout("other1", 5, dsA, "controllerId==other1*");
|
||||
|
||||
mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*2")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
@@ -1535,7 +1521,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// create rollout including the created targets with prefix 'rollout'
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
|
||||
// retrieve rollout groups from created rollout
|
||||
mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())
|
||||
@@ -1580,8 +1566,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
// create a running rollout for the created targets
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name("rollout1").distributionSetId(dsA.getId())
|
||||
.targetFilterQuery("controllerId==rollout*"),
|
||||
Create.builder().name("rollout1").distributionSet(dsA).targetFilterQuery("controllerId==rollout*").build(),
|
||||
4, false, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -1667,7 +1652,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
testdataFactory.createTargets(amountTargets, "rollout", "rollout");
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*");
|
||||
final Rollout rollout = createRollout("rollout1", 4, dsA, "controllerId==rollout*");
|
||||
rolloutManagement.start(rollout.getId());
|
||||
rolloutHandler.handleAll();
|
||||
|
||||
@@ -1691,7 +1676,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("");
|
||||
|
||||
// CREATING state
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA.getId(), "controllerId==rollout*", false);
|
||||
final Rollout rollout = createRollout("rollout1", 3, dsA, "controllerId==rollout*", false);
|
||||
triggerNextGroupAndExpect(rollout, status().isBadRequest());
|
||||
|
||||
// READY state
|
||||
@@ -1720,7 +1705,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
setTargetsStatus(targets, Status.FINISHED);
|
||||
rolloutHandler.handleAll();
|
||||
triggerNextGroupAndExpect(rollout, status().isBadRequest());
|
||||
|
||||
}
|
||||
|
||||
private static Stream<Arguments> confirmationOptions() {
|
||||
@@ -1923,8 +1907,10 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
}
|
||||
|
||||
private static final Duration ROLLOUT_AT_LEAST = Duration.ofMillis(Integer.getInteger("hawkbit.it.rest.await.rolloutAtLeastMs", 50));
|
||||
private static final Duration ROLLOUT_POLL_INTERVAL = Duration.ofMillis(Integer.getInteger("hawkbit.it.rest.await.rolloutPollIntervalMs", 100));
|
||||
private static final Duration ROLLOUT_POLL_INTERVAL = Duration.ofMillis(
|
||||
Integer.getInteger("hawkbit.it.rest.await.rolloutPollIntervalMs", 100));
|
||||
private static final Duration ROLLOUT_TIMEOUT = Duration.ofMillis(Integer.getInteger("hawkbit.it.rest.await.rolloutTimeoutMs", 60_000));
|
||||
|
||||
private ConditionFactory awaitRollout() {
|
||||
return Awaitility.await().atLeast(ROLLOUT_AT_LEAST).pollInterval(ROLLOUT_POLL_INTERVAL).atMost(ROLLOUT_TIMEOUT);
|
||||
}
|
||||
@@ -1987,15 +1973,16 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
"$._links.groups.href", allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))));
|
||||
}
|
||||
|
||||
private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId,
|
||||
final String targetFilterQuery) {
|
||||
return createRollout(name, amountGroups, distributionSetId, targetFilterQuery, false);
|
||||
private Rollout createRollout(
|
||||
final String name, final int amountGroups, final DistributionSet distributionSet, final String targetFilterQuery) {
|
||||
return createRollout(name, amountGroups, distributionSet, targetFilterQuery, false);
|
||||
}
|
||||
|
||||
private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId,
|
||||
final String targetFilterQuery, final boolean confirmationRequired) {
|
||||
private Rollout createRollout(
|
||||
final String name, final int amountGroups, final DistributionSet distributionSet, final String targetFilterQuery,
|
||||
final boolean confirmationRequired) {
|
||||
final Rollout rollout = rolloutManagement.create(
|
||||
entityFactory.rollout().create().name(name).distributionSetId(distributionSetId).targetFilterQuery(targetFilterQuery),
|
||||
Create.builder().name(name).distributionSet(distributionSet).targetFilterQuery(targetFilterQuery).build(),
|
||||
amountGroups, confirmationRequired, new RolloutGroupConditionBuilder().withDefaults()
|
||||
.successCondition(RolloutGroupSuccessCondition.THRESHOLD, "100").build());
|
||||
|
||||
@@ -2013,10 +2000,9 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
private void setTargetsStatus(final List<Target> targets, final Status status) {
|
||||
for (final Target target : targets) {
|
||||
final Long action = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).toList().get(0)
|
||||
.getId();
|
||||
controllerManagement
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action).status(status).message("test"));
|
||||
final Long action = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).toList().get(0).getId();
|
||||
controllerManagement.addUpdateActionStatus(
|
||||
ActionStatusCreate.builder().actionId(action).status(status).messages(List.of("test")).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,13 +56,11 @@ import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -287,7 +285,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String expectedStatusMessage2 = "some-custom-message2";
|
||||
final Status expectedStatusAfterActionConfirmationCall = Status.RUNNING;
|
||||
final long actionId = doAssignmentAndTestConfirmation("targetId");
|
||||
testActionConfirmation("targetId", actionId, MgmtActionConfirmationRequestBodyPut.Confirmation.CONFIRMED, expectedStatusCode, new String[]{expectedStatusMessage1, expectedStatusMessage2}, HttpStatus.OK ,expectedStatusAfterActionConfirmationCall);
|
||||
testActionConfirmation("targetId", actionId, MgmtActionConfirmationRequestBodyPut.Confirmation.CONFIRMED, expectedStatusCode,
|
||||
new String[] { expectedStatusMessage1, expectedStatusMessage2 }, HttpStatus.OK, expectedStatusAfterActionConfirmationCall);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +299,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String expectedStatusMessage2 = "some-error-custom-message2";
|
||||
final Status expectedStatusAfterActionConfirmationCall = Status.WAIT_FOR_CONFIRMATION;
|
||||
final long actionId = doAssignmentAndTestConfirmation("targetId");
|
||||
testActionConfirmation("targetId", actionId, MgmtActionConfirmationRequestBodyPut.Confirmation.DENIED, expectedStatusCode, new String[]{expectedStatusMessage1, expectedStatusMessage2}, HttpStatus.OK, expectedStatusAfterActionConfirmationCall);
|
||||
testActionConfirmation("targetId", actionId, MgmtActionConfirmationRequestBodyPut.Confirmation.DENIED, expectedStatusCode,
|
||||
new String[] { expectedStatusMessage1, expectedStatusMessage2 }, HttpStatus.OK, expectedStatusAfterActionConfirmationCall);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,10 +316,10 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
// test that target id and action id are checked correctly and only actions assigned to given targets are confirmed/denied
|
||||
// if action is not assigned to the target, confirmation call must fail
|
||||
testActionConfirmation("controller1", controller2Action, MgmtActionConfirmationRequestBodyPut.Confirmation.CONFIRMED,
|
||||
payloadCallCode, new String[]{payloadCallMessage1, payloadCallMessage2}, HttpStatus.NOT_FOUND,
|
||||
payloadCallCode, new String[] { payloadCallMessage1, payloadCallMessage2 }, HttpStatus.NOT_FOUND,
|
||||
Status.WAIT_FOR_CONFIRMATION);
|
||||
testActionConfirmation("controller2", controller1Action, MgmtActionConfirmationRequestBodyPut.Confirmation.CONFIRMED,
|
||||
payloadCallCode, new String[]{payloadCallMessage1, payloadCallMessage2}, HttpStatus.NOT_FOUND,
|
||||
payloadCallCode, new String[] { payloadCallMessage1, payloadCallMessage2 }, HttpStatus.NOT_FOUND,
|
||||
Status.WAIT_FOR_CONFIRMATION);
|
||||
}
|
||||
|
||||
@@ -339,10 +339,11 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
return action.getId();
|
||||
}
|
||||
|
||||
void testActionConfirmation(final String controllerId, final long actionId, final MgmtActionConfirmationRequestBodyPut.Confirmation payloadConfirmation, final int payloadCode, final String[] payloadMessages, final HttpStatus expectedHttpResponseStatus,final Status expectedGeneratedStatus) throws Exception {
|
||||
void testActionConfirmation(final String controllerId, final long actionId,
|
||||
final MgmtActionConfirmationRequestBodyPut.Confirmation payloadConfirmation, final int payloadCode, final String[] payloadMessages,
|
||||
final HttpStatus expectedHttpResponseStatus, final Status expectedGeneratedStatus) throws Exception {
|
||||
String url = MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + controllerId + "/" + MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId + "/confirmation";
|
||||
mvc.perform(put(url)
|
||||
.content(String.format("{\"confirmation\":\"%s\",\"details\":[\"%s\",\"%s\"],\"code\":%d}",
|
||||
mvc.perform(put(url).content(String.format("{\"confirmation\":\"%s\",\"details\":[\"%s\",\"%s\"],\"code\":%d}",
|
||||
payloadConfirmation.getName(),
|
||||
payloadMessages[0],
|
||||
payloadMessages[1],
|
||||
@@ -352,7 +353,6 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().is(expectedHttpResponseStatus.value()));
|
||||
|
||||
|
||||
// check status after confirmation is done (either confirmed or denied)
|
||||
final List<Action> actionHistory = deploymentManagement.findActionsByTarget(controllerId, PAGE).getContent();
|
||||
assertThat(actionHistory).hasSize(1);
|
||||
@@ -362,18 +362,18 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
// confirmation call was successful, check if Action status ,status code and messages are updated appropriately
|
||||
if (expectedHttpResponseStatus == HttpStatus.OK) {
|
||||
assertThat(jpaAction.getStatus()).isEqualTo(expectedGeneratedStatus);
|
||||
assertThat(jpaAction.getLastActionStatusCode().get()).isEqualTo(payloadCode);
|
||||
assertThat(jpaAction.getLastActionStatusCode()).hasValue(payloadCode);
|
||||
|
||||
actionStatuses.sort(Comparator.comparingLong(Identifiable::getId));
|
||||
assertThat(actionStatuses.size()).isEqualTo(2);
|
||||
assertThat(actionStatuses).hasSize(2);
|
||||
assertThat((actionStatuses.get(0)).getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
|
||||
assertThat((actionStatuses.get(0)).getCode().isEmpty()).isTrue();
|
||||
assertThat((actionStatuses.get(0)).getCode()).isEmpty();
|
||||
assertThat((actionStatuses.get(1)).getStatus()).isEqualTo(expectedGeneratedStatus);
|
||||
assertThat((actionStatuses.get(1)).getCode().get()).isEqualTo(payloadCode);
|
||||
assertThat((actionStatuses.get(1)).getCode()).hasValue(payloadCode);
|
||||
assertThat(((JpaActionStatus) actionStatuses.get(1)).getMessages()).contains(payloadMessages[0], payloadMessages[1]);
|
||||
} else { // confirmation call not successful, check if Action status is not updated, no new Action status added as well.
|
||||
assertThat(jpaAction.getStatus()).isEqualTo(Status.WAIT_FOR_CONFIRMATION);
|
||||
assertThat(jpaAction.getLastActionStatusCode().isEmpty()).isTrue();
|
||||
assertThat(jpaAction.getLastActionStatusCode()).isEmpty();
|
||||
assertThat(jpaAction.getActionStatus()).hasSize(1);
|
||||
}
|
||||
}
|
||||
@@ -949,7 +949,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
final SoftwareModule os = findFirstModuleByType(ds, osType).orElseThrow();
|
||||
final SoftwareModule jvm = findFirstModuleByType(ds, runtimeType).orElseThrow();
|
||||
final SoftwareModule bApp = findFirstModuleByType(ds,appType).orElseThrow();
|
||||
final SoftwareModule bApp = findFirstModuleByType(ds, appType).orElseThrow();
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId + "/assignedDS"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -1161,9 +1161,9 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
assertThat((Object) JsonPath.compile("[0]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
|
||||
.hasToString("http://localhost/rest/v1/targets/id1");
|
||||
assertThat((Object)JsonPath.compile("[1]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
|
||||
assertThat((Object) JsonPath.compile("[1]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
|
||||
.hasToString("http://localhost/rest/v1/targets/id2");
|
||||
assertThat((Object)JsonPath.compile("[2]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
|
||||
assertThat((Object) JsonPath.compile("[2]._links.self.href").read(mvcResult.getResponse().getContentAsString()))
|
||||
.hasToString("http://localhost/rest/v1/targets/id3");
|
||||
|
||||
final Target t1 = assertTarget("id1", "testname1", "testid1");
|
||||
@@ -1723,7 +1723,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that an offline DS to target assignment is reflected by the repository and that repeating
|
||||
* Verifies that an offline DS to target assignment is reflected by the repository and that repeating
|
||||
* the assignment does not change the target.
|
||||
*/
|
||||
@Test
|
||||
@@ -3066,15 +3066,15 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
assertThat(action).isNotNull();
|
||||
assertThat(status).isNotNull();
|
||||
|
||||
final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId());
|
||||
final Action.ActionStatusCreate.ActionStatusCreateBuilder actionStatus = Action.ActionStatusCreate.builder().actionId(action.getId());
|
||||
actionStatus.status(status);
|
||||
if (statusCode != null) {
|
||||
actionStatus.code(statusCode);
|
||||
}
|
||||
if (message != null) {
|
||||
actionStatus.message(message);
|
||||
actionStatus.messages(List.of(message));
|
||||
}
|
||||
|
||||
return controllerManagement.addUpdateActionStatus(actionStatus);
|
||||
return controllerManagement.addUpdateActionStatus(actionStatus.build());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user