protected DistributionSetAssignmentResult assignDistributionSetWithMaintenanceWindowTimeForced(final long dsID, final String controllerId, final String maintenanceWindowSchedule, final String maintenanceWindowDuration, final String maintenanceWindowTimeZone) { return deploymentManagement.assignDistributionSet(dsID, Arrays.asList(new TargetWithActionType(controllerId, ActionType.TIMEFORCED, System.currentTimeMillis(), maintenanceWindowSchedule, maintenanceWindowDuration, maintenanceWindowTimeZone))); }
@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); } // both functions will throw an exception, when action is in wrong // state, which is mapped by MgmtResponseExceptionHandler. return ResponseEntity.noContent().build(); }
@Override public 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) { findTargetWithExceptionIfNotFound(targetId); final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); final Sort sorting = PagingUtility.sanitizeActionSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Slice<Action> activeActions; final Long totalActionCount; if (rsqlParam != null) { activeActions = this.deploymentManagement.findActionsByTarget(rsqlParam, targetId, pageable); totalActionCount = this.deploymentManagement.countActionsByTarget(rsqlParam, targetId); } else { activeActions = this.deploymentManagement.findActionsByTarget(targetId, pageable); totalActionCount = this.deploymentManagement.countActionsByTarget(targetId); } return ResponseEntity.ok( new PagedList<>(MgmtTargetMapper.toResponse(targetId, activeActions.getContent()), totalActionCount)); }
private void styleDistributionTableOnPinning() { managementUIState.getDistributionTableFilters().getPinnedTarget().map(TargetIdName::getControllerId) .ifPresent(controllerId -> { final Long installedDistId = deploymentManagement.getInstalledDistributionSet(controllerId) .map(DistributionSet::getId).orElse(null); final Long assignedDistId = deploymentManagement.getAssignedDistributionSet(controllerId) .map(DistributionSet::getId).orElse(null); styleDistributionSetTable(installedDistId, assignedDistId); }); }
.assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType())).getActions() .get(0); final Action cancelAction = deploymentManagement.cancelAction(actionId);
@Override public ResponseEntity<MgmtTargetAssignmentResponseBody> createAssignedTarget( @PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final List<MgmtTargetAssignmentRequestBody> assignments, @RequestParam(value = "offline", required = false) final boolean offline) { if (offline) { return ResponseEntity.ok(MgmtDistributionSetMapper .toResponse(this.deployManagament.offlineAssignedDistributionSet(distributionSetId, assignments .stream().map(MgmtTargetAssignmentRequestBody::getId).collect(Collectors.toList())))); } final DistributionSetAssignmentResult assignDistributionSet = this.deployManagament .assignDistributionSet(distributionSetId, assignments.stream().map(t -> { final MgmtMaintenanceWindowRequestBody maintenanceWindow = t.getMaintenanceWindow(); if (maintenanceWindow == null) { return new TargetWithActionType(t.getId(), MgmtRestModelMapper.convertActionType(t.getType()), t.getForcetime()); } final String cronSchedule = maintenanceWindow.getSchedule(); final String duration = maintenanceWindow.getDuration(); final String timezone = maintenanceWindow.getTimezone(); MaintenanceScheduleHelper.validateMaintenanceSchedule(cronSchedule, duration, timezone); return new TargetWithActionType(t.getId(), MgmtRestModelMapper.convertActionType(t.getType()), t.getForcetime(), cronSchedule, duration, timezone); }).collect(Collectors.toList())); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(assignDistributionSet)); }
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);
@Override protected List<ProxyAction> loadBeans(final int startIndex, final int count) { Slice<Action> actionBeans; if (startIndex == 0) { if (firstPageActions == null) { firstPageActions = getDeploymentManagement().findActionsByTarget(currentSelectedConrollerId, PageRequest.of(0, SPUIDefinitions.PAGE_SIZE, sort)); } actionBeans = firstPageActions; } else { actionBeans = getDeploymentManagement().findActionsByTarget(currentSelectedConrollerId, PageRequest.of(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort)); } return createProxyActions(actionBeans); }
@Override public ResponseEntity<MgmtAction> updateAction(@PathVariable("targetId") final String targetId, @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(targetId)) { LOG.warn(ACTION_TARGET_MISSING_ASSIGN_WARN, action.getId(), targetId); return ResponseEntity.notFound().build(); } if (!MgmtActionType.FORCED.equals(actionUpdate.getForceType())) { throw new ValidationException("Resource supports only switch to FORCED."); } action = deploymentManagement.forceTargetAction(actionId); return ResponseEntity.ok(MgmtTargetMapper.toResponseWithLinks(targetId, action)); }
@Override public 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) { final Target target = findTargetWithExceptionIfNotFound(targetId); final Action action = deploymentManagement.findAction(actionId) .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId)); if (!action.getTarget().getId().equals(target.getId())) { LOG.warn(ACTION_TARGET_MISSING_ASSIGN_WARN, action.getId(), target.getId()); return ResponseEntity.notFound().build(); } final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam); final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusByAction( new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action.getId()); return ResponseEntity.ok(new PagedList<>( MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent(), deploymentManagement), statusList.getTotalElements())); }
static List<MgmtActionStatus> toActionStatusRestResponse(final Collection<ActionStatus> actionStatus, final DeploymentManagement deploymentManagement) { if (actionStatus == null) { return Collections.emptyList(); } return actionStatus.stream().map(status -> toResponse(status, deploymentManagement.findMessagesByActionStatusId( PageRequest.of(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), status.getId()) .getContent())) .collect(Collectors.toList()); }
private boolean cancelActiveAction(final Long actionId) { if (actionId != null) { try { deploymentManagement.cancelAction(actionId); return true; } catch (final CancelActionNotAllowedException e) { LOG.info("Cancel action not allowed exception :{}", e); return false; } } return false; }
@Override protected List<ProxyActionStatus> loadBeans(final int startIndex, final int count) { Page<ActionStatus> actionBeans; if (startIndex == 0 && firstPageActionStates != null) { actionBeans = firstPageActionStates; } else { actionBeans = getDeploymentManagement().findActionStatusByAction( PageRequest.of(startIndex / SPUIDefinitions.PAGE_SIZE, SPUIDefinitions.PAGE_SIZE, sort), currentSelectedActionId); } return createProxyActionStates(actionBeans); }
@Override public int size() { long size = 0; if (currentSelectedConrollerId != null) { size = getDeploymentManagement().countActionsByTarget(currentSelectedConrollerId); } if (size > Integer.MAX_VALUE) { return Integer.MAX_VALUE; } return (int) size; }
@Override public ResponseEntity<MgmtAction> getAction(@PathVariable("targetId") final String targetId, @PathVariable("actionId") final Long actionId) { 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, action.getId(), targetId); return ResponseEntity.notFound().build(); } return ResponseEntity.ok(MgmtTargetMapper.toResponseWithLinks(targetId, action)); }
private boolean forceQuitActiveAction(final Long actionId) { if (actionId != null) { try { deploymentManagement.forceQuitAction(actionId); return true; } catch (final CancelActionNotAllowedException e) { LOG.info("Force Cancel action not allowed exception :{}", e); return false; } } return false; }
/** * Show confirmation window and if ok then only, force the action. * * @param actionId * as Id if the action needs to be forced. */ private void confirmAndForceAction(final Long actionId) { /* Display the confirmation */ final ConfirmationDialog confirmDialog = new ConfirmationDialog( i18n.getMessage("caption.force.action.confirmbox"), i18n.getMessage("message.force.action.confirm"), i18n.getMessage(UIMessageIdProvider.BUTTON_OK), i18n.getMessage(UIMessageIdProvider.BUTTON_CANCEL), ok -> { if (!ok) { return; } deploymentManagement.forceTargetAction(actionId); populateAndUpdateTargetDetails(selectedTarget); notification.displaySuccess(i18n.getMessage("message.force.action.success")); }, UIComponentIdProvider.CONFIRMATION_POPUP_ID); UI.getCurrent().addWindow(confirmDialog.getWindow()); confirmDialog.getWindow().bringToFront(); }
@Override public ResponseEntity<MgmtDistributionSet> getAssignedDistributionSet( @PathVariable("targetId") final String targetId) { final MgmtDistributionSet distributionSetRest = deploymentManagement.getAssignedDistributionSet(targetId) .map(ds -> { final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(ds); MgmtDistributionSetMapper.addLinks(ds, response); return response; }).orElse(null); if (distributionSetRest == null) { return ResponseEntity.noContent().build(); } return ResponseEntity.ok(distributionSetRest); }
.assignDistributionSet(set.getId(), Arrays.asList(target.getTargetWithActionType())).getActions() .get(0); final Action cancelAction = deploymentManagement.cancelAction(actionId);
private void styleDistributionTableOnPinning() { managementUIState.getDistributionTableFilters().getPinnedTarget().map(TargetIdName::getControllerId) .ifPresent(controllerId -> { final Long installedDistId = deploymentManagement.getInstalledDistributionSet(controllerId) .map(DistributionSet::getId).orElse(null); final Long assignedDistId = deploymentManagement.getAssignedDistributionSet(controllerId) .map(DistributionSet::getId).orElse(null); styleDistributionSetTable(installedDistId, assignedDistId); }); }