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:
@@ -250,22 +250,10 @@ public interface ActionRepository extends BaseEntityRepository<Action, Long>, Jp
|
||||
*/
|
||||
Long countByTarget(Target target);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.repository.CrudRepository#save(java.lang.
|
||||
* Iterable)
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
|
||||
<S extends Action> List<S> save(Iterable<S> entities);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.repository.CrudRepository#save(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(value = "feedbackReceivedOverTime", allEntries = true)
|
||||
<S extends Action> S save(S entity);
|
||||
|
||||
@@ -378,11 +378,13 @@ public class DeploymentManagement {
|
||||
actionStatusRepository.save(actionStatus);
|
||||
});
|
||||
|
||||
// flush to get action IDs
|
||||
entityManager.flush();
|
||||
// select updated targets in order to return them
|
||||
final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult(
|
||||
targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(),
|
||||
controllerIDs.size() - targets.size(), Lists.newArrayList(targetIdsToActions.values()),
|
||||
targetManagement);
|
||||
controllerIDs.size() - targets.size(),
|
||||
targetIdsToActions.values().stream().map(Action::getId).collect(Collectors.toList()), targetManagement);
|
||||
|
||||
LOG.debug("assignDistribution({}) finished {}", set, result);
|
||||
|
||||
@@ -392,7 +394,6 @@ public class DeploymentManagement {
|
||||
entityManager.detach(set);
|
||||
|
||||
// send distribution set assignment event
|
||||
|
||||
targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId()))
|
||||
.forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(),
|
||||
softwareModules));
|
||||
|
||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.AssignmentResult;
|
||||
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
|
||||
* how much of the assignments had already been existed.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
|
||||
private final List<String> assignedTargets;
|
||||
private final List<Action> actions;
|
||||
private final List<Long> actions;
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
|
||||
@@ -48,7 +44,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult {
|
||||
*
|
||||
*/
|
||||
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);
|
||||
this.assignedTargets = assignedTargets;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
distributionSetManagement, new ArrayList<DistributionSetTag>());
|
||||
final List<Target> testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1));
|
||||
// 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
|
||||
actionStatusRepository.save(new ActionStatus(action, Status.RETRIEVED, 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
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
|
||||
.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
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
assertThat(findAction.getActionType()).isEqualTo(ActionType.SOFT);
|
||||
@@ -828,7 +829,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
||||
// assign ds to create an action
|
||||
final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement
|
||||
.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
|
||||
Action findAction = deploymentManagement.findAction(action.getId());
|
||||
assertThat(findAction.getActionType()).isEqualTo(ActionType.FORCED);
|
||||
|
||||
@@ -138,7 +138,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final Target createTarget = targetManagement.createTarget(new Target("t" + month));
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
|
||||
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.");
|
||||
}
|
||||
DataReportSeries<LocalDate> feedbackReceivedOverTime = reportManagement
|
||||
@@ -158,7 +159,8 @@ public class ReportManagementTest extends AbstractIntegrationTest {
|
||||
final Target createTarget = targetManagement.createTarget(new Target("t2" + month));
|
||||
final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet,
|
||||
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.");
|
||||
}
|
||||
feedbackReceivedOverTime = reportManagement.feedbackReceivedOverTime(DateTypes.perMonth(), from, to);
|
||||
|
||||
@@ -174,7 +174,7 @@ public class TargetManagementTest extends AbstractIntegrationTest {
|
||||
|
||||
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);
|
||||
controllerManagament.addUpdateActionStatus(
|
||||
new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action);
|
||||
|
||||
@@ -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();
|
||||
|
||||
int index = 0;
|
||||
for (final Action actionGiven : actions) {
|
||||
for (final Long actionGiven : actions) {
|
||||
// retrieved
|
||||
Action action = controllerManagement.registerRetrieved(actionGiven,
|
||||
Action action = controllerManagement.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(actionGiven),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
// download
|
||||
@@ -260,10 +261,11 @@ public final class RepositoryDataGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private void createSimpleActionStatusHistory(final List<Action> actions) {
|
||||
for (final Action actionGiven : actions) {
|
||||
private void createSimpleActionStatusHistory(final List<Long> actions) {
|
||||
for (final Long actionGiven : actions) {
|
||||
// retrieved
|
||||
Action action = controllerManagement.registerRetrieved(actionGiven,
|
||||
Action action = controllerManagement.registerRetrieved(
|
||||
deploymentManagement.findActionWithDetails(actionGiven),
|
||||
"Controller retrieved update action and should start now the download.");
|
||||
|
||||
// close
|
||||
|
||||
Reference in New Issue
Block a user