private static HandlingType calculateUpdateType(final Action action, final HandlingType downloadType) { if (action.hasMaintenanceSchedule()) { return action.isMaintenanceWindowAvailable() ? downloadType : HandlingType.SKIP; } return downloadType; }
private static DdiMaintenanceWindowStatus calculateMaintenanceWindow(final Action action) { if (action.hasMaintenanceSchedule()) { return action.isMaintenanceWindowAvailable() ? DdiMaintenanceWindowStatus.AVAILABLE : DdiMaintenanceWindowStatus.UNAVAILABLE; } return null; }
private static HandlingType calculateUpdateType(final Action action, final HandlingType downloadType) { if (action.hasMaintenanceSchedule()) { return action.isMaintenanceWindowAvailable() ? downloadType : HandlingType.SKIP; } return downloadType; }
private static DdiMaintenanceWindowStatus calculateMaintenanceWindow(final Action action) { if (action.hasMaintenanceSchedule()) { return action.isMaintenanceWindowAvailable() ? DdiMaintenanceWindowStatus.AVAILABLE : DdiMaintenanceWindowStatus.UNAVAILABLE; } return null; }
protected void sendTargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> actions) { if (CollectionUtils.isEmpty(actions)) { return; } afterCommit.afterCommit( () -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId, actions, applicationContext.getId(), actions.get(0).isMaintenanceWindowAvailable()))); }
protected void sendTargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> actions) { if (CollectionUtils.isEmpty(actions)) { return; } afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant, distributionSetId, actions, bus.getId(), actions.get(0).isMaintenanceWindowAvailable()))); }
/** * Calculates an etag for the given {@link Action} based on the entities * hashcode and the {@link Action#isHitAutoForceTime(long)} to reflect a * force switch. * * @param action * to calculate the etag for * @return the etag */ private static int calculateEtag(final Action action) { final int prime = 31; int result = action.hashCode(); int offsetPrime = action.isHitAutoForceTime(System.currentTimeMillis()) ? 1231 : 1237; offsetPrime = (action.hasMaintenanceSchedule() && action.isMaintenanceWindowAvailable()) ? 1249 : offsetPrime; result = prime * result + offsetPrime; return result; }
/** * Calculates an etag for the given {@link Action} based on the entities * hashcode and the {@link Action#isHitAutoForceTime(long)} to reflect a * force switch. * * @param action * to calculate the etag for * @return the etag */ private static int calculateEtag(final Action action) { final int prime = 31; int result = action.hashCode(); int offsetPrime = action.isHitAutoForceTime(System.currentTimeMillis()) ? 1231 : 1237; offsetPrime = action.hasMaintenanceSchedule() && action.isMaintenanceWindowAvailable() ? 1249 : offsetPrime; result = prime * result + offsetPrime; return result; }
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()); }
/** * Method to update the action status of an action through the event. * * @param actionUpdateStatus * the object form the ampq message */ private void updateActionStatus(final Message message) { final DmfActionUpdateStatus actionUpdateStatus = convertMessage(message, DmfActionUpdateStatus.class); final Action action = checkActionExist(message, actionUpdateStatus); final List<String> messages = actionUpdateStatus.getMessage(); if (isCorrelationIdNotEmpty(message)) { messages.add(RepositoryConstants.SERVER_MESSAGE_PREFIX + "DMF message correlation-id " + message.getMessageProperties().getCorrelationId()); } final Status status = mapStatus(message, actionUpdateStatus, action); final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId()).status(status) .messages(messages); final Action addUpdateActionStatus = getUpdateActionStatus(status, actionStatus); if (!addUpdateActionStatus.isActive() || (addUpdateActionStatus.hasMaintenanceSchedule() && addUpdateActionStatus.isMaintenanceWindowAvailable())) { lookIfUpdateAvailable(action.getTarget()); } }