Multi-Asssignments feature removal (#2893)
* Multi-Asssignments feature removal Signed-off-by: strailov <Stanislav.Trailov@bosch.io> * fix some sonar findings Signed-off-by: strailov <Stanislav.Trailov@bosch.io> * fixes after review Signed-off-by: strailov <Stanislav.Trailov@bosch.io> --------- Signed-off-by: strailov <Stanislav.Trailov@bosch.io>
This commit is contained in:
committed by
GitHub
parent
2bf443661d
commit
c33156b134
@@ -1484,52 +1484,30 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
|
||||
.andExpect(jsonPath("total", equalTo(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigning targets multiple times to a DS in one request works in multi-assignment mode.
|
||||
*/
|
||||
@Test
|
||||
void multiAssignment() throws Exception {
|
||||
final List<String> targetIds = testdataFactory.createTargets(2).stream().map(Target::getControllerId).toList();
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
|
||||
final JSONArray body = new JSONArray();
|
||||
body.put(getAssignmentObject(targetIds.get(0), MgmtActionType.FORCED, 56));
|
||||
body.put(getAssignmentObject(targetIds.get(0), MgmtActionType.FORCED, 78));
|
||||
body.put(getAssignmentObject(targetIds.get(1), MgmtActionType.FORCED, 67));
|
||||
body.put(getAssignmentObject(targetIds.get(1), MgmtActionType.SOFT, 34));
|
||||
|
||||
enableMultiAssignments();
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
|
||||
.contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("total", equalTo(body.length())));
|
||||
}
|
||||
|
||||
/**
|
||||
* An assignment request containing a weight is only accepted when weight is valide and multi assignment is on.
|
||||
*/
|
||||
@Test
|
||||
void weightValidation() throws Exception {
|
||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
final Long dsId1 = testdataFactory.createDistributionSet().getId();
|
||||
final Long dsId2 = testdataFactory.createDistributionSet().getId();
|
||||
final int weight = 78;
|
||||
|
||||
final JSONArray bodyValide = new JSONArray().put(getAssignmentObject(targetId, MgmtActionType.FORCED, weight));
|
||||
final JSONArray bodyInvalide = new JSONArray()
|
||||
.put(getAssignmentObject(targetId, MgmtActionType.FORCED, Action.WEIGHT_MIN - 1));
|
||||
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString())
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId1).content(bodyValide.toString())
|
||||
.contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
enableMultiAssignments();
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyInvalide.toString())
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId2).content(bodyInvalide.toString())
|
||||
.contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString())
|
||||
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId2).content(bodyValide.toString())
|
||||
.contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
@@ -105,7 +105,6 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void getRollout() throws Exception {
|
||||
enableMultiAssignments();
|
||||
approvalStrategy.setApprovalNeeded(true);
|
||||
try {
|
||||
approvalStrategy.setApprovalDecidedBy("exampleUsername");
|
||||
@@ -1678,26 +1677,20 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
null, null);
|
||||
final String valideWeightRequest = JsonBuilder.rollout("withWeight", "d", 2, dsId, "id==rollout*",
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, weight, null, null, null);
|
||||
final String valideWeightRequestMultiAssignment = JsonBuilder.rollout("withWeightMultiAssignment", "d", 2, dsId, "id==rollout*",
|
||||
new RolloutGroupConditionBuilder().withDefaults().build(), null, null, weight, null, null, null);
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts").content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated());
|
||||
enableMultiAssignments();
|
||||
|
||||
mvc.perform(post("/rest/v1/rollouts").content(invalideWeightRequest).contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
|
||||
mvc.perform(post("/rest/v1/rollouts").content(valideWeightRequestMultiAssignment).contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated());
|
||||
|
||||
final List<Rollout> rollouts = rolloutManagement.findAll(false, PAGE).getContent();
|
||||
assertThat(rollouts).hasSize(2);
|
||||
assertThat(rollouts).hasSize(1);
|
||||
assertThat(rollouts.get(0).getWeight()).get().isEqualTo(weight);
|
||||
}
|
||||
|
||||
|
||||
@@ -560,7 +560,6 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
|
||||
*/
|
||||
@Test
|
||||
void createAutoAssignDS() throws Exception {
|
||||
enableMultiAssignments();
|
||||
enableConfirmationFlow();
|
||||
|
||||
final String filterName = "filter_01";
|
||||
@@ -643,7 +642,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
|
||||
filterId).content(valideWeightRequest).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
enableMultiAssignments();
|
||||
|
||||
mvc.perform(post(MgmtTargetFilterQueryRestApi.TARGETFILTERS_V1 + "/{targetFilterQueryId}/autoAssignDS",
|
||||
filterId).content(invalideWeightRequest).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
|
||||
@@ -2213,24 +2213,6 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("total", equalTo(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign multiple DSs to a target in one request with multiassignments enabled.
|
||||
*/
|
||||
@Test
|
||||
void multiAssignment() throws Exception {
|
||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||
final List<Long> dsIds = testdataFactory.createDistributionSets(2).stream().map(DistributionSet::getId).toList();
|
||||
|
||||
final JSONArray body = new JSONArray();
|
||||
dsIds.forEach(id -> body.put(getAssignmentObject(id, MgmtActionType.FORCED, 76)));
|
||||
|
||||
enableMultiAssignments();
|
||||
mvc.perform(post("/rest/v1/targets/{targetId}/assignedDS", targetId).content(body.toString()).contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("total", equalTo(2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* An assignment request containing a weight is only accepted when weight is valid and multi assignment is on.
|
||||
*/
|
||||
@@ -2243,7 +2225,6 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final JSONObject bodyValid = getAssignmentObject(dsId, MgmtActionType.FORCED, weight);
|
||||
final JSONObject bodyInvalid = getAssignmentObject(dsId, MgmtActionType.FORCED, Action.WEIGHT_MIN - 1);
|
||||
|
||||
enableMultiAssignments();
|
||||
mvc.perform(post("/rest/v1/targets/{targetId}/assignedDS", targetId).content(bodyInvalid.toString()).contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest())
|
||||
@@ -2272,48 +2253,24 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
/**
|
||||
* An assignment request containing a valid weight when multi assignment is on.
|
||||
*/
|
||||
@Test
|
||||
void weightWithMultiAssignment() throws Exception {
|
||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
final int weight = 98;
|
||||
|
||||
final JSONObject bodyValid = getAssignmentObject(dsId, MgmtActionType.FORCED, weight);
|
||||
|
||||
enableMultiAssignments();
|
||||
mvc.perform(post("/rest/v1/targets/{targetId}/assignedDS", targetId).content(bodyValid.toString()).contentType(APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
final List<Action> actions = deploymentManagement.findActionsAll(PAGE).get().toList();
|
||||
assertThat(actions).size().isEqualTo(1);
|
||||
assertThat(actions.get(0).getWeight()).get().isEqualTo(weight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get weight of action
|
||||
*/
|
||||
@Test
|
||||
void getActionWeight() throws Exception {
|
||||
final String targetId = testdataFactory.createTarget().getControllerId();
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
final int customWeightHigh = 800;
|
||||
final int customWeightLow = 300;
|
||||
assignDistributionSet(dsId, targetId); // default weight 1000
|
||||
enableMultiAssignments();
|
||||
assignDistributionSet(dsId, targetId, customWeightHigh);
|
||||
assignDistributionSet(dsId, targetId, customWeightLow);
|
||||
final Long dsId1 = testdataFactory.createDistributionSet().getId();
|
||||
final Long dsId2 = testdataFactory.createDistributionSet().getId();
|
||||
final int customWeight = 800;
|
||||
assignDistributionSet(dsId1, targetId); // default weight 1000
|
||||
assignDistributionSet(dsId2, targetId, customWeight);
|
||||
|
||||
mvc.perform(get("/rest/v1/targets/{targetId}/actions", targetId)
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "WEIGHT:ASC"))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("content.[0].weight", equalTo(customWeightLow)))
|
||||
.andExpect(jsonPath("content.[1].weight", equalTo(customWeightHigh)))
|
||||
.andExpect(jsonPath("content.[2].weight", equalTo(1000)));
|
||||
.andExpect(jsonPath("content.[0].weight", equalTo(customWeight)))
|
||||
.andExpect(jsonPath("content.[1].weight", equalTo(1000)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,6 @@ import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.get
|
||||
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.withUser;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_ENABLED;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.MULTI_ASSIGNMENTS_ENABLED;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED;
|
||||
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
@@ -141,27 +140,6 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
|
||||
assertDefaultDsTypeUpdateBadRequestFails(newDefaultDsType, oldDefaultDsType, status().isNotFound());
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'multi.assignments.enabled' property must not be changed to false.
|
||||
*/
|
||||
@Test
|
||||
void deactivateMultiAssignment() throws Exception {
|
||||
final String bodyActivate = new JSONObject().put("value", true).toString();
|
||||
final String bodyDeactivate = new JSONObject().put("value", false).toString();
|
||||
|
||||
mvc.perform(put(SYSTEM_V1 + "/configs/{keyName}", MULTI_ASSIGNMENTS_ENABLED)
|
||||
.content(bodyActivate)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
mvc.perform(put(SYSTEM_V1 + "/configs/{keyName}", MULTI_ASSIGNMENTS_ENABLED)
|
||||
.content(bodyDeactivate)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
/**
|
||||
* The Batch configuration should not be applied, because of invalid TenantConfiguration props
|
||||
*/
|
||||
@@ -249,36 +227,6 @@ public class MgmtTenantManagementResourceTest extends AbstractManagementApiInteg
|
||||
"Change BatchConfiguration was successful but TenantConfiguration property was not actually changed.");
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'repository.actions.autoclose.enabled' property must not be modified if Multi-Assignments is enabled.
|
||||
*/
|
||||
@Test
|
||||
void autoCloseCannotBeModifiedIfMultiAssignmentIsEnabled() throws Exception {
|
||||
final String bodyActivate = new JSONObject().put("value", true).toString();
|
||||
final String bodyDeactivate = new JSONObject().put("value", false).toString();
|
||||
|
||||
// enable Multi-Assignments
|
||||
mvc.perform(put(SYSTEM_V1 + "/configs/{keyName}", MULTI_ASSIGNMENTS_ENABLED)
|
||||
.content(bodyActivate)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
// try to enable Auto-Close
|
||||
mvc.perform(put(SYSTEM_V1 + "/configs/{keyName}", REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED)
|
||||
.content(bodyActivate)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
// try to disable Auto-Close
|
||||
mvc.perform(put(SYSTEM_V1 + "/configs/{keyName}", REPOSITORY_ACTIONS_AUTOCLOSE_ENABLED)
|
||||
.content(bodyDeactivate)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles DELETE request deleting a tenant specific configuration.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user