Add resource collection /rest/v1/actions to Management REST API (#1299)
* Initial commit Signed-off-by: Stefan Behl <stefan.behl@bosch.io> * Added filtering by RSQL Signed-off-by: Stefan Behl <stefan.behl@bosch.io> * Support for filtering actions by distribution set, target, rollout * Added REST docs * Fixed REST docs * Introduce a config property which allows to disable the actions endpoint * Introduce representation mode parameter * Adapt REST docs * Incorporate review findings * Adapt REST docs * Improve unit tests * Minor improvements * Fix REST docs * Fix REST docs * Fix PR review findings Signed-off-by: Stefan Behl <stefan.behl@bosch.io>
This commit is contained in:
@@ -217,6 +217,16 @@ public interface DeploymentManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
long countActionsAll();
|
||||
|
||||
/**
|
||||
* Counts the actions which match the given query.
|
||||
*
|
||||
* @param rsqlParam
|
||||
* RSQL query.
|
||||
* @return the total number of actions matching the given RSQL query.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
long countActions(@NotNull String rsqlParam);
|
||||
|
||||
/**
|
||||
* Counts all actions associated to a specific target.
|
||||
*
|
||||
@@ -274,6 +284,19 @@ public interface DeploymentManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Action> findActionsAll(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action} entities which match the given RSQL query.
|
||||
*
|
||||
* @param rsqlParam
|
||||
* RSQL query string
|
||||
* @param pageable
|
||||
* the page request parameter for paging and sorting the result
|
||||
*
|
||||
* @return a paged list of {@link Action}s.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
|
||||
Slice<Action> findActions(@NotNull String rsqlParam, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link Action} which assigned to a specific
|
||||
* {@link DistributionSet}.
|
||||
|
||||
@@ -72,8 +72,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetInvalidation.CancelationType;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
@@ -582,7 +580,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
if (rolloutGroupActions.getContent().isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
|
||||
final List<Action> newTargetAssignments = handleTargetAssignments(rolloutGroupActions);
|
||||
|
||||
if (!newTargetAssignments.isEmpty()) {
|
||||
@@ -592,7 +590,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
return rolloutGroupActions.getTotalElements();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private List<Action> handleTargetAssignments(final Page<Action> rolloutGroupActions) {
|
||||
// Close actions already assigned and collect pending assignments
|
||||
final List<JpaAction> pendingTargetAssignments = rolloutGroupActions.getContent().stream()
|
||||
@@ -651,9 +649,9 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
return Collections.unmodifiableList(savedActions);
|
||||
}
|
||||
|
||||
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)
|
||||
.collect(Collectors.toList());
|
||||
.collect(Collectors.toList());
|
||||
if (isActionsAutocloseEnabled()) {
|
||||
onlineDsAssignmentStrategy.closeObsoleteUpdateActions(targetIds);
|
||||
} else {
|
||||
@@ -661,7 +659,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
}
|
||||
}
|
||||
|
||||
private List<JpaAction> activateActions(final List<JpaAction> actions){
|
||||
private List<JpaAction> activateActions(final List<JpaAction> actions) {
|
||||
actions.forEach(action -> {
|
||||
action.setActive(true);
|
||||
action.setStatus(Status.RUNNING);
|
||||
@@ -860,6 +858,13 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
return actionRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countActions(final String rsqlParam) {
|
||||
final List<Specification<JpaAction>> specList = Arrays.asList(
|
||||
RSQLUtility.buildRsqlSpecification(rsqlParam, ActionFields.class, virtualPropertyReplacer, database));
|
||||
return JpaManagementHelper.countBySpec(actionRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countActionsByDistributionSetIdAndActiveIsTrue(final Long distributionSet) {
|
||||
return actionRepository.countByDistributionSetIdAndActiveIsTrue(distributionSet);
|
||||
@@ -882,6 +887,13 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(actionRepository, pageable, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Action> findActions(final String rsqlParam, final Pageable pageable) {
|
||||
final List<Specification<JpaAction>> specList = Arrays.asList(
|
||||
RSQLUtility.buildRsqlSpecification(rsqlParam, ActionFields.class, virtualPropertyReplacer, database));
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(actionRepository, pageable, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<DistributionSet> getAssignedDistributionSet(final String controllerId) {
|
||||
throwExceptionIfTargetDoesNotExist(controllerId);
|
||||
@@ -990,4 +1002,5 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user