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;
|
||||
|
||||
Reference in New Issue
Block a user