From e3801e9e56a1e322d0edd615c9d6cd502db5d1df Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 16 Feb 2016 13:48:52 +0100 Subject: [PATCH 1/7] 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 --- .../hawkbit/repository/ActionRepository.java | 58 ++++++++----------- .../repository/DeploymentManagement.java | 7 ++- .../DistributionSetAssignmentResult.java | 12 ++-- .../repository/DeploymentManagementTest.java | 11 ++-- .../repository/ReportManagementTest.java | 8 ++- .../repository/TargetManagementTest.java | 4 +- .../utils/RepositoryDataGenerator.java | 14 +++-- 7 files changed, 52 insertions(+), 62 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java index 331fdad5b..a93fbdca7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java @@ -40,7 +40,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /* * (non-Javadoc) - * + * * @see org.springframework.data.repository.CrudRepository#findAll() */ @Override @@ -49,7 +49,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves an Action with all lazy attributes. - * + * * @param actionId * the ID of the action * @return the found {@link Action} @@ -73,7 +73,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s which are referring the given * {@link Target}. - * + * * @param pageable * page parameters * @param target @@ -85,7 +85,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s which are active and referring the given * {@link Target} in a specified order. - * + * * @param pageable * page parameters * @param target @@ -132,7 +132,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target, without pagination * ordered by action ID. - * + * * @param target * to search for * @return a list of actions according to the searched target @@ -143,7 +143,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target and given active flag * ordered by action ID. - * + * * @param pageable * the pagination parameter * @param target @@ -160,7 +160,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target and given active flag * ordered by action ID. - * + * * @param target * to search for * @param active @@ -174,7 +174,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Updates all {@link Action} to inactive for all targets with given ID. - * + * * @param keySet * the list of actions to set inactive * @param targetsIds @@ -190,7 +190,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * 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 * operation. - * + * * @param statusToSet * the new status the actions should get * @param targetIds @@ -210,7 +210,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * 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 * operation. - * + * * @param statusToSet * the new status the actions should get * @param rollout @@ -227,7 +227,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp @Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus); /** - * + * * Retrieves all {@link Action}s which are active and referring to the given * target Ids and distribution set required migration step. * @@ -243,36 +243,24 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all {@link Action}s referring to the given target. - * + * * @param target * the target to count the {@link Action}s * @return the count of actions referring to the given target */ Long countByTarget(Target target); - /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.CrudRepository#save(java.lang. - * Iterable) - */ @Override @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) List save(Iterable entities); - /* - * (non-Javadoc) - * - * @see - * org.springframework.data.repository.CrudRepository#save(java.lang.Object) - */ @Override @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) S save(S entity); /** * Counts all {@link Action}s referring to the given DistributionSet. - * + * * @param distributionSet * DistributionSet to count the {@link Action}s from * @return the count of actions referring to the given distributionSet @@ -281,7 +269,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all {@link Action}s referring to the given rollout. - * + * * @param rollout * the rollout to count the {@link Action}s from * @return the count of actions referring to the given rollout @@ -293,7 +281,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * 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 * rollout-management to find out actions which are not in specific states. - * + * * @param rollout * the rollout the actions are belong to * @param rolloutGroup @@ -312,7 +300,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all actions referring to a given rollout and rolloutgroup. - * + * * @param rollout * the rollout the actions belong to * @param rolloutGroup @@ -323,7 +311,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all actions referring to a given rollout, rolloutgroup and status. - * + * * @param rolloutId * the ID of rollout the actions belong to * @param rolloutGroupId @@ -338,7 +326,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieving all actions referring to a given rollout with a specific * action as parent reference and a specific status. - * + * * Finding all actions of a specific rolloutgroup parent relation. * * @param rollout @@ -355,7 +343,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all actions for a specific rollout and in a specific status. - * + * * @param rollout * the rollout the actions beglong to * @param actionStatus @@ -367,7 +355,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout. - * + * * @param rolloutId * id of {@link Rollout} * @return list of objects with status and target count @@ -378,7 +366,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout. - * + * * @param rolloutId * id of {@link Rollout} * @return list of objects with status and target count @@ -389,7 +377,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout group. - * + * * @param rolloutGroupId * id of {@link RolloutGroup} * @return list of objects with status and target count @@ -400,7 +388,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout group. - * + * * @param rolloutGroupId * list of id of {@link RolloutGroup} * @return list of objects with status and target count diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 172f1c3e1..b0a61395b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -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)); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index ac562131d..3e61e4499 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -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 assignedTargets; - private final List actions; + private final List actions; private final TargetManagement targetManagement; @@ -48,7 +44,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult { * */ public DistributionSetAssignmentResult(final List assignedTargets, final int assigned, - final int alreadyAssigned, final List actions, final TargetManagement targetManagement) { + final int alreadyAssigned, final List 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 getActions() { + public List getActions() { return actions; } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 46747cd9c..5ad98069a 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -73,7 +73,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { distributionSetManagement, new ArrayList()); final List 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())); @@ -349,7 +350,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { * test a simple deployment by calling the * {@link TargetRepository#assignDistributionSet(DistributionSet, Iterable)} * and checking the active action and the action history of the targets. - * + * * @throws InterruptedException */ @Test @@ -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); @@ -848,7 +849,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { *

* All created distribution sets are assigned to all targets of the * target list deployedTargets. - * + * * @param undeployedTargetPrefix * prefix to be used as target controller prefix * @param noOfUndeployedTargets diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java index bb5450083..0f91fb521 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java @@ -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 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); @@ -572,7 +574,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { /* * (non-Javadoc) - * + * * @see org.springframework.data.auditing.DateTimeProvider#getNow() */ @Override diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index 3a70441ca..cdcaff25e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -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); @@ -221,7 +221,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { * verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted * that the target have additional tags assigned to them which are not * contained within parameter tags. - * + * * @param strict * if true, the given targets MUST contain EXACTLY ALL given * tags, AND NO OTHERS. If false, the given targets MUST contain diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index dffec4df1..d7efa50d5 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -199,13 +199,14 @@ public final class RepositoryDataGenerator { } - private void createActionStatusHistory(final List actions, final int sizeMultiplikator) { + private void createActionStatusHistory(final List 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 actions) { - for (final Action actionGiven : actions) { + private void createSimpleActionStatusHistory(final List 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 From 38b750f674465d5ae4fabc706547cfe8e506feed Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 16 Feb 2016 13:48:52 +0100 Subject: [PATCH 2/7] 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 --- .../hawkbit/repository/ActionRepository.java | 58 ++++++++----------- .../repository/DeploymentManagement.java | 7 ++- .../DistributionSetAssignmentResult.java | 12 ++-- .../repository/DeploymentManagementTest.java | 11 ++-- .../repository/ReportManagementTest.java | 8 ++- .../repository/TargetManagementTest.java | 4 +- .../utils/RepositoryDataGenerator.java | 14 +++-- .../hawkbit/controller/CancelActionTest.java | 29 +++++----- .../controller/DeploymentBaseTest.java | 15 ++--- 9 files changed, 76 insertions(+), 82 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java index 331fdad5b..a93fbdca7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java @@ -40,7 +40,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /* * (non-Javadoc) - * + * * @see org.springframework.data.repository.CrudRepository#findAll() */ @Override @@ -49,7 +49,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves an Action with all lazy attributes. - * + * * @param actionId * the ID of the action * @return the found {@link Action} @@ -73,7 +73,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s which are referring the given * {@link Target}. - * + * * @param pageable * page parameters * @param target @@ -85,7 +85,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s which are active and referring the given * {@link Target} in a specified order. - * + * * @param pageable * page parameters * @param target @@ -132,7 +132,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target, without pagination * ordered by action ID. - * + * * @param target * to search for * @return a list of actions according to the searched target @@ -143,7 +143,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target and given active flag * ordered by action ID. - * + * * @param pageable * the pagination parameter * @param target @@ -160,7 +160,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target and given active flag * ordered by action ID. - * + * * @param target * to search for * @param active @@ -174,7 +174,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Updates all {@link Action} to inactive for all targets with given ID. - * + * * @param keySet * the list of actions to set inactive * @param targetsIds @@ -190,7 +190,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * 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 * operation. - * + * * @param statusToSet * the new status the actions should get * @param targetIds @@ -210,7 +210,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * 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 * operation. - * + * * @param statusToSet * the new status the actions should get * @param rollout @@ -227,7 +227,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp @Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus); /** - * + * * Retrieves all {@link Action}s which are active and referring to the given * target Ids and distribution set required migration step. * @@ -243,36 +243,24 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all {@link Action}s referring to the given target. - * + * * @param target * the target to count the {@link Action}s * @return the count of actions referring to the given target */ Long countByTarget(Target target); - /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.CrudRepository#save(java.lang. - * Iterable) - */ @Override @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) List save(Iterable entities); - /* - * (non-Javadoc) - * - * @see - * org.springframework.data.repository.CrudRepository#save(java.lang.Object) - */ @Override @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) S save(S entity); /** * Counts all {@link Action}s referring to the given DistributionSet. - * + * * @param distributionSet * DistributionSet to count the {@link Action}s from * @return the count of actions referring to the given distributionSet @@ -281,7 +269,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all {@link Action}s referring to the given rollout. - * + * * @param rollout * the rollout to count the {@link Action}s from * @return the count of actions referring to the given rollout @@ -293,7 +281,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * 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 * rollout-management to find out actions which are not in specific states. - * + * * @param rollout * the rollout the actions are belong to * @param rolloutGroup @@ -312,7 +300,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all actions referring to a given rollout and rolloutgroup. - * + * * @param rollout * the rollout the actions belong to * @param rolloutGroup @@ -323,7 +311,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Counts all actions referring to a given rollout, rolloutgroup and status. - * + * * @param rolloutId * the ID of rollout the actions belong to * @param rolloutGroupId @@ -338,7 +326,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieving all actions referring to a given rollout with a specific * action as parent reference and a specific status. - * + * * Finding all actions of a specific rolloutgroup parent relation. * * @param rollout @@ -355,7 +343,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all actions for a specific rollout and in a specific status. - * + * * @param rollout * the rollout the actions beglong to * @param actionStatus @@ -367,7 +355,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout. - * + * * @param rolloutId * id of {@link Rollout} * @return list of objects with status and target count @@ -378,7 +366,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout. - * + * * @param rolloutId * id of {@link Rollout} * @return list of objects with status and target count @@ -389,7 +377,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout group. - * + * * @param rolloutGroupId * id of {@link RolloutGroup} * @return list of objects with status and target count @@ -400,7 +388,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Get list of objects which has details of status and count of targets in * each status in specified rollout group. - * + * * @param rolloutGroupId * list of id of {@link RolloutGroup} * @return list of objects with status and target count diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 172f1c3e1..b0a61395b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -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)); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index ac562131d..3e61e4499 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -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 assignedTargets; - private final List actions; + private final List actions; private final TargetManagement targetManagement; @@ -48,7 +44,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult { * */ public DistributionSetAssignmentResult(final List assignedTargets, final int assigned, - final int alreadyAssigned, final List actions, final TargetManagement targetManagement) { + final int alreadyAssigned, final List 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 getActions() { + public List getActions() { return actions; } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 46747cd9c..5ad98069a 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -73,7 +73,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { distributionSetManagement, new ArrayList()); final List 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())); @@ -349,7 +350,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { * test a simple deployment by calling the * {@link TargetRepository#assignDistributionSet(DistributionSet, Iterable)} * and checking the active action and the action history of the targets. - * + * * @throws InterruptedException */ @Test @@ -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); @@ -848,7 +849,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { *

* All created distribution sets are assigned to all targets of the * target list deployedTargets. - * + * * @param undeployedTargetPrefix * prefix to be used as target controller prefix * @param noOfUndeployedTargets diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java index bb5450083..0f91fb521 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java @@ -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 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); @@ -572,7 +574,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { /* * (non-Javadoc) - * + * * @see org.springframework.data.auditing.DateTimeProvider#getNow() */ @Override diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index 3a70441ca..cdcaff25e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -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); @@ -221,7 +221,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { * verifies, that all {@link TargetTag} of parameter. NOTE: it's accepted * that the target have additional tags assigned to them which are not * contained within parameter tags. - * + * * @param strict * if true, the given targets MUST contain EXACTLY ALL given * tags, AND NO OTHERS. If false, the given targets MUST contain diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index dffec4df1..d7efa50d5 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -199,13 +199,14 @@ public final class RepositoryDataGenerator { } - private void createActionStatusHistory(final List actions, final int sizeMultiplikator) { + private void createActionStatusHistory(final List 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 actions) { - for (final Action actionGiven : actions) { + private void createSimpleActionStatusHistory(final List 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 diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java index 267b95408..e7b94cb30 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/CancelActionTest.java @@ -56,7 +56,8 @@ public class CancelActionTest extends AbstractIntegrationTest { final List toAssign = new ArrayList(); toAssign.add(savedTarget); - final Action updateAction = deploymentManagement.assignDistributionSet(ds, toAssign).getActions().get(0); + final Action updateAction = deploymentManagement + .findActionWithDetails(deploymentManagement.assignDistributionSet(ds, toAssign).getActions().get(0)); final Action cancelAction = deploymentManagement.cancelAction(updateAction, targetManagement.findTargetByControllerID(savedTarget.getControllerId())); @@ -112,7 +113,8 @@ public class CancelActionTest extends AbstractIntegrationTest { final List toAssign = new ArrayList(); toAssign.add(savedTarget); - final Action updateAction = deploymentManagement.assignDistributionSet(ds, toAssign).getActions().get(0); + final Action updateAction = deploymentManagement + .findActionWithDetails(deploymentManagement.assignDistributionSet(ds, toAssign).getActions().get(0)); long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) @@ -227,7 +229,8 @@ public class CancelActionTest extends AbstractIntegrationTest { final Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList(); toAssign.add(savedTarget); - final Action updateAction = deploymentManagement.assignDistributionSet(ds, toAssign).getActions().get(0); + final Action updateAction = deploymentManagement + .findActionWithDetails(deploymentManagement.assignDistributionSet(ds, toAssign).getActions().get(0)); return deploymentManagement.cancelAction(updateAction, targetManagement.findTargetByControllerID(savedTarget.getControllerId())); @@ -243,8 +246,8 @@ public class CancelActionTest extends AbstractIntegrationTest { final Target savedTarget = targetManagement.createTarget(target); - final Action updateAction = deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }) - .getActions().get(0); + final Action updateAction = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }).getActions().get(0)); // cancel action manually final Action cancelAction = deploymentManagement.cancelAction(updateAction, @@ -340,12 +343,12 @@ public class CancelActionTest extends AbstractIntegrationTest { final Target savedTarget = targetManagement.createTarget(target); - final Action updateAction = deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }) - .getActions().get(0); - final Action updateAction2 = deploymentManagement.assignDistributionSet(ds2.getId(), new String[] { "4712" }) - .getActions().get(0); - final Action updateAction3 = deploymentManagement.assignDistributionSet(ds3.getId(), new String[] { "4712" }) - .getActions().get(0); + final Action updateAction = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }).getActions().get(0)); + final Action updateAction2 = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds2.getId(), new String[] { "4712" }).getActions().get(0)); + final Action updateAction3 = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds3.getId(), new String[] { "4712" }).getActions().get(0)); assertThat(actionStatusRepository.findAll()).hasSize(3); @@ -456,8 +459,8 @@ public class CancelActionTest extends AbstractIntegrationTest { final List toAssign = new ArrayList(); toAssign.add(target); - final Action action = deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }) - .getActions().get(0); + final Action action = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }).getActions().get(0)); final Action cancelAction = deploymentManagement.cancelAction(action, targetManagement.findTargetByControllerID(target.getControllerId())); diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java index e0a4b8e5c..2aabb0cba 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/controller/DeploymentBaseTest.java @@ -484,7 +484,8 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); - final Action action1 = deploymentManagement.assignDistributionSet(savedSet, toAssign).getActions().get(0); + final Action action1 = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(savedSet, toAssign).getActions().get(0)); mvc.perform( get("/{tenant}/controller/v1/4712/deploymentBase/" + action1.getId(), tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -544,12 +545,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { final List toAssign = new ArrayList(); toAssign.add(savedTarget1); - final Action action1 = deploymentManagement.assignDistributionSet(ds1.getId(), new String[] { "4712" }) - .getActions().get(0); - final Action action2 = deploymentManagement.assignDistributionSet(ds2.getId(), new String[] { "4712" }) - .getActions().get(0); - final Action action3 = deploymentManagement.assignDistributionSet(ds3.getId(), new String[] { "4712" }) - .getActions().get(0); + final Action action1 = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds1.getId(), new String[] { "4712" }).getActions().get(0)); + final Action action2 = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds2.getId(), new String[] { "4712" }).getActions().get(0)); + final Action action3 = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(ds3.getId(), new String[] { "4712" }).getActions().get(0)); Target myT = targetManagement.findTargetByControllerID("4712"); assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); From 6a2b74e5651e8f1e15eaf74f31d529cfa7578000 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 16 Feb 2016 17:37:34 +0100 Subject: [PATCH 3/7] Enabled target.assignedDs load through action enitygraph. Signed-off-by: Kai Zimmermann --- .../hawkbit/repository/DeploymentManagement.java | 4 ++-- .../eclipse/hawkbit/repository/model/Action.java | 3 ++- .../repository/DeploymentManagementTest.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index b0a61395b..c9b08a554 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -710,8 +710,8 @@ public class DeploymentManagement { } /** - * Get the {@link Action} entity for given actionId with all lazy - * attributes. + * Get the {@link Action} entity for given actionId with all lazy attributes + * (i.e. distributionSet, target, target.assignedDs). * * @param actionId * to be id of the action diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 0554e6c58..1f8a71d76 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -24,6 +24,7 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedAttributeNode; import javax.persistence.NamedEntityGraph; import javax.persistence.NamedEntityGraphs; +import javax.persistence.NamedSubgraph; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Transient; @@ -55,7 +56,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), - @NamedAttributeNode("target") }) }) + @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet") ) ) }) @Entity public class Action extends BaseEntity implements Comparable { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 5ad98069a..248f630db 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -66,6 +66,22 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Autowired private EventBus eventBus; + @Test + @Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.") + public void findActionWithLazyDetails() { + final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement, + distributionSetManagement, new ArrayList()); + final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1)); + // one action with one action status is generated + final Action action = deploymentManagement.findActionWithDetails( + deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0)); + + assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull(); + assertThat(action.getTarget()).as("Target in action").isNotNull(); + assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action") + .isNotNull(); + } + @Test @Description("Test verifies that the custom query to find all actions include the count of action status is working correctly") public void findActionsWithStatusCountByTarget() { From 3334cf4a649f723e17b9ccdae6f8a4f7f0df835d Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 17 Feb 2016 08:36:36 +0100 Subject: [PATCH 4/7] Updated test Signed-off-by: Kai Zimmermann --- .../eclipse/hawkbit/repository/DeploymentManagementTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 248f630db..693a67082 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -73,8 +73,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { distributionSetManagement, new ArrayList()); final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1)); // one action with one action status is generated - final Action action = deploymentManagement.findActionWithDetails( - deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0)); + final Long actionId = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0); + final Action action = deploymentManagement.findActionWithDetails(actionId); assertThat(action.getDistributionSet()).as("DistributionSet in action").isNotNull(); assertThat(action.getTarget()).as("Target in action").isNotNull(); From 01b75fc93207623d96edc8876f26efbc7f7fa722 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 17 Feb 2016 09:57:07 +0100 Subject: [PATCH 5/7] Removed unnecessary entitygraph usage. Signed-off-by: Kai Zimmermann --- .../hawkbit/repository/ActionRepository.java | 18 ++++-------------- .../hawkbit/repository/model/Action.java | 16 +++++----------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java index a93fbdca7..8221fa0ca 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java @@ -37,16 +37,6 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true) public interface ActionRepository extends BaseEntityRepository, JpaSpecificationExecutor { - - /* - * (non-Javadoc) - * - * @see org.springframework.data.repository.CrudRepository#findAll() - */ - @Override - @EntityGraph(value = "Action.all", type = EntityGraphType.LOAD) - Iterable findAll(); - /** * Retrieves an Action with all lazy attributes. * @@ -67,7 +57,6 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the {@link DistributionSet} on which will be filtered * @return the found {@link Action}s */ - @EntityGraph(value = "Action.all", type = EntityGraphType.LOAD) Page findByDistributionSet(final Pageable pageable, final DistributionSet ds); /** @@ -84,7 +73,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s which are active and referring the given - * {@link Target} in a specified order. + * {@link Target} in a specified order. Loads also the lazy + * {@link Action#getDistributionSet()} field. * * @param pageable * page parameters @@ -125,7 +115,6 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return the found {@link UpdateAction}s */ @Query("Select a from Action a where a.target = :target and a.distributionSet = :ds order by a.id") - @EntityGraph(value = "Action.all", type = EntityGraphType.LOAD) Page findByTargetAndDistributionSet(final Pageable pageable, @Param("target") final Target target, @Param("ds") DistributionSet ds); @@ -159,7 +148,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp /** * Retrieves all {@link Action}s of a specific target and given active flag - * ordered by action ID. + * ordered by action ID. Loads also the lazy + * {@link Action#getDistributionSet()} field. * * @param target * to search for diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 1f8a71d76..c19b947de 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -35,21 +35,15 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; /** *

- * Applicable transition changes of the software {@link SoftwareModule} state of - * a {@link Target}, e.g. install, uninstall, update, start, stop, and - * preparations for the transition change, i.e. download. + * Applicable transition changes of the {@link SoftwareModule}s state of a + * {@link Target}, e.g. install, uninstall, update and preparations for the + * transition change, i.e. download. *

* *

- * Actions are managed by the SP server (SPS) and applied to the edge controller - * by the SP controller (SPC). Actions may also be value added commands that are - * nor directly related to SP, e.g. factory reset. + * Actions are managed by the SP server and applied to the targets by the + * client. *

- * - * - * - * - * */ @Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"), @Index(name = "sp_idx_action_02", columnList = "tenant,target,active"), From 1c6223ba5d2ab994c405763698fc5b97dd5f7daa Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 18 Feb 2016 10:12:36 +0100 Subject: [PATCH 6/7] Improved readibility Signed-off-by: Kai Zimmermann --- .../repository/DeploymentManagement.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index c9b08a554..f266ffac4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -380,7 +380,7 @@ public class DeploymentManagement { // flush to get action IDs entityManager.flush(); - // select updated targets in order to return them + // collect updated target and actions IDs 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(), @@ -393,12 +393,22 @@ public class DeploymentManagement { // detaching as it is not necessary to persist the set itself entityManager.detach(set); - // send distribution set assignment event + sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions, softwareModules); + + return result; + } + + /** + * @param targets + * @param targetIdsCancellList + * @param targetIdsToActions + * @param softwareModules + */ + private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, + final Map targetIdsToActions, final List softwareModules) { targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId())) .forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(), softwareModules)); - - return result; } /** From b6509750bc7e623237de5c4b1260f7d30ef2a579 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 18 Feb 2016 10:22:21 +0100 Subject: [PATCH 7/7] Removed broken javadoc. Signed-off-by: Kai Zimmermann --- .../eclipse/hawkbit/repository/DeploymentManagement.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index f266ffac4..560549e7e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -398,12 +398,6 @@ public class DeploymentManagement { return result; } - /** - * @param targets - * @param targetIdsCancellList - * @param targetIdsToActions - * @param softwareModules - */ private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, final Map targetIdsToActions, final List softwareModules) { targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId()))