New MGMT API resource for action to forced switch. (#525)

* New rest resource for action to forced switch.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Utility usage for response.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Raise test timeout.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* PUT resource for similar to GET resource.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-06-06 14:11:32 +02:00
committed by GitHub
parent b69bedd8f9
commit 1a47c3da25
33 changed files with 533 additions and 403 deletions

View File

@@ -106,7 +106,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
}
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(findDsPage.getContent());
return new ResponseEntity<>(new PagedList<>(rest, findDsPage.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, findDsPage.getTotalElements()));
}
@Override
@@ -114,7 +114,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@PathVariable("distributionSetId") final Long distributionSetId) {
final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId);
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponse(foundDs), HttpStatus.OK);
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(foundDs));
}
@Override
@@ -138,7 +138,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@Override
public ResponseEntity<Void> deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId) {
distributionSetManagement.deleteDistributionSet(distributionSetId);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
@@ -146,12 +146,10 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@PathVariable("distributionSetId") final Long distributionSetId,
@RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) {
return new ResponseEntity<>(
MgmtDistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet(
entityFactory.distributionSet().update(distributionSetId).name(toUpdate.getName())
.description(toUpdate.getDescription()).version(toUpdate.getVersion())
.requiredMigrationStep(toUpdate.isRequiredMigrationStep()))),
HttpStatus.OK);
return ResponseEntity.ok(MgmtDistributionSetMapper
.toResponse(distributionSetManagement.updateDistributionSet(entityFactory.distributionSet()
.update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription())
.version(toUpdate.getVersion()).requiredMigrationStep(toUpdate.isRequiredMigrationStep()))));
}
@Override
@@ -175,8 +173,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, pageable);
}
return new ResponseEntity<>(new PagedList<>(MgmtTargetMapper.toResponse(targetsAssignedDS.getContent()),
targetsAssignedDS.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetsAssignedDS.getContent()),
targetsAssignedDS.getTotalElements()));
}
@Override
@@ -204,8 +202,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
pageable);
}
return new ResponseEntity<>(new PagedList<>(MgmtTargetMapper.toResponse(targetsInstalledDS.getContent()),
targetsInstalledDS.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(MgmtTargetMapper.toResponse(targetsInstalledDS.getContent()),
targetsInstalledDS.getTotalElements()));
}
@Override
@@ -223,10 +221,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
final Page<TargetFilterQuery> targetFilterQueries = targetFilterQueryManagement
.findTargetFilterQueryByAutoAssignDS(pageable, distributionSetId, rsqlParam);
return new ResponseEntity<>(
new PagedList<>(MgmtTargetFilterQueryMapper.toResponse(targetFilterQueries.getContent()),
targetFilterQueries.getTotalElements()),
HttpStatus.OK);
return ResponseEntity
.ok(new PagedList<>(MgmtTargetFilterQueryMapper.toResponse(targetFilterQueries.getContent()),
targetFilterQueries.getTotalElements()));
}
@Override
@@ -241,7 +238,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
MgmtRestModelMapper.convertActionType(t.getType()), t.getForcetime()))
.collect(Collectors.toList()));
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponse(assignDistributionSet), HttpStatus.OK);
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(assignDistributionSet));
}
@Override
@@ -267,10 +264,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
pageable);
}
return new ResponseEntity<>(
new PagedList<>(MgmtDistributionSetMapper.toResponseDsMetadata(metaDataPage.getContent()),
metaDataPage.getTotalElements()),
HttpStatus.OK);
return ResponseEntity
.ok(new PagedList<>(MgmtDistributionSetMapper.toResponseDsMetadata(metaDataPage.getContent()),
metaDataPage.getTotalElements()));
}
@@ -324,7 +320,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
distributionSetManagement.assignSoftwareModules(distributionSetId,
softwareModuleIDs.stream().map(MgmtSoftwareModuleAssigment::getId).collect(Collectors.toList()));
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
@@ -348,8 +344,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<SoftwareModule> softwaremodules = softwareModuleManagement.findSoftwareModuleByAssignedTo(pageable,
distributionSetId);
return new ResponseEntity<>(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(softwaremodules.getContent()),
softwaremodules.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(softwaremodules.getContent()),
softwaremodules.getTotalElements()));
}
private DistributionSet findDistributionSetWithExceptionIfNotFound(final Long distributionSetId) {

View File

@@ -80,14 +80,14 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
}
final List<MgmtTag> rest = MgmtTagMapper.toResponseDistributionSetTag(findTargetsAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, findTargetsAll.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, findTargetsAll.getTotalElements()));
}
@Override
public ResponseEntity<MgmtTag> getDistributionSetTag(
@PathVariable("distributionsetTagId") final Long distributionsetTagId) {
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
return new ResponseEntity<>(MgmtTagMapper.toResponse(tag), HttpStatus.OK);
return ResponseEntity.ok(MgmtTagMapper.toResponse(tag));
}
@Override
@@ -106,11 +106,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@PathVariable("distributionsetTagId") final Long distributionsetTagId,
@RequestBody final MgmtTagRequestBodyPut restDSTagRest) {
return new ResponseEntity<>(
MgmtTagMapper.toResponse(tagManagement.updateDistributionSetTag(
entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName())
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()))),
HttpStatus.OK);
return ResponseEntity.ok(MgmtTagMapper.toResponse(tagManagement
.updateDistributionSetTag(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName())
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()))));
}
@Override
@@ -121,16 +119,16 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
this.tagManagement.deleteDistributionSetTag(tag.getName());
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<List<MgmtDistributionSet>> getAssignedDistributionSets(
@PathVariable("distributionsetTagId") final Long distributionsetTagId) {
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(distributionSetManagement
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(distributionSetManagement
.findDistributionSetsByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT),
distributionsetTagId)
.getContent()), HttpStatus.OK);
.getContent()));
}
@Override
@@ -156,7 +154,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper
.toResponseFromDsList(findDistrAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, findDistrAll.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, findDistrAll.getTotalElements()));
}
@Override
@@ -180,7 +178,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
LOG.debug("Toggled assignedDS {} and unassignedDS{}", assigmentResult.getAssigned(),
assigmentResult.getUnassigned());
return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK);
return ResponseEntity.ok(tagAssigmentResultRest);
}
@Override
@@ -191,7 +189,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
final List<DistributionSet> assignedDs = this.distributionSetManagement
.assignTag(findDistributionSetIds(assignedDSRequestBodies), distributionsetTagId);
LOG.debug("Assignd DistributionSet {}", assignedDs.size());
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs), HttpStatus.OK);
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs));
}
@Override
@@ -200,7 +198,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@PathVariable("distributionsetId") final Long distributionsetId) {
LOG.debug("Unassign ds {} for ds tag {}", distributionsetId, distributionsetTagId);
this.distributionSetManagement.unAssignTag(distributionsetId, distributionsetTagId);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) {

View File

@@ -71,7 +71,7 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
final DownloadArtifactCache artifactCache = downloadIdCache.get(downloadId);
if (artifactCache == null) {
LOGGER.warn("Download Id {} could not be found", downloadId);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.notFound().build();
}
DbArtifact artifact = null;
@@ -85,7 +85,7 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
if (artifact == null) {
LOGGER.warn("Artifact with cached id {} and download type {} could not be found.",
artifactCache.getId(), artifactCache.getDownloadType());
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.notFound().build();
}
final HttpServletResponse response = requestResponseContextHolder.getHttpServletResponse();

View File

@@ -45,13 +45,6 @@ final class MgmtRestModelMapper {
response.setDescription(base.getDescription());
}
/**
* Convert a action rest type to a action repository type.
*
* @param actionTypeRest
* the rest type
* @return <null> or the action repository type
*/
/**
* Convert a action rest type to a action repository type.
*
@@ -75,4 +68,28 @@ final class MgmtRestModelMapper {
throw new IllegalStateException("Action Type is not supported");
}
}
/**
* Convert a action repository type to rest type.
*
* @param actionType
* the rest type
* @return <null> or the action repository type
*/
public static MgmtActionType convertActionType(final ActionType actionType) {
if (actionType == null) {
return null;
}
switch (actionType) {
case SOFT:
return MgmtActionType.SOFT;
case FORCED:
return MgmtActionType.FORCED;
case TIMEFORCED:
return MgmtActionType.TIMEFORCED;
default:
throw new IllegalStateException("Action Type is not supported");
}
}
}

View File

@@ -86,7 +86,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
}
final List<MgmtRolloutResponseBody> rest = MgmtRolloutMapper.toResponseRollout(findModulesAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, findModulesAll.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, findModulesAll.getTotalElements()));
}
@Override
@@ -94,7 +94,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Rollout findRolloutById = rolloutManagement.findRolloutWithDetailedStatus(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
return new ResponseEntity<>(MgmtRolloutMapper.toResponseRollout(findRolloutById, true), HttpStatus.OK);
return ResponseEntity.ok(MgmtRolloutMapper.toResponseRollout(findRolloutById, true));
}
@Override
@@ -174,7 +174,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final List<MgmtRolloutGroupResponseBody> rest = MgmtRolloutMapper
.toResponseRolloutGroup(findRolloutGroupsAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, findRolloutGroupsAll.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, findRolloutGroupsAll.getTotalElements()));
}
@Override
@@ -215,7 +215,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
rolloutGroupTargets = pageTargets;
}
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent());
return new ResponseEntity<>(new PagedList<>(rest, rolloutGroupTargets.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, rolloutGroupTargets.getTotalElements()));
}
private DistributionSet findDistributionSetOrThrowException(final MgmtRolloutRestRequestBody rolloutRequestBody) {

View File

@@ -70,7 +70,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@RequestParam(value = "sha1sum", required = false) final String sha1Sum) {
if (file.isEmpty()) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return ResponseEntity.badRequest().build();
}
String fileName = optionalFileName;
@@ -208,10 +208,11 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
final Page<SoftwareModuleMetadata> metaDataPage;
if (rsqlParam != null) {
metaDataPage = softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, rsqlParam,
pageable);
metaDataPage = softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId,
rsqlParam, pageable);
} else {
metaDataPage = softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, pageable);
metaDataPage = softwareModuleManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId,
pageable);
}
return ResponseEntity
@@ -252,8 +253,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@PathVariable("softwareModuleId") final Long softwareModuleId,
@RequestBody final List<MgmtMetadata> metadataRest) {
final List<SoftwareModuleMetadata> created = softwareModuleManagement.createSoftwareModuleMetadata(softwareModuleId,
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, metadataRest));
final List<SoftwareModuleMetadata> created = softwareModuleManagement.createSoftwareModuleMetadata(
softwareModuleId, MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, metadataRest));
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponseSwMetadata(created));
}

View File

@@ -73,7 +73,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
final List<MgmtSoftwareModuleType> rest = MgmtSoftwareModuleTypeMapper
.toTypesResponse(findModuleTypessAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, countModulesAll), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
}
@Override
@@ -81,14 +81,14 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
final SoftwareModuleType foundType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toResponse(foundType), HttpStatus.OK);
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(foundType));
}
@Override
public ResponseEntity<Void> deleteSoftwareModuleType(
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
softwareModuleTypeManagement.deleteSoftwareModuleType(softwareModuleTypeId);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
@@ -96,11 +96,12 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId,
@RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement.updateSoftwareModuleType(entityFactory
.softwareModuleType().update(softwareModuleTypeId).description(restSoftwareModuleType.getDescription())
.colour(restSoftwareModuleType.getColour()));
final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement
.updateSoftwareModuleType(entityFactory.softwareModuleType().update(softwareModuleTypeId)
.description(restSoftwareModuleType.getDescription())
.colour(restSoftwareModuleType.getColour()));
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType), HttpStatus.OK);
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType));
}
@Override

View File

@@ -57,7 +57,7 @@ public class MgmtSystemManagementResource implements MgmtSystemManagementRestApi
@Override
public ResponseEntity<Void> deleteTenant(@PathVariable("tenant") final String tenant) {
systemManagement.deleteTenant(tenant);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
/**

View File

@@ -60,9 +60,8 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
*/
@Override
public ResponseEntity<Map<String, MgmtSystemTenantConfigurationValue>> getSystemConfiguration() {
return new ResponseEntity<>(
MgmtSystemMapper.toResponse(tenantConfigurationManagement, tenantConfigurationProperties),
HttpStatus.OK);
return ResponseEntity
.ok(MgmtSystemMapper.toResponse(tenantConfigurationManagement, tenantConfigurationProperties));
}
/**
@@ -81,7 +80,7 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
tenantConfigurationManagement.deleteConfiguration(keyName);
LOG.debug("{} config value deleted, return status {}", keyName, HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return ResponseEntity.ok().build();
}
/**
@@ -99,9 +98,8 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
@PathVariable("keyName") final String keyName) {
LOG.debug("{} config value getted, return status {}", keyName, HttpStatus.OK);
return new ResponseEntity<>(
MgmtSystemMapper.toResponse(keyName, tenantConfigurationManagement.getConfigurationValue(keyName)),
HttpStatus.OK);
return ResponseEntity
.ok(MgmtSystemMapper.toResponse(keyName, tenantConfigurationManagement.getConfigurationValue(keyName)));
}
/**
@@ -123,7 +121,7 @@ public class MgmtSystemResource implements MgmtSystemRestApi {
final TenantConfigurationValue<? extends Serializable> updatedValue = tenantConfigurationManagement
.addOrUpdateConfiguration(keyName, configurationValueRest.getValue());
return new ResponseEntity<>(MgmtSystemMapper.toResponse(keyName, updatedValue), HttpStatus.OK);
return ResponseEntity.ok(MgmtSystemMapper.toResponse(keyName, updatedValue));
}
}

View File

@@ -56,7 +56,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
// to single response include poll status
final MgmtTargetFilterQuery response = MgmtTargetFilterQueryMapper.toResponse(findTarget);
return new ResponseEntity<>(response, HttpStatus.OK);
return ResponseEntity.ok(response);
}
@Override
@@ -85,7 +85,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
final List<MgmtTargetFilterQuery> rest = MgmtTargetFilterQueryMapper
.toResponse(findTargetFiltersAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, countTargetsAll));
}
@Override
@@ -106,14 +106,14 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
.updateTargetFilterQuery(entityFactory.targetFilterQuery().update(filterId)
.name(targetFilterRest.getName()).query(targetFilterRest.getQuery()));
return new ResponseEntity<>(MgmtTargetFilterQueryMapper.toResponse(updateFilter), HttpStatus.OK);
return ResponseEntity.ok(MgmtTargetFilterQueryMapper.toResponse(updateFilter));
}
@Override
public ResponseEntity<Void> deleteFilter(@PathVariable("filterId") final Long filterId) {
filterManagement.deleteTargetFilterQuery(filterId);
LOG.debug("{} target filter query deleted, return status {}", filterId, HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
@@ -123,7 +123,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
final TargetFilterQuery updateFilter = filterManagement.updateTargetFilterQueryAutoAssignDS(filterId,
dsId.getId());
return new ResponseEntity<>(MgmtTargetFilterQueryMapper.toResponse(updateFilter), HttpStatus.OK);
return ResponseEntity.ok(MgmtTargetFilterQueryMapper.toResponse(updateFilter));
}
@Override
@@ -140,7 +140,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
public ResponseEntity<Void> deleteAssignedDistributionSet(@PathVariable("filterId") final Long filterId) {
filterManagement.updateTargetFilterQueryAutoAssignDS(filterId, null);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return ResponseEntity.noContent().build();
}
private TargetFilterQuery findFilterWithExceptionIfNotFound(final Long filterId) {

View File

@@ -24,13 +24,16 @@ import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtActionStatus;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.builder.TargetCreate;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.PollStatus;
import org.eclipse.hawkbit.repository.model.Target;
@@ -175,13 +178,17 @@ public final class MgmtTargetMapper {
.collect(Collectors.toList());
}
static MgmtAction toResponse(final String targetId, final Action action, final boolean isActive) {
static MgmtAction toResponse(final String targetId, final Action action) {
final MgmtAction result = new MgmtAction();
result.setActionId(action.getId());
result.setType(getType(action));
if (ActionType.TIMEFORCED.equals(action.getActionType())) {
result.setForceTime(action.getForcedTime());
}
result.setForceType(MgmtRestModelMapper.convertActionType(action.getActionType()));
if (isActive) {
if (action.isActive()) {
result.setStatus(MgmtAction.ACTION_PENDING);
} else {
result.setStatus(MgmtAction.ACTION_FINISHED);
@@ -194,13 +201,32 @@ public final class MgmtTargetMapper {
return result;
}
static MgmtAction toResponseWithLinks(final String controllerId, final Action action) {
final MgmtAction result = toResponse(controllerId, action);
if (action.isCancelingOrCanceled()) {
result.add(linkTo(methodOn(MgmtTargetRestApi.class).getAction(controllerId, action.getId()))
.withRel(MgmtRestConstants.TARGET_V1_CANCELED_ACTION));
} else {
result.add(linkTo(
methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(action.getDistributionSet().getId()))
.withRel("distributionset"));
}
result.add(linkTo(methodOn(MgmtTargetRestApi.class).getActionStatusList(controllerId, action.getId(), 0,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
ActionStatusFields.ID.getFieldName() + ":" + SortDirection.DESC))
.withRel(MgmtRestConstants.TARGET_V1_ACTION_STATUS));
return result;
}
static List<MgmtAction> toResponse(final String targetId, final Collection<Action> actions) {
if (actions == null) {
return Collections.emptyList();
}
return actions.stream().map(action -> toResponse(targetId, action, action.isActive()))
.collect(Collectors.toList());
return actions.stream().map(action -> toResponse(targetId, action)).collect(Collectors.toList());
}
private static String getType(final Action action) {

View File

@@ -8,9 +8,6 @@
*/
package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -18,26 +15,26 @@ import java.util.Map;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtActionRequestBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtActionStatus;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtDistributionSetAssigment;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAttributes;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.rest.data.SortDirection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -76,7 +73,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
MgmtTargetMapper.addPollStatus(findTarget, response);
MgmtTargetMapper.addTargetLinks(response);
return new ResponseEntity<>(response, HttpStatus.OK);
return ResponseEntity.ok(response);
}
@Override
@@ -103,7 +100,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
}
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, countTargetsAll));
}
@Override
@@ -123,27 +120,27 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
.securityToken(targetRest.getSecurityToken()));
return new ResponseEntity<>(MgmtTargetMapper.toResponse(updateTarget), HttpStatus.OK);
return ResponseEntity.ok(MgmtTargetMapper.toResponse(updateTarget));
}
@Override
public ResponseEntity<Void> deleteTarget(@PathVariable("controllerId") final String controllerId) {
this.targetManagement.deleteTarget(controllerId);
LOG.debug("{} target deleted, return status {}", controllerId, HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<MgmtTargetAttributes> getAttributes(@PathVariable("controllerId") final String controllerId) {
final Map<String, String> controllerAttributes = targetManagement.getControllerAttributes(controllerId);
if (controllerAttributes.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return ResponseEntity.noContent().build();
}
final MgmtTargetAttributes result = new MgmtTargetAttributes();
result.putAll(controllerAttributes);
return new ResponseEntity<>(result, HttpStatus.OK);
return ResponseEntity.ok(result);
}
@Override
@@ -171,10 +168,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
totalActionCount = this.deploymentManagement.countActionsByTarget(controllerId);
}
return new ResponseEntity<>(
new PagedList<>(MgmtTargetMapper.toResponse(controllerId, activeActions.getContent()),
totalActionCount),
HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(MgmtTargetMapper.toResponse(controllerId, activeActions.getContent()),
totalActionCount));
}
@Override
@@ -185,26 +180,10 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.getTarget().getControllerId().equals(controllerId)) {
LOG.warn("given action ({}) is not assigned to given target ({}).", action.getId(), controllerId);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.notFound().build();
}
final MgmtAction result = MgmtTargetMapper.toResponse(controllerId, action, action.isActive());
if (!action.isCancelingOrCanceled()) {
result.add(linkTo(
methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(action.getDistributionSet().getId()))
.withRel("distributionset"));
} else if (action.isCancelingOrCanceled()) {
result.add(linkTo(methodOn(MgmtTargetRestApi.class).getAction(controllerId, action.getId()))
.withRel(MgmtRestConstants.TARGET_V1_CANCELED_ACTION));
}
result.add(linkTo(methodOn(MgmtTargetRestApi.class).getActionStatusList(controllerId, action.getId(), 0,
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
ActionStatusFields.ID.getFieldName() + ":" + SortDirection.DESC))
.withRel(MgmtRestConstants.TARGET_V1_ACTION_STATUS));
return new ResponseEntity<>(result, HttpStatus.OK);
return ResponseEntity.ok(MgmtTargetMapper.toResponseWithLinks(controllerId, action));
}
@Override
@@ -216,7 +195,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
if (!action.getTarget().getControllerId().equals(controllerId)) {
LOG.warn("given action ({}) is not assigned to given target ({}).", actionId, controllerId);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.notFound().build();
}
if (force) {
@@ -227,7 +206,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
// both functions will throw an exception, when action is in wrong
// state, which is mapped by MgmtResponseExceptionHandler.
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return ResponseEntity.noContent().build();
}
@Override
@@ -244,7 +223,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
if (!action.getTarget().getId().equals(target.getId())) {
LOG.warn("given action ({}) is not assigned to given target ({}).", action.getId(), target.getId());
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return ResponseEntity.notFound().build();
}
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
@@ -254,9 +233,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusByAction(
new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action.getId());
return new ResponseEntity<>(new PagedList<>(
return ResponseEntity.ok(new PagedList<>(
MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent(), deploymentManagement),
statusList.getTotalElements()), HttpStatus.OK);
statusList.getTotalElements()));
}
@@ -267,9 +246,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.map(MgmtDistributionSetMapper::toResponse).orElse(null);
if (distributionSetRest == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return ResponseEntity.noContent().build();
}
return new ResponseEntity<>(distributionSetRest, HttpStatus.OK);
return ResponseEntity.ok(distributionSetRest);
}
@Override
@@ -282,7 +261,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
this.deploymentManagement.assignDistributionSet(dsId.getId(), type, dsId.getForcetime(),
Arrays.asList(controllerId));
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
@@ -292,9 +271,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.map(MgmtDistributionSetMapper::toResponse).orElse(null);
if (distributionSetRest == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return ResponseEntity.noContent().build();
}
return new ResponseEntity<>(distributionSetRest, HttpStatus.OK);
return ResponseEntity.ok(distributionSetRest);
}
private Target findTargetWithExceptionIfNotFound(final String controllerId) {
@@ -302,4 +281,24 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
}
@Override
public ResponseEntity<MgmtAction> updateAction(@PathVariable("controllerId") final String controllerId,
@PathVariable("actionId") final Long actionId, @RequestBody final MgmtActionRequestBodyPut actionUpdate) {
Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.getTarget().getControllerId().equals(controllerId)) {
LOG.warn("given action ({}) is not assigned to given target ({}).", action.getId(), controllerId);
return ResponseEntity.notFound().build();
}
if (!MgmtActionType.FORCED.equals(actionUpdate.getForceType())) {
throw new ConstraintViolationException("Resource supports only switch to FORCED.");
}
action = deploymentManagement.forceTargetAction(actionId);
return ResponseEntity.ok(MgmtTargetMapper.toResponseWithLinks(controllerId, action));
}
}

View File

@@ -79,13 +79,13 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
}
final List<MgmtTag> rest = MgmtTagMapper.toResponse(findTargetsAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, findTargetsAll.getTotalElements()), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, findTargetsAll.getTotalElements()));
}
@Override
public ResponseEntity<MgmtTag> getTargetTag(@PathVariable("targetTagId") final Long targetTagId) {
final TargetTag tag = findTargetTagById(targetTagId);
return new ResponseEntity<>(MgmtTagMapper.toResponse(tag), HttpStatus.OK);
return ResponseEntity.ok(MgmtTagMapper.toResponse(tag));
}
@Override
@@ -107,7 +107,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
LOG.debug("target tag updated");
return new ResponseEntity<>(MgmtTagMapper.toResponse(updateTargetTag), HttpStatus.OK);
return ResponseEntity.ok(MgmtTagMapper.toResponse(updateTargetTag));
}
@Override
@@ -117,15 +117,15 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
this.tagManagement.deleteTargetTag(targetTag.getName());
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
@Override
public ResponseEntity<List<MgmtTarget>> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId) {
return new ResponseEntity<>(MgmtTargetMapper.toResponse(targetManagement
return ResponseEntity.ok(MgmtTargetMapper.toResponse(targetManagement
.findTargetsByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), targetTagId)
.getContent()), HttpStatus.OK);
.getContent()));
}
@Override
@@ -151,7 +151,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
final Long countTargetsAll = findTargetsAll.getTotalElements();
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent());
return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK);
return ResponseEntity.ok(new PagedList<>(rest, countTargetsAll));
}
@Override
@@ -167,7 +167,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
final MgmtTargetTagAssigmentResult tagAssigmentResultRest = new MgmtTargetTagAssigmentResult();
tagAssigmentResultRest.setAssignedTargets(MgmtTargetMapper.toResponse(assigmentResult.getAssignedEntity()));
tagAssigmentResultRest.setUnassignedTargets(MgmtTargetMapper.toResponse(assigmentResult.getUnassignedEntity()));
return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK);
return ResponseEntity.ok(tagAssigmentResultRest);
}
@Override
@@ -176,7 +176,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
final List<Target> assignedTarget = this.targetManagement
.assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTagId);
return new ResponseEntity<>(MgmtTargetMapper.toResponse(assignedTarget), HttpStatus.OK);
return ResponseEntity.ok(MgmtTargetMapper.toResponse(assignedTarget));
}
@Override
@@ -184,7 +184,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
@PathVariable("controllerId") final String controllerId) {
LOG.debug("Unassign target {} for target tag {}", controllerId, targetTagId);
this.targetManagement.unAssignTag(controllerId, targetTagId);
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok().build();
}
private TargetTag findTargetTagById(final Long targetTagId) {

View File

@@ -838,12 +838,14 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actions.get(0).getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("id", equalTo(actions.get(0).getId().intValue())))
.andExpect(jsonPath("type", equalTo("cancel"))).andExpect(jsonPath("status", equalTo("pending")))
.andExpect(jsonPath("_links.self.href", equalTo(generateActionSelfLink(knownTargetId, actions.get(0)))))
.andExpect(jsonPath("forceType", equalTo("forced"))).andExpect(jsonPath("type", equalTo("cancel")))
.andExpect(jsonPath("status", equalTo("pending")))
.andExpect(jsonPath("_links.self.href",
equalTo(generateActionSelfLink(knownTargetId, actions.get(0).getId()))))
.andExpect(jsonPath("_links.canceledaction.href",
equalTo(generateCanceledactionreferenceLink(knownTargetId, actions.get(0)))))
.andExpect(jsonPath("_links.status.href",
equalTo(generateStatusreferenceLink(knownTargetId, actions.get(0)))));
equalTo(generateStatusreferenceLink(knownTargetId, actions.get(0).getId()))));
}
@Test
@@ -859,12 +861,12 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.andExpect(jsonPath("content.[1].type", equalTo("update")))
.andExpect(jsonPath("content.[1].status", equalTo("pending")))
.andExpect(jsonPath("content.[1]._links.self.href",
equalTo(generateActionSelfLink(knownTargetId, actions.get(1)))))
equalTo(generateActionSelfLink(knownTargetId, actions.get(1).getId()))))
.andExpect(jsonPath("content.[0].id", equalTo(actions.get(0).getId().intValue())))
.andExpect(jsonPath("content.[0].type", equalTo("cancel")))
.andExpect(jsonPath("content.[0].status", equalTo("pending")))
.andExpect(jsonPath("content.[0]._links.self.href",
equalTo(generateActionSelfLink(knownTargetId, actions.get(0)))))
equalTo(generateActionSelfLink(knownTargetId, actions.get(0).getId()))))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(2)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(2)));
@@ -1000,7 +1002,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.andExpect(jsonPath("content.[0].type", equalTo("cancel")))
.andExpect(jsonPath("content.[0].status", equalTo("pending")))
.andExpect(jsonPath("content.[0]._links.self.href",
equalTo(generateActionSelfLink(knownTargetId, actions.get(0)))))
equalTo(generateActionSelfLink(knownTargetId, actions.get(0).getId()))))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
@@ -1017,15 +1019,15 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.andExpect(jsonPath("content.[0].type", equalTo("update")))
.andExpect(jsonPath("content.[0].status", equalTo("pending")))
.andExpect(jsonPath("content.[0]._links.self.href",
equalTo(generateActionSelfLink(knownTargetId, actions.get(1)))))
equalTo(generateActionSelfLink(knownTargetId, actions.get(1).getId()))))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_TOTAL, equalTo(2)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_SIZE, equalTo(1)))
.andExpect(jsonPath(JSON_PATH_PAGED_LIST_CONTENT, hasSize(1)));
}
private String generateActionSelfLink(final String knownTargetId, final Action action) {
private String generateActionSelfLink(final String knownTargetId, final Long actionId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + action.getId();
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
}
private String generateCanceledactionreferenceLink(final String knownTargetId, final Action action) {
@@ -1033,10 +1035,10 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + action.getId();
}
private String generateStatusreferenceLink(final String knownTargetId, final Action action) {
private String generateStatusreferenceLink(final String knownTargetId, final Long actionId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + action.getId() + "/"
+ MgmtRestConstants.TARGET_V1_ACTION_STATUS + "?offset=0&limit=50&sort=id:DESC";
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId + "/" + MgmtRestConstants.TARGET_V1_ACTION_STATUS
+ "?offset=0&limit=50&sort=id:DESC";
}
private List<Action> generateTargetWithTwoUpdatesWithOneOverride(final String knownTargetId)
@@ -1074,12 +1076,41 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("id", equalTo(actions.get(1).getId().intValue())))
.andExpect(jsonPath("type", equalTo("update"))).andExpect(jsonPath("status", equalTo("pending")))
.andExpect(jsonPath("_links.self.href", equalTo(generateActionSelfLink(knownTargetId, actions.get(1)))))
.andExpect(jsonPath("forceType", equalTo("forced")))
.andExpect(jsonPath("_links.self.href",
equalTo(generateActionSelfLink(knownTargetId, actions.get(1).getId()))))
.andExpect(jsonPath("_links.distributionset.href",
equalTo("http://localhost/rest/v1/distributionsets/"
+ actions.get(1).getDistributionSet().getId())))
.andExpect(jsonPath("_links.status.href",
equalTo(generateStatusreferenceLink(knownTargetId, actions.get(1)))));
equalTo(generateStatusreferenceLink(knownTargetId, actions.get(1).getId()))));
}
@Test
@Description("Verfies that an action is switched from soft to forced if requested by management API")
public void updateAction() throws Exception {
final Target target = testdataFactory.createTarget();
final DistributionSet set = testdataFactory.createDistributionSet();
final Long actionId = deploymentManagement
.assignDistributionSet(set.getId(), ActionType.SOFT, 0, Arrays.asList(target.getControllerId()))
.getActions().get(0);
assertThat(deploymentManagement.findAction(actionId).get().getActionType()).isEqualTo(ActionType.SOFT);
final String body = new JSONObject().put("forceType", "forced").toString();
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + target.getControllerId() + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId).content(body)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("id", equalTo(actionId.intValue()))).andExpect(jsonPath("type", equalTo("update")))
.andExpect(jsonPath("status", equalTo("pending"))).andExpect(jsonPath("forceType", equalTo("forced")))
.andExpect(jsonPath("_links.self.href",
equalTo(generateActionSelfLink(target.getControllerId(), actionId))))
.andExpect(jsonPath("_links.distributionset.href",
equalTo("http://localhost/rest/v1/distributionsets/" + set.getId())))
.andExpect(jsonPath("_links.status.href",
equalTo(generateStatusreferenceLink(target.getControllerId(), actionId))));
assertThat(deploymentManagement.findAction(actionId).get().getActionType()).isEqualTo(ActionType.FORCED);
}
@Test
@@ -1179,12 +1210,14 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.andExpect(status().isNotFound());
// not allowed methods
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
// Invalid content
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
}
@Test