added triggeredBy for rollouts and autoassignment (#1017)
* added triggeredBy for rollouts and autoassignment Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * use createdBy as fallback for triggeredBy in AutoAssignChecker Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * removed 'NOT NULL' from db migration scripts for JpaTargetFilterQuery Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed tests Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * inlined redundant method in JpaDeploymentManagement Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * added tests + renamed property to 'initiatedBy' Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com>
This commit is contained in:
@@ -104,6 +104,7 @@ public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest {
|
||||
generateAction.setTarget(testdataFactory.createTarget("Test"));
|
||||
generateAction.setDistributionSet(dsA);
|
||||
generateAction.setStatus(Status.RUNNING);
|
||||
generateAction.setInitiatedBy(tenantAware.getCurrentUsername());
|
||||
|
||||
final Action action = actionRepository.save(generateAction);
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ public class ActionEventTest extends AbstractRemoteEntityEventTest<Action> {
|
||||
generateAction.setTarget(target);
|
||||
generateAction.setDistributionSet(distributionSet);
|
||||
generateAction.setStatus(Status.RUNNING);
|
||||
generateAction.setInitiatedBy(tenantAware.getCurrentUsername());
|
||||
return actionRepository.save(generateAction);
|
||||
}
|
||||
|
||||
|
||||
@@ -480,7 +480,9 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(actionRepository.count()).isEqualTo(20);
|
||||
assertThat(actionRepository.findByDistributionSetId(PAGE, ds.getId())).as("Offline actions are not active")
|
||||
.allMatch(action -> !action.isActive());
|
||||
.allMatch(action -> !action.isActive())
|
||||
.as("Actions should be initiated by current user")
|
||||
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
||||
|
||||
assertThat(targetManagement.findByInstalledDistributionSet(PAGE, ds.getId()).getContent())
|
||||
.usingElementComparator(controllerIdComparator()).containsAll(targets).hasSize(10)
|
||||
@@ -514,6 +516,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(getResultingActionCount(assignmentResults)).isEqualTo(4);
|
||||
targetIds.forEach(controllerId -> {
|
||||
final List<Long> assignedDsIds = actionRepository.findByTargetControllerId(PAGE, controllerId).stream()
|
||||
.peek(a -> assertThat(a.getInitiatedBy()).as("Actions should be initiated by current user")
|
||||
.isEqualTo(tenantAware.getCurrentUsername()))
|
||||
.map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
|
||||
assertThat(assignedDsIds).containsExactlyInAnyOrderElementsOf(dsIds);
|
||||
});
|
||||
@@ -587,10 +591,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
private void assertDsExclusivelyAssignedToTargets(final List<Target> targets, final long dsId, final boolean active,
|
||||
final Status status) {
|
||||
final List<Action> assignment = actionRepository.findByDistributionSetId(PAGE, dsId).getContent();
|
||||
final String currentUsername = tenantAware.getCurrentUsername();
|
||||
|
||||
assertThat(assignment).hasSize(10).allMatch(action -> action.isActive() == active)
|
||||
.as("Is assigned to DS " + dsId).allMatch(action -> action.getDistributionSet().getId().equals(dsId))
|
||||
.as("State is " + status).allMatch(action -> action.getStatus() == status);
|
||||
.as("State is " + status).allMatch(action -> action.getStatus() == status)
|
||||
.as("Initiated by " + currentUsername).allMatch(a -> a.getInitiatedBy().equals(currentUsername));
|
||||
final long[] targetIds = targets.stream().mapToLong(Target::getId).toArray();
|
||||
assertThat(targetIds).as("All targets represented in assignment").containsExactlyInAnyOrder(
|
||||
assignment.stream().mapToLong(action -> action.getTarget().getId()).toArray());
|
||||
@@ -617,7 +623,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<Long> dsIds = distributionSets.stream().map(DistributionSet::getId).collect(Collectors.toList());
|
||||
targets.forEach(target -> {
|
||||
final List<Long> assignedDsIds = actionRepository.findByTargetControllerId(PAGE, target.getControllerId())
|
||||
.stream().map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
|
||||
.stream()
|
||||
.peek(a -> assertThat(a.getInitiatedBy()).as("Initiated by current user")
|
||||
.isEqualTo(tenantAware.getCurrentUsername()))
|
||||
.map(action -> action.getDistributionSet().getId()).collect(Collectors.toList());
|
||||
assertThat(assignedDsIds).containsExactlyInAnyOrderElementsOf(dsIds);
|
||||
});
|
||||
}
|
||||
@@ -647,6 +656,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
targets.forEach(target -> {
|
||||
actionRepository.findByTargetControllerId(PAGE, target.getControllerId()).forEach(action -> {
|
||||
assertThat(action.getDistributionSet().getId()).isIn(dsIds);
|
||||
assertThat(action.getInitiatedBy()).as("Should be Initiated by current user")
|
||||
.isEqualTo(tenantAware.getCurrentUsername());
|
||||
deploymentManagement.cancelAction(action.getId());
|
||||
});
|
||||
});
|
||||
@@ -851,7 +862,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(ds, savedDeployedTargets);
|
||||
|
||||
// verify that one Action for each assignDistributionSet
|
||||
assertThat(actionRepository.findAll(PAGE).getNumberOfElements()).as("wrong size of actions").isEqualTo(20);
|
||||
final Page<JpaAction> actions = actionRepository.findAll(PAGE);
|
||||
assertThat(actions.getNumberOfElements()).as("wrong size of actions").isEqualTo(20);
|
||||
assertThat(actions).as("Actions should be initiated by current user")
|
||||
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
||||
|
||||
final Iterable<Target> allFoundTargets = targetManagement.findAll(PAGE).getContent();
|
||||
|
||||
@@ -945,6 +959,8 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// retrieving all Actions created by the assignDistributionSet call
|
||||
final Page<JpaAction> page = actionRepository.findAll(PAGE);
|
||||
assertThat(page).as("Actions should be initiated by current user")
|
||||
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
||||
// and verify the number
|
||||
assertThat(page.getTotalElements()).as("wrong size of actions")
|
||||
.isEqualTo(noOfDeployedTargets * noOfDistributionSets);
|
||||
|
||||
@@ -252,6 +252,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest {
|
||||
// running
|
||||
final List<Action> runningActions = findActionsByRolloutAndStatus(createdRollout, Status.RUNNING);
|
||||
assertThat(runningActions).hasSize(amountTargetsForRollout / amountGroups);
|
||||
assertThat(runningActions).as("Created actions are initiated by rollout creator")
|
||||
.allMatch(a -> a.getInitiatedBy().equals(createdRollout.getCreatedBy()));
|
||||
// the rest targets are only scheduled
|
||||
assertThat(findActionsByRolloutAndStatus(createdRollout, Status.SCHEDULED))
|
||||
.hasSize(amountTargetsForRollout - (amountTargetsForRollout / amountGroups));
|
||||
|
||||
@@ -12,10 +12,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -26,6 +28,7 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
@@ -44,6 +47,9 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
@Autowired
|
||||
private AutoAssignChecker autoAssignChecker;
|
||||
|
||||
@Autowired
|
||||
private ActionRepository actionRepository;
|
||||
|
||||
@Test
|
||||
@Description("Verifies that a running action is auto canceled by a AutoAssignment which assigns another distribution-set.")
|
||||
public void autoAssignDistributionSetAndAutoCloseOldActions() {
|
||||
@@ -99,10 +105,11 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet setB = testdataFactory.createDistributionSet("dsB");
|
||||
|
||||
// target filter query that matches all targets
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement
|
||||
.create(entityFactory.targetFilterQuery().create().name("filterA").query("name==*"));
|
||||
targetFilterQueryManagement.updateAutoAssignDS(
|
||||
entityFactory.targetFilterQuery().updateAutoAssign(targetFilterQuery.getId()).ds(setA.getId()));
|
||||
final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.updateAutoAssignDS(
|
||||
entityFactory.targetFilterQuery()
|
||||
.updateAutoAssign(targetFilterQueryManagement.create(
|
||||
entityFactory.targetFilterQuery().create().name("filterA").query("name==*")).getId())
|
||||
.ds(setA.getId()));
|
||||
|
||||
final String targetDsAIdPref = "targ";
|
||||
final List<Target> targets = testdataFactory.createTargets(100, targetDsAIdPref,
|
||||
@@ -134,6 +141,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
// first 5 should keep their dsB, because they already had the dsA once
|
||||
verifyThatTargetsHaveDistributionSetAssignment(setB, targets.subList(0, 5), targetsCount);
|
||||
|
||||
verifyThatCreatedActionsAreInitiatedByCurrentUser(targetFilterQuery, setA, targets);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,6 +216,18 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
}
|
||||
|
||||
@Step
|
||||
private void verifyThatCreatedActionsAreInitiatedByCurrentUser(final TargetFilterQuery targetFilterQuery,
|
||||
final DistributionSet distributionSet, final List<Target> targets) {
|
||||
final Set<String> targetIds = targets.stream().map(Target::getControllerId).collect(Collectors.toSet());
|
||||
|
||||
actionRepository.findByDistributionSetId(Pageable.unpaged(), distributionSet.getId())
|
||||
.stream().filter(a -> targetIds.contains(a.getTarget().getControllerId()))
|
||||
.forEach(a -> assertThat(a.getInitiatedBy()).as(
|
||||
"Action should be initiated by the user who initiated the auto assignment")
|
||||
.isEqualTo(targetFilterQuery.getAutoAssignInitiatedBy()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test auto assignment of a distribution set with FORCED, SOFT and DOWNLOAD_ONLY action types")
|
||||
public void checkAutoAssignWithDifferentActionTypes() {
|
||||
|
||||
@@ -47,6 +47,7 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
action.setTarget(target);
|
||||
action.setStatus(Status.RUNNING);
|
||||
action.setWeight(45);
|
||||
action.setInitiatedBy(tenantAware.getCurrentUsername());
|
||||
target.addAction(action);
|
||||
|
||||
actionRepository.save(action);
|
||||
@@ -58,6 +59,7 @@ public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
newAction.setStatus(Status.RUNNING);
|
||||
newAction.setTarget(target);
|
||||
newAction.setWeight(45);
|
||||
newAction.setInitiatedBy(tenantAware.getCurrentUsername());
|
||||
actionRepository.save(newAction);
|
||||
target.addAction(newAction);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user