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

@@ -250,22 +250,10 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
*/ */
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);

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()));
@@ -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);

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);

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);

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