Fix already assigned targets (#919)
* Dont count not existing targets as already assigned to DS Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Add test for deploymentManagement Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Delete 404 error message from docs when target is not found Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Add text to implementation notes Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Add assertions to test Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Add expected behaviour to test description Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Refactor deploymentMgmtTest Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Filter out non-existing controllerIds Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Extend test descriptions Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Refactor createTargets method Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Add createTargetAndJsonArray method Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Correct expected test result Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Adapt rest docs Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Correct test Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Only count targets that exist for total and adapt test Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Use only existign targetWithActionTypes for assignment Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com> * Rename targetIds to providedTargetIds Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
5feb5873c4
commit
8d3ba68be9
@@ -37,11 +37,11 @@ import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdated
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.MultiAssignmentIsNotEnabledException;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
@@ -187,7 +187,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(ds1, targets);
|
||||
|
||||
targets.add(testdataFactory.createTarget("assignmentTest2"));
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class).isThrownBy(() -> assignDistributionSet(ds2, targets));
|
||||
assertThatExceptionOfType(AssignmentQuotaExceededException.class)
|
||||
.isThrownBy(() -> assignDistributionSet(ds2, targets));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -647,6 +648,40 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
deploymentManagement.assignDistributionSets(Arrays.asList(targetToDS0, targetToDS1)))).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Assigning distribution set to the list of targets with a non-existing one leads to successful assignment of valid targets, while not found targets are silently ignored.")
|
||||
public void assignDistributionSetToNotExistingTarget() {
|
||||
final String notExistingId = "notExistingTarget";
|
||||
|
||||
final DistributionSet createdDs = testdataFactory.createDistributionSet();
|
||||
|
||||
final String[] knownTargetIdsArray = { "1", "2" };
|
||||
final List<String> knownTargetIds = Lists.newArrayList(knownTargetIdsArray);
|
||||
testdataFactory.createTargets(knownTargetIdsArray);
|
||||
|
||||
// add not existing target to targets
|
||||
knownTargetIds.add(notExistingId);
|
||||
|
||||
final List<DistributionSetAssignmentResult> assignDistributionSetsResults = assignDistributionSetToTargets(
|
||||
createdDs, knownTargetIds);
|
||||
|
||||
for (final DistributionSetAssignmentResult assignDistributionSetsResult : assignDistributionSetsResults) {
|
||||
assertThat(assignDistributionSetsResult.getAlreadyAssigned()).isEqualTo(0);
|
||||
assertThat(assignDistributionSetsResult.getAssigned()).isEqualTo(2);
|
||||
assertThat(assignDistributionSetsResult.getTotal()).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
private List<DistributionSetAssignmentResult> assignDistributionSetToTargets(final DistributionSet distributionSet,
|
||||
final Iterable<String> targetIds) {
|
||||
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
||||
for (final String controllerId : targetIds) {
|
||||
deploymentRequests.add(new DeploymentRequest(controllerId, distributionSet.getId(), ActionType.FORCED, 0,
|
||||
null, null, null, null));
|
||||
}
|
||||
return deploymentManagement.assignDistributionSets(deploymentRequests);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Duplicate Assignments are removed from a request when multiassignment is disabled, otherwise not")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
|
||||
Reference in New Issue
Block a user