public TargetAssignDistributionSetEvent(final Action action, final String applicationId) { this(action.getTenant(), action.getDistributionSet().getId(), Arrays.asList(action), applicationId, action.isMaintenanceWindowAvailable()); }
private long startScheduledActionsByRolloutGroupParentInNewTransaction(final Long rolloutId, final Long distributionSetId, final Long rolloutGroupParentId, final int limit) { return DeploymentHelper.runInNewTransaction(txManager, "startScheduledActions-" + rolloutId, status -> { final Page<Action> rolloutGroupActions = findActionsByRolloutAndRolloutGroupParent(rolloutId, rolloutGroupParentId, limit); if (rolloutGroupActions.getContent().isEmpty()) { return 0L; } final String tenant = rolloutGroupActions.getContent().get(0).getTenant(); final boolean maintenanceWindowAvailable = rolloutGroupActions.getContent().get(0) .isMaintenanceWindowAvailable(); final List<Action> targetAssignments = rolloutGroupActions.getContent().stream() .map(action -> (JpaAction) action).map(this::closeActionIfSetWasAlreadyAssigned) .filter(Objects::nonNull).map(this::startScheduledActionIfNoCancelationHasToBeHandledFirst) .filter(Objects::nonNull).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(targetAssignments)) { afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId, targetAssignments, bus.getId(), maintenanceWindowAvailable))); } return rolloutGroupActions.getTotalElements(); }); }
private long startScheduledActionsByRolloutGroupParentInNewTransaction(final Long rolloutId, final Long distributionSetId, final Long rolloutGroupParentId, final int limit) { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("startScheduledActions-" + rolloutId); def.setReadOnly(false); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); return new TransactionTemplate(txManager, def).execute(status -> { final Page<Action> rolloutGroupActions = findActionsByRolloutAndRolloutGroupParent(rolloutId, rolloutGroupParentId, limit); if (rolloutGroupActions.getContent().isEmpty()) { return 0L; } final String tenant = rolloutGroupActions.getContent().get(0).getTenant(); final boolean maintenanceWindowAvailable = rolloutGroupActions.getContent().get(0) .isMaintenanceWindowAvailable(); final List<Action> targetAssignments = rolloutGroupActions.getContent().stream() .map(action -> (JpaAction) action).map(this::closeActionIfSetWasAlreadyAssigned) .filter(Objects::nonNull).map(this::startScheduledActionIfNoCancelationHasToBeHandledFirst) .filter(Objects::nonNull).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(targetAssignments)) { afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId, targetAssignments, applicationContext.getId(), maintenanceWindowAvailable))); } return rolloutGroupActions.getTotalElements(); }); }
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()); }