Sonar Fixes (7) (#2215)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -198,11 +198,12 @@ public class RolloutStatusCache {
|
|||||||
cacheManager.evictCaches(tenant);
|
cacheManager.evictCaches(tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Long, List<TotalTargetCountActionStatus>> retrieveFromCache(final List<Long> ids,
|
private @NotNull Map<Long, List<TotalTargetCountActionStatus>> retrieveFromCache(final List<Long> ids,
|
||||||
@NotNull final Cache cache) {
|
@NotNull final Cache cache) {
|
||||||
return ids.stream().map(id -> cache.get(id, CachedTotalTargetCountActionStatus.class)).filter(Objects::nonNull)
|
return ids.stream()
|
||||||
.collect(Collectors.toMap(CachedTotalTargetCountActionStatus::getId,
|
.map(id -> cache.get(id, CachedTotalTargetCountActionStatus.class))
|
||||||
CachedTotalTargetCountActionStatus::getStatus));
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toMap(CachedTotalTargetCountActionStatus::getId, CachedTotalTargetCountActionStatus::getStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TotalTargetCountActionStatus> retrieveFromCache(final Long id, @NotNull final Cache cache) {
|
private List<TotalTargetCountActionStatus> retrieveFromCache(final Long id, @NotNull final Cache cache) {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
|||||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
|
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
|
||||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,12 +67,12 @@ public class JpaEntityFactory implements EntityFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetaData generateDsMetadata(final String key, final String value) {
|
public MetaData generateDsMetadata(final String key, final String value) {
|
||||||
return new JpaDistributionSetMetadata(key, StringUtils.trimWhitespace(value));
|
return new JpaDistributionSetMetadata(key, value == null ? null : value.strip());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetaData generateTargetMetadata(final String key, final String value) {
|
public MetaData generateTargetMetadata(final String key, final String value) {
|
||||||
return new JpaTargetMetadata(key, StringUtils.trimWhitespace(value));
|
return new JpaTargetMetadata(key, value == null ? null : value.strip());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public final class JpaManagementHelper {
|
|||||||
: (filterString + "%");
|
: (filterString + "%");
|
||||||
final String filterVersion = semicolonIndex != -1 ? (filterString.substring(semicolonIndex + 1) + "%") : "%";
|
final String filterVersion = semicolonIndex != -1 ? (filterString.substring(semicolonIndex + 1) + "%") : "%";
|
||||||
|
|
||||||
return new String[] { !StringUtils.isEmpty(filterName) ? filterName : "%", filterVersion };
|
return new String[] { ObjectUtils.isEmpty(filterName) ? "%" : filterName, filterVersion };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,9 +317,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
rollout.setStatus(RolloutStatus.FINISHED);
|
rollout.setStatus(RolloutStatus.FINISHED);
|
||||||
rolloutRepository.save(rollout);
|
rolloutRepository.save(rollout);
|
||||||
|
|
||||||
final List<Long> groupIds = rollout.getRolloutGroups().stream().map(RolloutGroup::getId)
|
final List<Long> groupIds = rollout.getRolloutGroups().stream().map(RolloutGroup::getId).toList();
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(new RolloutStoppedEvent(
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(new RolloutStoppedEvent(
|
||||||
tenantAware.getCurrentTenant(), eventPublisherHolder.getApplicationId(), rollout.getId(), groupIds)));
|
tenantAware.getCurrentTenant(), eventPublisherHolder.getApplicationId(), rollout.getId(), groupIds)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
|||||||
private void handleRolloutInNewTransaction(final long rolloutId, final String handlerId) {
|
private void handleRolloutInNewTransaction(final long rolloutId, final String handlerId) {
|
||||||
DeploymentHelper.runInNewTransaction(txManager, handlerId + "-" + rolloutId, status -> {
|
DeploymentHelper.runInNewTransaction(txManager, handlerId + "-" + rolloutId, status -> {
|
||||||
rolloutManagement.get(rolloutId).ifPresentOrElse(
|
rolloutManagement.get(rolloutId).ifPresentOrElse(
|
||||||
rollout -> {
|
rollout ->
|
||||||
// auditor is retrieved and set on transaction commit
|
// auditor is retrieved and set on transaction commit
|
||||||
// if not overridden, the system user will be the auditor
|
// if not overridden, the system user will be the auditor
|
||||||
rollout.getAccessControlContext().ifPresentOrElse(
|
rollout.getAccessControlContext().ifPresentOrElse(
|
||||||
@@ -113,9 +113,7 @@ public class JpaRolloutHandler implements RolloutHandler {
|
|||||||
rollout.getCreatedBy(), () -> {
|
rollout.getCreatedBy(), () -> {
|
||||||
rolloutExecutor.execute(rollout);
|
rolloutExecutor.execute(rollout);
|
||||||
return null;
|
return null;
|
||||||
})
|
})),
|
||||||
);
|
|
||||||
},
|
|
||||||
() -> log.error("Could not retrieve rollout with id {}. Will not continue with execution.",
|
() -> log.error("Could not retrieve rollout with id {}. Will not continue with execution.",
|
||||||
rolloutId));
|
rolloutId));
|
||||||
return 0L;
|
return 0L;
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
|||||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create/build implementation.
|
* Create/build implementation.
|
||||||
@@ -47,7 +45,7 @@ public class JpaDistributionSetCreate extends AbstractDistributionSetUpdateCreat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DistributionSetCreate type(final String type) {
|
public DistributionSetCreate type(final String type) {
|
||||||
this.type = ObjectUtils.isEmpty(type) ? type : type.strip();
|
this.type = type == null ? null : type.strip();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class JpaRolloutCreate extends AbstractNamedEntityBuilder<RolloutCreate>
|
|||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public RolloutCreate targetFilterQuery(final String targetFilterQuery) {
|
public RolloutCreate targetFilterQuery(final String targetFilterQuery) {
|
||||||
this.targetFilterQuery = StringUtils.trimWhitespace(targetFilterQuery);
|
this.targetFilterQuery = targetFilterQuery == null ? null : targetFilterQuery.strip();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -332,7 +332,8 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
|||||||
}
|
}
|
||||||
private Target findOrRegisterTargetIfItDoesNotExist0(final String controllerId, final URI address, final String name, final String type) {
|
private Target findOrRegisterTargetIfItDoesNotExist0(final String controllerId, final URI address, final String name, final String type) {
|
||||||
final Specification<JpaTarget> spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTarget_.controllerId), controllerId);
|
final Specification<JpaTarget> spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(JpaTarget_.controllerId), controllerId);
|
||||||
return targetRepository.findOne(spec).map(target -> updateTarget(target, address, name, type))
|
return targetRepository.findOne(spec)
|
||||||
|
.map(target -> updateTarget(target, address, name, type))
|
||||||
.orElseGet(() -> createTarget(controllerId, address, name, type));
|
.orElseGet(() -> createTarget(controllerId, address, name, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,13 +195,18 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||||
public List<DistributionSetAssignmentResult> assignDistributionSets(final List<DeploymentRequest> deploymentRequests) {
|
public List<DistributionSetAssignmentResult> assignDistributionSets(final List<DeploymentRequest> deploymentRequests) {
|
||||||
return assignDistributionSets(tenantAware.getCurrentUsername(), deploymentRequests, null);
|
return assignDistributionSets0(tenantAware.getCurrentUsername(), deploymentRequests, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||||
public List<DistributionSetAssignmentResult> assignDistributionSets(
|
public List<DistributionSetAssignmentResult> assignDistributionSets(
|
||||||
final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||||
|
return assignDistributionSets0(initiatedBy, deploymentRequests, actionMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DistributionSetAssignmentResult> assignDistributionSets0(
|
||||||
|
final String initiatedBy, final List<DeploymentRequest> deploymentRequests, final String actionMessage) {
|
||||||
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).validate(deploymentRequests);
|
WeightValidationHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).validate(deploymentRequests);
|
||||||
return assignDistributionSets(initiatedBy, deploymentRequests, actionMessage, onlineDsAssignmentStrategy);
|
return assignDistributionSets(initiatedBy, deploymentRequests, actionMessage, onlineDsAssignmentStrategy);
|
||||||
}
|
}
|
||||||
@@ -232,6 +237,10 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public Action cancelAction(final long actionId) {
|
public Action cancelAction(final long actionId) {
|
||||||
|
return cancelAction0(actionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Action cancelAction0(final long actionId) {
|
||||||
log.debug("cancelAction({})", actionId);
|
log.debug("cancelAction({})", actionId);
|
||||||
|
|
||||||
final JpaAction action = actionRepository.findById(actionId)
|
final JpaAction action = actionRepository.findById(actionId)
|
||||||
@@ -393,6 +402,10 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public Action forceQuitAction(final long actionId) {
|
public Action forceQuitAction(final long actionId) {
|
||||||
|
return forceQuitAction0(actionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Action forceQuitAction0(final long actionId) {
|
||||||
final JpaAction action = actionRepository.findById(actionId)
|
final JpaAction action = actionRepository.findById(actionId)
|
||||||
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
|
||||||
|
|
||||||
@@ -495,12 +508,14 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<DistributionSet> getAssignedDistributionSet(final String controllerId) {
|
public Optional<DistributionSet> getAssignedDistributionSet(final String controllerId) {
|
||||||
return targetRepository.findWithDetailsByControllerId(controllerId, JpaTarget_.GRAPH_TARGET_ASSIGNED_DISTRIBUTION_SET).map(JpaTarget::getAssignedDistributionSet);
|
return targetRepository.findWithDetailsByControllerId(controllerId, JpaTarget_.GRAPH_TARGET_ASSIGNED_DISTRIBUTION_SET)
|
||||||
|
.map(JpaTarget::getAssignedDistributionSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<DistributionSet> getInstalledDistributionSet(final String controllerId) {
|
public Optional<DistributionSet> getInstalledDistributionSet(final String controllerId) {
|
||||||
return targetRepository.findWithDetailsByControllerId(controllerId, JpaTarget_.GRAPH_TARGET_INSTALLED_DISTRIBUTION_SET).map(JpaTarget::getInstalledDistributionSet);
|
return targetRepository.findWithDetailsByControllerId(controllerId, JpaTarget_.GRAPH_TARGET_INSTALLED_DISTRIBUTION_SET)
|
||||||
|
.map(JpaTarget::getInstalledDistributionSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -542,7 +557,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
.forEach(action -> {
|
.forEach(action -> {
|
||||||
try {
|
try {
|
||||||
assertTargetUpdateAllowed(action);
|
assertTargetUpdateAllowed(action);
|
||||||
cancelAction(action.getId());
|
cancelAction0(action.getId());
|
||||||
log.debug("Action {} canceled", action.getId());
|
log.debug("Action {} canceled", action.getId());
|
||||||
} catch (final InsufficientPermissionException e) {
|
} catch (final InsufficientPermissionException e) {
|
||||||
log.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e);
|
log.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e);
|
||||||
@@ -555,7 +570,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
.forEach(action -> {
|
.forEach(action -> {
|
||||||
try {
|
try {
|
||||||
assertTargetUpdateAllowed(action);
|
assertTargetUpdateAllowed(action);
|
||||||
forceQuitAction(action.getId());
|
forceQuitAction0(action.getId());
|
||||||
log.debug("Action {} force canceled (force)", action.getId());
|
log.debug("Action {} force canceled (force)", action.getId());
|
||||||
} catch (final InsufficientPermissionException e) {
|
} catch (final InsufficientPermissionException e) {
|
||||||
log.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e);
|
log.trace("Could not cancel action {} due to insufficient permissions.", action.getId(), e);
|
||||||
@@ -588,7 +603,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
* statements
|
* statements
|
||||||
*/
|
*/
|
||||||
private static List<List<Long>> getTargetEntitiesAsChunks(final List<JpaTarget> targetEntities) {
|
private static List<List<Long>> getTargetEntitiesAsChunks(final List<JpaTarget> targetEntities) {
|
||||||
return ListUtils.partition(targetEntities.stream().map(Target::getId).collect(Collectors.toList()), Constants.MAX_ENTRIES_IN_STATEMENT);
|
return ListUtils.partition(targetEntities.stream().map(Target::getId).toList(), Constants.MAX_ENTRIES_IN_STATEMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DistributionSetAssignmentResult buildAssignmentResult(
|
private static DistributionSetAssignmentResult buildAssignmentResult(
|
||||||
@@ -855,8 +870,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
quota, Action.class, Target.class, actionRepository::countByTargetControllerId));
|
quota, Action.class, Target.class, actionRepository::countByTargetControllerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeOrCancelActiveActions(final AbstractDsAssignmentStrategy assignmentStrategy,
|
private void closeOrCancelActiveActions(final AbstractDsAssignmentStrategy assignmentStrategy, final List<List<Long>> targetIdsChunks) {
|
||||||
final List<List<Long>> targetIdsChunks) {
|
|
||||||
if (isActionsAutocloseEnabled()) {
|
if (isActionsAutocloseEnabled()) {
|
||||||
assignmentStrategy.closeActiveActions(targetIdsChunks);
|
assignmentStrategy.closeActiveActions(targetIdsChunks);
|
||||||
} else {
|
} else {
|
||||||
@@ -864,7 +878,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAssignedDistributionSetAndTargetUpdateStatus(final AbstractDsAssignmentStrategy assignmentStrategy,
|
private void setAssignedDistributionSetAndTargetUpdateStatus(
|
||||||
|
final AbstractDsAssignmentStrategy assignmentStrategy,
|
||||||
final JpaDistributionSet set, final List<List<Long>> targetIdsChunks) {
|
final JpaDistributionSet set, final List<List<Long>> targetIdsChunks) {
|
||||||
final String currentUser = auditorProvider.getCurrentAuditor().orElse(null);
|
final String currentUser = auditorProvider.getCurrentAuditor().orElse(null);
|
||||||
assignmentStrategy.setAssignedDistributionSetAndTargetStatus(set, targetIdsChunks, currentUser);
|
assignmentStrategy.setAssignedDistributionSetAndTargetStatus(set, targetIdsChunks, currentUser);
|
||||||
@@ -970,8 +985,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeOrCancelOpenDeviceActions(final List<JpaAction> actions) {
|
private void closeOrCancelOpenDeviceActions(final List<JpaAction> actions) {
|
||||||
final List<Long> targetIds = actions.stream().map(JpaAction::getTarget).map(Target::getId)
|
final List<Long> targetIds = actions.stream().map(JpaAction::getTarget).map(Target::getId).toList();
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (isActionsAutocloseEnabled()) {
|
if (isActionsAutocloseEnabled()) {
|
||||||
onlineDsAssignmentStrategy.closeObsoleteUpdateActions(targetIds);
|
onlineDsAssignmentStrategy.closeObsoleteUpdateActions(targetIds);
|
||||||
} else {
|
} else {
|
||||||
@@ -999,7 +1013,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
mergedTarget.setAssignedDistributionSet((JpaDistributionSet) savedAction.getDistributionSet());
|
mergedTarget.setAssignedDistributionSet((JpaDistributionSet) savedAction.getDistributionSet());
|
||||||
mergedTarget.setUpdateStatus(TargetUpdateStatus.PENDING);
|
mergedTarget.setUpdateStatus(TargetUpdateStatus.PENDING);
|
||||||
return mergedTarget;
|
return mergedTarget;
|
||||||
}).collect(Collectors.toList());
|
}).toList();
|
||||||
|
|
||||||
targetRepository.saveAll(assignedDsTargets);
|
targetRepository.saveAll(assignedDsTargets);
|
||||||
}
|
}
|
||||||
@@ -1041,12 +1055,12 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JpaAction assertTargetUpdateAllowed(final JpaAction action) {
|
private JpaAction assertTargetUpdateAllowed(final JpaAction action) {
|
||||||
targetRepository.findOne(TargetSpecifications.hasId(action.getTarget().getId())).ifPresentOrElse(target -> {
|
targetRepository.findOne(TargetSpecifications.hasId(action.getTarget().getId())).ifPresentOrElse(
|
||||||
targetRepository.getAccessController()
|
target -> targetRepository.getAccessController()
|
||||||
.ifPresent(acm -> acm.assertOperationAllowed(AccessController.Operation.UPDATE, target));
|
.ifPresent(acm -> acm.assertOperationAllowed(AccessController.Operation.UPDATE, target)),
|
||||||
}, () -> {
|
() -> {
|
||||||
throw new EntityNotFoundException(Action.class, action);
|
throw new EntityNotFoundException(Action.class, action);
|
||||||
});
|
});
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public void delete(final long id) {
|
public void delete(final long id) {
|
||||||
delete(List.of(id));
|
delete0(List.of(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -218,6 +218,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public void delete(final Collection<Long> distributionSetIDs) {
|
public void delete(final Collection<Long> distributionSetIDs) {
|
||||||
|
delete0(distributionSetIDs);
|
||||||
|
}
|
||||||
|
private void delete0(final Collection<Long> distributionSetIDs) {
|
||||||
getDistributionSets(distributionSetIDs); // throws EntityNotFoundException if any of these do not exists
|
getDistributionSets(distributionSetIDs); // throws EntityNotFoundException if any of these do not exists
|
||||||
final List<JpaDistributionSet> setsFound = distributionSetRepository.findAll(
|
final List<JpaDistributionSet> setsFound = distributionSetRepository.findAll(
|
||||||
AccessController.Operation.DELETE, distributionSetRepository.byIdsSpec(distributionSetIDs));
|
AccessController.Operation.DELETE, distributionSetRepository.byIdsSpec(distributionSetIDs));
|
||||||
@@ -418,8 +421,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
|||||||
|
|
||||||
// touch it to update the lock revision because we are modifying the
|
// touch it to update the lock revision because we are modifying the
|
||||||
// DS indirectly, it will, also check UPDATE access
|
// DS indirectly, it will, also check UPDATE access
|
||||||
JpaManagementHelper.touch(entityManager, distributionSetRepository,
|
JpaManagementHelper.touch(entityManager, distributionSetRepository, metadata.getDistributionSet());
|
||||||
(JpaDistributionSet) metadata.getDistributionSet());
|
|
||||||
distributionSetMetadataRepository.deleteById(metadata.getId());
|
distributionSetMetadataRepository.deleteById(metadata.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,8 +124,9 @@ public class JpaDistributionSetTagManagement implements DistributionSetTagManage
|
|||||||
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAllById(ids);
|
final List<JpaDistributionSetTag> setsFound = distributionSetTagRepository.findAllById(ids);
|
||||||
|
|
||||||
if (setsFound.size() < ids.size()) {
|
if (setsFound.size() < ids.size()) {
|
||||||
throw new EntityNotFoundException(DistributionSetTag.class, ids,
|
throw new EntityNotFoundException(
|
||||||
setsFound.stream().map(DistributionSetTag::getId).collect(Collectors.toList()));
|
DistributionSetTag.class, ids,
|
||||||
|
setsFound.stream().map(DistributionSetTag::getId).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
distributionSetTagRepository.deleteAll(setsFound);
|
distributionSetTagRepository.deleteAll(setsFound);
|
||||||
|
|||||||
@@ -184,6 +184,11 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
public Rollout create(
|
public Rollout create(
|
||||||
final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
|
final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
|
||||||
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
|
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
|
||||||
|
return create0(rollout, amountGroup, confirmationRequired, conditions, dynamicRolloutGroupTemplate);
|
||||||
|
}
|
||||||
|
private Rollout create0(
|
||||||
|
final RolloutCreate rollout, final int amountGroup, final boolean confirmationRequired,
|
||||||
|
final RolloutGroupConditions conditions, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
|
||||||
if (amountGroup < 0) {
|
if (amountGroup < 0) {
|
||||||
throw new ValidationException("The amount of groups cannot be lower than or equal to zero for static rollouts");
|
throw new ValidationException("The amount of groups cannot be lower than or equal to zero for static rollouts");
|
||||||
} else if (amountGroup == 0) {
|
} else if (amountGroup == 0) {
|
||||||
@@ -208,17 +213,17 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public Rollout create(@NotNull @Valid RolloutCreate create, int amountGroup, boolean confirmationRequired,
|
public Rollout create(
|
||||||
|
@NotNull @Valid RolloutCreate create, int amountGroup, boolean confirmationRequired,
|
||||||
@NotNull RolloutGroupConditions conditions) {
|
@NotNull RolloutGroupConditions conditions) {
|
||||||
return create(create, amountGroup, confirmationRequired, conditions, null);
|
return create0(create, amountGroup, confirmationRequired, conditions, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups,
|
public Rollout create(final RolloutCreate rollout, final List<RolloutGroupCreate> groups, final RolloutGroupConditions conditions) {
|
||||||
final RolloutGroupConditions conditions) {
|
|
||||||
if (groups.isEmpty()) {
|
if (groups.isEmpty()) {
|
||||||
throw new ValidationException("The amount of groups cannot be 0");
|
throw new ValidationException("The amount of groups cannot be 0");
|
||||||
}
|
}
|
||||||
@@ -353,7 +358,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision) {
|
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision) {
|
||||||
return this.approveOrDeny(rolloutId, decision, null);
|
return approveOrDeny0(rolloutId, decision, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -361,6 +366,9 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||||
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) {
|
public Rollout approveOrDeny(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) {
|
||||||
|
return approveOrDeny0(rolloutId, decision, remark);
|
||||||
|
}
|
||||||
|
private Rollout approveOrDeny0(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) {
|
||||||
log.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision);
|
log.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision);
|
||||||
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
|
final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
|
||||||
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL);
|
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL);
|
||||||
@@ -474,10 +482,10 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRolloutStatusDetails(final Slice<Rollout> rollouts) {
|
public void setRolloutStatusDetails(final Slice<Rollout> rollouts) {
|
||||||
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).collect(Collectors.toList());
|
final List<Long> rolloutIds = rollouts.getContent().stream().map(Rollout::getId).toList();
|
||||||
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(rolloutIds);
|
final Map<Long, List<TotalTargetCountActionStatus>> allStatesForRollout = getStatusCountItemForRollout(rolloutIds);
|
||||||
|
|
||||||
if (allStatesForRollout != null) {
|
if (!allStatesForRollout.isEmpty()) {
|
||||||
rollouts.forEach(rollout -> {
|
rollouts.forEach(rollout -> {
|
||||||
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(
|
final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(
|
||||||
allStatesForRollout.get(rollout.getId()), rollout.getTotalTargets(), rollout.getActionType());
|
allStatesForRollout.get(rollout.getId()), rollout.getTotalTargets(), rollout.getActionType());
|
||||||
@@ -703,9 +711,9 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Long, List<TotalTargetCountActionStatus>> getStatusCountItemForRollout(final List<Long> rollouts) {
|
private @NotNull Map<Long, List<TotalTargetCountActionStatus>> getStatusCountItemForRollout(final List<Long> rollouts) {
|
||||||
if (rollouts.isEmpty()) {
|
if (rollouts.isEmpty()) {
|
||||||
return null;
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<Long, List<TotalTargetCountActionStatus>> fromCache = rolloutStatusCache.getRolloutStatus(rollouts);
|
final Map<Long, List<TotalTargetCountActionStatus>> fromCache = rolloutStatusCache.getRolloutStatus(rollouts);
|
||||||
|
|||||||
@@ -124,8 +124,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAssignedDistributionSetAndTargetStatus(final JpaDistributionSet set, final List<List<Long>> targetIds,
|
public void setAssignedDistributionSetAndTargetStatus(final JpaDistributionSet set, final List<List<Long>> targetIds, final String currentUser) {
|
||||||
final String currentUser) {
|
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
targetIds.forEach(targetIdsChunk -> {
|
targetIds.forEach(targetIdsChunk -> {
|
||||||
if (targetRepository.count(AccessController.Operation.UPDATE,
|
if (targetRepository.count(AccessController.Operation.UPDATE,
|
||||||
@@ -151,8 +150,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Long> cancelActiveActions(final List<List<Long>> targetIds) {
|
public Set<Long> cancelActiveActions(final List<List<Long>> targetIds) {
|
||||||
return targetIds.stream().map(this::overrideObsoleteUpdateActions).flatMap(Collection::stream)
|
return targetIds.stream().map(this::overrideObsoleteUpdateActions).flatMap(Collection::stream).collect(Collectors.toSet());
|
||||||
.collect(Collectors.toSet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import java.time.ZoneOffset;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -376,7 +375,7 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
|||||||
public static class StatusConverter extends MapAttributeConverter<Status, Integer> {
|
public static class StatusConverter extends MapAttributeConverter<Status, Integer> {
|
||||||
|
|
||||||
public StatusConverter() {
|
public StatusConverter() {
|
||||||
super(new EnumMap<>(new HashMap<>() {{
|
super(new HashMap<>() {{
|
||||||
put(Status.FINISHED, 0);
|
put(Status.FINISHED, 0);
|
||||||
put(Status.ERROR, 1);
|
put(Status.ERROR, 1);
|
||||||
put(Status.WARNING, 2);
|
put(Status.WARNING, 2);
|
||||||
@@ -389,7 +388,7 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
|
|||||||
put(Status.CANCEL_REJECTED, 9);
|
put(Status.CANCEL_REJECTED, 9);
|
||||||
put(Status.DOWNLOADED, 10);
|
put(Status.DOWNLOADED, 10);
|
||||||
put(Status.WAIT_FOR_CONFIRMATION, 11);
|
put(Status.WAIT_FOR_CONFIRMATION, 11);
|
||||||
}}), null);
|
}}, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -585,7 +585,7 @@ public class JpaQueryRsqlVisitor<A extends Enum<A> & RsqlQueryField, T> extends
|
|||||||
|
|
||||||
private Predicate in(final Expression<String> expressionToCompare, final List<Object> transformedValues) {
|
private Predicate in(final Expression<String> expressionToCompare, final List<Object> transformedValues) {
|
||||||
final List<String> inParams = transformedValues.stream().filter(String.class::isInstance)
|
final List<String> inParams = transformedValues.stream().filter(String.class::isInstance)
|
||||||
.map(String.class::cast).map(this::caseWise).collect(Collectors.toList());
|
.map(String.class::cast).map(this::caseWise).toList();
|
||||||
return inParams.isEmpty() ? expressionToCompare.in(transformedValues) : caseWise(cb, expressionToCompare).in(inParams);
|
return inParams.isEmpty() ? expressionToCompare.in(transformedValues) : caseWise(cb, expressionToCompare).in(inParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user