MgmtTargetResource implements MgmtTargetRestApi { @Override public ResponseEntity<Void> cancelAction(@PathVariable("targetId") final String targetId, @PathVariable("actionId") final Long actionId, @RequestParam(value = "force", required = false, defaultValue = "false") final boolean force) { final Action action = deploymentManagement.findAction(actionId) .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); if (!action.getTarget().getControllerId().equals(targetId)) { LOG.warn(ACTION_TARGET_MISSING_ASSIGN_WARN, actionId, targetId); return ResponseEntity.notFound().build(); } if (force) { this.deploymentManagement.forceQuitAction(actionId); } else { this.deploymentManagement.cancelAction(actionId); } return ResponseEntity.noContent().build(); } MgmtTargetResource(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
            final EntityFactory entityFactory); @Override ResponseEntity<MgmtTarget> getTarget(@PathVariable("targetId") final String targetId); @Override ResponseEntity<PagedList<MgmtTarget>> getTargets(
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); @Override ResponseEntity<List<MgmtTarget>> createTargets(@RequestBody final List<MgmtTargetRequestBody> targets); @Override ResponseEntity<MgmtTarget> updateTarget(@PathVariable("targetId") final String targetId,
            @RequestBody final MgmtTargetRequestBody targetRest); @Override ResponseEntity<Void> deleteTarget(@PathVariable("targetId") final String targetId); @Override ResponseEntity<MgmtTargetAttributes> getAttributes(@PathVariable("targetId") final String targetId); @Override ResponseEntity<PagedList<MgmtAction>> getActionHistory(@PathVariable("targetId") final String targetId,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); @Override ResponseEntity<MgmtAction> getAction(@PathVariable("targetId") final String targetId,
            @PathVariable("actionId") final Long actionId); @Override ResponseEntity<Void> cancelAction(@PathVariable("targetId") final String targetId,
            @PathVariable("actionId") final Long actionId,
            @RequestParam(value = "force", required = false, defaultValue = "false") final boolean force); @Override ResponseEntity<PagedList<MgmtActionStatus>> getActionStatusList(
            @PathVariable("targetId") final String targetId, @PathVariable("actionId") final Long actionId,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam); @Override ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet(
            @PathVariable("targetId") final String targetId); @Override ResponseEntity<MgmtTargetAssignmentResponseBody> postAssignedDistributionSet(
            @PathVariable("targetId") final String targetId,
            @Valid @RequestBody final MgmtDistributionSetAssignments dsAssignments,
            @RequestParam(value = "offline", required = false) final boolean offline); @Override ResponseEntity<MgmtDistributionSet> getInstalledDistributionSet(
            @PathVariable("targetId") final String targetId); @Override ResponseEntity<MgmtAction> updateAction(@PathVariable("targetId") final String targetId,
            @PathVariable("actionId") final Long actionId, @RequestBody final MgmtActionRequestBodyPut actionUpdate); @Override ResponseEntity<PagedList<MgmtMetadata>> getMetadata(@PathVariable("targetId") final String targetId,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
            @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); @Override ResponseEntity<MgmtMetadata> getMetadataValue(@PathVariable("targetId") final String targetId,
            @PathVariable("metadataKey") final String metadataKey); @Override ResponseEntity<MgmtMetadata> updateMetadata(@PathVariable("targetId") final String targetId,
            @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadataBodyPut metadata); @Override ResponseEntity<Void> deleteMetadata(@PathVariable("targetId") final String targetId,
            @PathVariable("metadataKey") final String metadataKey); @Override ResponseEntity<List<MgmtMetadata>> createMetadata(@PathVariable("targetId") final String targetId,
            @RequestBody final List<MgmtMetadata> metadataRest);  }
@Test @Description("Ensures that method not allowed is returned if cancelation is triggered on already canceled action.") public void cancelAndCancelActionIsNotAllowed() throws Exception { final Target tA = createTargetAndStartAction(); deploymentManagement.cancelAction( deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE).getContent().get(0).getId()); final List<Action> cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE) .getContent().stream().filter(Action::isCancelingOrCanceled).collect(Collectors.toList()); assertThat(cancelActions).hasSize(1); mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}", tA.getControllerId(), cancelActions.get(0).getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isMethodNotAllowed()); }
@Test @Description("Force Quit an Action, which is already canceled. Expected Result is an HTTP response code 204.") public void forceQuitAnCanceledActionReturnsOk() throws Exception { final Target tA = createTargetAndStartAction(); deploymentManagement.cancelAction( deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE).getContent().get(0).getId()); final List<Action> cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE) .getContent().stream().filter(Action::isCancelingOrCanceled).collect(Collectors.toList()); assertThat(cancelActions).hasSize(1); assertThat(cancelActions.get(0).isCancelingOrCanceled()).isTrue(); mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true", tA.getControllerId(), cancelActions.get(0).getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isNoContent()); }