/** * Constructor. * * @param tenant * of the event * @param distributionSetId * of the set that was assigned * @param a * the actions and the targets * @param applicationId * the application id. * @param maintenanceWindowAvailable * see {@link Action#isMaintenanceWindowAvailable()} */ public TargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> a, final String applicationId, final boolean maintenanceWindowAvailable) { super(distributionSetId, tenant, applicationId); this.distributionSetId = distributionSetId; this.maintenanceWindowAvailable = maintenanceWindowAvailable; actions.putAll(a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId) .collect(Collectors.toMap(action -> action.getTarget().getControllerId(), Action::getId))); }
public TargetAssignDistributionSetEvent(final Action action, final String applicationId) { this(action.getTenant(), action.getDistributionSet().getId(), Arrays.asList(action), applicationId, action.isMaintenanceWindowAvailable()); }
static List<DdiChunk> createChunks(final Target target, final Action uAction, final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement, final HttpRequest request, final ControllerManagement controllerManagement) { final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement .findTargetVisibleMetaDataBySoftwareModuleId(uAction.getDistributionSet().getModules().stream() .map(SoftwareModule::getId).collect(Collectors.toList())); return uAction.getDistributionSet().getModules().stream() .map(module -> new DdiChunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(), module.getName(), createArtifacts(target, module, artifactUrlHandler, systemManagement, request), mapMetadata(metadata.get(module.getId())))) .collect(Collectors.toList()); }
static List<DdiChunk> createChunks(final Target target, final Action uAction, final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement, final HttpRequest request, final ControllerManagement controllerManagement) { final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement .findTargetVisibleMetaDataBySoftwareModuleId(uAction.getDistributionSet().getModules().stream() .map(SoftwareModule::getId).collect(Collectors.toList())); return new ResponseList<>(uAction.getDistributionSet().getModules().stream() .map(module -> new DdiChunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(), module.getName(), createArtifacts(target, module, artifactUrlHandler, systemManagement, request), mapMetadata(metadata.get(module.getId())))) .collect(Collectors.toList())); }
private void lookIfUpdateAvailable(final Target target) { final Optional<Action> actionOptional = controllerManagement .findOldestActiveActionByTarget(target.getControllerId()); if (!actionOptional.isPresent()) { return; } final Action action = actionOptional.get(); if (action.isCancelingOrCanceled()) { amqpMessageDispatcherService.sendCancelMessageToTarget(target.getTenant(), target.getControllerId(), action.getId(), target.getAddress()); return; } final Map<SoftwareModule, List<SoftwareModuleMetadata>> modules = Maps .newHashMapWithExpectedSize(action.getDistributionSet().getModules().size()); final Map<Long, List<SoftwareModuleMetadata>> metadata = controllerManagement .findTargetVisibleMetaDataBySoftwareModuleId(action.getDistributionSet().getModules().stream() .map(SoftwareModule::getId).collect(Collectors.toList())); action.getDistributionSet().getModules().forEach(module -> modules.put(module, metadata.get(module.getId()))); amqpMessageDispatcherService.sendUpdateMessageToTarget(action.getTenant(), action.getTarget(), action.getId(), modules, action.isMaintenanceWindowAvailable()); }
/** * This method is called, when cancellation has been successful. It sets the * action to canceled, resets the meta data of the target and in case there * is a new action this action is triggered. * * @param action * the action which is set to canceled * @param actionRepository * for the operation * @param targetRepository * for the operation */ public static void successCancellation(final JpaAction action, final ActionRepository actionRepository, final TargetRepository targetRepository) { // set action inactive action.setActive(false); action.setStatus(Status.CANCELED); final JpaTarget target = (JpaTarget) action.getTarget(); final List<Action> nextActiveActions = actionRepository.findByTargetAndActiveOrderByIdAsc(target, true).stream() .filter(a -> !a.getId().equals(action.getId())).collect(Collectors.toList()); if (nextActiveActions.isEmpty()) { target.setAssignedDistributionSet(target.getInstalledDistributionSet()); target.setUpdateStatus(TargetUpdateStatus.IN_SYNC); } else { target.setAssignedDistributionSet(nextActiveActions.get(0).getDistributionSet()); } targetRepository.save(target); }
/** * This method is called, when cancellation has been successful. It sets the * action to canceled, resets the meta data of the target and in case there * is a new action this action is triggered. * * @param action * the action which is set to canceled * @param actionRepository * for the operation * @param targetRepository * for the operation * @param targetInfoRepository * for the operation */ static void successCancellation(final JpaAction action, final ActionRepository actionRepository, final TargetRepository targetRepository) { // set action inactive action.setActive(false); action.setStatus(Status.CANCELED); final JpaTarget target = (JpaTarget) action.getTarget(); final List<Action> nextActiveActions = actionRepository.findByTargetAndActiveOrderByIdAsc(target, true).stream() .filter(a -> !a.getId().equals(action.getId())).collect(Collectors.toList()); if (nextActiveActions.isEmpty()) { target.setAssignedDistributionSet(target.getInstalledDistributionSet()); updateTargetInfo(target, TargetUpdateStatus.IN_SYNC, false); } else { target.setAssignedDistributionSet(nextActiveActions.get(0).getDistributionSet()); } targetRepository.save(target); }
/** * Creates a list of {@link ProxyAction}s for presentation layer from slice * of {@link Action}s. * * @param actionBeans * slice of {@link Action}s * @return list of {@link ProxyAction}s */ private static List<ProxyAction> createProxyActions(final Slice<Action> actionBeans) { final List<ProxyAction> proxyActions = new ArrayList<>(); for (final Action action : actionBeans) { final ProxyAction proxyAction = new ProxyAction(); final String dsNameVersion = action.getDistributionSet().getName() + ":" + action.getDistributionSet().getVersion(); proxyAction.setActive(action.isActive()); proxyAction.setIsActiveDecoration(buildIsActiveDecoration(action)); proxyAction.setDsNameVersion(dsNameVersion); proxyAction.setAction(action); proxyAction.setId(action.getId()); proxyAction.setLastModifiedAt(action.getLastModifiedAt()); proxyAction.setRolloutName(action.getRollout() != null ? action.getRollout().getName() : ""); proxyAction.setStatus(action.getStatus()); proxyAction.setMaintenanceWindow( action.hasMaintenanceSchedule() ? buildMaintenanceWindowDisplayText(action) : ""); proxyActions.add(proxyAction); } return proxyActions; }
/** * Creates a list of {@link ProxyAction}s for presentation layer from slice * of {@link Action}s. * * @param actionBeans * slice of {@link Action}s * @return list of {@link ProxyAction}s */ private static List<ProxyAction> createProxyActions(final Slice<Action> actionBeans) { final List<ProxyAction> proxyActions = new ArrayList<>(); for (final Action action : actionBeans) { final ProxyAction proxyAction = new ProxyAction(); final String dsNameVersion = action.getDistributionSet().getName() + ":" + action.getDistributionSet().getVersion(); proxyAction.setActive(action.isActive()); proxyAction.setIsActiveDecoration(buildIsActiveDecoration(action)); proxyAction.setDsNameVersion(dsNameVersion); proxyAction.setAction(action); proxyAction.setId(action.getId()); proxyAction.setLastModifiedAt(action.getLastModifiedAt()); proxyAction.setRolloutName(action.getRollout() != null ? action.getRollout().getName() : ""); proxyAction.setStatus(action.getStatus()); proxyAction.setMaintenanceWindow( action.hasMaintenanceSchedule() ? buildMaintenanceWindowDisplayText(action) : ""); proxyActions.add(proxyAction); } return proxyActions; }
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)); } 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; }