DistributionSetAssignmentResult contains actions that do not reflect the

status on the DB. Needs to be avoided by returning actions IDs only and
force the user to query an updated action entity.

Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-02-16 13:48:52 +01:00
parent 2ef04bb437
commit e3801e9e56
7 changed files with 52 additions and 62 deletions

View File

@@ -40,7 +40,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.springframework.data.repository.CrudRepository#findAll() * @see org.springframework.data.repository.CrudRepository#findAll()
*/ */
@Override @Override
@@ -49,7 +49,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves an Action with all lazy attributes. * Retrieves an Action with all lazy attributes.
* *
* @param actionId * @param actionId
* the ID of the action * the ID of the action
* @return the found {@link Action} * @return the found {@link Action}
@@ -73,7 +73,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves all {@link Action}s which are referring the given * Retrieves all {@link Action}s which are referring the given
* {@link Target}. * {@link Target}.
* *
* @param pageable * @param pageable
* page parameters * page parameters
* @param target * @param target
@@ -85,7 +85,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves all {@link Action}s which are active and referring the given * Retrieves all {@link Action}s which are active and referring the given
* {@link Target} in a specified order. * {@link Target} in a specified order.
* *
* @param pageable * @param pageable
* page parameters * page parameters
* @param target * @param target
@@ -132,7 +132,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves all {@link Action}s of a specific target, without pagination * Retrieves all {@link Action}s of a specific target, without pagination
* ordered by action ID. * ordered by action ID.
* *
* @param target * @param target
* to search for * to search for
* @return a list of actions according to the searched target * @return a list of actions according to the searched target
@@ -143,7 +143,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves all {@link Action}s of a specific target and given active flag * Retrieves all {@link Action}s of a specific target and given active flag
* ordered by action ID. * ordered by action ID.
* *
* @param pageable * @param pageable
* the pagination parameter * the pagination parameter
* @param target * @param target
@@ -160,7 +160,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves all {@link Action}s of a specific target and given active flag * Retrieves all {@link Action}s of a specific target and given active flag
* ordered by action ID. * ordered by action ID.
* *
* @param target * @param target
* to search for * to search for
* @param active * @param active
@@ -174,7 +174,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Updates all {@link Action} to inactive for all targets with given ID. * Updates all {@link Action} to inactive for all targets with given ID.
* *
* @param keySet * @param keySet
* the list of actions to set inactive * the list of actions to set inactive
* @param targetsIds * @param targetsIds
@@ -190,7 +190,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
* Switches the status of actions from one specific status into another, * Switches the status of actions from one specific status into another,
* only if the actions are in a specific status. This should be a atomar * only if the actions are in a specific status. This should be a atomar
* operation. * operation.
* *
* @param statusToSet * @param statusToSet
* the new status the actions should get * the new status the actions should get
* @param targetIds * @param targetIds
@@ -210,7 +210,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
* Switches the status of actions from one specific status into another, * Switches the status of actions from one specific status into another,
* only if the actions are in a specific status. This should be a atomar * only if the actions are in a specific status. This should be a atomar
* operation. * operation.
* *
* @param statusToSet * @param statusToSet
* the new status the actions should get * the new status the actions should get
* @param rollout * @param rollout
@@ -227,7 +227,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
@Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus); @Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus);
/** /**
* *
* Retrieves all {@link Action}s which are active and referring to the given * Retrieves all {@link Action}s which are active and referring to the given
* target Ids and distribution set required migration step. * target Ids and distribution set required migration step.
* *
@@ -243,36 +243,24 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Counts all {@link Action}s referring to the given target. * Counts all {@link Action}s referring to the given target.
* *
* @param target * @param target
* the target to count the {@link Action}s * the target to count the {@link Action}s
* @return the count of actions referring to the given target * @return the count of actions referring to the given target
*/ */
Long countByTarget(Target target); Long countByTarget(Target target);
/*
* (non-Javadoc)
*
* @see org.springframework.data.repository.CrudRepository#save(java.lang.
* Iterable)
*/
@Override @Override
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
<S extends Action> List<S> save(Iterable<S> entities); <S extends Action> List<S> save(Iterable<S> entities);
/*
* (non-Javadoc)
*
* @see
* org.springframework.data.repository.CrudRepository#save(java.lang.Object)
*/
@Override @Override
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
<S extends Action> S save(S entity); <S extends Action> S save(S entity);
/** /**
* Counts all {@link Action}s referring to the given DistributionSet. * Counts all {@link Action}s referring to the given DistributionSet.
* *
* @param distributionSet * @param distributionSet
* DistributionSet to count the {@link Action}s from * DistributionSet to count the {@link Action}s from
* @return the count of actions referring to the given distributionSet * @return the count of actions referring to the given distributionSet
@@ -281,7 +269,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Counts all {@link Action}s referring to the given rollout. * Counts all {@link Action}s referring to the given rollout.
* *
* @param rollout * @param rollout
* the rollout to count the {@link Action}s from * the rollout to count the {@link Action}s from
* @return the count of actions referring to the given rollout * @return the count of actions referring to the given rollout
@@ -293,7 +281,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
* are currently not in the given status. An in-clause statement does not * are currently not in the given status. An in-clause statement does not
* work with the spring-data, so this is specific usecase regarding to the * work with the spring-data, so this is specific usecase regarding to the
* rollout-management to find out actions which are not in specific states. * rollout-management to find out actions which are not in specific states.
* *
* @param rollout * @param rollout
* the rollout the actions are belong to * the rollout the actions are belong to
* @param rolloutGroup * @param rolloutGroup
@@ -312,7 +300,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Counts all actions referring to a given rollout and rolloutgroup. * Counts all actions referring to a given rollout and rolloutgroup.
* *
* @param rollout * @param rollout
* the rollout the actions belong to * the rollout the actions belong to
* @param rolloutGroup * @param rolloutGroup
@@ -323,7 +311,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Counts all actions referring to a given rollout, rolloutgroup and status. * Counts all actions referring to a given rollout, rolloutgroup and status.
* *
* @param rolloutId * @param rolloutId
* the ID of rollout the actions belong to * the ID of rollout the actions belong to
* @param rolloutGroupId * @param rolloutGroupId
@@ -338,7 +326,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieving all actions referring to a given rollout with a specific * Retrieving all actions referring to a given rollout with a specific
* action as parent reference and a specific status. * action as parent reference and a specific status.
* *
* Finding all actions of a specific rolloutgroup parent relation. * Finding all actions of a specific rolloutgroup parent relation.
* *
* @param rollout * @param rollout
@@ -355,7 +343,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Retrieves all actions for a specific rollout and in a specific status. * Retrieves all actions for a specific rollout and in a specific status.
* *
* @param rollout * @param rollout
* the rollout the actions beglong to * the rollout the actions beglong to
* @param actionStatus * @param actionStatus
@@ -367,7 +355,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Get list of objects which has details of status and count of targets in * Get list of objects which has details of status and count of targets in
* each status in specified rollout. * each status in specified rollout.
* *
* @param rolloutId * @param rolloutId
* id of {@link Rollout} * id of {@link Rollout}
* @return list of objects with status and target count * @return list of objects with status and target count
@@ -378,7 +366,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Get list of objects which has details of status and count of targets in * Get list of objects which has details of status and count of targets in
* each status in specified rollout. * each status in specified rollout.
* *
* @param rolloutId * @param rolloutId
* id of {@link Rollout} * id of {@link Rollout}
* @return list of objects with status and target count * @return list of objects with status and target count
@@ -389,7 +377,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Get list of objects which has details of status and count of targets in * Get list of objects which has details of status and count of targets in
* each status in specified rollout group. * each status in specified rollout group.
* *
* @param rolloutGroupId * @param rolloutGroupId
* id of {@link RolloutGroup} * id of {@link RolloutGroup}
* @return list of objects with status and target count * @return list of objects with status and target count
@@ -400,7 +388,7 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
/** /**
* Get list of objects which has details of status and count of targets in * Get list of objects which has details of status and count of targets in
* each status in specified rollout group. * each status in specified rollout group.
* *
* @param rolloutGroupId * @param rolloutGroupId
* list of id of {@link RolloutGroup} * list of id of {@link RolloutGroup}
* @return list of objects with status and target count * @return list of objects with status and target count

View File

@@ -378,11 +378,13 @@ public class DeploymentManagement {
actionStatusRepository.save(actionStatus); actionStatusRepository.save(actionStatus);
}); });
// flush to get action IDs
entityManager.flush();
// select updated targets in order to return them // select updated targets in order to return them
final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult( final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult(
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(), targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(),
controllerIDs.size() - targets.size(), Lists.newArrayList(targetIdsToActions.values()), controllerIDs.size() - targets.size(),
targetManagement); targetIdsToActions.values().stream().map(Action::getId).collect(Collectors.toList()), targetManagement);
LOG.debug("assignDistribution({}) finished {}", set, result); LOG.debug("assignDistribution({}) finished {}", set, result);
@@ -392,7 +394,6 @@ public class DeploymentManagement {
entityManager.detach(set); entityManager.detach(set);
// send distribution set assignment event // send distribution set assignment event
targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId())) targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId()))
.forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(), .forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(),
softwareModules)); softwareModules));

View File

@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
import java.util.List; import java.util.List;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.AssignmentResult;
import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.Target;
@@ -19,14 +18,11 @@ import org.eclipse.hawkbit.repository.model.Target;
* information of an assignment and how much of the assignment has been done and * information of an assignment and how much of the assignment has been done and
* how much of the assignments had already been existed. * how much of the assignments had already been existed.
* *
*
*
*
*/ */
public class DistributionSetAssignmentResult extends AssignmentResult { public class DistributionSetAssignmentResult extends AssignmentResult {
private final List<String> assignedTargets; private final List<String> assignedTargets;
private final List<Action> actions; private final List<Long> actions;
private final TargetManagement targetManagement; private final TargetManagement targetManagement;
@@ -48,7 +44,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
* *
*/ */
public DistributionSetAssignmentResult(final List<String> assignedTargets, final int assigned, public DistributionSetAssignmentResult(final List<String> assignedTargets, final int assigned,
final int alreadyAssigned, final List<Action> actions, final TargetManagement targetManagement) { final int alreadyAssigned, final List<Long> actions, final TargetManagement targetManagement) {
super(assigned, alreadyAssigned); super(assigned, alreadyAssigned);
this.assignedTargets = assignedTargets; this.assignedTargets = assignedTargets;
this.actions = actions; this.actions = actions;
@@ -63,9 +59,9 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
} }
/** /**
* @return the actionId * @return the actionIds
*/ */
public List<Action> getActions() { public List<Long> getActions() {
return actions; return actions;
} }

View File

@@ -73,7 +73,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
distributionSetManagement, new ArrayList<DistributionSetTag>()); distributionSetManagement, new ArrayList<DistributionSetTag>());
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1)); final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
// one action with one action status is generated // one action with one action status is generated
final Action action = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0); final Action action = deploymentManagement.findActionWithDetails(
deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0));
// save 2 action status // save 2 action status
actionStatusRepository.save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis())); actionStatusRepository.save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis()));
actionStatusRepository.save(new ActionStatus(action, Status.RUNNING, System.currentTimeMillis())); actionStatusRepository.save(new ActionStatus(action, Status.RUNNING, System.currentTimeMillis()));
@@ -349,7 +350,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
* test a simple deployment by calling the * test a simple deployment by calling the
* {@link TargetRepository#assignDistributionSet(DistributionSet, Iterable)} * {@link TargetRepository#assignDistributionSet(DistributionSet, Iterable)}
* and checking the active action and the action history of the targets. * and checking the active action and the action history of the targets.
* *
* @throws InterruptedException * @throws InterruptedException
*/ */
@Test @Test
@@ -805,7 +806,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
// assign ds to create an action // assign ds to create an action
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
.assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, target.getControllerId()); .assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, target.getControllerId());
final Action action = assignDistributionSet.getActions().get(0); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
// verify preparation // verify preparation
Action findAction = deploymentManagement.findAction(action.getId()); Action findAction = deploymentManagement.findAction(action.getId());
assertThat(findAction.getActionType()).isEqualTo(ActionType.SOFT); assertThat(findAction.getActionType()).isEqualTo(ActionType.SOFT);
@@ -828,7 +829,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
// assign ds to create an action // assign ds to create an action
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
.assignDistributionSet(ds.getId(), ActionType.FORCED, Action.NO_FORCE_TIME, target.getControllerId()); .assignDistributionSet(ds.getId(), ActionType.FORCED, Action.NO_FORCE_TIME, target.getControllerId());
final Action action = assignDistributionSet.getActions().get(0); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0));
// verify perparation // verify perparation
Action findAction = deploymentManagement.findAction(action.getId()); Action findAction = deploymentManagement.findAction(action.getId());
assertThat(findAction.getActionType()).isEqualTo(ActionType.FORCED); assertThat(findAction.getActionType()).isEqualTo(ActionType.FORCED);
@@ -848,7 +849,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
* <p> * <p>
* <b>All created distribution sets are assigned to all targets of the * <b>All created distribution sets are assigned to all targets of the
* target list deployedTargets.</b> * target list deployedTargets.</b>
* *
* @param undeployedTargetPrefix * @param undeployedTargetPrefix
* prefix to be used as target controller prefix * prefix to be used as target controller prefix
* @param noOfUndeployedTargets * @param noOfUndeployedTargets

View File

@@ -138,7 +138,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final Target createTarget = targetManagement.createTarget(new Target("t" + month)); final Target createTarget = targetManagement.createTarget(new Target("t" + month));
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet, final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
Lists.newArrayList(createTarget)); Lists.newArrayList(createTarget));
controllerManagament.registerRetrieved(result.getActions().get(0), controllerManagament.registerRetrieved(
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
"Controller retrieved update action and should start now the download."); "Controller retrieved update action and should start now the download.");
} }
DataReportSeries<LocalDate> feedbackReceivedOverTime = reportManagement DataReportSeries<LocalDate> feedbackReceivedOverTime = reportManagement
@@ -158,7 +159,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
final Target createTarget = targetManagement.createTarget(new Target("t2" + month)); final Target createTarget = targetManagement.createTarget(new Target("t2" + month));
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet, final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
Lists.newArrayList(createTarget)); Lists.newArrayList(createTarget));
controllerManagament.registerRetrieved(result.getActions().get(0), controllerManagament.registerRetrieved(
deploymentManagement.findActionWithDetails(result.getActions().get(0)),
"Controller retrieved update action and should start now the download."); "Controller retrieved update action and should start now the download.");
} }
feedbackReceivedOverTime = reportManagement.feedbackReceivedOverTime(DateTypes.perMonth(), from, to); feedbackReceivedOverTime = reportManagement.feedbackReceivedOverTime(DateTypes.perMonth(), from, to);
@@ -572,7 +574,7 @@ public class ReportManagementTest extends AbstractIntegrationTest {
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.springframework.data.auditing.DateTimeProvider#getNow() * @see org.springframework.data.auditing.DateTimeProvider#getNow()
*/ */
@Override @Override

View File

@@ -174,7 +174,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(set.getId(), "4711"); final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(set.getId(), "4711");
final Action action = result.getActions().get(0); final Action action = deploymentManagement.findActionWithDetails(result.getActions().get(0));
action.setStatus(Status.FINISHED); action.setStatus(Status.FINISHED);
controllerManagament.addUpdateActionStatus( controllerManagament.addUpdateActionStatus(
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
@@ -221,7 +221,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
* verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted * verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted
* that the target have additional tags assigned to them which are not * that the target have additional tags assigned to them which are not
* contained within parameter tags. * contained within parameter tags.
* *
* @param strict * @param strict
* if true, the given targets MUST contain EXACTLY ALL given * if true, the given targets MUST contain EXACTLY ALL given
* tags, AND NO OTHERS. If false, the given targets MUST contain * tags, AND NO OTHERS. If false, the given targets MUST contain

View File

@@ -199,13 +199,14 @@ public final class RepositoryDataGenerator {
} }
private void createActionStatusHistory(final List<Action> actions, final int sizeMultiplikator) { private void createActionStatusHistory(final List<Long> actions, final int sizeMultiplikator) {
final AtomicInteger counter = new AtomicInteger(); final AtomicInteger counter = new AtomicInteger();
int index = 0; int index = 0;
for (final Action actionGiven : actions) { for (final Long actionGiven : actions) {
// retrieved // retrieved
Action action = controllerManagement.registerRetrieved(actionGiven, Action action = controllerManagement.registerRetrieved(
deploymentManagement.findActionWithDetails(actionGiven),
"Controller retrieved update action and should start now the download."); "Controller retrieved update action and should start now the download.");
// download // download
@@ -260,10 +261,11 @@ public final class RepositoryDataGenerator {
} }
} }
private void createSimpleActionStatusHistory(final List<Action> actions) { private void createSimpleActionStatusHistory(final List<Long> actions) {
for (final Action actionGiven : actions) { for (final Long actionGiven : actions) {
// retrieved // retrieved
Action action = controllerManagement.registerRetrieved(actionGiven, Action action = controllerManagement.registerRetrieved(
deploymentManagement.findActionWithDetails(actionGiven),
"Controller retrieved update action and should start now the download."); "Controller retrieved update action and should start now the download.");
// close // close