diff --git a/README.md b/README.md index 5fa61dab1..990707312 100644 --- a/README.md +++ b/README.md @@ -100,4 +100,7 @@ $ java -jar ./examples/hawkbit-example-mgmt-simulator/target/hawkbit-example-mgm hawkBit is currently in '0.X' semantic version. That is due to the need that there is still content in hawkBit that is in need for refactoring. That includes the maven module structure, Spring Boot Properties, Spring Boot auto configuration as well as internal Java APIs (e.g. the [repository API](https://github.com/eclipse/hawkbit/issues/197) ). -However, the external APIs (i.e. [Management API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-mgmt-api), [DDI API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-ddi-api), [DDI Artifact Download API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-ddi-dl-api) and [DMF API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-dmf/hawkbit-dmf-api) are on major version 'v1' and will be kept stable. +However, the device facing [DDI API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-ddi-api) is on major version 'v1' and will be kept stable. + +Server facing and [DMF API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-dmf/hawkbit-dmf-api) are [Management API](https://github.com/eclipse/hawkbit/tree/master/hawkbit-mgmt-api) are on v1 as well. However, we cannot fully guarantee the same stability during hawkBit's 0.X development but we will try as best we can. + diff --git a/examples/hawkbit-device-simulator/README.md b/examples/hawkbit-device-simulator/README.md index 79c0217d8..4d8183dd7 100644 --- a/examples/hawkbit-device-simulator/README.md +++ b/examples/hawkbit-device-simulator/README.md @@ -27,8 +27,10 @@ This can be configured/disabled by spring boot properties ## hawkBit APIs The simulator supports `DDI` as well as the `DMF` integration APIs. -In case there is no AMQP message broker (like rabbitMQ) running, you can disable the AMQP support for the device simulator, so the simulator is not trying to connect to an amqp message broker. -Configuration property `hawkbit.device.simulator.amqp.enabled=true` + +In case there is no AMQP message broker (like rabbitMQ) running, you can disable the AMQP support for the device simulator, so the simulator is not trying to connect to an amqp message broker. + +Configuration property `hawkbit.device.simulator.amqp.enabled=false` ## Usage diff --git a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java index 7b911e5b8..7f3c1d2ce 100644 --- a/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java +++ b/examples/hawkbit-example-mgmt-simulator/src/main/java/org/eclipse/hawkbit/mgmt/client/scenarios/ConfigurableScenario.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.mgmt.client.scenarios; +import java.math.BigDecimal; import java.security.SecureRandom; import java.util.List; import java.util.Random; @@ -316,31 +317,38 @@ public class ConfigurableScenario { private void createDistributionSets(final Scenario scenario) { LOGGER.info("Creating {} distribution sets", scenario.getDistributionSets()); + final BigDecimal pages = new BigDecimal(scenario.getDistributionSets()) + .divide(new BigDecimal(PAGE_SIZE), BigDecimal.ROUND_UP).max(new BigDecimal(1)); + + IntStream.range(0, pages.intValue()).parallel().forEach(i -> createDistributionSetPage(scenario, i)); + LOGGER.info("Creating {} distribution sets -> Done", scenario.getDistributionSets()); + } + + private void createDistributionSetPage(final Scenario scenario, final int page) { final List sets = distributionSetResource .createDistributionSets(new DistributionSetBuilder().name(scenario.getDsName()).type("os_app") - .version("1.0.").buildAsList(scenario.getDistributionSets())) + .version("1.0.").buildAsList(calculateOffset(page), + (page + 1) * PAGE_SIZE > scenario.getDistributionSets() + ? (scenario.getDistributionSets() - calculateOffset(page)) : PAGE_SIZE)) .getBody(); assignSoftwareModulesTo(scenario, sets); - tagDistributionSets(scenario, sets); + tagDistributionSets(page, sets); - LOGGER.info("Creating {} distribution sets -> Done", scenario.getDistributionSets()); } - private void tagDistributionSets(final Scenario scenario, final List sets) { - for (int i = 0; i < scenario.getDsTags(); i++) { - final MgmtTag tag = distributionSetTagResource - .createDistributionSetTags( - new TagBuilder().name("DS Tag" + i).description("DS tag for DS " + i).build()) - .getBody().get(0); + private void tagDistributionSets(final int page, final List sets) { + final MgmtTag tag = distributionSetTagResource + .createDistributionSetTags( + new TagBuilder().name("Page " + page).description("DS tag for DS page" + page).build()) + .getBody().get(0); - distributionSetTagResource.assignDistributionSets(tag.getTagId(), - sets.stream().map( - set -> new MgmtAssignedDistributionSetRequestBody().setDistributionSetId(set.getDsId())) - .collect(Collectors.toList())); - } + distributionSetTagResource.assignDistributionSets(tag.getTagId(), + sets.stream() + .map(set -> new MgmtAssignedDistributionSetRequestBody().setDistributionSetId(set.getDsId())) + .collect(Collectors.toList())); } private void assignSoftwareModulesTo(final Scenario scenario, final List sets) { @@ -379,8 +387,10 @@ public class ConfigurableScenario { private void createTargets(final Scenario scenario, final List deviceGroupTags) { LOGGER.info("Creating {} targets", scenario.getTargets()); - IntStream.range(0, scenario.getTargets() / PAGE_SIZE).parallel() - .forEach(i -> createTargetPage(scenario, i, deviceGroupTags)); + final BigDecimal pages = new BigDecimal(scenario.getTargets()) + .divide(new BigDecimal(PAGE_SIZE), BigDecimal.ROUND_UP).max(new BigDecimal(1)); + + IntStream.range(0, pages.intValue()).parallel().forEach(i -> createTargetPage(scenario, i, deviceGroupTags)); LOGGER.info("Creating {} targets -> Done", scenario.getTargets()); } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java index 1eeebf049..25cfb2934 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TagFields.java @@ -14,6 +14,11 @@ package org.eclipse.hawkbit.repository; * */ public enum TagFields implements FieldNameProvider { + /** + * The id field. + */ + ID("id"), + /** * The name field. */ diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java index 1cee4c369..e41cf1893 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryFields.java @@ -34,7 +34,6 @@ public enum TargetFilterQueryFields implements FieldNameProvider { */ AUTOASSIGNDISTRIBUTIONSET("autoAssignDistributionSet", "name", "version"); - private final String fieldName; private List subEntityAttributes; private boolean mapField; diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 70583ae1d..c1b3678da 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -161,7 +161,7 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest { public void downloadArtifactThroughFileName() throws Exception { downLoadProgress = 1; shippedBytes = 0; - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0); // create target final Target target = testdataFactory.createTarget(); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index a00a3e343..c5d8e1bbd 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -126,13 +126,14 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { // Retrieved is reported List activeActionsByTarget = deploymentManagement - .findActiveActionsByTarget(savedTarget.getControllerId()); + .findActiveActionsByTarget(PAGE, savedTarget.getControllerId()).getContent(); assertThat(activeActionsByTarget).hasSize(1); assertThat(activeActionsByTarget.get(0).getStatus()).isEqualTo(Status.RUNNING); final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId()); - activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()); + activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent(); // the canceled action should still be active! assertThat(cancelAction.isActive()).isTrue(); @@ -174,7 +175,8 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()); + activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent(); assertThat(activeActionsByTarget).hasSize(0); final Action canceledAction = deploymentManagement.findAction(cancelAction.getId()).get(); assertThat(canceledAction.isActive()).isFalse(); @@ -241,14 +243,14 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "proceeding")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3); mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" @@ -256,7 +258,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "resumed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4); mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" @@ -265,30 +267,30 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); // cancellation canceled -> should remove the action from active - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "canceled")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); // cancellation rejected -> action still active until controller close // it // with finished or // error - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant()) .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "rejected")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); // update closed -> should remove the action from active mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/deploymentBase/" @@ -297,7 +299,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(0); } @Test @@ -325,12 +327,12 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3); // 3 update actions, 0 cancel actions - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(3); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(3); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(3); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(3); final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId()); final Action cancelAction2 = deploymentManagement.cancelAction(updateAction2.getId()); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(3); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(3); assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3); mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)) @@ -357,7 +359,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); // 1 update actions, 1 cancel actions - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3); mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction2.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)) @@ -391,12 +393,12 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10); // 1 update actions, 0 cancel actions - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); final Action cancelAction3 = deploymentManagement.cancelAction(updateAction3.getId()); // action is in cancelling state - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3); assertThat(deploymentManagement.getAssignedDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get()) .isEqualTo(ds3); @@ -418,7 +420,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest { assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(13); // final status - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(0); assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3); } diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index cb895adb5..13b7f5c1c 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -119,24 +119,26 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final Target savedTarget = testdataFactory.createTarget("4712"); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).isEmpty(); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).isEmpty(); assertThat(deploymentManagement.countActionsAll()).isEqualTo(0); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED, RepositoryModelConstants.NO_FORCE_TIME, Lists.newArrayList(savedTarget.getControllerId())) .getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); - final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action action = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); assertThat(deploymentManagement.countActionsAll()).isEqualTo(1); saved = assignDistributionSet(ds2, saved).getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); assertThat(deploymentManagement.countActionsAll()).isEqualTo(2); - final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action uaction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); assertThat(uaction.getDistributionSet()).isEqualTo(ds); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); // Run test long current = System.currentTimeMillis(); @@ -234,7 +236,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { Lists.newArrayList(target.getControllerId())); final Action action = deploymentManagement - .findActiveActionsByTarget(result.getAssignedEntity().get(0).getControllerId()).get(0); + .findActiveActionsByTarget(PAGE, result.getAssignedEntity().get(0).getControllerId()).getContent() + .get(0); MvcResult mvcResult = mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -278,24 +281,26 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final Target savedTarget = testdataFactory.createTarget("4712"); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).isEmpty(); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).isEmpty(); assertThat(deploymentManagement.countActionsAll()).isEqualTo(0); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.SOFT, RepositoryModelConstants.NO_FORCE_TIME, Lists.newArrayList(savedTarget.getControllerId())) .getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); - final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action action = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); assertThat(deploymentManagement.countActionsAll()).isEqualTo(1); saved = assignDistributionSet(ds2, saved).getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); assertThat(deploymentManagement.countActionsAll()).isEqualTo(2); - final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action uaction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); assertThat(uaction.getDistributionSet()).isEqualTo(ds); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); // Run test @@ -391,23 +396,25 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final Target savedTarget = testdataFactory.createTarget("4712"); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).isEmpty(); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).isEmpty(); assertThat(deploymentManagement.countActionsAll()).isEqualTo(0); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.TIMEFORCED, System.currentTimeMillis(), Lists.newArrayList(savedTarget.getControllerId())).getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(1); - final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action action = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); assertThat(deploymentManagement.countActionsAll()).isEqualTo(1); saved = assignDistributionSet(ds2, saved).getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); - final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action uaction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); assertThat(uaction.getDistributionSet()).isEqualTo(ds); - assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId())).hasSize(2); // Run test @@ -538,7 +545,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet(""); assignDistributionSet(ds.getId(), "4712"); - final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent() + final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent() .get(0); final String feedback = JsonBuilder.deploymentActionFeedback(action.getId().toString(), "proceeding"); @@ -579,7 +586,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { Target myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(3); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(3); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId())).isNotPresent(); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.UNKNOWN)) @@ -594,7 +601,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(2); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId()).get()).isEqualTo(ds1); @@ -612,7 +619,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId()).get()).isEqualTo(ds2); actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")) @@ -628,7 +635,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); assertThat(deploymentManagement.getInstalledDistributionSet(myT.getControllerId()).get()).isEqualTo(ds3); actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")) @@ -650,7 +657,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { assertThat(targetManagement.findTargetByControllerID("4712").get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); assignDistributionSet(ds, toAssign); - final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent() + final Action action = deploymentManagement.findActionsByDistributionSet(PAGE, ds.getId()).getContent() .get(0); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -668,7 +675,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .hasSize(1); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); assertThat(deploymentManagement.countActionsByTarget(myT.getControllerId())).isEqualTo(1); final Iterable actionStatusMessages = deploymentManagement .findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")).getContent(); @@ -678,7 +685,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { // redo ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId()).get(); assignDistributionSet(ds, Lists.newArrayList(targetManagement.findTargetByControllerID("4712").get())); - final Action action2 = deploymentManagement.findActiveActionsByTarget(myT.getControllerId()).get(0); + final Action action2 = deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId()) + .getContent().get(0); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback", tenantAware.getCurrentTenant()) @@ -694,12 +702,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .hasSize(0); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(1); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0); - assertThat(deploymentManagement.findInActiveActionsByTarget(myT.getControllerId())).hasSize(2); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); + assertThat(deploymentManagement.findInActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(2); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.ERROR)); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, action2.getId()).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusByAction(PAGE, action2.getId()).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); } @@ -716,13 +724,13 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { Target myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); assignDistributionSet(ds, toAssign); - final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent() + final Action action = deploymentManagement.findActionsByDistributionSet(PAGE, ds.getId()).getContent() .get(0); myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(0); - assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1); + assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), PAGE)).hasSize(0); + assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), PAGE)).hasSize(1); // Now valid Feedback for (int i = 0; i < 4; i++) { @@ -741,9 +749,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .hasSize(0); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(5, new ActionStatusCondition(Status.RUNNING)); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -759,9 +767,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .hasSize(0); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(5, new ActionStatusCondition(Status.RUNNING)); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -777,9 +785,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .hasSize(0); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(6, new ActionStatusCondition(Status.RUNNING)); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -789,7 +797,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING)) .hasSize(1); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) @@ -798,9 +806,9 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .hasSize(0); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(7, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(7, new ActionStatusCondition(Status.RUNNING)); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -810,13 +818,13 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(6, new ActionStatusCondition(Status.RUNNING)); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.WARNING)); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -826,24 +834,24 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); myT = targetManagement.findTargetByControllerID("4712").get(); assertThat(myT.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); - assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, myT.getControllerId())).hasSize(0); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR)) .hasSize(0); assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(1); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(7, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(7, new ActionStatusCondition(Status.RUNNING)); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.WARNING)); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); - assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusAll(PAGE).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); - assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(1); - assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1); + assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), PAGE)).hasSize(1); + assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), PAGE)).hasSize(1); } @Test @@ -873,8 +881,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { savedTarget = assignDistributionSet(savedSet, toAssign).getAssignedEntity().iterator().next(); assignDistributionSet(savedSet2, toAssign2); - final Action updateAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()) - .get(0); + final Action updateAction = deploymentManagement + .findActiveActionsByTarget(PAGE, savedTarget.getControllerId()).getContent().get(0); // action exists but is not assigned to this target mvc.perform(post("/{tenant}/controller/v1/4713/deploymentBase/" + updateAction.getId() + "/feedback", @@ -907,7 +915,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet(""); assignDistributionSet(ds.getId(), "1080"); - final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent() + final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent() .get(0); mvc.perform(post("/{tenant}/controller/v1/1080/deploymentBase/" + action.getId() + "/feedback", @@ -929,7 +937,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet(""); assignDistributionSet(ds.getId(), "1080"); - final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent() + final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent() .get(0); final String missingResultInFeedback = JsonBuilder.missingResultInFeedback(action.getId().toString(), "closed", "test"); @@ -953,7 +961,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet(""); assignDistributionSet(ds.getId(), "1080"); - final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent() + final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE).getContent() .get(0); final String missingFinishedResultInFeedback = JsonBuilder .missingFinishedResultInFeedback(action.getId().toString(), "closed", "test"); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index 43bf8fd57..0e742e380 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -198,7 +198,8 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { assignDistributionSet(ds.getId(), "4711"); - final Action updateAction = deploymentManagement.findActiveActionsByTarget(target.getControllerId()).get(0); + final Action updateAction = deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId()) + .getContent().get(0); final String etagWithFirstUpdate = mvc .perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) .header("If-None-Match", etag).accept(MediaType.APPLICATION_JSON)) @@ -231,7 +232,8 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { assignDistributionSet(ds2.getId(), "4711"); - final Action updateAction2 = deploymentManagement.findActiveActionsByTarget(target.getControllerId()).get(0); + final Action updateAction2 = deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId()) + .getContent().get(0); mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) .header("If-None-Match", etagWithFirstUpdate).accept(MediaType.APPLICATION_JSON)) @@ -329,7 +331,8 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest { Target savedTarget = testdataFactory.createTarget("911"); savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator() .next(); - final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + final Action savedAction = deploymentManagement + .findActiveActionsByTarget(PAGE, savedTarget.getControllerId()).getContent().get(0); mvc.perform(post("/{tenant}/controller/v1/911/deploymentBase/" + savedAction.getId() + "/feedback", tenantAware.getCurrentTenant()) .content(JsonBuilder.deploymentActionFeedback(savedAction.getId().toString(), "proceeding")) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java index c1f4e2424..9cf85cdfc 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java @@ -150,9 +150,10 @@ public class DosFilterTest extends AbstractDDiApiIntegrationTest { final List toAssign = Lists.newArrayList(target); final Iterable saved = assignDistributionSet(ds, toAssign).getAssignedEntity(); - assertThat(deploymentManagement.findActiveActionsByTarget(target.getControllerId())).hasSize(1); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId())).hasSize(1); - final Action uaction = deploymentManagement.findActiveActionsByTarget(target.getControllerId()).get(0); + final Action uaction = deploymentManagement.findActiveActionsByTarget(PAGE, target.getControllerId()) + .getContent().get(0); return uaction.getId(); } diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java new file mode 100644 index 000000000..e0d14671e --- /dev/null +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java @@ -0,0 +1,627 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.integration; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; +import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; +import org.eclipse.hawkbit.dmf.amqp.api.MessageType; +import org.eclipse.hawkbit.dmf.json.model.ActionStatus; +import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; +import org.eclipse.hawkbit.dmf.json.model.AttributeUpdate; +import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetPollEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +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.model.Action.Status; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.test.matcher.Expect; +import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessageProperties; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Component Tests - Device Management Federation API") +@Stories("Amqp Message Handler Service") +public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegrationTest { + + @Test + @Description("Tests register target") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 2), + @Expect(type = TargetPollEvent.class, count = 3) }) + public void registerTargets() { + registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1); + + final String target2 = "Target2"; + registerAndAssertTargetWithExistingTenant(target2, 2); + final Long pollingTimeTarget2 = controllerManagement.findByControllerId(target2).get().getLastTargetQuery(); + registerSameTargetAndAssertBasedOnLastPolling(target2, 2, TargetUpdateStatus.REGISTERED, pollingTimeTarget2); + Mockito.verifyZeroInteractions(getDeadletterListener()); + } + + @Test + @Description("Tests register invalid target withy empty controller id. Tests register invalid target with null controller id") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void registerEmptyTarget() { + createAndSendTarget("", TENANT_EXIST); + assertAllTargetsCount(0); + verifyDeadLetterMessages(1); + + } + + @Test + @Description("Tests register invalid target with whitspace controller id. Tests register invalid target with null controller id") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void registerWhitespaceTarget() { + createAndSendTarget("Invalid Invalid", TENANT_EXIST); + assertAllTargetsCount(0); + verifyDeadLetterMessages(1); + + } + + @Test + @Description("Tests register invalid target with null controller id. Tests register invalid target with null controller id") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void registerInvalidNullTargets() { + createAndSendTarget(null, TENANT_EXIST); + assertAllTargetsCount(0); + verifyDeadLetterMessages(1); + + } + + @Test + @Description("Tests not allowed content-type in message. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void wrongContentType() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, TENANT_EXIST); + createTargetMessage.getMessageProperties().setContentType("WrongContentType"); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests null reply to property in message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void missingReplyToProperty() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, TENANT_EXIST); + createTargetMessage.getMessageProperties().setReplyTo(null); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests missing reply to property in message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void emptyReplyToProperty() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, TENANT_EXIST); + createTargetMessage.getMessageProperties().setReplyTo(""); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests missing thing id property in message. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void missingThingIdProperty() { + final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); + createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.THING_ID); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests null thing id property in message. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void nullThingIdProperty() { + final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests missing tenant message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void missingTenantHeader() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, TENANT_EXIST); + createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TENANT); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests null tenant message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void nullTenantHeader() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, null); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests empty tenant message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void emptyTenantHeader() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, ""); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests tenant not exist. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void tenantNotExist() { + final Message createTargetMessage = createTargetMessage(REGISTER_TARGET, "TenantNotExist"); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertThat(systemManagement.findTenants(pageReq)).hasSize(1); + } + + @Test + @Description("Tests missing type message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void missingTypeHeader() { + final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); + createTargetMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TYPE); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests null type message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void nullTypeHeader() { + final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); + createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, null); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests empty type message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void emptyTypeHeader() { + final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); + createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, ""); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests invalid type message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void invalidTypeHeader() { + final Message createTargetMessage = createTargetMessage(null, TENANT_EXIST); + createTargetMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TYPE, "NotExist"); + getDmfClient().send(createTargetMessage); + + verifyDeadLetterMessages(1); + assertAllTargetsCount(0); + } + + @Test + @Description("Tests null topic message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void nullTopicHeader() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, ""); + eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, null); + getDmfClient().send(eventMessage); + + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests null topic message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void emptyTopicHeader() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, ""); + eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, ""); + getDmfClient().send(eventMessage); + + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests null topic message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void invalidTopicHeader() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, ""); + eventMessage.getMessageProperties().getHeaders().put(MessageHeaderKey.TOPIC, "NotExist"); + getDmfClient().send(eventMessage); + + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests missing topic message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void missingTopicHeader() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, ""); + eventMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.TOPIC); + getDmfClient().send(eventMessage); + + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests invalid null message content. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void updateActionStatusWithNullContent() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, null); + getDmfClient().send(eventMessage); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests invalid empty message content. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void updateActionStatusWithEmptyContent() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, ""); + getDmfClient().send(eventMessage); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests invalid json message content. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void updateActionStatusWithInvalidJsonContent() { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, + "Invalid Content"); + getDmfClient().send(eventMessage); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests invalid topic message header. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void updateActionStatusWithInvalidActionId() { + final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus(1L, ActionStatus.RUNNING); + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, + actionUpdateStatus); + getDmfClient().send(eventMessage); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Tests register target and cancel a assignment") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) + public void finishActionStatus() { + registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.FINISHED, Status.FINISHED); + } + + @Test + @Description("Register a target and send a update action status (running). Verfiy if the updated action status is correct.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 0), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void runningActionStatus() { + registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.RUNNING, Status.RUNNING); + } + + @Test + @Description("Register a target and send a update action status (download). Verfiy if the updated action status is correct.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void downloadActionStatus() { + registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.DOWNLOAD, Status.DOWNLOAD); + } + + @Test + @Description("Register a target and send a update action status (error). Verfiy if the updated action status is correct.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 2), @Expect(type = TargetPollEvent.class, count = 1) }) + public void errorActionStatus() { + registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.ERROR, Status.ERROR); + } + + @Test + @Description("Register a target and send a update action status (warning). Verfiy if the updated action status is correct.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void warningActionStatus() { + registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.WARNING, Status.WARNING); + } + + @Test + @Description("Register a target and send a update action status (retrieved). Verfiy if the updated action status is correct.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void retrievedActionStatus() { + registerTargetAndSendAndAssertUpdateActionStatus(ActionStatus.RETRIEVED, Status.RETRIEVED); + } + + @Test + @Description("Register a target and send a invalid update action status (cancel). This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void cancelNotAllowActionStatus() { + registerTargetAndSendActionStatus(ActionStatus.CANCELED); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Verfiy receiving a download and install message if a deployment is done before the target has polled the first time.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void receiveDownLoadAndInstallMessageAfterAssignment() { + + // setup + controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, null); + final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString()); + assignDistributionSet(distributionSet.getId(), REGISTER_TARGET); + + // test + registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1, TargetUpdateStatus.PENDING, "bumlux"); + + // verify + assertDownloadAndInstallMessage(distributionSet.getModules()); + Mockito.verifyZeroInteractions(getDeadletterListener()); + } + + @Test + @Description("Verfiy receiving a cancel update message if a deployment is canceled before the target has polled the first time.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = CancelTargetAssignmentEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1), + @Expect(type = TargetPollEvent.class, count = 1) }) + public void receiveCancelUpdateMessageAfterAssignmentWasCanceled() { + + // Setup + controllerManagement.findOrRegisterTargetIfItDoesNotexist(REGISTER_TARGET, null); + final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString()); + final DistributionSetAssignmentResult distributionSetAssignmentResult = assignDistributionSet( + distributionSet.getId(), REGISTER_TARGET); + deploymentManagement.cancelAction(distributionSetAssignmentResult.getActions().get(0)); + + // test + registerAndAssertTargetWithExistingTenant(REGISTER_TARGET, 1, TargetUpdateStatus.PENDING, "bumlux"); + + // verify + assertCancelActionMessage(distributionSetAssignmentResult.getActions().get(0)); + Mockito.verifyZeroInteractions(getDeadletterListener()); + } + + @Test + @Description("Register a target and send a invalid update action status (canceled). The current status (pending) is not a canceling state. This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = CancelTargetAssignmentEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void actionNotExists() { + final Long actionId = registerTargetAndCancelActionId(); + final Long actionNotExist = actionId + 1; + + sendActionUpdateStatus(new ActionUpdateStatus(actionNotExist, ActionStatus.CANCELED)); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Register a target and send a invalid update action status (cancel_rejected). This message should forwarded to the deadletter queue") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void canceledRejectedNotAllowActionStatus() { + registerTargetAndSendActionStatus(ActionStatus.CANCEL_REJECTED); + verifyDeadLetterMessages(1); + } + + @Test + @Description("Register a target and send a valid update action status (cancel_rejected). Verfiy if the updated action status is correct.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetAssignDistributionSetEvent.class, count = 1), + @Expect(type = CancelTargetAssignmentEvent.class, count = 1), + @Expect(type = ActionUpdatedEvent.class, count = 1), @Expect(type = ActionCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void canceledRejectedActionStatus() { + final Long actionId = registerTargetAndCancelActionId(); + + sendActionUpdateStatus(new ActionUpdateStatus(actionId, ActionStatus.CANCEL_REJECTED)); + assertAction(actionId, Status.RUNNING, Status.CANCELING, Status.CANCEL_REJECTED); + } + + @Test + @Description("Verify that sending an update controller attribute message to an existing target works.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 1), @Expect(type = TargetPollEvent.class, count = 1) }) + public void updateAttributes() { + + // setup + final String target = "ControllerAttributeTestTarget"; + registerAndAssertTargetWithExistingTenant(target, 1); + final AttributeUpdate controllerAttribute = new AttributeUpdate(); + controllerAttribute.getAttributes().put("test1", "testA"); + controllerAttribute.getAttributes().put("test2", "testB"); + + // test + sendUpdateAttributeMessage(target, TENANT_EXIST, controllerAttribute); + + // validate + assertUpdateAttributes(target, controllerAttribute.getAttributes()); + } + + @Test + @Description("Verify that sending an update controller attribute message with no thingid header to an existing target does not work.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 0), @Expect(type = TargetPollEvent.class, count = 1) }) + public void updateAttributesWithNoThingId() { + + // setup + final String target = "ControllerAttributeTestTarget"; + registerAndAssertTargetWithExistingTenant(target, 1); + final AttributeUpdate controllerAttribute = new AttributeUpdate(); + controllerAttribute.getAttributes().put("test1", "testA"); + controllerAttribute.getAttributes().put("test2", "testB"); + final Message createUpdateAttributesMessage = createUpdateAttributesMessage(null, TENANT_EXIST, + controllerAttribute); + createUpdateAttributesMessage.getMessageProperties().getHeaders().remove(MessageHeaderKey.THING_ID); + + // test + getDmfClient().send(createUpdateAttributesMessage); + + // verify + verifyDeadLetterMessages(1); + final AttributeUpdate controllerAttributeEmpty = new AttributeUpdate(); + assertUpdateAttributes(target, controllerAttributeEmpty.getAttributes()); + } + + @Test + @Description("Verify that sending an update controller attribute message with invalid body to an existing target does not work.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1), + @Expect(type = TargetUpdatedEvent.class, count = 0), @Expect(type = TargetPollEvent.class, count = 1) }) + public void updateAttributesWithWrongBody() { + + // setup + final String target = "ControllerAttributeTestTarget"; + registerAndAssertTargetWithExistingTenant(target, 1); + final AttributeUpdate controllerAttribute = new AttributeUpdate(); + controllerAttribute.getAttributes().put("test1", "testA"); + controllerAttribute.getAttributes().put("test2", "testB"); + final Message createUpdateAttributesMessageWrongBody = createUpdateAttributesMessageWrongBody(target, + TENANT_EXIST); + + // test + getDmfClient().send(createUpdateAttributesMessageWrongBody); + + // verify + verifyDeadLetterMessages(1); + } + + private Long registerTargetAndSendActionStatus(final ActionStatus sendActionStatus) { + final DistributionSetAssignmentResult assignmentResult = registerTargetAndAssignDistributionSet(); + final Long actionId = assignmentResult.getActions().get(0); + sendActionUpdateStatus(new ActionUpdateStatus(actionId, sendActionStatus)); + return actionId; + } + + private void sendActionUpdateStatus(final ActionUpdateStatus actionStatus) { + final Message eventMessage = createEventMessage(TENANT_EXIST, EventTopic.UPDATE_ACTION_STATUS, actionStatus); + getDmfClient().send(eventMessage); + } + + private void registerTargetAndSendAndAssertUpdateActionStatus(final ActionStatus sendActionStatus, + final Status expectedActionStatus) { + final Long actionId = registerTargetAndSendActionStatus(sendActionStatus); + assertAction(actionId, Status.RUNNING, expectedActionStatus); + } + + private void assertAction(final Long actionId, final Status... expectedActionStates) { + createConditionFactory().await().until(() -> { + try { + securityRule.runAsPrivileged(() -> { + final List status = deploymentManagement.findActionStatusByAction(pageReq, actionId) + .getContent().stream().map(actionStatus -> actionStatus.getStatus()) + .collect(Collectors.toList()); + assertThat(status).containsOnly(expectedActionStates); + return null; + }); + } catch (final Exception e) { + fail(e.getMessage()); + } + }); + } + + private Message createEventMessage(final String tenant, final EventTopic eventTopic, final Object payload) { + final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant); + messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.EVENT.toString()); + messageProperties.getHeaders().put(MessageHeaderKey.TOPIC, eventTopic.toString()); + + return createMessage(payload, messageProperties); + } + + private void sendUpdateAttributeMessage(final String target, final String tenant, + final AttributeUpdate attributeUpdate) { + final Message updateMessage = createUpdateAttributesMessage(target, tenant, attributeUpdate); + getDmfClient().send(updateMessage); + } + +} diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf/hawkbit-dmf-amqp/pom.xml index 7d11c7e12..f0ca44a72 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf/hawkbit-dmf-amqp/pom.xml @@ -67,14 +67,6 @@ slf4j-api - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.eclipse.hawkbit diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java index ec54849af..351e47f1a 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java @@ -12,7 +12,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import java.util.List; -import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -32,7 +31,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreated 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.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; @@ -202,7 +200,7 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra getDmfClient().send(createTargetMessage); verifyOneDeadLetterMessage(); - assertThat(systemManagement.findTenants()).hasSize(1); + assertThat(systemManagement.findTenants(PAGE)).hasSize(1); } @Test @@ -606,9 +604,10 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra createConditionFactory().await().until(() -> { try { securityRule.runAsPrivileged(() -> { - final Optional findActionWithDetails = controllerManagement.findActionWithDetails(actionId); - assertThat(findActionWithDetails).isPresent(); - assertThat(convertStatusList(findActionWithDetails.get())).containsOnly(expectedActionStates); + final List status = deploymentManagement.findActionStatusByAction(PAGE, actionId) + .getContent().stream().map(actionStatus -> actionStatus.getStatus()) + .collect(Collectors.toList()); + assertThat(status).containsOnly(expectedActionStates); return null; }); } catch (final Exception e) { @@ -617,11 +616,6 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AmqpServiceIntegra }); } - private List convertStatusList(Action action) { - return action.getActionStatus().stream().map(actionStatus -> actionStatus.getStatus()) - .collect(Collectors.toList()); - } - private Message createEventMessage(final String tenant, final EventTopic eventTopic, final Object payload) { final MessageProperties messageProperties = createMessagePropertiesWithTenant(tenant); messageProperties.getHeaders().put(MessageHeaderKey.TYPE, MessageType.EVENT.toString()); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rollout/MgmtRolloutRestRequestBody.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rollout/MgmtRolloutRestRequestBody.java index 0b3cd4992..510a9328a 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rollout/MgmtRolloutRestRequestBody.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rollout/MgmtRolloutRestRequestBody.java @@ -8,14 +8,14 @@ */ package org.eclipse.hawkbit.mgmt.json.model.rollout; +import java.util.List; + import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; +import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroup; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; -import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroup; - -import java.util.List; /** * Model for request containing a rollout body e.g. in a POST request of diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rolloutgroup/MgmtRolloutGroup.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rolloutgroup/MgmtRolloutGroup.java index c628f45e0..89d1e6084 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rolloutgroup/MgmtRolloutGroup.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/rolloutgroup/MgmtRolloutGroup.java @@ -8,9 +8,10 @@ */ package org.eclipse.hawkbit.mgmt.json.model.rolloutgroup; +import org.eclipse.hawkbit.mgmt.json.model.rollout.AbstractMgmtRolloutConditionsEntity; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; -import org.eclipse.hawkbit.mgmt.json.model.rollout.AbstractMgmtRolloutConditionsEntity; /** * Model for defining the Attributes of a Rollout Group diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java index a6c6a2135..df04e7f12 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtDistributionSetTagRestApi.java @@ -122,10 +122,46 @@ public interface MgmtDistributionSetTagRestApi { * * @param distributionsetTagId * the ID of the distribution set tag + * @param pagingOffsetParam + * the offset of list of target tags for pagination, might not be + * present in the rest request then default value will be applied + * @param pagingLimitParam + * the limit of the paged request, might not be present in the + * rest request then default value will be applied + * @param sortParam + * the sorting parameter in the request URL, syntax + * {@code field:direction, field:direction} + * @param rsqlParam + * the search parameter in the request URL, syntax + * {@code q=name==abc} * * @return the list of assigned distribution sets. */ - @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING, produces = { + @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING, produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) + ResponseEntity> getAssignedDistributionSets( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); + + /** + * Handles the GET request of retrieving all assigned distribution sets by + * the given tag id. + * + * @param distributionsetTagId + * the ID of the distribution set tag + * + * @return the list of assigned distribution sets. + * + * @deprecated please use + * {@link #getAssignedDistributionSets(Long, int, int, String, String)} + * instead as this variant does not include paging and as result + * returns only a limited list of distributionsets + */ + @Deprecated + @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.DEPRECATED_DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> getAssignedDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId); @@ -142,12 +178,34 @@ public interface MgmtDistributionSetTagRestApi { * @return the list of assigned distribution sets and unassigned * distribution sets. */ - @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING + "/toggleTagAssignment") ResponseEntity toggleTagAssignment( @PathVariable("distributionsetTagId") final Long distributionsetTagId, final List assignedDSRequestBodies); + /** + * Handles the POST request to toggle the assignment of distribution sets by + * the given tag id. + * + * @param distributionsetTagId + * the ID of the distribution set tag to retrieve + * @param assignedDSRequestBodies + * list of distribution set ids to be toggled + * + * @return the list of assigned distribution sets and unassigned + * distribution sets. + * + * @deprecated please use + * {@link MgmtDistributionSetTagRestApi#toggleTagAssignment} + */ + @Deprecated + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DEPRECATED_DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING + + "/toggleTagAssignment") + ResponseEntity toggleTagAssignmentUnpaged( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + final List assignedDSRequestBodies); + /** * Handles the POST request to assign distribution sets to the given tag id. * @@ -158,7 +216,7 @@ public interface MgmtDistributionSetTagRestApi { * * @return the list of assigned distribution set. */ - @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING, consumes = { + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING, consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) ResponseEntity> assignDistributionSets( @@ -166,16 +224,25 @@ public interface MgmtDistributionSetTagRestApi { final List assignedDSRequestBodies); /** - * Handles the DELETE request to unassign all distribution set from the - * given tag id. + * Handles the POST request to assign distribution sets to the given tag id. * * @param distributionsetTagId * the ID of the distribution set tag to retrieve - * @return http status code + * @param assignedDSRequestBodies + * list of distribution sets ids to be assigned + * + * @return the list of assigned distribution set. + * + * @deprecated please use + * {@link MgmtDistributionSetTagRestApi#assignDistributionSets} */ - @RequestMapping(method = RequestMethod.DELETE, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING) - ResponseEntity unassignDistributionSets( - @PathVariable("distributionsetTagId") final Long distributionsetTagId); + @Deprecated + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DEPRECATED_DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING, consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + ResponseEntity> assignDistributionSetsUnpaged( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + final List assignedDSRequestBodies); /** * Handles the DELETE request to unassign one distribution set from the @@ -187,8 +254,28 @@ public interface MgmtDistributionSetTagRestApi { * the ID of the distribution set to unassign * @return http status code */ - @RequestMapping(method = RequestMethod.DELETE, value = MgmtRestConstants.DISTRIBUTIONSET_REQUEST_MAPPING + @RequestMapping(method = RequestMethod.DELETE, value = MgmtRestConstants.DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING + "/{distributionsetId}") ResponseEntity unassignDistributionSet(@PathVariable("distributionsetTagId") final Long distributionsetTagId, @PathVariable("distributionsetId") final Long distributionsetId); + + /** + * Handles the DELETE request to unassign one distribution set from the + * given tag id. + * + * @param distributionsetTagId + * the ID of the distribution set tag + * @param distributionsetId + * the ID of the distribution set to unassign + * @return http status code + * + * @deprecated please use + * {@link MgmtDistributionSetTagRestApi#unassignDistributionSet} + */ + @Deprecated + @RequestMapping(method = RequestMethod.DELETE, value = MgmtRestConstants.DEPRECATED_DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING + + "/{distributionsetId}") + ResponseEntity unassignDistributionSetUnpaged( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @PathVariable("distributionsetId") final Long distributionsetId); } diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java index ce775d2ce..f1d0bddf3 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java @@ -24,19 +24,20 @@ public final class MgmtRestConstants { */ public static final String BASE_V1_REQUEST_MAPPING = "/rest/v1"; + /** + * String representation of + * {@link #REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE}. + */ + public static final String REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT = "50"; + /** * The default limit parameter in case the limit parameter is not present in * the request. * * @see #REQUEST_PARAMETER_PAGING_LIMIT */ - public static final int REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE = 50; - - /** - * String representation of - * {@link #REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE}. - */ - public static final String REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT = "50"; + public static final int REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE = Integer + .parseInt(REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT); /** * The software module URL mapping rest resource. @@ -93,10 +94,20 @@ public final class MgmtRestConstants { * The tag URL mapping rest resource. */ public static final String TARGET_TAG_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targettags"; + + /** + * The tag URL mapping rest resource. + * + * @deprecated {@link #TARGET_TAG_TARGETS_REQUEST_MAPPING} is preferred as + * this resource on GET supports paging + */ + @Deprecated + public static final String DEPRECATAED_TARGET_TAG_TARGETS_REQUEST_MAPPING = "/{targetTagId}/targets"; + /** * The tag URL mapping rest resource. */ - public static final String TARGET_TAG_TARGETS_REQUEST_MAPPING = "/{targetTagId}/targets"; + public static final String TARGET_TAG_TARGETS_REQUEST_MAPPING = "/{targetTagId}/assigned"; /** * The tag URL mapping rest resource. @@ -109,10 +120,19 @@ public final class MgmtRestConstants { */ public static final String TARGET_FILTER_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targetfilters"; + /** + * The deprecated tag URL mapping rest resource. + * + * @deprecated {@link #DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING} + * is preferred as this resource on GET supports paging + */ + @Deprecated + public static final String DEPRECATED_DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING = "/{distributionsetTagId}/distributionsets"; + /** * The tag URL mapping rest resource. */ - public static final String DISTRIBUTIONSET_REQUEST_MAPPING = "/{distributionsetTagId}/distributionsets"; + public static final String DISTRIBUTIONSET_TAG_DISTRIBUTIONSETS_REQUEST_MAPPING = "/{distributionsetTagId}/assigned"; /** * The default offset parameter in case the offset parameter is not present @@ -122,6 +142,15 @@ public final class MgmtRestConstants { */ public static final String REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET = "0"; + /** + * The default offset parameter in case the offset parameter is not present + * in the request. + * + * @see #REQUEST_PARAMETER_PAGING_OFFSET + */ + public static final int REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE = Integer + .parseInt(REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET); + /** * Limit http parameter for the limitation of returned values for a paged * request. diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java index 35d32c6ae..641b56d86 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetTagRestApi.java @@ -98,7 +98,7 @@ public interface MgmtTargetTagRestApi { @RequestMapping(method = RequestMethod.PUT, value = "/{targetTagId}", consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) - ResponseEntity updateTagretTag(@PathVariable("targetTagId") final Long targetTagId, + ResponseEntity updateTargetTag(@PathVariable("targetTagId") final Long targetTagId, final MgmtTagRequestBodyPut restTargetTagRest); /** @@ -120,10 +120,45 @@ public interface MgmtTargetTagRestApi { * the ID of the target tag to retrieve * * @return the list of assigned targets. + * + * @deprecated please use + * {@link #getAssignedTargets(Long, int, int, String, String)} + * instead as this variant does not include paging and as result + * returns only a limited list of targets + */ + @Deprecated + @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.DEPRECATAED_TARGET_TAG_TARGETS_REQUEST_MAPPING, produces = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) + ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId); + + /** + * Handles the GET request of retrieving all assigned targets by the given + * tag id. + * + * @param targetTagId + * the ID of the target tag to retrieve + * @param pagingOffsetParam + * the offset of list of target tags for pagination, might not be + * present in the rest request then default value will be applied + * @param pagingLimitParam + * the limit of the paged request, might not be present in the + * rest request then default value will be applied + * @param sortParam + * the sorting parameter in the request URL, syntax + * {@code field:direction, field:direction} + * @param rsqlParam + * the search parameter in the request URL, syntax + * {@code q=name==abc} + * + * @return the list of assigned targets. */ @RequestMapping(method = RequestMethod.GET, value = MgmtRestConstants.TARGET_TAG_TARGETS_REQUEST_MAPPING, produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) - ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId); + ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam); /** * Handles the POST request to toggle the assignment of targets by the given @@ -144,6 +179,27 @@ public interface MgmtTargetTagRestApi { @PathVariable("targetTagId") final Long targetTagId, final List assignedTargetRequestBodies); + /** + * Handles the POST request to toggle the assignment of targets by the given + * tag id. + * + * @param targetTagId + * the ID of the target tag to retrieve + * @param assignedTargetRequestBodies + * list of controller ids to be toggled + * + * @return the list of assigned targets and unassigned targets. + * @deprecated please use {@link MgmtTargetTagRestApi#toggleTagAssignment} + */ + @Deprecated + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DEPRECATAED_TARGET_TAG_TARGETS_REQUEST_MAPPING + + "/toggleTagAssignment", consumes = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + ResponseEntity toggleTagAssignmentUnpaged( + @PathVariable("targetTagId") final Long targetTagId, + final List assignedTargetRequestBodies); + /** * Handles the POST request to assign targets to the given tag id. * @@ -161,14 +217,23 @@ public interface MgmtTargetTagRestApi { final List assignedTargetRequestBodies); /** - * Handles the DELETE request to unassign all targets from the given tag id. + * Handles the POST request to assign targets to the given tag id. * * @param targetTagId * the ID of the target tag to retrieve - * @return http status code + * @param assignedTargetRequestBodies + * list of controller ids to be assigned + * + * @return the list of assigned targets. + * + * @deprecated please use {@link MgmtTargetTagRestApi#assignTargets} */ - @RequestMapping(method = RequestMethod.DELETE, value = MgmtRestConstants.TARGET_TAG_TARGETS_REQUEST_MAPPING) - ResponseEntity unassignTargets(@PathVariable("targetTagId") final Long targetTagId); + @Deprecated + @RequestMapping(method = RequestMethod.POST, value = MgmtRestConstants.DEPRECATAED_TARGET_TAG_TARGETS_REQUEST_MAPPING, consumes = { + MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE, + MediaType.APPLICATION_JSON_VALUE }) + ResponseEntity> assignTargetsUnpaged(@PathVariable("targetTagId") final Long targetTagId, + final List assignedTargetRequestBodies); /** * Handles the DELETE request to unassign one target from the given tag id. @@ -183,4 +248,21 @@ public interface MgmtTargetTagRestApi { + "/{controllerId}") ResponseEntity unassignTarget(@PathVariable("targetTagId") final Long targetTagId, @PathVariable("controllerId") final String controllerId); + + /** + * Handles the DELETE request to unassign one target from the given tag id. + * + * @param targetTagId + * the ID of the target tag + * @param controllerId + * the ID of the target to unassign + * @return http status code + * + * @deprecated please use {@link MgmtTargetTagRestApi#unassignTarget} + */ + @Deprecated + @RequestMapping(method = RequestMethod.DELETE, value = MgmtRestConstants.DEPRECATAED_TARGET_TAG_TARGETS_REQUEST_MAPPING + + "/{controllerId}") + ResponseEntity unassignTargetUnpaged(@PathVariable("targetTagId") final Long targetTagId, + @PathVariable("controllerId") final String controllerId); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index d486cad26..fffc14a8a 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -121,8 +121,8 @@ public final class MgmtDistributionSetMapper { .getDistributionSetType(distributionSet.getType().getId())).withRel("type")); response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getMetadata(response.getDsId(), - Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET), - Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null)) + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) .withRel("metadata")); return response; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index 10da9b8d0..56034437b 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -31,8 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -67,25 +67,20 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); - final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam); + final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); - final Slice findTargetsAll; - final Long countTargetsAll; + final Page findTargetsAll; if (rsqlParam == null) { - findTargetsAll = this.tagManagement.findAllDistributionSetTags(pageable); - countTargetsAll = this.tagManagement.countTargetTags(); + findTargetsAll = tagManagement.findAllDistributionSetTags(pageable); } else { - final Page findTargetPage = this.tagManagement.findAllDistributionSetTags(rsqlParam, - pageable); - countTargetsAll = findTargetPage.getTotalElements(); - findTargetsAll = findTargetPage; + findTargetsAll = tagManagement.findAllDistributionSetTags(rsqlParam, pageable); } final List rest = MgmtTagMapper.toResponseDistributionSetTag(findTargetsAll.getContent()); - return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, findTargetsAll.getTotalElements()), HttpStatus.OK); } @Override @@ -132,10 +127,36 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes @Override public ResponseEntity> getAssignedDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId) { - final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); - return new ResponseEntity<>( - MgmtDistributionSetMapper.toResponseDistributionSets(tag.getAssignedToDistributionSet()), - HttpStatus.OK); + return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(distributionSetManagement + .findDistributionSetsByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), + distributionsetTagId) + .getContent()), HttpStatus.OK); + } + + @Override + public ResponseEntity> getAssignedDistributionSets( + @PathVariable("distributionsetTagId") final Long distributionsetTagId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { + final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); + final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); + final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam); + + final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); + Page findDistrAll; + if (rsqlParam == null) { + findDistrAll = distributionSetManagement.findDistributionSetsByTag(pageable, distributionsetTagId); + + } else { + findDistrAll = distributionSetManagement.findDistributionSetsByTag(pageable, rsqlParam, + distributionsetTagId); + } + + final List rest = MgmtDistributionSetMapper + .toResponseFromDsList(findDistrAll.getContent()); + return new ResponseEntity<>(new PagedList<>(rest, findDistrAll.getTotalElements()), HttpStatus.OK); } @Override @@ -173,17 +194,6 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs), HttpStatus.OK); } - @Override - public ResponseEntity unassignDistributionSets( - @PathVariable("distributionsetTagId") final Long distributionsetTagId) { - LOG.debug("Unassign all DS for ds tag {}", distributionsetTagId); - - final List distributionSets = this.distributionSetManagement - .unAssignAllDistributionSetsByTag(distributionsetTagId); - LOG.debug("Unassigned ds {}", distributionSets.size()); - return new ResponseEntity<>(HttpStatus.OK); - } - @Override public ResponseEntity unassignDistributionSet( @PathVariable("distributionsetTagId") final Long distributionsetTagId, @@ -203,4 +213,24 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes return assignedDistributionSetRequestBodies.stream() .map(MgmtAssignedDistributionSetRequestBody::getDistributionSetId).collect(Collectors.toList()); } + + @Override + public ResponseEntity toggleTagAssignmentUnpaged( + final Long distributionsetTagId, + final List assignedDSRequestBodies) { + return toggleTagAssignment(distributionsetTagId, assignedDSRequestBodies); + } + + @Override + public ResponseEntity> assignDistributionSetsUnpaged(final Long distributionsetTagId, + final List assignedDSRequestBodies) { + return assignDistributionSets(distributionsetTagId, assignedDSRequestBodies); + } + + @Override + public ResponseEntity unassignDistributionSetUnpaged(final Long distributionsetTagId, + final Long distributionsetId) { + return unassignDistributionSet(distributionsetTagId, distributionsetId); + } + } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java index 6e318ae7d..e9caf2aa8 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java @@ -90,8 +90,8 @@ final class MgmtRolloutMapper { body.add(linkTo(methodOn(MgmtRolloutRestApi.class).pause(rollout.getId())).withRel("pause")); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).resume(rollout.getId())).withRel("resume")); body.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRolloutGroups(rollout.getId(), - Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET), - Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null)) + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) .withRel("groups")); return body; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index ba441bbb7..ca4d4fe46 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -115,8 +115,8 @@ public final class MgmtSoftwareModuleMapper { .withRel(MgmtRestConstants.SOFTWAREMODULE_V1_TYPE)); response.add(linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getModuleId(), - Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET), - Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null)) + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) .withRel("metadata").expand(ArrayUtils.toArray())); return response; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java index 02f3853db..fec1d0772 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java @@ -19,6 +19,7 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.builder.TagCreate; @@ -61,8 +62,10 @@ final class MgmtTagMapper { response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getTargetTag(targetTag.getId())).withSelfRel()); - response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getAssignedTargets(targetTag.getId())) - .withRel("assignedTargets")); + response.add(linkTo(methodOn(MgmtTargetTagRestApi.class).getAssignedTargets(targetTag.getId(), + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) + .withRel("assignedTargets")); return response; } @@ -93,8 +96,9 @@ final class MgmtTagMapper { linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getDistributionSetTag(distributionSetTag.getId())) .withSelfRel()); - response.add(linkTo( - methodOn(MgmtDistributionSetTagRestApi.class).getAssignedDistributionSets(distributionSetTag.getId())) + response.add(linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getAssignedDistributionSets( + distributionSetTag.getId(), MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE, + MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)) .withRel("assignedDistributionSets")); return response; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java index 9da9b2637..826368688 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java @@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; import org.eclipse.hawkbit.repository.ActionFields; +import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.builder.TargetCreate; import org.eclipse.hawkbit.repository.model.Action; @@ -37,6 +38,7 @@ import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.data.ResponseList; import org.eclipse.hawkbit.rest.data.SortDirection; import org.eclipse.hawkbit.util.IpUtil; +import org.springframework.data.domain.PageRequest; /** * A mapper which maps repository model to RESTful model representation and @@ -161,12 +163,17 @@ public final class MgmtTargetMapper { .address(targetRest.getAddress()); } - static List toActionStatusRestResponse(final Collection actionStatus) { + static List toActionStatusRestResponse(final Collection actionStatus, + final DeploymentManagement deploymentManagement) { if (actionStatus == null) { return Collections.emptyList(); } - return actionStatus.stream().map(MgmtTargetMapper::toResponse).collect(Collectors.toList()); + return actionStatus.stream().map(status -> toResponse(status, + deploymentManagement.findMessagesByActionStatusId( + new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), status.getId()) + .getContent())) + .collect(Collectors.toList()); } static MgmtAction toResponse(final String targetId, final Action action, final boolean isActive) { @@ -207,10 +214,10 @@ public final class MgmtTargetMapper { return null; } - private static MgmtActionStatus toResponse(final ActionStatus actionStatus) { + private static MgmtActionStatus toResponse(final ActionStatus actionStatus, final List messages) { final MgmtActionStatus result = new MgmtActionStatus(); - result.setMessages(actionStatus.getMessages()); + result.setMessages(messages); result.setReportedAt(actionStatus.getCreatedAt()); result.setStatusId(actionStatus.getId()); result.setType(actionStatus.getStatus().name().toLowerCase()); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index 943af5098..e34e7c39e 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -252,13 +252,12 @@ public class MgmtTargetResource implements MgmtTargetRestApi { final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam); - final Page statusList = this.deploymentManagement.findActionStatusByActionWithMessages( + final Page statusList = this.deploymentManagement.findActionStatusByAction( new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action.getId()); - return new ResponseEntity<>( - new PagedList<>(MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent()), - statusList.getTotalElements()), - HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>( + MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent(), deploymentManagement), + statusList.getTotalElements()), HttpStatus.OK); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java index 4c8e0dd85..98f8ca2da 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java @@ -31,8 +31,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -67,24 +67,19 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); - final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam); + final Sort sorting = PagingUtility.sanitizeTagSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); - final Slice findTargetsAll; - final Long countTargetsAll; + Page findTargetsAll; if (rsqlParam == null) { findTargetsAll = this.tagManagement.findAllTargetTags(pageable); - countTargetsAll = this.tagManagement.countTargetTags(); } else { - final Page findTargetPage = this.tagManagement.findAllTargetTags(rsqlParam, pageable); - countTargetsAll = findTargetPage.getTotalElements(); - findTargetsAll = findTargetPage; - + findTargetsAll = this.tagManagement.findAllTargetTags(rsqlParam, pageable); } final List rest = MgmtTagMapper.toResponse(findTargetsAll.getContent()); - return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK); + return new ResponseEntity<>(new PagedList<>(rest, findTargetsAll.getTotalElements()), HttpStatus.OK); } @Override @@ -102,7 +97,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { } @Override - public ResponseEntity updateTagretTag(@PathVariable("targetTagId") final Long targetTagId, + public ResponseEntity updateTargetTag(@PathVariable("targetTagId") final Long targetTagId, @RequestBody final MgmtTagRequestBodyPut restTargetTagRest) { LOG.debug("update {} target tag", restTargetTagRest); @@ -127,8 +122,36 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { @Override public ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId) { - final TargetTag targetTag = findTargetTagById(targetTagId); - return new ResponseEntity<>(MgmtTargetMapper.toResponse(targetTag.getAssignedToTargets()), HttpStatus.OK); + + return new ResponseEntity<>(MgmtTargetMapper.toResponse(targetManagement + .findTargetsByTag(new PageRequest(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT), targetTagId) + .getContent()), HttpStatus.OK); + } + + @Override + public ResponseEntity> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { + + final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); + final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); + final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam); + + final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); + Page findTargetsAll; + if (rsqlParam == null) { + findTargetsAll = targetManagement.findTargetsByTag(pageable, targetTagId); + + } else { + findTargetsAll = targetManagement.findTargetsByTag(pageable, rsqlParam, targetTagId); + } + + final Long countTargetsAll = findTargetsAll.getTotalElements(); + + final List rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent()); + return new ResponseEntity<>(new PagedList<>(rest, countTargetsAll), HttpStatus.OK); } @Override @@ -156,14 +179,6 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { return new ResponseEntity<>(MgmtTargetMapper.toResponse(assignedTarget), HttpStatus.OK); } - @Override - public ResponseEntity unassignTargets(@PathVariable("targetTagId") final Long targetTagId) { - LOG.debug("Unassign all Targets for target tag {}", targetTagId); - - this.targetManagement.unAssignAllTargetsByTag(targetTagId); - return new ResponseEntity<>(HttpStatus.OK); - } - @Override public ResponseEntity unassignTarget(@PathVariable("targetTagId") final Long targetTagId, @PathVariable("controllerId") final String controllerId) { @@ -183,4 +198,21 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { .collect(Collectors.toList()); } + @Override + public ResponseEntity toggleTagAssignmentUnpaged(final Long targetTagId, + final List assignedTargetRequestBodies) { + return toggleTagAssignment(targetTagId, assignedTargetRequestBodies); + } + + @Override + public ResponseEntity> assignTargetsUnpaged(final Long targetTagId, + final List assignedTargetRequestBodies) { + return assignTargets(targetTagId, assignedTargetRequestBodies); + } + + @Override + public ResponseEntity unassignTargetUnpaged(final Long targetTagId, final String controllerId) { + return unassignTarget(targetTagId, controllerId); + } + } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java index d70109e3d..4b357358f 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java @@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.RolloutGroupFields; import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; +import org.eclipse.hawkbit.repository.TagFields; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFilterQueryFields; import org.eclipse.hawkbit.rest.util.SortUtility; @@ -38,14 +39,14 @@ public final class PagingUtility { static int sanitizeOffsetParam(final int offset) { if (offset < 0) { - return Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET); + return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE; } return offset; } static int sanitizePageLimitParam(final int pageLimit) { if (pageLimit < 1) { - return Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT); + return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE; } else if (pageLimit > MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT) { return MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT; } @@ -55,15 +56,23 @@ public final class PagingUtility { static Sort sanitizeTargetSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, TargetFields.NAME.getFieldName()); + return new Sort(Direction.ASC, TargetFields.CONTROLLERID.getFieldName()); } return new Sort(SortUtility.parse(TargetFields.class, sortParam)); } + static Sort sanitizeTagSortParam(final String sortParam) { + if (sortParam == null) { + // default + return new Sort(Direction.ASC, TagFields.ID.getFieldName()); + } + return new Sort(SortUtility.parse(TagFields.class, sortParam)); + } + static Sort sanitizeTargetFilterQuerySortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, TargetFilterQueryFields.NAME.getFieldName()); + return new Sort(Direction.ASC, TargetFilterQueryFields.ID.getFieldName()); } return new Sort(SortUtility.parse(TargetFilterQueryFields.class, sortParam)); } @@ -71,7 +80,7 @@ public final class PagingUtility { static Sort sanitizeSoftwareModuleSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, SoftwareModuleFields.NAME.getFieldName()); + return new Sort(Direction.ASC, SoftwareModuleFields.ID.getFieldName()); } return new Sort(SortUtility.parse(SoftwareModuleFields.class, sortParam)); } @@ -79,7 +88,7 @@ public final class PagingUtility { static Sort sanitizeSoftwareModuleTypeSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, SoftwareModuleTypeFields.NAME.getFieldName()); + return new Sort(Direction.ASC, SoftwareModuleTypeFields.ID.getFieldName()); } return new Sort(SortUtility.parse(SoftwareModuleTypeFields.class, sortParam)); } @@ -87,7 +96,7 @@ public final class PagingUtility { static Sort sanitizeDistributionSetSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, DistributionSetFields.NAME.getFieldName()); + return new Sort(Direction.ASC, DistributionSetFields.ID.getFieldName()); } return new Sort(SortUtility.parse(DistributionSetFields.class, sortParam)); } @@ -95,7 +104,7 @@ public final class PagingUtility { static Sort sanitizeDistributionSetTypeSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, DistributionSetTypeFields.NAME.getFieldName()); + return new Sort(Direction.ASC, DistributionSetTypeFields.ID.getFieldName()); } return new Sort(SortUtility.parse(DistributionSetTypeFields.class, sortParam)); } @@ -137,7 +146,7 @@ public final class PagingUtility { static Sort sanitizeRolloutSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, RolloutFields.NAME.getFieldName()); + return new Sort(Direction.ASC, RolloutFields.ID.getFieldName()); } return new Sort(SortUtility.parse(RolloutFields.class, sortParam)); } @@ -145,7 +154,7 @@ public final class PagingUtility { static Sort sanitizeRolloutGroupSortParam(final String sortParam) { if (sortParam == null) { // default - return new Sort(Direction.ASC, RolloutGroupFields.NAME.getFieldName()); + return new Sort(Direction.ASC, RolloutGroupFields.ID.getFieldName()); } return new Sort(SortUtility.parse(RolloutGroupFields.class, sortParam)); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java index 833aacb58..c983904c8 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/AbstractManagementApiIntegrationTest.java @@ -8,10 +8,186 @@ */ package org.eclipse.hawkbit.mgmt.rest.resource; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; + +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.web.servlet.ResultMatcher; @SpringApplicationConfiguration(classes = { MgmtApiConfiguration.class }) public abstract class AbstractManagementApiIntegrationTest extends AbstractRestIntegrationTest { + protected static ResultMatcher applyBaseEntityMatcherOnArrayResult(final BaseEntity entity, + final String arrayElement) throws Exception { + return mvcResult -> { + jsonPath("$." + arrayElement + ".[?(@.id==" + entity.getId() + ")].createdBy", + contains(entity.getCreatedBy())).match(mvcResult); + jsonPath("$." + arrayElement + ".[?(@.id==" + entity.getId() + ")].createdAt", + contains(entity.getCreatedAt())).match(mvcResult); + jsonPath("$." + arrayElement + ".[?(@.id==" + entity.getId() + ")].lastModifiedBy", + contains(entity.getLastModifiedBy())).match(mvcResult); + jsonPath("$." + arrayElement + ".[?(@.id==" + entity.getId() + ")].lastModifiedAt", + contains(entity.getLastModifiedAt())).match(mvcResult); + }; + } + + protected static ResultMatcher applyTargetEntityMatcherOnArrayResult(final Target entity, final String arrayElement) + throws Exception { + return mvcResult -> { + jsonPath("$." + arrayElement + ".[?(@.controllerId==" + entity.getControllerId() + ")].createdBy", + contains(entity.getCreatedBy())).match(mvcResult); + jsonPath("$." + arrayElement + ".[?(@.controllerId==" + entity.getControllerId() + ")].createdAt", + contains(entity.getCreatedAt())).match(mvcResult); + jsonPath("$." + arrayElement + ".[?(@.controllerId==" + entity.getControllerId() + ")].lastModifiedBy", + contains(entity.getLastModifiedBy())).match(mvcResult); + jsonPath("$." + arrayElement + ".[?(@.controllerId==" + entity.getControllerId() + ")].lastModifiedAt", + contains(entity.getLastModifiedAt())).match(mvcResult); + }; + } + + protected static ResultMatcher applyBaseEntityMatcherOnPagedResult(final BaseEntity entity) throws Exception { + return applyBaseEntityMatcherOnArrayResult(entity, "content"); + } + + protected static ResultMatcher applyNamedEntityMatcherOnPagedResult(final NamedEntity entity) throws Exception { + return mvcResult -> { + applyBaseEntityMatcherOnPagedResult(entity).match(mvcResult); + jsonPath("$.content.[?(@.id==" + entity.getId() + ")].name", contains(entity.getName())).match(mvcResult); + jsonPath("$.content.[?(@.id==" + entity.getId() + ")].description", contains(entity.getDescription())) + .match(mvcResult); + }; + + } + + protected static ResultMatcher applyNamedVersionedEntityMatcherOnPagedResult(final NamedVersionedEntity entity) + throws Exception { + return mvcResult -> { + applyNamedEntityMatcherOnPagedResult(entity).match(mvcResult); + jsonPath("$.content.[?(@.id==" + entity.getId() + ")].version", contains(entity.getVersion())) + .match(mvcResult); + }; + } + + protected static ResultMatcher applyTagMatcherOnPagedResult(final Tag entity) throws Exception { + return mvcResult -> { + applyNamedEntityMatcherOnPagedResult(entity).match(mvcResult); + jsonPath("$.content.[?(@.id==" + entity.getId() + ")].colour", contains(entity.getColour())) + .match(mvcResult); + }; + } + + protected static ResultMatcher applySelfLinkMatcherOnPagedResult(final BaseEntity entity, final String link) + throws Exception { + + return mvcResult -> { + jsonPath("$.content.[?(@.id==" + entity.getId() + ")]._links.self.href", contains(link)).match(mvcResult); + }; + } + + protected static ResultMatcher applyBaseEntityMatcherOnArrayResult(final BaseEntity entity) throws Exception { + return mvcResult -> { + jsonPath("$.[?(@.id==" + entity.getId() + ")].createdBy", contains(entity.getCreatedBy())).match(mvcResult); + jsonPath("$.[?(@.id==" + entity.getId() + ")].createdAt", contains(entity.getCreatedAt())).match(mvcResult); + jsonPath("$.[?(@.id==" + entity.getId() + ")].lastModifiedBy", contains(entity.getLastModifiedBy())) + .match(mvcResult); + jsonPath("$.[?(@.id==" + entity.getId() + ")].lastModifiedAt", contains(entity.getLastModifiedAt())) + .match(mvcResult); + }; + } + + protected static ResultMatcher applyTargetEntityMatcherOnArrayResult(final Target entity) throws Exception { + return mvcResult -> { + jsonPath("$.[?(@.controllerId==" + entity.getControllerId() + ")].createdBy", + contains(entity.getCreatedBy())).match(mvcResult); + jsonPath("$.[?(@.controllerId==" + entity.getControllerId() + ")].createdAt", + contains(entity.getCreatedAt())).match(mvcResult); + jsonPath("$.[?(@.controllerId==" + entity.getControllerId() + ")].lastModifiedBy", + contains(entity.getLastModifiedBy())).match(mvcResult); + jsonPath("$.[?(@.controllerId==" + entity.getControllerId() + ")].lastModifiedAt", + contains(entity.getLastModifiedAt())).match(mvcResult); + }; + } + + protected static ResultMatcher applyNamedEntityMatcherOnArrayResult(final NamedEntity entity) throws Exception { + return mvcResult -> { + applyBaseEntityMatcherOnPagedResult(entity); + + jsonPath("$.[?(@.id==" + entity.getId() + ")].name", contains(entity.getName())).match(mvcResult); + jsonPath("$.[?(@.id==" + entity.getId() + ")].description", contains(entity.getDescription())) + .match(mvcResult); + }; + } + + protected static ResultMatcher applyNamedVersionedEntityMatcherOnArrayResult(final NamedVersionedEntity entity) + throws Exception { + return mvcResult -> { + applyNamedEntityMatcherOnPagedResult(entity); + + jsonPath("$.[?(@.id==" + entity.getId() + ")].version", contains(entity.getVersion())).match(mvcResult); + }; + } + + protected static ResultMatcher applyTagMatcherOnArrayResult(final Tag entity) throws Exception { + return mvcResult -> { + applyNamedEntityMatcherOnPagedResult(entity); + + jsonPath("$.[?(@.id==" + entity.getId() + ")].colour", contains(entity.getColour())).match(mvcResult); + }; + } + + protected static ResultMatcher applySelfLinkMatcherOnArrayResult(final BaseEntity entity, final String link) + throws Exception { + return mvcResult -> { + jsonPath("$.[?(@.id==" + entity.getId() + ")]._links.self.href", contains(link)).match(mvcResult); + }; + } + + protected static ResultMatcher applyBaseEntityMatcherOnSingleResult(final BaseEntity entity) throws Exception { + return mvcResult -> { + jsonPath("createdBy", equalTo(entity.getCreatedBy())).match(mvcResult); + jsonPath("createdAt", equalTo(entity.getCreatedAt())).match(mvcResult); + jsonPath("lastModifiedBy", equalTo(entity.getLastModifiedBy())).match(mvcResult); + jsonPath("lastModifiedAt", equalTo(entity.getLastModifiedAt())).match(mvcResult); + }; + } + + protected static ResultMatcher applyNamedEntityMatcherOnSingleResult(final NamedEntity entity) throws Exception { + return mvcResult -> { + applyBaseEntityMatcherOnSingleResult(entity); + + jsonPath("name", equalTo(entity.getName())).match(mvcResult); + jsonPath("description", equalTo(entity.getDescription())).match(mvcResult); + }; + } + + protected static ResultMatcher applyNamedVersionedEntityMatcherOnSingleResult(final NamedVersionedEntity entity) + throws Exception { + return mvcResult -> { + applyNamedEntityMatcherOnSingleResult(entity); + + jsonPath("version", equalTo(entity.getVersion())).match(mvcResult); + }; + } + + protected static ResultMatcher applyTagMatcherOnSingleResult(final Tag entity) throws Exception { + return mvcResult -> { + applyNamedEntityMatcherOnSingleResult(entity); + + jsonPath("colour", equalTo(entity.getColour())).match(mvcResult); + }; + } + + protected static ResultMatcher applySelfLinkMatcherOnSingleResult(final String link) throws Exception { + return mvcResult -> { + jsonPath("_links.self.href", equalTo(link)).match(mvcResult); + }; + } + } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 10a051f7d..22f79f20b 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -169,14 +169,11 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr // create Software Modules final List smIDs = Lists.newArrayList(testdataFactory.createSoftwareModuleOs().getId(), testdataFactory.createSoftwareModuleApp().getId()); - final JSONArray list = new JSONArray(); - for (final Long smID : smIDs) { - list.put(new JSONObject().put("id", Long.valueOf(smID))); - } + // post assignment mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") - .contentType(MediaType.APPLICATION_JSON).content(list.toString())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()); + .contentType(MediaType.APPLICATION_JSON).content(JsonBuilder.ids(smIDs))) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // Test if size is 3 mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -228,7 +225,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.total", equalTo(knownTargetIds.length))); - assertThat(targetManagement.findTargetByAssignedDistributionSet(createdDs.getId(), pageReq).getContent()) + assertThat(targetManagement.findTargetByAssignedDistributionSet(createdDs.getId(), PAGE).getContent()) .as("Five targets in repository have DS assigned").hasSize(5); } @@ -417,7 +414,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that multiple DS requested are listed with expected payload.") public void getDistributionSets() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); DistributionSet set = testdataFactory.createDistributionSet("one"); @@ -427,7 +424,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr // load also lazy stuff set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get(); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(1); // perform request @@ -491,7 +488,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Ensures that multipe DS posted to API are created in the repository.") public void createDistributionSets() throws Exception { - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); @@ -510,11 +507,11 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr final MvcResult mvcResult = executeMgmtTargetPost(one, two, three); one = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement - .findDistributionSetsAll("name==one", pageReq, false).getContent().get(0).getId()).get(); + .findDistributionSetsAll("name==one", PAGE, false).getContent().get(0).getId()).get(); two = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement - .findDistributionSetsAll("name==two", pageReq, false).getContent().get(0).getId()).get(); + .findDistributionSetsAll("name==two", PAGE, false).getContent().get(0).getId()).get(); three = distributionSetManagement.findDistributionSetByIdWithDetails(distributionSetManagement - .findDistributionSetsAll("name==three", pageReq, false).getContent().get(0).getId()).get(); + .findDistributionSetsAll("name==three", PAGE, false).getContent().get(0).getId()).get(); assertThat( JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) @@ -545,7 +542,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .isEqualTo(String.valueOf(three.getId())); // check in database - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(3); assertThat(one.isRequiredMigrationStep()).isEqualTo(false); assertThat(two.isRequiredMigrationStep()).isEqualTo(false); @@ -610,12 +607,12 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that DS deletion request to API is reflected by the repository.") public void deleteUnassignedistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(1); // perform request @@ -623,7 +620,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(status().isOk()); // check repository content - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .isEmpty(); assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(0); } @@ -639,14 +636,14 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr @Description("Ensures that assigned DS deletion request to API is reflected by the repository by means of deleted flag set.") public void deleteAssignedDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); testdataFactory.createTarget("test"); assignDistributionSet(set.getId(), "test"); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(1); // perform request @@ -654,9 +651,9 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr .andExpect(status().isOk()); // check repository content - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, true, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, true, true)) .hasSize(1); } @@ -665,7 +662,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr public void updateDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); @@ -689,7 +686,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr public void updateRequiredMigrationStepFailsIfDistributionSetisInUse() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(0); final DistributionSet set = testdataFactory.createDistributionSet("one"); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java new file mode 100644 index 000000000..84d7049c2 --- /dev/null +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java @@ -0,0 +1,328 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.mgmt.rest.resource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.test.matcher.Expect; +import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; +import org.eclipse.hawkbit.rest.util.JsonBuilder; +import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; +import org.json.JSONException; +import org.junit.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Component Tests - Management API") +@Stories("Distribution Set Tag Resource") +public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegrationTest { + + private static final String DISTRIBUTIONSETTAGS_ROOT = "http://localhost" + + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/"; + + @Test + @Description("Verfies that a paged result list of DS tags reflects the content on the repository side.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) + public void getDistributionSetTags() throws Exception { + final List tags = testdataFactory.createDistributionSetTags(2); + final DistributionSetTag assigned = tags.get(0); + final DistributionSetTag unassigned = tags.get(1); + + mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(applyBaseEntityMatcherOnPagedResult(assigned)) + .andExpect(applyBaseEntityMatcherOnPagedResult(unassigned)) + .andExpect(applySelfLinkMatcherOnPagedResult(assigned, DISTRIBUTIONSETTAGS_ROOT + assigned.getId())) + .andExpect(applySelfLinkMatcherOnPagedResult(unassigned, DISTRIBUTIONSETTAGS_ROOT + unassigned.getId())) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2))) + .andExpect(jsonPath( + "$.content.[?(@.id==" + assigned.getId() + ")]._links.assignedDistributionSets.href", + contains(DISTRIBUTIONSETTAGS_ROOT + assigned.getId() + "/assigned?offset=0&limit=50{&sort,q}"))) + .andExpect( + jsonPath("$.content.[?(@.id==" + unassigned.getId() + ")]._links.assignedDistributionSets.href", + contains(DISTRIBUTIONSETTAGS_ROOT + unassigned.getId() + + "/assigned?offset=0&limit=50{&sort,q}"))); + } + + @Test + @Description("Verfies that a single result of a DS tag reflects the content on the repository side.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) + public void getDistributionSetTag() throws Exception { + final List tags = testdataFactory.createDistributionSetTags(2); + final DistributionSetTag assigned = tags.get(0); + + mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + assigned.getId()) + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(applyTagMatcherOnSingleResult(assigned)) + .andExpect(applySelfLinkMatcherOnSingleResult(DISTRIBUTIONSETTAGS_ROOT + assigned.getId())) + .andExpect(jsonPath("_links.assignedDistributionSets.href", + equalTo(DISTRIBUTIONSETTAGS_ROOT + assigned.getId() + "/assigned?offset=0&limit=50{&sort,q}"))); + } + + @Test + @Description("Verifies that created DS tags are stored in the repository as send to the API.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 2) }) + public void createDistributionSetTags() throws JSONException, Exception { + final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1") + .build(); + final Tag tagTwo = entityFactory.tag().create().colour("testcol2").description("its a test2").name("thetest2") + .build(); + + final ResultActions result = mvc + .perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING) + .content(JsonBuilder.tags(Arrays.asList(tagOne, tagTwo))) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + + final Tag createdOne = tagManagement.findAllDistributionSetTags("name==thetest1", PAGE).getContent().get(0); + assertThat(createdOne.getName()).isEqualTo(tagOne.getName()); + assertThat(createdOne.getDescription()).isEqualTo(tagOne.getDescription()); + assertThat(createdOne.getColour()).isEqualTo(tagOne.getColour()); + final Tag createdTwo = tagManagement.findAllDistributionSetTags("name==thetest2", PAGE).getContent().get(0); + assertThat(createdTwo.getName()).isEqualTo(tagTwo.getName()); + assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription()); + assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour()); + + result.andExpect(applyTagMatcherOnArrayResult(createdOne)).andExpect(applyTagMatcherOnArrayResult(createdTwo)); + } + + @Test + @Description("Verifies that an updated DS tag is stored in the repository as send to the API.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetTagUpdatedEvent.class, count = 1) }) + public void updateDistributionSetTag() throws Exception { + final List tags = testdataFactory.createDistributionSetTags(1); + final DistributionSetTag original = tags.get(0); + + final Tag update = entityFactory.tag().create().name("updatedName").colour("updatedCol") + .description("updatedDesc").build(); + + final ResultActions result = mvc + .perform(put(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + original.getId()) + .content(JsonBuilder.tag(update)).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + + final Tag updated = tagManagement.findAllDistributionSetTags("name==updatedName", PAGE).getContent().get(0); + assertThat(updated.getName()).isEqualTo(update.getName()); + assertThat(updated.getDescription()).isEqualTo(update.getDescription()); + assertThat(updated.getColour()).isEqualTo(update.getColour()); + + result.andExpect(applyTagMatcherOnArrayResult(updated)).andExpect(applyTagMatcherOnArrayResult(updated)); + } + + @Test + @Description("Verfies that the delete call is reflected by the repository.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetTagDeletedEvent.class, count = 1) }) + public void deleteDistributionSetTag() throws Exception { + final List tags = testdataFactory.createDistributionSetTags(1); + final DistributionSetTag original = tags.get(0); + + mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + original.getId())) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); + + assertThat(tagManagement.findDistributionSetTagById(original.getId())).isNotPresent(); + } + + @Test + @Description("Ensures that assigned DS to tag in repository are listed with proper paging results.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 5), + @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) + public void getAssignedDistributionSets() throws Exception { + final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); + final int setsAssigned = 5; + final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); + distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(setsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(setsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(setsAssigned))); + } + + @Test + @Description("Ensures that assigned DS to tag in repository are listed with proper paging results with paging limit parameter.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 5), + @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) + public void getAssignedDistributionSetsWithPagingLimitRequestParameter() throws Exception { + final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); + final int setsAssigned = 5; + final int limitSize = 1; + final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); + distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") + .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize))) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(setsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize))); + } + + @Test + @Description("Ensures that assigned DS to tag in repository are listed with proper paging results with paging limit and offset parameter.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 5), + @Expect(type = DistributionSetUpdatedEvent.class, count = 5) }) + public void getAssignedDistributionSetsWithPagingLimitAndOffsetRequestParameter() throws Exception { + final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); + final int setsAssigned = 5; + final int offsetParam = 2; + final int expectedSize = setsAssigned - offsetParam; + + final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); + distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") + .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)) + .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(setsAssigned))) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(setsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize))); + } + + @Test + @Description("Verfies that tag assignments done through toggle API command are correctly assigned or unassigned.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 2), + @Expect(type = DistributionSetUpdatedEvent.class, count = 4) }) + public void toggleTagAssignment() throws Exception { + final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); + final int setsAssigned = 2; + final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); + + // 2 DistributionSetUpdateEvent + ResultActions result = toggle(tag, sets); + + List updated = distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()) + .getContent(); + + assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) + .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); + + result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "assignedDistributionSets")) + .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "assignedDistributionSets")); + + // 2 DistributionSetUpdateEvent + result = toggle(tag, sets); + + updated = distributionSetManagement.findDistributionSetsAll(PAGE, false).getContent(); + + result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "unassignedDistributionSets")) + .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "unassignedDistributionSets")); + + assertThat(distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId())).isEmpty(); + } + + private ResultActions toggle(final DistributionSetTag tag, final List sets) throws Exception { + return mvc + .perform(post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + + "/assigned/toggleTagAssignment").content( + JsonBuilder.ids(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()))) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + } + + @Test + @Description("Verfies that tag assignments done through tag API command are correctly stored in the repository.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 2), + @Expect(type = DistributionSetUpdatedEvent.class, count = 2) }) + public void assignDistributionSets() throws Exception { + final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); + final int setsAssigned = 2; + final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); + + final ResultActions result = mvc + .perform( + post(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") + .content(JsonBuilder + .ids(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()))) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + + final List updated = distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()) + .getContent(); + + assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) + .containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList())); + + result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0))) + .andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1))); + } + + @Test + @Description("Verfies that tag unassignments done through tag API command are correctly stored in the repository.") + @ExpectEvents({ @Expect(type = DistributionSetTagCreatedEvent.class, count = 1), + @Expect(type = DistributionSetCreatedEvent.class, count = 2), + @Expect(type = DistributionSetUpdatedEvent.class, count = 3) }) + public void unassignDistributionSet() throws Exception { + final DistributionSetTag tag = testdataFactory.createDistributionSetTags(1).get(0); + final int setsAssigned = 2; + final List sets = testdataFactory.createDistributionSetsWithoutModules(setsAssigned); + final DistributionSet assigned = sets.get(0); + final DistributionSet unassigned = sets.get(1); + + distributionSetManagement.toggleTagAssignment(sets.stream().map(BaseEntity::getId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" + + unassigned.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); + + final List updated = distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()) + .getContent(); + + assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList())) + .containsOnly(assigned.getId()); + } +} diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 2dc017991..64c2be505 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -71,7 +71,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra @Before public void assertPreparationOfRepo() { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("no softwaremodule should be founded") + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("no softwaremodule should be founded") .hasSize(0); } @@ -182,7 +182,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra @Test @Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST") public void emptyUploadArtifact() throws Exception { - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); @@ -313,7 +313,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra assertTrue("Response has wrong response content", Arrays.equals(result2.getResponse().getContentAsByteArray(), random)); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); } @@ -551,7 +551,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("$.content.[?(@.id==" + app.getId() + ")]._links.self.href", contains("http://localhost/rest/v1/softwaremodules/" + app.getId()))); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(2); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(2); } @Test @@ -562,7 +562,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra testdataFactory.createSoftwareModuleOs("2"); final SoftwareModule app2 = testdataFactory.createSoftwareModuleApp("2"); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(4); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(4); // only by name, only one exists per name mvc.perform(get("/rest/v1/softwaremodules?q=name==" + os1.getName()).accept(MediaType.APPLICATION_JSON)) @@ -652,7 +652,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andExpect(jsonPath("$._links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1); } @Test @@ -707,14 +707,14 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .toString()).as("Response contains invalid artifacts href") .isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId() + "/artifacts"); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(2); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0).getName()) + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("Wrong softwaremodule size").hasSize(2); + assertThat(softwareManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(os.getName()); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0) + assertThat(softwareManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0) .getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester"); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0) + assertThat(softwareManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent().get(0) .getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType.getId()).getContent().get(0).getName()) + assertThat(softwareManagement.findSoftwareModulesByType(PAGE, appType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(ah.getName()); } @@ -728,13 +728,13 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("Softwaremoudle size is wrong").hasSize(1); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)) + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)) .as("After delete no softwarmodule should be available").isEmpty(); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); } @@ -749,7 +749,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra artifactManagement.createArtifact(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).get().getId(), "file1", false); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(3); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).get().getId())) @@ -760,7 +760,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // all 3 are now marked as deleted - assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber()) + assertThat(softwareManagement.findSoftwareModulesAll(PAGE).getNumber()) .as("After delete no softwarmodule should be available").isEqualTo(0); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); } @@ -779,7 +779,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); // check repo before delete - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(1); assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()).hasSize(2); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); @@ -789,7 +789,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); // check that only one artifact is still alive and still assigned - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted") + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).as("After the sm should be marked as deleted") .hasSize(1); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).get().getArtifacts()) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index b48934a81..5382a155f 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -110,9 +110,10 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest entityFactory.actionStatus().create(actions.get(0).getId()).status(Status.FINISHED).message("test")); final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName()); - final ActionStatus status = deploymentManagement.findActionsByTarget(knownTargetId, pageRequest).getContent() - .get(0).getActionStatus().stream().sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId())) - .collect(Collectors.toList()).get(0); + final Action action = deploymentManagement.findActionsByTarget(knownTargetId, pageRequest).getContent().get(0); + + final ActionStatus status = deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getContent() + .stream().sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId())).collect(Collectors.toList()).get(0); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" + MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actions.get(0).getId() + "/status") @@ -224,12 +225,12 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // test - cancel the active action mvc.perform( delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}", - tA.getControllerId(), deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq) + tA.getControllerId(), deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE) .getContent().get(0).getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNoContent()); final Action action = deploymentManagement.findAction( - deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq).getContent().get(0).getId()) + deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE).getContent().get(0).getId()) .get(); // still active because in "canceling" state and waiting for controller // feedback @@ -250,10 +251,10 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // cancel the active action deploymentManagement.cancelAction( - deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq).getContent().get(0).getId()); + deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE).getContent().get(0).getId()); // find the current active action - final List cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq) + final List cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE) .getContent().stream().filter(Action::isCancelingOrCanceled).collect(Collectors.toList()); assertThat(cancelActions).hasSize(1); @@ -271,10 +272,10 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // cancel the active action deploymentManagement.cancelAction( - deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq).getContent().get(0).getId()); + deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE).getContent().get(0).getId()); // find the current active action - final List cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq) + final List cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE) .getContent().stream().filter(Action::isCancelingOrCanceled).collect(Collectors.toList()); assertThat(cancelActions).hasSize(1); assertThat(cancelActions.get(0).isCancelingOrCanceled()).isTrue(); @@ -294,7 +295,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // test - cancel an cancel action returns forbidden mvc.perform( delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/actions/{actionId}?force=true", - tA.getControllerId(), deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq) + tA.getControllerId(), deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE) .getContent().get(0).getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed()); } @@ -876,8 +877,9 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest final String knownTargetId = "targetId"; final Action action = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId).get(0); // retrieve list in default descending order for actionstaus entries - final List actionStatus = action.getActionStatus().stream() - .sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId())).collect(Collectors.toList()); + final List actionStatus = deploymentManagement.findActionStatusByAction(PAGE, action.getId()) + .getContent().stream().sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId())) + .collect(Collectors.toList()); // sort is default descending order, latest status first mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" @@ -902,8 +904,9 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest public void getMultipleActionStatusSortedByReportedAt() throws Exception { final String knownTargetId = "targetId"; final Action action = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId).get(0); - final List actionStatus = action.getActionStatus().stream() - .sorted((e1, e2) -> Long.compare(e1.getId(), e2.getId())).collect(Collectors.toList()); + final List actionStatus = deploymentManagement.findActionStatusByAction(PAGE, action.getId()) + .getContent().stream().sorted((e1, e2) -> Long.compare(e1.getId(), e2.getId())) + .collect(Collectors.toList()); // descending order mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" @@ -948,8 +951,9 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest final String knownTargetId = "targetId"; final Action action = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId).get(0); - final List actionStatus = action.getActionStatus().stream() - .sorted((e1, e2) -> Long.compare(e1.getId(), e2.getId())).collect(Collectors.toList()); + final List actionStatus = deploymentManagement.findActionStatusByAction(PAGE, action.getId()) + .getContent().stream().sorted((e1, e2) -> Long.compare(e1.getId(), e2.getId())) + .collect(Collectors.toList()); // Page 1 mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" @@ -1054,7 +1058,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest assignDistributionSet(two, updatedTargets); // two updates, one cancellation - final List actions = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq) + final List actions = deploymentManagement.findActionsByTarget(target.getControllerId(), PAGE) .getContent(); assertThat(actions).hasSize(2); @@ -1118,7 +1122,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest .andExpect(status().isOk()); final List findActiveActionsByTarget = deploymentManagement - .findActiveActionsByTarget(target.getControllerId()); + .findActiveActionsByTarget(PAGE, target.getControllerId()).getContent(); assertThat(findActiveActionsByTarget).hasSize(1); assertThat(findActiveActionsByTarget.get(0).getActionType()).isEqualTo(ActionType.TIMEFORCED); assertThat(findActiveActionsByTarget.get(0).getForcedTime()).isEqualTo(forceTime); @@ -1298,7 +1302,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest // assign a distribution set so we get an active update action assignDistributionSet(dsA, Lists.newArrayList(tA)); // verify active action - final Slice actionsByTarget = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq); + final Slice actionsByTarget = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE); assertThat(actionsByTarget.getContent()).hasSize(1); return targetManagement.findTargetByControllerID(tA.getControllerId()).get(); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java new file mode 100644 index 000000000..a93cfb084 --- /dev/null +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java @@ -0,0 +1,318 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.mgmt.rest.resource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; +import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.test.matcher.Expect; +import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; +import org.eclipse.hawkbit.rest.util.JsonBuilder; +import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; +import org.junit.Test; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Spring MVC Tests against the MgmtTargetTagResource. + * + */ +@Features("Component Tests - Management API") +@Stories("Target Tag Resource") +public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationTest { + + private static final String TARGETTAGS_ROOT = "http://localhost" + MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + + "/"; + + @Test + @Description("Verfies that a paged result list of target tags reflects the content on the repository side.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) }) + public void getTargetTags() throws Exception { + final List tags = testdataFactory.createTargetTags(2, ""); + final TargetTag assigned = tags.get(0); + final TargetTag unassigned = tags.get(1); + + mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(applyTagMatcherOnPagedResult(assigned)).andExpect(applyTagMatcherOnPagedResult(unassigned)) + .andExpect(applySelfLinkMatcherOnPagedResult(assigned, TARGETTAGS_ROOT + assigned.getId())) + .andExpect(applySelfLinkMatcherOnPagedResult(unassigned, TARGETTAGS_ROOT + unassigned.getId())) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(2))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(2))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(2))) + .andExpect(jsonPath("$.content.[?(@.id==" + assigned.getId() + ")]._links.assignedTargets.href", + contains(TARGETTAGS_ROOT + assigned.getId() + "/assigned?offset=0&limit=50{&sort,q}"))) + .andExpect(jsonPath("$.content.[?(@.id==" + unassigned.getId() + ")]._links.assignedTargets.href", + contains(TARGETTAGS_ROOT + unassigned.getId() + "/assigned?offset=0&limit=50{&sort,q}"))); + + } + + @Test + @Description("Verfies that a single result of a target tag reflects the content on the repository side.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) }) + public void getTargetTag() throws Exception { + final List tags = testdataFactory.createTargetTags(2, ""); + final TargetTag assigned = tags.get(0); + + mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + assigned.getId()) + .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) + .andExpect(applyTagMatcherOnSingleResult(assigned)) + .andExpect(applySelfLinkMatcherOnSingleResult(TARGETTAGS_ROOT + assigned.getId())) + .andExpect(jsonPath("_links.assignedTargets.href", + equalTo(TARGETTAGS_ROOT + assigned.getId() + "/assigned?offset=0&limit=50{&sort,q}"))); + + } + + @Test + @Description("Verifies that created target tags are stored in the repository as send to the API.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 2) }) + public void createTargetTags() throws Exception { + final Tag tagOne = entityFactory.tag().create().colour("testcol1").description("its a test1").name("thetest1") + .build(); + final Tag tagTwo = entityFactory.tag().create().colour("testcol2").description("its a test2").name("thetest2") + .build(); + + final ResultActions result = mvc + .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING) + .content(JsonBuilder.tags(Arrays.asList(tagOne, tagTwo))) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + + final Tag createdOne = tagManagement.findAllTargetTags("name==thetest1", PAGE).getContent().get(0); + assertThat(createdOne.getName()).isEqualTo(tagOne.getName()); + assertThat(createdOne.getDescription()).isEqualTo(tagOne.getDescription()); + assertThat(createdOne.getColour()).isEqualTo(tagOne.getColour()); + final Tag createdTwo = tagManagement.findAllTargetTags("name==thetest2", PAGE).getContent().get(0); + assertThat(createdTwo.getName()).isEqualTo(tagTwo.getName()); + assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription()); + assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour()); + + result.andExpect(applyTagMatcherOnArrayResult(createdOne)).andExpect(applyTagMatcherOnArrayResult(createdTwo)); + } + + @Test + @Description("Verifies that an updated target tag is stored in the repository as send to the API.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetTagUpdatedEvent.class, count = 1) }) + public void updateTargetTag() throws Exception { + final List tags = testdataFactory.createTargetTags(1, ""); + final TargetTag original = tags.get(0); + + final Tag update = entityFactory.tag().create().name("updatedName").colour("updatedCol") + .description("updatedDesc").build(); + + final ResultActions result = mvc + .perform(put(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + original.getId()) + .content(JsonBuilder.tag(update)).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + + final Tag updated = tagManagement.findAllTargetTags("name==updatedName", PAGE).getContent().get(0); + assertThat(updated.getName()).isEqualTo(update.getName()); + assertThat(updated.getDescription()).isEqualTo(update.getDescription()); + assertThat(updated.getColour()).isEqualTo(update.getColour()); + + result.andExpect(applyTagMatcherOnArrayResult(updated)).andExpect(applyTagMatcherOnArrayResult(updated)); + } + + @Test + @Description("Verfies that the delete call is reflected by the repository.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetTagDeletedEvent.class, count = 1) }) + public void deleteTargetTag() throws Exception { + final List tags = testdataFactory.createTargetTags(1, ""); + final TargetTag original = tags.get(0); + + mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + original.getId())) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); + + assertThat(tagManagement.findTargetTagById(original.getId())).isNotPresent(); + } + + @Test + @Description("Ensures that assigned targets to tag in repository are listed with proper paging results.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 5), @Expect(type = TargetUpdatedEvent.class, count = 5) }) + public void getAssignedTargets() throws Exception { + final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); + final int targetsAssigned = 5; + final List targets = testdataFactory.createTargets(targetsAssigned); + targetManagement.toggleTagAssignment(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(targetsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(targetsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(targetsAssigned))); + } + + @Test + @Description("Ensures that assigned DS to tag in repository are listed with proper paging results with paging limit parameter.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 5), @Expect(type = TargetUpdatedEvent.class, count = 5) }) + public void getAssignedTargetsWithPagingLimitRequestParameter() throws Exception { + final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); + final int targetsAssigned = 5; + final int limitSize = 1; + final List targets = testdataFactory.createTargets(targetsAssigned); + targetManagement.toggleTagAssignment(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") + .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize))) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(targetsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limitSize))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limitSize))); + } + + @Test + @Description("Ensures that assigned targets to tag in repository are listed with proper paging results with paging limit and offset parameter.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 5), @Expect(type = TargetUpdatedEvent.class, count = 5) }) + public void getAssignedTargetsWithPagingLimitAndOffsetRequestParameter() throws Exception { + final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); + final int targetsAssigned = 5; + final int offsetParam = 2; + final int expectedSize = targetsAssigned - offsetParam; + + final List targets = testdataFactory.createTargets(targetsAssigned); + targetManagement.toggleTagAssignment(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(get(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") + .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)) + .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(targetsAssigned))) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(targetsAssigned))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize))) + .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize))); + } + + @Test + @Description("verfies that tag assignments done through toggle API command are correctly assigned or unassigned.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 4) }) + public void toggleTagAssignment() throws Exception { + final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); + final int targetsAssigned = 2; + final List targets = testdataFactory.createTargets(targetsAssigned); + + ResultActions result = toggle(tag, targets); + + List updated = targetManagement.findTargetsByTag(PAGE, tag.getId()).getContent(); + + assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) + .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); + + result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0), "assignedTargets")) + .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1), "assignedTargets")); + + result = toggle(tag, targets); + + updated = targetManagement.findTargetsAll(PAGE).getContent(); + + result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0), "unassignedTargets")) + .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1), "unassignedTargets")); + + assertThat(targetManagement.findTargetsByTag(PAGE, tag.getId())).isEmpty(); + } + + private ResultActions toggle(final TargetTag tag, final List targets) throws Exception { + return mvc + .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + + "/assigned/toggleTagAssignment") + .content(JsonBuilder.controllerIds( + targets.stream().map(Target::getControllerId).collect(Collectors.toList()))) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + } + + @Test + @Description("Verfies that tag assignments done through tag API command are correctly stored in the repository.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2) }) + public void assignTargets() throws Exception { + final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); + final int targetsAssigned = 2; + final List targets = testdataFactory.createTargets(targetsAssigned); + + final ResultActions result = mvc + .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") + .content(JsonBuilder.controllerIds( + targets.stream().map(Target::getControllerId).collect(Collectors.toList()))) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); + + final List updated = targetManagement.findTargetsByTag(PAGE, tag.getId()).getContent(); + + assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) + .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); + + result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0))) + .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1))); + } + + @Test + @Description("Verfies that tag unassignments done through tag API command are correctly stored in the repository.") + @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 3) }) + public void unassignTarget() throws Exception { + final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); + final int targetsAssigned = 2; + final List targets = testdataFactory.createTargets(targetsAssigned); + final Target assigned = targets.get(0); + final Target unassigned = targets.get(1); + + targetManagement.toggleTagAssignment(targets.stream().map(Target::getControllerId).collect(Collectors.toList()), + tag.getName()); + + mvc.perform(delete(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned/" + + unassigned.getControllerId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); + + final List updated = targetManagement.findTargetsByTag(PAGE, tag.getId()).getContent(); + + assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) + .containsOnly(assigned.getControllerId()); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 58e79c458..c8c895b45 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.repository; import java.util.Collection; -import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import javax.validation.constraints.NotNull; @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -71,6 +70,7 @@ public interface DeploymentManagement { DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, @NotNull ActionType actionType, long forcedTimestamp, @NotEmpty Collection controllerIDs); + /** * method assigns the {@link DistributionSet} to all {@link Target}s by * their IDs with a specific {@link ActionType} and {@code forcetime}. @@ -274,22 +274,6 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Long actionId); - /** - * Retrieves all {@link ActionStatus} inclusive their messages by a specific - * {@link Action}. - * - * @param pageable - * the page request parameter for paging and sorting the result - * @param actionId - * the {@link Action} to retrieve the {@link ActionStatus} from - * @return a page of {@link ActionStatus} by a speciifc {@link Action} - * - * @throws EntityNotFoundException - * if action with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Long actionId); - /** * Retrieves all messages for an {@link ActionStatus}. * @@ -303,20 +287,6 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findMessagesByActionStatusId(@NotNull Pageable pageable, @NotNull Long actionStatusId); - /** - * Retrieves all {@link Action}s of a specific target ordered by action ID. - * - * @param controllerId - * the target associated with the actions - * @return a list of actions associated with the given target ordered by - * action ID - * - * @throws EntityNotFoundException - * if target with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findActionsWithStatusCountByTargetOrderByIdDesc(@NotNull String controllerId); - /** * Get the {@link Action} entity for given actionId with all lazy attributes * (i.e. distributionSet, target, target.assignedDs). @@ -331,7 +301,9 @@ public interface DeploymentManagement { /** * Retrieves all active {@link Action}s of a specific target ordered by * action ID. - * + * + * @param pageable + * the page request parameter for paging and sorting the result * @param controllerId * the target associated with the actions * @return a list of actions associated with the given target @@ -340,12 +312,14 @@ public interface DeploymentManagement { * if target with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findActiveActionsByTarget(@NotEmpty String controllerId); + Page findActiveActionsByTarget(@NotNull Pageable pageable, @NotEmpty String controllerId); /** * Retrieves all inactive {@link Action}s of a specific target ordered by * action ID. * + * @param pageable + * the page request parameter for paging and sorting the result * @param controllerId * the target associated with the actions * @return a list of actions associated with the given target @@ -354,7 +328,7 @@ public interface DeploymentManagement { * if target with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findInActiveActionsByTarget(@NotEmpty String controllerId); + Page findInActiveActionsByTarget(@NotNull Pageable pageable, @NotEmpty String controllerId); /** * Force cancels given {@link Action} for given {@link Target}. Force diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index a67eb6e94..0fae2f9ba 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -363,17 +363,6 @@ public interface DistributionSetManagement { Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, @NotNull String rsqlParam, @NotNull Pageable pageable); - /** - * Retrieves {@link DistributionSet} List for overview purposes (no - * {@link SoftwareModule}s and {@link DistributionSetTag}s). - * - * @param dist - * List of {@link DistributionSet} IDs to be found - * @return the found {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findDistributionSetsAll(Collection dist); - /** * finds all {@link DistributionSet}s. * @@ -420,6 +409,21 @@ public interface DistributionSetManagement { Page findDistributionSetsAll(@NotNull String rsqlParam, @NotNull Pageable pageReq, Boolean deleted); + /** + * finds all {@link DistributionSet}s. + * + * @param pageReq + * the pagination parameter + * @param deleted + * if TRUE, {@link DistributionSet}s marked as deleted are + * returned. If FALSE, on {@link DistributionSet}s not marked as + * deleted are returned. null if both are to be + * returned + * @return all found {@link DistributionSet}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findDistributionSetsAll(@NotNull Pageable pageReq, Boolean deleted); + /** * method retrieves all {@link DistributionSet}s from the repository in the * following order: @@ -458,6 +462,45 @@ public interface DistributionSetManagement { Page findDistributionSetsByFilters(@NotNull Pageable pageable, @NotNull DistributionSetFilter distributionSetFilter); + /** + * retrieves {@link DistributionSet}s by filtering on the given parameters. + * + * @param pageable + * page parameter + * @param tagId + * of the tag the DS are assigned to + * @return the page of found {@link DistributionSet} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + * + * @throws EntityNotFoundException + * of distribution set tag with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findDistributionSetsByTag(@NotNull final Pageable pageable, @NotNull final Long tagId); + + /** + * retrieves {@link DistributionSet}s by filtering on the given parameters. + * + * @param pageable + * page parameter + * @param rsqlParam + * rsql query string + * @param tagId + * of the tag the DS are assigned to + * @return the page of found {@link DistributionSet} + * + * @throws EntityNotFoundException + * of distribution set tag with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findDistributionSetsByTag(@NotNull final Pageable pageable, @NotNull String rsqlParam, + @NotNull final Long tagId); + /** * @param id * as {@link DistributionSetType#getId()} @@ -556,20 +599,6 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection dsIds, @NotNull String tagName); - /** - * Unassign all {@link DistributionSet} from a given - * {@link DistributionSetTag} . - * - * @param tagId - * to unassign all ds - * @return list of unassigned ds - * - * @throws EntityNotFoundException - * if tag with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - List unAssignAllDistributionSetsByTag(@NotNull Long tagId); - /** * Unassigns a {@link SoftwareModule} form an existing * {@link DistributionSet}. @@ -731,6 +760,6 @@ public interface DistributionSetManagement { * @return the found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findDistributionSetAllById(@NotEmpty Collection ids); + List findDistributionSetsById(@NotEmpty Collection ids); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/QuotaManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/QuotaManagement.java new file mode 100644 index 000000000..039736d1a --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/QuotaManagement.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; + +/** + * Central service for defined limits of the repository. + * + */ +public interface QuotaManagement { + + /** + * @return Maximum number of {@link ActionStatus} entries that the + * controller can report for an {@link Action}. + */ + int getMaxStatusEntriesPerAction(); + + /** + * @return maximum number of attributes that the controller can report; + */ + int getMaxAttributeEntriesPerTarget(); + + /** + * @return maximum number of allowed {@link RolloutGroup}s per + * {@link Rollout}. + */ + int getMaxRolloutGroupsPerRollout(); + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index cb65bf270..2e23b246e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -82,7 +82,7 @@ public interface RolloutGroupManagement { * Retrieves a page of {@link RolloutGroup}s filtered by a given * {@link Rollout} and the an rsql filter. * - * @param rollout + * @param rolloutId * the rollout to filter the {@link RolloutGroup}s * @param rsqlParam * the specification to filter the result set based on attributes @@ -98,7 +98,7 @@ public interface RolloutGroupManagement { * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsAll(@NotNull Long rollout, @NotNull String rsqlParam, + Page findRolloutGroupsAll(@NotNull Long rolloutId, @NotNull String rsqlParam, @NotNull Pageable pageable); /** @@ -114,6 +114,19 @@ public interface RolloutGroupManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable pageable); + /** + * Retrieves a page of {@link RolloutGroup}s filtered by a given + * {@link Rollout}. + * + * @param rolloutId + * the ID of the rollout to filter the {@link RolloutGroup}s + * @param pageable + * the page request to sort and limit the result + * @return a page of found {@link RolloutGroup}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + long countRolloutGroupsByRolloutId(@NotNull Long rolloutId); + /** * Get targets of specified rollout group. * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index f8b7ba705..4003c05d6 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -334,6 +334,23 @@ public interface SoftwareManagement { Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId, @NotNull String rsqlParam, @NotNull Pageable pageable); + /** + * Finds all meta data by the given software module id. + * + * @param pageable + * pagination parameter + * + * @param moduleId + * the software module id to retrieve the meta data from + * @return page with found software module metadata + * + * @throws EntityNotFoundException + * of software module with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Pageable pageable, + @NotNull Long moduleId); + /** * Filter {@link SoftwareModule}s with given * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} @@ -522,25 +539,4 @@ public interface SoftwareManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleTypeUpdate update); - - /** - * Finds all meta data by the given software module id. - * - * @param moduleId - * the software module id to retrieve the meta data from - * - * - * @throws RSQLParameterUnsupportedFieldException - * if a field in the RSQL string is used but not provided by the - * given {@code fieldNameProvider} - * @throws RSQLParameterSyntaxException - * if the RSQL syntax is wrong - * @return result of all meta data entries for a given software module id. - * - * @throws EntityNotFoundException - * of software module with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index d07316868..fbb1701d8 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository; -import java.util.List; +import java.util.function.Consumer; import javax.validation.constraints.NotNull; @@ -18,6 +18,8 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; import org.eclipse.hawkbit.tenancy.TenantAware; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -44,10 +46,22 @@ public interface SystemManagement { /** * + * @param pageable + * for paging information * @return list of all tenant names in the system. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) - List findTenants(); + Page findTenants(@NotNull Pageable pageable); + + /** + * Runs consumer for each teant as + * {@link TenantAware#runAsTenant(String, org.eclipse.hawkbit.tenancy.TenantAware.TenantRunner)} + * + * @param consumer + * to run as teanant + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) + void forEachTenant(Consumer consumer); /** * Calculated system usage statistics, both overall for the entire system diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java index d7fe9e0f3..515375af8 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -122,13 +122,6 @@ public interface TagManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) void deleteTargetTag(@NotEmpty String targetTagName); - /** - * - * @return all {@link DistributionSetTag}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findAllDistributionSetTags(); - /** * returns all {@link DistributionSetTag}s. * @@ -241,6 +234,22 @@ public interface TagManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Optional findTargetTagById(@NotNull Long id); + /** + * Finds all {@link TargetTag} assigned to given {@link Target}. + * + * @param pageable + * information for page size, offset and sort order. + * + * @param setId + * of the {@link DistributionSet} + * @return page of the found {@link TargetTag}s + * + * @throws EntityNotFoundException + * if {@link DistributionSet} with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findDistributionSetTagsByDistributionSet(@NotNull Pageable pageable, @NotNull Long setId); + /** * Updates an existing {@link DistributionSetTag}. * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index 632b642f1..4c8c88a10 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -339,7 +339,7 @@ public interface TargetManagement { * @return List of found{@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findTargetByControllerID(@NotEmpty Collection controllerIDs); + List findTargetsByControllerID(@NotEmpty Collection controllerIDs); /** * Find a {@link Target} based a given ID. @@ -533,13 +533,41 @@ public interface TargetManagement { /** * Find targets by tag name. - * - * @param tagName - * tag name + * + * @param pageable + * the page request parameter for paging and sorting the result + * @param tagId + * tag ID * @return list of matching targets + * + * @throws EntityNotFoundException + * if target tag with given ID does not exist */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findTargetsByTag(@NotEmpty String tagName); + Page findTargetsByTag(@NotNull Pageable pageable, @NotNull Long tagId); + + /** + * Find targets by tag name. + * + * @param pageable + * the page request parameter for paging and sorting the result + * @param tagId + * tag ID + * @param rsqlParam + * in RSQL notation + * + * @return list of matching targets + * + * @throws EntityNotFoundException + * if target tag with given ID does not exist + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findTargetsByTag(@NotNull Pageable pageable, @NotNull String rsqlParam, @NotNull Long tagId); /** * Toggles {@link TargetTag} assignment to given {@link Target}s by means @@ -559,19 +587,6 @@ public interface TargetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection controllerIds, @NotEmpty String tagName); - /** - * Un-assign all {@link Target} from a given {@link TargetTag} . - * - * @param targetTagId - * to un-assign all targets - * @return list of unassigned targets - * - * @throws EntityNotFoundException - * if TAG with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - List unAssignAllTargetsByTag(@NotNull Long targetTagId); - /** * Un-assign a {@link TargetTag} assignment to given {@link Target}. * @@ -623,7 +638,7 @@ public interface TargetManagement { * @return the found {@link Target}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - List findTargetAllById(@NotNull Collection ids); + List findTargetsById(@NotNull Collection ids); /** * Get controller attributes of given {@link Target}. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdatedEvent.java similarity index 78% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdatedEvent.java index c55114ddb..288dd12c6 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdateEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdatedEvent.java @@ -14,14 +14,14 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag; * Defines the remote event for update a {@link DistributionSetTag}. * */ -public class DistributionSetTagUpdateEvent extends RemoteEntityEvent { +public class DistributionSetTagUpdatedEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; /** * Default constructor. */ - public DistributionSetTagUpdateEvent() { + public DistributionSetTagUpdatedEvent() { // for serialization libs like jackson } @@ -33,7 +33,7 @@ public class DistributionSetTagUpdateEvent extends RemoteEntityEvent { +public class DistributionSetUpdatedEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; /** * Default constructor. */ - public DistributionSetUpdateEvent() { + public DistributionSetUpdatedEvent() { // for serialization libs like jackson } @@ -33,7 +33,7 @@ public class DistributionSetUpdateEvent extends RemoteEntityEvent { +public class TargetTagUpdatedEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; /** * Default constructor. */ - public TargetTagUpdateEvent() { + public TargetTagUpdatedEvent() { // for serialization libs like jackson } @@ -33,7 +33,7 @@ public class TargetTagUpdateEvent extends RemoteEntityEvent { * @param applicationId * the origin application id */ - public TargetTagUpdateEvent(final TargetTag tag, final String applicationId) { + public TargetTagUpdatedEvent(final TargetTag tag, final String applicationId) { super(tag, applicationId); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 464095b71..749318388 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.List; import java.util.concurrent.TimeUnit; /** @@ -45,11 +44,6 @@ public interface Action extends TenantAwareBaseEntity { */ ActionType getActionType(); - /** - * @return list of {@link ActionStatus} entries. - */ - List getActionStatus(); - /** * @return {@link Target} of this {@link Action}. */ diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java index 467a2cc68..bc97c60f4 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.List; import java.util.concurrent.TimeUnit; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -28,12 +27,6 @@ public interface ActionStatus extends TenantAwareBaseEntity { */ Long getOccurredAt(); - /** - * @return immutable list of message entries that in the - * {@link ActionStatus}. - */ - List getMessages(); - /** * @return {@link Action} this {@link ActionStatus} belongs to. */ diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java deleted file mode 100644 index 268c37853..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.model; - -/** - * View for querying {@link Action} include the count of the action's - * {@link ActionStatus} entries. - * - */ -public interface ActionWithStatusCount { - - /** - * @return {@link Action} - */ - Action getAction(); - - /** - * @return {@link DistributionSet} ID. - */ - Long getDsId(); - - /** - * @return {@link DistributionSet} name. - */ - String getDsName(); - - /** - * @return {@link DistributionSet} version. - */ - String getDsVersion(); - - /** - * @return number of {@link ActionStatus} entries - */ - Long getActionStatusCount(); - - /** - * @return name of the {@link Rollout}. - */ - String getRolloutName(); - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index 2e7e2c7ac..40f9ed3d2 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -24,11 +24,6 @@ import java.util.Set; */ public interface DistributionSet extends NamedVersionedEntity { - /** - * @return immutable {@link Set} of assigned {@link DistributionSetTag}s. - */ - Set getTags(); - /** * @return true if the set is deleted and only kept for history * purposes. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java index c7bff07a3..f4b85e245 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java @@ -69,7 +69,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult { return Collections.emptyList(); } - return targetManagement.findTargetByControllerID(assignedTargets); + return targetManagement.findTargetsByControllerID(assignedTargets); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java index c095d0f7e..da8c68347 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java @@ -15,11 +15,7 @@ import java.util.Collection; */ public final class DistributionSetFilter { /** - * * Distribution set filter builder. - * - * - * */ public static class DistributionSetFilterBuilder { private Boolean isDeleted; @@ -81,6 +77,7 @@ public final class DistributionSetFilter { } } + private final Boolean isDeleted; private final Boolean isComplete; private final DistributionSetType type; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index 9507e29b2..aec150152 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -8,18 +8,10 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.List; - /** * {@link Tag} of a {@link DistributionSet}. * */ public interface DistributionSetTag extends Tag { - /** - * @return immutable {@link List} of {@link DistributionSet}s this - * {@link Tag} is assigned to. - */ - List getAssignedToDistributionSet(); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index 277262dc1..3e6cd314b 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.List; import java.util.concurrent.TimeUnit; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -37,11 +36,6 @@ public interface Rollout extends NamedEntity { */ DistributionSet getDistributionSet(); - /** - * @return immutable list of deployment groups of the rollout. - */ - List getRolloutGroups(); - /** * @return rsql query that identifies the targets that are part of this * rollout. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java index afe0ff59a..9923c194e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java @@ -8,17 +8,10 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.List; - /** * Target tag element. * */ public interface TargetTag extends Tag { - /** - * @return immutable {@link List} of targets assigned to this {@link Tag}. - */ - List getAssignedToTargets(); - } diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/EventType.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/EventType.java index f12693a73..6f4f56d06 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/EventType.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/EventType.java @@ -26,8 +26,8 @@ import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; @@ -35,7 +35,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedE import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; /** @@ -66,7 +66,7 @@ public class EventType { // target tag TYPES.put(6, TargetTagCreatedEvent.class); - TYPES.put(7, TargetTagUpdateEvent.class); + TYPES.put(7, TargetTagUpdatedEvent.class); TYPES.put(8, TargetTagDeletedEvent.class); // action @@ -75,12 +75,12 @@ public class EventType { // distribution set TYPES.put(11, DistributionSetCreatedEvent.class); - TYPES.put(12, DistributionSetUpdateEvent.class); + TYPES.put(12, DistributionSetUpdatedEvent.class); TYPES.put(13, DistributionSetDeletedEvent.class); // distribution set tag TYPES.put(14, DistributionSetTagCreatedEvent.class); - TYPES.put(15, DistributionSetTagUpdateEvent.class); + TYPES.put(15, DistributionSetTagUpdatedEvent.class); TYPES.put(16, DistributionSetTagDeletedEvent.class); // rollout diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/PropertiesQuotaManagement.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/PropertiesQuotaManagement.java new file mode 100644 index 000000000..480f8dafd --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/PropertiesQuotaManagement.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import org.eclipse.hawkbit.security.HawkbitSecurityProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * {@link QuotaManagement} implementation based on spring boot + * {@link ConfigurationProperties}. + * + */ +public class PropertiesQuotaManagement implements QuotaManagement { + + private final HawkbitSecurityProperties securityProperties; + + /** + * @param securityProperties + * that holds the quota definitions + */ + public PropertiesQuotaManagement(final HawkbitSecurityProperties securityProperties) { + this.securityProperties = securityProperties; + } + + @Override + public int getMaxStatusEntriesPerAction() { + return securityProperties.getDos().getMaxStatusEntriesPerAction(); + } + + @Override + public int getMaxAttributeEntriesPerTarget() { + return securityProperties.getDos().getMaxAttributeEntriesPerTarget(); + } + + @Override + public int getMaxRolloutGroupsPerRollout() { + return securityProperties.getDos().getMaxRolloutGroupsPerRollout(); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/RolloutHelper.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/RolloutHelper.java index b66c54524..36dae89c2 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/RolloutHelper.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/RolloutHelper.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; * A collection of static helper methods for the {@link RolloutManagement} */ public final class RolloutHelper { + private RolloutHelper() { } @@ -68,12 +69,14 @@ public final class RolloutHelper { * * @param amountGroup * amount of groups + * @param quotaManagement + * to retrieve maximum number of groups allowed */ - public static void verifyRolloutGroupParameter(final int amountGroup) { + public static void verifyRolloutGroupParameter(final int amountGroup, final QuotaManagement quotaManagement) { if (amountGroup <= 0) { - throw new ConstraintViolationException("the amountGroup must be greater than zero"); - } else if (amountGroup > 500) { - throw new ConstraintViolationException("the amountGroup must not be greater than 500"); + throw new ConstraintViolationException("the amount of groups cannot be lower than zero"); + } else if (amountGroup > quotaManagement.getMaxRolloutGroupsPerRollout()) { + throw new ConstraintViolationException("the amount of groups cannot be greater than 500"); } } @@ -144,32 +147,12 @@ public final class RolloutHelper { * the group to add * @return list of groups */ - public static List getGroupsByStatusIncludingGroup(final Rollout rollout, + public static List getGroupsByStatusIncludingGroup(final List groups, final RolloutGroup.RolloutGroupStatus status, final RolloutGroup group) { - return rollout.getRolloutGroups().stream() - .filter(innerGroup -> innerGroup.getStatus().equals(status) || innerGroup.equals(group)) + return groups.stream().filter(innerGroup -> innerGroup.getStatus().equals(status) || innerGroup.equals(group)) .map(RolloutGroup::getId).collect(Collectors.toList()); } - /** - * Returns the groups of a rollout by their Ids order - * - * @param rollout - * the rollout - * @return ordered list of groups - */ - public static List getOrderedGroups(final Rollout rollout) { - return rollout.getRolloutGroups().stream().sorted((group1, group2) -> { - if (group1.getId() < group2.getId()) { - return -1; - } - if (group1.getId() > group2.getId()) { - return 1; - } - return 0; - }).collect(Collectors.toList()); - } - /** * Creates an RSQL expression that matches all targets in the provided * groups. Links all target filter queries with OR. diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutUpdateCreate.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutUpdateCreate.java index 6c413a929..0e16f105f 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutUpdateCreate.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/builder/AbstractRolloutUpdateCreate.java @@ -8,10 +8,10 @@ */ package org.eclipse.hawkbit.repository.builder; -import org.eclipse.hawkbit.repository.model.Action.ActionType; - import java.util.Optional; +import org.eclipse.hawkbit.repository.model.Action.ActionType; + /** * Create and update builder DTO. * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java index b408ebb5b..639dd8328 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java @@ -172,7 +172,8 @@ public interface ActionRepository extends BaseEntityRepository, */ @EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD) @Query("Select a from JpaAction a where a.target.controllerId = :target and a.active= :active order by a.id") - List findByActiveAndTarget(@Param("target") String target, @Param("active") boolean active); + Page findByActiveAndTarget(Pageable pageable, @Param("target") String target, + @Param("active") boolean active); /** * Switches the status of actions from one specific status into another, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java index 2a7abb694..28305207a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java @@ -17,11 +17,12 @@ import javax.persistence.EntityManager; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -38,13 +39,29 @@ public interface DistributionSetRepository /** * Finds {@link DistributionSet}s by assigned {@link Tag}. + * + * @param pageable + * paging and sorting information * - * @param tag + * @param tagId * to be found * @return list of found {@link DistributionSet}s */ - @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst = :tag") - List findByTag(@Param("tag") final DistributionSetTag tag); + @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tag") + Page findByTag(Pageable pageable, @Param("tag") final Long tagId); + + /** + * Finds {@link DistributionSet}s by assigned {@link Tag}. + * + * @param pageable + * paging and sorting information + * + * @param tagId + * to be found + * @return page of found {@link DistributionSet}s + */ + @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst.id = :tagId") + Page findByTagId(Pageable pageable, @Param("tagId") final Long tagId); /** * deletes the {@link DistributionSet}s with the given IDs. @@ -147,9 +164,9 @@ public interface DistributionSetRepository /** * Deletes all {@link TenantAwareBaseEntity} of a given tenant. For safety - * reasons (this is a "delete everything" query after all) we add the tenant manually to - * query even if this will by done by {@link EntityManager} anyhow. The DB - * should take care of optimizing this away. + * reasons (this is a "delete everything" query after all) we add the tenant + * manually to query even if this will by done by {@link EntityManager} + * anyhow. The DB should take care of optimizing this away. * * @param tenant * to delete data from diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java index 3943dc679..c2192c4b3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java @@ -51,6 +51,16 @@ public interface DistributionSetTagRepository */ Optional findByNameEquals(final String tagName); + /** + * Checks if tag with given name exists. + * + * @param tagName + * to check for + * @return true is tag with given name exists + */ + @Query("SELECT CASE WHEN COUNT(t)>0 THEN 'true' ELSE 'false' END FROM JpaDistributionSetTag t WHERE t.name=:tagName") + boolean existsByName(@Param("tagName") String tagName); + /** * Returns all instances of the type. * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 0832c0822..9bb5ba76f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -20,6 +20,7 @@ import javax.persistence.criteria.Root; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RepositoryProperties; import org.eclipse.hawkbit.repository.TargetManagement; @@ -47,7 +48,6 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; @@ -92,7 +92,7 @@ public class JpaControllerManagement implements ControllerManagement { private ActionStatusRepository actionStatusRepository; @Autowired - private HawkbitSecurityProperties securityProperties; + private QuotaManagement quotaManagement; @Autowired private RepositoryProperties repositoryProperties; @@ -313,15 +313,14 @@ public class JpaControllerManagement implements ControllerManagement { private Action handleAddUpdateActionStatus(final JpaActionStatus actionStatus, final JpaAction action) { LOG.debug("addUpdateActionStatus for action {}", action.getId()); - JpaTarget target = (JpaTarget) action.getTarget(); - switch (actionStatus.getStatus()) { case ERROR: - target = DeploymentHelper.updateTargetInfo(target, TargetUpdateStatus.ERROR, false); + final JpaTarget target = DeploymentHelper.updateTargetInfo((JpaTarget) action.getTarget(), + TargetUpdateStatus.ERROR, false); handleErrorOnAction(action, target); break; case FINISHED: - handleFinishedAndStoreInTargetStatus(target, action); + handleFinishedAndStoreInTargetStatus(action); break; default: // information status entry - check for a potential DOS attack @@ -332,7 +331,7 @@ public class JpaControllerManagement implements ControllerManagement { actionStatus.setAction(action); actionStatusRepository.save(actionStatus); - LOG.debug("addUpdateActionStatus {} for target {} is finished.", action, target.getId()); + LOG.debug("addUpdateActionStatus for action {} isfinished.", action.getId()); return actionRepository.save(action); } @@ -346,21 +345,21 @@ public class JpaControllerManagement implements ControllerManagement { } private void checkForToManyStatusEntries(final JpaAction action) { - if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) { + if (quotaManagement.getMaxStatusEntriesPerAction() > 0) { final Long statusCount = actionStatusRepository.countByAction(action); - if (statusCount >= securityProperties.getDos().getMaxStatusEntriesPerAction()) { + if (statusCount >= quotaManagement.getMaxStatusEntriesPerAction()) { LOG_DOS.error( "Potential denial of service (DOS) attack identfied. More status entries in the system than permitted ({})!", - securityProperties.getDos().getMaxStatusEntriesPerAction()); - throw new TooManyStatusEntriesException( - String.valueOf(securityProperties.getDos().getMaxStatusEntriesPerAction())); + quotaManagement.getMaxStatusEntriesPerAction()); + throw new TooManyStatusEntriesException(String.valueOf(quotaManagement.getMaxStatusEntriesPerAction())); } } } - private void handleFinishedAndStoreInTargetStatus(final JpaTarget target, final JpaAction action) { + private void handleFinishedAndStoreInTargetStatus(final JpaAction action) { + final JpaTarget target = (JpaTarget) action.getTarget(); action.setActive(false); action.setStatus(Status.FINISHED); final JpaDistributionSet ds = (JpaDistributionSet) entityManager.merge(action.getDistributionSet()); @@ -388,11 +387,11 @@ public class JpaControllerManagement implements ControllerManagement { target.getControllerAttributes().putAll(data); - if (target.getControllerAttributes().size() > securityProperties.getDos().getMaxAttributeEntriesPerTarget()) { + if (target.getControllerAttributes().size() > quotaManagement.getMaxAttributeEntriesPerTarget()) { LOG_DOS.info("Target tries to insert more than the allowed number of entries ({}). DOS attack anticipated!", - securityProperties.getDos().getMaxAttributeEntriesPerTarget()); + quotaManagement.getMaxAttributeEntriesPerTarget()); throw new ToManyAttributeEntriesException( - String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget())); + String.valueOf(quotaManagement.getMaxAttributeEntriesPerTarget())); } target.setRequestControllerAttributes(false); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 0b18ca79e..c8cae34dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -21,7 +21,6 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; import javax.persistence.criteria.JoinType; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Root; @@ -43,13 +42,10 @@ import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecuto import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_; -import org.eclipse.hawkbit.repository.jpa.model.JpaActionWithStatusCount; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; @@ -58,7 +54,6 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -538,31 +533,6 @@ public class JpaDeploymentManagement implements DeploymentManagement { return actionRepository.findByTargetControllerId(pageable, controllerId); } - @Override - public List findActionsWithStatusCountByTargetOrderByIdDesc(final String controllerId) { - throwExceptionIfTargetDoesNotExist(controllerId); - - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = cb.createQuery(JpaActionWithStatusCount.class); - final Root actionRoot = query.from(JpaAction.class); - final ListJoin actionStatusJoin = actionRoot.join(JpaAction_.actionStatus, - JoinType.LEFT); - final Join actionDsJoin = actionRoot.join(JpaAction_.distributionSet); - final Join actionRolloutJoin = actionRoot.join(JpaAction_.rollout, JoinType.LEFT); - - final CriteriaQuery multiselect = query.distinct(true).multiselect( - actionRoot.get(JpaAction_.id), actionRoot.get(JpaAction_.actionType), actionRoot.get(JpaAction_.active), - actionRoot.get(JpaAction_.forcedTime), actionRoot.get(JpaAction_.status), - actionRoot.get(JpaAction_.createdAt), actionRoot.get(JpaAction_.lastModifiedAt), - actionDsJoin.get(JpaDistributionSet_.id), actionDsJoin.get(JpaDistributionSet_.name), - actionDsJoin.get(JpaDistributionSet_.version), cb.count(actionStatusJoin), - actionRolloutJoin.get(JpaRollout_.name)); - multiselect.where(cb.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId)); - multiselect.orderBy(cb.desc(actionRoot.get(JpaAction_.id))); - multiselect.groupBy(actionRoot.get(JpaAction_.id)); - return Collections.unmodifiableList(entityManager.createQuery(multiselect).getResultList()); - } - @Override public Page findActionsByTarget(final String rsqlParam, final String controllerId, final Pageable pageable) { @@ -584,17 +554,17 @@ public class JpaDeploymentManagement implements DeploymentManagement { } @Override - public List findActiveActionsByTarget(final String controllerId) { + public Page findActiveActionsByTarget(final Pageable pageable, final String controllerId) { throwExceptionIfTargetDoesNotExist(controllerId); - return actionRepository.findByActiveAndTarget(controllerId, true); + return actionRepository.findByActiveAndTarget(pageable, controllerId, true); } @Override - public List findInActiveActionsByTarget(final String controllerId) { + public Page findInActiveActionsByTarget(final Pageable pageable, final String controllerId) { throwExceptionIfTargetDoesNotExist(controllerId); - return actionRepository.findByActiveAndTarget(controllerId, false); + return actionRepository.findByActiveAndTarget(pageable, controllerId, false); } @Override @@ -645,15 +615,6 @@ public class JpaDeploymentManagement implements DeploymentManagement { return actionStatusRepository.findByActionId(pageReq, actionId); } - @Override - public Page findActionStatusByActionWithMessages(final Pageable pageReq, final Long actionId) { - if (!actionRepository.exists(actionId)) { - throw new EntityNotFoundException(Action.class, actionId); - } - - return actionStatusRepository.getByActionId(pageReq, actionId); - } - @Override public Page findMessagesByActionStatusId(final Pageable pageable, final Long actionStatusId) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 6f9e13750..4650e4fda 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -125,6 +125,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Autowired private SoftwareModuleTypeRepository softwareModuleTypeRepository; + @Autowired + private DistributionSetTagRepository distributionSetTagRepository; + @Override public Optional findDistributionSetByIdWithDetails(final Long distid) { return Optional.ofNullable(distributionSetRepository.findOne(DistributionSetSpecification.byId(distid))); @@ -235,7 +238,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Override @Transactional public void deleteDistributionSet(final Collection distributionSetIDs) { - final List setsFound = findDistributionSetAllById(distributionSetIDs); + final List setsFound = findDistributionSetsById(distributionSetIDs); if (setsFound.size() < distributionSetIDs.size()) { throw new EntityNotFoundException(DistributionSet.class, distributionSetIDs, @@ -485,6 +488,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); } + @Override + public Page findDistributionSetsAll(final Pageable pageReq, final Boolean deleted) { + + final List> specList = new ArrayList<>(1); + if (deleted != null) { + specList.add(DistributionSetSpecification.isDeleted(deleted)); + } + + return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); + } + @Override public Page findDistributionSetsAllOrderedByLinkTarget(final Pageable pageable, final DistributionSetFilterBuilder distributionSetFilterBuilder, final String assignedOrInstalled) { @@ -536,12 +550,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } - @Override - public List findDistributionSetsAll(final Collection dist) { - return Collections - .unmodifiableList(distributionSetRepository.findAll(DistributionSetSpecification.byIds(dist))); - } - @Override public Long countDistributionSetsAll() { final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE); @@ -827,20 +835,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { .unmodifiableList(allDs.stream().map(distributionSetRepository::save).collect(Collectors.toList())); } - @Override - @Transactional - public List unAssignAllDistributionSetsByTag(final Long dsTagId) { - - final DistributionSetTag distributionSetTag = tagManagement.findDistributionSetTagById(dsTagId) - .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId)); - - @SuppressWarnings({ "unchecked", "rawtypes" }) - final Collection distributionSets = (Collection) distributionSetTag - .getAssignedToDistributionSet(); - - return Collections.unmodifiableList(unAssignTag(distributionSets, distributionSetTag)); - } - @Override @Transactional public DistributionSet unAssignTag(final Long dsId, final Long dsTagId) { @@ -894,8 +888,36 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public List findDistributionSetAllById(final Collection ids) { + public List findDistributionSetsById(final Collection ids) { return Collections.unmodifiableList(distributionSetRepository.findAll(ids)); } + @Override + public Page findDistributionSetsByTag(final Pageable pageable, final Long tagId) { + throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId); + + return convertDsPage(distributionSetRepository.findByTag(pageable, tagId), pageable); + + } + + private void throwEntityNotFoundExceptionIfDsTagDoesNotExist(final Long tagId) { + if (!distributionSetTagRepository.exists(tagId)) { + throw new EntityNotFoundException(DistributionSetTag.class, tagId); + } + } + + @Override + public Page findDistributionSetsByTag(final Pageable pageable, final String rsqlParam, + final Long tagId) { + throwEntityNotFoundExceptionIfDsTagDoesNotExist(tagId); + + final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class, + virtualPropertyReplacer); + + return convertDsPage(distributionSetRepository.findAll((Specification) (root, query, + cb) -> cb.and(DistributionSetSpecification.hasTag(tagId).toPredicate(root, query, cb), + spec.toPredicate(root, query, cb)), + pageable), pageable); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index dc81d3e8a..53a01f95d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -86,6 +86,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { @Override public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable pageable) { + throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); + return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable); } @@ -100,6 +102,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { @Override public Page findRolloutGroupsAll(final Long rolloutId, final String rsqlParam, final Pageable pageable) { + throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); final Specification specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class, virtualPropertyReplacer); @@ -115,11 +118,15 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { pageable); } - @Override - public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) { + private void throwEntityNotFoundExceptionIfRolloutDoesNotExist(final Long rolloutId) { if (!rolloutRepository.exists(rolloutId)) { throw new EntityNotFoundException(Rollout.class, rolloutId); } + } + + @Override + public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) { + throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable); final List rolloutGroupIds = rolloutGroups.getContent().stream().map(RolloutGroup::getId) @@ -173,6 +180,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { public Page findRolloutGroupTargets(final Long rolloutGroupId, final String rsqlParam, final Pageable pageable) { + throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); + final Specification rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer); @@ -253,4 +262,11 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } } + @Override + public long countRolloutGroupsByRolloutId(final Long rolloutId) { + throwEntityNotFoundExceptionIfRolloutDoesNotExist(rolloutId); + + return rolloutGroupRepository.countByRolloutId(rolloutId); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 8a969e2eb..613cb81b1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -24,6 +24,7 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.AbstractRolloutManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutHelper; @@ -77,6 +78,8 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; import org.springframework.integration.support.locks.LockRegistry; import org.springframework.scheduling.annotation.Async; @@ -129,6 +132,9 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Autowired private EntityManager entityManager; + @Autowired + private QuotaManagement quotaManagement; + JpaRolloutManagement(final TargetManagement targetManagement, final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement, final DistributionSetManagement distributionSetManagement, final ApplicationContext context, @@ -175,7 +181,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional public Rollout createRollout(final RolloutCreate rollout, final int amountGroup, final RolloutGroupConditions conditions) { - RolloutHelper.verifyRolloutGroupParameter(amountGroup); + RolloutHelper.verifyRolloutGroupParameter(amountGroup, quotaManagement); final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build()); return createRolloutGroups(amountGroup, conditions, savedRollout); } @@ -184,7 +190,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { @Transactional public Rollout createRollout(final RolloutCreate rollout, final List groups, final RolloutGroupConditions conditions) { - RolloutHelper.verifyRolloutGroupParameter(groups.size()); + RolloutHelper.verifyRolloutGroupParameter(groups.size(), quotaManagement); final JpaRollout savedRollout = createRollout((JpaRollout) rollout.build()); return createRolloutGroups(groups, conditions, savedRollout); } @@ -297,7 +303,10 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { private void handleCreateRollout(final JpaRollout rollout) { LOGGER.debug("handleCreateRollout called for rollout {}", rollout.getId()); - final List rolloutGroups = RolloutHelper.getOrderedGroups(rollout); + final List rolloutGroups = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), + new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout(), new Sort(Direction.ASC, "id"))) + .getContent(); + int readyGroups = 0; int totalTargets = 0; for (final RolloutGroup group : rolloutGroups) { @@ -325,7 +334,7 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } } - private RolloutGroup fillRolloutGroupWithTargets(final Rollout rollout, final RolloutGroup group1) { + private RolloutGroup fillRolloutGroupWithTargets(final JpaRollout rollout, final RolloutGroup group1) { RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING); final JpaRolloutGroup group = (JpaRolloutGroup) group1; @@ -338,8 +347,8 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { groupTargetFilter = baseFilter + ";" + group.getTargetFilterQuery(); } - final List readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout, RolloutGroupStatus.READY, - group); + final List readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(), + RolloutGroupStatus.READY, group); final long targetsInGroupFilter = runInNewTransaction("countAllTargetsByTargetFilterQueryAndNotInRolloutGroups", count -> targetManagement.countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(readyGroups, @@ -376,12 +385,12 @@ public class JpaRolloutManagement extends AbstractRolloutManagement { } } - private Long assignTargetsToGroupInNewTransaction(final Rollout rollout, final RolloutGroup group, + private Long assignTargetsToGroupInNewTransaction(final JpaRollout rollout, final RolloutGroup group, final String targetFilter, final long limit) { return runInNewTransaction("assignTargetsToRolloutGroup", status -> { final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit)); - final List readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout, + final List readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(), RolloutGroupStatus.READY, group); final Page targets = targetManagement .findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index ed72f0e65..b3bcef388 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -622,7 +622,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { return convertSmMdPage( softwareModuleMetadataRepository .findAll( - (Specification) (root, query, cb) -> cb.and( + (root, query, cb) -> cb.and( cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule) .get(JpaSoftwareModule_.id), softwareModuleId), spec.toPredicate(root, query, cb)), @@ -631,13 +631,13 @@ public class JpaSoftwareManagement implements SoftwareManagement { } @Override - public List findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId) { + public Page findSoftwareModuleMetadataBySoftwareModuleId(final Pageable pageable, + final Long softwareModuleId) { throwExceptionIfSoftwareModuleDoesNotExist(softwareModuleId); - return Collections.unmodifiableList(softwareModuleMetadataRepository - .findAll((Specification) (root, query, cb) -> cb - .and(cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), - softwareModuleId)))); + return convertSmMdPage(softwareModuleMetadataRepository.findAll((root, query, cb) -> cb.equal( + root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), softwareModuleId), + pageable), pageable); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index 95ab6415a..e5e7bc20d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -9,7 +9,9 @@ package org.eclipse.hawkbit.repository.jpa; import java.math.BigDecimal; +import java.util.Collections; import java.util.List; +import java.util.function.Consumer; import java.util.stream.Collectors; import javax.persistence.EntityManager; @@ -32,6 +34,10 @@ import org.eclipse.persistence.config.PersistenceUnitProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.annotation.Propagation; @@ -47,6 +53,8 @@ import org.springframework.validation.annotation.Validated; @Transactional(readOnly = true) @Validated public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, SystemManagement { + private static final int MAX_TENANTS_QUERY = 500; + @Autowired private EntityManager entityManager; @@ -135,7 +143,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } private void usageStatsPerTenant(final SystemUsageReport report) { - final List tenants = findTenants(); + final List tenants = findTenants(new PageRequest(0, MAX_TENANTS_QUERY)).getContent(); tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> { report.addTenantData(systemStatsManagement.getStatsOfTenant()); @@ -192,8 +200,13 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } @Override - public List findTenants() { - return tenantMetaDataRepository.findAll().stream().map(TenantMetaData::getTenant).collect(Collectors.toList()); + public Page findTenants(final Pageable pageable) { + final Page result = tenantMetaDataRepository.findAll(pageable); + + return new PageImpl<>( + Collections.unmodifiableList( + result.getContent().stream().map(TenantMetaData::getTenant).collect(Collectors.toList())), + pageable, result.getTotalElements()); } @Override @@ -271,4 +284,20 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst public TenantMetaData getTenantMetadata(final Long tenantId) { return tenantMetaDataRepository.findOne(tenantId); } + + @Override + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public void forEachTenant(final Consumer consumer) { + + Page tenants; + Pageable query = new PageRequest(0, MAX_TENANTS_QUERY); + do { + tenants = findTenants(query); + tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> { + consumer.accept(tenant); + return null; + })); + } while (tenants.hasNext() && (query = tenants.nextPageable()) != null); + + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index 7665bff43..c5b9fb802 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -25,7 +25,9 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.TagSpecification; +import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.springframework.beans.factory.annotation.Autowired; @@ -85,17 +87,12 @@ public class JpaTagManagement implements TagManagement { @Override @Transactional public void deleteTargetTag(final String targetTagName) { - final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName) - .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagName)); - - targetRepository.findByTag(tag.getId()).forEach(set -> { - set.removeTag(tag); - targetRepository.save(set); - }); + if (!targetTagRepository.existsByName(targetTagName)) { + throw new EntityNotFoundException(TargetTag.class, targetTagName); + } // finally delete the tag itself targetTagRepository.deleteByName(targetTagName); - } @Override @@ -177,22 +174,13 @@ public class JpaTagManagement implements TagManagement { @Override @Transactional public void deleteDistributionSetTag(final String tagName) { - final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName) - .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName)); - - distributionSetRepository.findByTag(tag).forEach(set -> { - set.removeTag(tag); - distributionSetRepository.save(set); - }); + if (!distributionSetTagRepository.existsByName(tagName)) { + throw new EntityNotFoundException(DistributionSetTag.class, tagName); + } distributionSetTagRepository.deleteByName(tagName); } - @Override - public List findAllDistributionSetTags() { - return Collections.unmodifiableList(distributionSetTagRepository.findAll()); - } - @Override public Optional findTargetTagById(final Long id) { return Optional.ofNullable(targetTagRepository.findOne(id)); @@ -223,7 +211,21 @@ public class JpaTagManagement implements TagManagement { @Override public Page findAllTargetTags(final Pageable pageable, final String controllerId) { + if (!targetRepository.existsByControllerId(controllerId)) { + throw new EntityNotFoundException(Target.class, controllerId); + } + return convertTPage(targetTagRepository.findAll(TagSpecification.ofTarget(controllerId), pageable), pageable); } + @Override + public Page findDistributionSetTagsByDistributionSet(final Pageable pageable, + final Long setId) { + if (!distributionSetRepository.exists(setId)) { + throw new EntityNotFoundException(DistributionSet.class, setId); + } + + return convertDsPage(distributionSetTagRepository.findAll(TagSpecification.ofDistributionSet(setId), pageable), + pageable); + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index 9c679b61d..6c2fbd0b4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -113,7 +113,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public List findTargetByControllerID(final Collection controllerIDs) { + public List findTargetsByControllerID(final Collection controllerIDs) { return Collections.unmodifiableList( targetRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs))); } @@ -376,41 +376,18 @@ public class JpaTargetManagement implements TargetManagement { .unmodifiableList(allTargets.stream().map(targetRepository::save).collect(Collectors.toList())); } - private List unAssignTag(final Collection targets, final TargetTag tag) { - @SuppressWarnings({ "unchecked", "rawtypes" }) - final Collection toUnassign = (Collection) targets; - - toUnassign.forEach(target -> target.removeTag(tag)); - - return Collections - .unmodifiableList(toUnassign.stream().map(targetRepository::save).collect(Collectors.toList())); - } - - @Override - @Transactional - public List unAssignAllTargetsByTag(final Long targetTagId) { - - final TargetTag tag = targetTagRepository.findById(targetTagId) - .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId)); - - if (tag.getAssignedToTargets().isEmpty()) { - return Collections.emptyList(); - } - - return unAssignTag(tag.getAssignedToTargets(), tag); - } - @Override @Transactional public Target unAssignTag(final String controllerID, final Long targetTagId) { - final Target target = targetRepository.findByControllerId(controllerID) + final JpaTarget target = (JpaTarget) targetRepository.findByControllerId(controllerID) .orElseThrow(() -> new EntityNotFoundException(Target.class, controllerID)); final TargetTag tag = targetTagRepository.findById(targetTagId) .orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId)); - final List unAssignTag = unAssignTag(Lists.newArrayList(target), tag); - return unAssignTag.isEmpty() ? null : unAssignTag.get(0); + target.removeTag(tag); + + return targetRepository.save(target); } @Override @@ -559,13 +536,28 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public List findTargetsByTag(final String tagName) { - final Optional tag = targetTagRepository.findByNameEquals(tagName); - if (!tag.isPresent()) { - return Collections.emptyList(); - } + public Page findTargetsByTag(final Pageable pageable, final Long tagId) { + throwEntityNotFoundExceptionIfTagDoesNotExist(tagId); - return Collections.unmodifiableList(targetRepository.findByTag(tag.get().getId())); + return convertPage(targetRepository.findByTag(pageable, tagId), pageable); + } + + private void throwEntityNotFoundExceptionIfTagDoesNotExist(final Long tagId) { + if (!targetTagRepository.exists(tagId)) { + throw new EntityNotFoundException(TargetTag.class, tagId); + } + } + + @Override + public Page findTargetsByTag(final Pageable pageable, final String rsqlParam, final Long tagId) { + + throwEntityNotFoundExceptionIfTagDoesNotExist(tagId); + + final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class, virtualPropertyReplacer); + + return convertPage(targetRepository.findAll((Specification) (root, query, cb) -> cb.and( + TargetSpecifications.hasTag(tagId).toPredicate(root, query, cb), spec.toPredicate(root, query, cb)), + pageable), pageable); } @Override @@ -594,7 +586,7 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public List findTargetAllById(final Collection ids) { + public List findTargetsById(final Collection ids) { return Collections.unmodifiableList(targetRepository.findAll(ids)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java index 27641ac60..96db9a4e9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.repository.RepositoryProperties; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.PropertiesQuotaManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; @@ -63,6 +64,7 @@ import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; +import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -123,6 +125,11 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { return new RsqlParserValidationOracle(); } + @Bean + PropertiesQuotaManagement staticQuotaManagement(final HawkbitSecurityProperties securityProperties) { + return new PropertiesQuotaManagement(securityProperties); + } + /** * @param distributionSetManagement * to loading the {@link DistributionSetType} @@ -557,8 +564,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { AutoAssignScheduler autoAssignScheduler(final TenantAware tenantAware, final SystemManagement systemManagement, final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker, final LockRegistry lockRegistry) { - return new AutoAssignScheduler(tenantAware, systemManagement, systemSecurityContext, autoAssignChecker, - lockRegistry); + return new AutoAssignScheduler(systemManagement, systemSecurityContext, autoAssignChecker, lockRegistry); } /** @@ -567,8 +573,6 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { * Note: does not activate in test profile, otherwise it is hard to test the * rollout handling functionality. * - * @param tenantAware - * to run as specific tenant * @param systemManagement * to find all tenants * @param rolloutManagement @@ -583,6 +587,6 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { @ConditionalOnProperty(prefix = "hawkbit.rollout.scheduler", name = "enabled", matchIfMissing = true) RolloutScheduler rolloutScheduler(final TenantAware tenantAware, final SystemManagement systemManagement, final RolloutManagement rolloutManagement, final SystemSecurityContext systemSecurityContext) { - return new RolloutScheduler(tenantAware, systemManagement, rolloutManagement, systemSecurityContext); + return new RolloutScheduler(systemManagement, rolloutManagement, systemSecurityContext); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java index e16545782..839a21a53 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java @@ -146,6 +146,16 @@ public interface RolloutGroupRepository */ Page findByRolloutId(final Long rolloutId, Pageable page); + /** + * Counts all {@link RolloutGroup} for a specific rollout. + * + * @param rolloutId + * the ID of the rollout to find the rollout groups + * + * @return the amount of found {@link RolloutGroup}s. + */ + long countByRolloutId(final Long rolloutId); + @Modifying @Query("DELETE FROM JpaRolloutGroup g where g.id in :rolloutGroupIds") void deleteByIds(@Param("rolloutGroupIds") List rolloutGroups); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java index f25502117..9e2cac6d0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java @@ -94,13 +94,16 @@ public interface TargetRepository extends BaseEntityRepository, /** * Finds {@link Target}s by assigned {@link Tag}. + * + * @param page + * pages query and sorting information * * @param tagId * to be found - * @return list of found targets + * @return page of found targets */ @Query(value = "SELECT DISTINCT t FROM JpaTarget t JOIN t.tags tt WHERE tt.id = :tag") - List findByTag(@Param("tag") final Long tagId); + Page findByTag(Pageable page, @Param("tag") final Long tagId); /** * Finds all {@link Target}s based on given {@link Target#getControllerId()} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java index 94a4e47c2..4bb28f0de 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java @@ -50,6 +50,16 @@ public interface TargetTagRepository */ Optional findByNameEquals(String tagName); + /** + * Checks if tag with given name exists. + * + * @param tagName + * to check for + * @return true is tag with given name exists + */ + @Query("SELECT CASE WHEN COUNT(t)>0 THEN 'true' ELSE 'false' END FROM JpaTargetTag t WHERE t.name=:tagName") + boolean existsByName(@Param("tagName") String tagName); + /** * Returns all instances of the type. * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index b46f45739..a50e0a6d5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -9,7 +9,6 @@ package org.eclipse.hawkbit.repository.jpa.aspects; import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -25,16 +24,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.Ordered; -import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; +import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator; import org.springframework.orm.jpa.JpaSystemException; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.security.access.AccessDeniedException; import org.springframework.transaction.TransactionSystemException; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; /** @@ -54,8 +54,7 @@ public class ExceptionMappingAspectHandler implements Ordered { * most specific mappable exception according to the type hierarchy of the * exception. */ - private static final List> MAPPED_EXCEPTION_ORDER = new ArrayList<>(4); - + private static final List> MAPPED_EXCEPTION_ORDER = Lists.newArrayListWithExpectedSize(4); @Autowired private JpaVendorAdapter jpaVendorAdapter; @@ -65,14 +64,14 @@ public class ExceptionMappingAspectHandler implements Ordered { MAPPED_EXCEPTION_ORDER.add(DuplicateKeyException.class); MAPPED_EXCEPTION_ORDER.add(DataIntegrityViolationException.class); - MAPPED_EXCEPTION_ORDER.add(ConcurrencyFailureException.class); + MAPPED_EXCEPTION_ORDER.add(OptimisticLockingFailureException.class); MAPPED_EXCEPTION_ORDER.add(AccessDeniedException.class); EXCEPTION_MAPPING.put(DuplicateKeyException.class.getName(), EntityAlreadyExistsException.class.getName()); EXCEPTION_MAPPING.put(DataIntegrityViolationException.class.getName(), EntityAlreadyExistsException.class.getName()); - EXCEPTION_MAPPING.put(ConcurrencyFailureException.class.getName(), + EXCEPTION_MAPPING.put(OptimisticLockingFailureException.class.getName(), ConcurrentModificationException.class.getName()); EXCEPTION_MAPPING.put(AccessDeniedException.class.getName(), InsufficientPermissionException.class.getName()); } @@ -86,10 +85,7 @@ public class ExceptionMappingAspectHandler implements Ordered { * @throws Throwable */ @AfterThrowing(pointcut = "( execution( * org.springframework.transaction..*.*(..)) " - + " || execution( * org.eclipse.hawkbit.repository.*.*(..)) " - + " || execution( * org.eclipse.hawkbit.controller.*.*(..)) " - + " || execution( * org.eclipse.hawkbit.rest.resource.*.*(..)) " - + " || execution( * org.eclipse.hawkbit.service.*.*(..)) )", throwing = "ex") + + " || execution( * org.eclipse.hawkbit.repository.*.*(..)) )", throwing = "ex") // Exception for squid:S00112, squid:S1162 // It is a AspectJ proxy which deals with exceptions. @SuppressWarnings({ "squid:S00112", "squid:S1162" }) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java index 0bbb2516a..beeecbd49 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignScheduler.java @@ -8,12 +8,10 @@ */ package org.eclipse.hawkbit.repository.jpa.autoassign; -import java.util.List; import java.util.concurrent.locks.Lock; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; -import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.integration.support.locks.LockRegistry; @@ -27,8 +25,6 @@ public class AutoAssignScheduler { private static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.autoassign.scheduler.fixedDelay:2000}"; - private final TenantAware tenantAware; - private final SystemManagement systemManagement; private final SystemSecurityContext systemSecurityContext; @@ -40,8 +36,6 @@ public class AutoAssignScheduler { /** * Instantiates a new AutoAssignScheduler * - * @param tenantAware - * to run as specific tenant * @param systemManagement * to find all tenants * @param systemSecurityContext @@ -51,10 +45,9 @@ public class AutoAssignScheduler { * @param lockRegistry * to acquire a lock per tenant */ - public AutoAssignScheduler(final TenantAware tenantAware, final SystemManagement systemManagement, + public AutoAssignScheduler(final SystemManagement systemManagement, final SystemSecurityContext systemSecurityContext, final AutoAssignChecker autoAssignChecker, final LockRegistry lockRegistry) { - this.tenantAware = tenantAware; this.systemManagement = systemManagement; this.systemSecurityContext = systemSecurityContext; this.autoAssignChecker = autoAssignChecker; @@ -82,24 +75,17 @@ public class AutoAssignScheduler { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So // iterate through all tenants and execute the rollout check for // each tenant separately. - final List tenants = systemManagement.findTenants(); - LOGGER.info("Checking target filter queries for tenants: {}", tenants.size()); - final Lock lock = lockRegistry.obtain("autoassign"); if (!lock.tryLock()) { return null; } try { - for (final String tenant : tenants) { - tenantAware.runAsTenant(tenant, () -> { - autoAssignChecker.check(); - return null; - }); - } + systemManagement.forEachTenant(tenant -> autoAssignChecker.check()); } finally { lock.unlock(); } + return null; } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index 36397da26..07f90cc3c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -131,7 +131,6 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio return actionType; } - @Override public List getActionStatus() { if (actionStatus == null) { return Collections.emptyList(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java index d6fd6862a..c7c7b79a0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -142,7 +142,6 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements } } - @Override public List getMessages() { if (messages == null) { messages = Collections.emptyList(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java deleted file mode 100644 index 648ba344b..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model; - -import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; - -/** - * Custom JPA Model for querying {@link Action} include the count of the - * action's {@link ActionStatus}. - * - */ -public class JpaActionWithStatusCount implements ActionWithStatusCount { - private final Long actionStatusCount; - private final Long dsId; - private final String dsName; - private final String dsVersion; - private final JpaAction action; - private final String rolloutName; - - /** - * JPA constructor, the parameter are the result set columns of the custom - * query. - * - * @param actionId - * the ID of the action - * @param actionType - * the action type - * @param active - * the active attribute of the action - * @param forcedTime - * the forced time attribute of the action - * @param status - * the status attribute of the action - * @param actionCreatedAt - * the createdAt timestamp of the action - * @param actionLastModifiedAt - * the last modified timestamp of the action - * @param dsId - * the ID of the distributionset - * @param dsName - * the name of the distributionset - * @param dsVersion - * the version of the distributionset - * @param actionStatusCount - * the count of the action status for this action - * @param rolloutName - * the rollout name - */ - // Exception squid:S00107 - needed this way for JPA to fill the view - @SuppressWarnings("squid:S00107") - public JpaActionWithStatusCount(final Long actionId, final ActionType actionType, final boolean active, - final Long forcedTime, final Status status, final Long actionCreatedAt, final Long actionLastModifiedAt, - final Long dsId, final String dsName, final String dsVersion, final Long actionStatusCount, - final String rolloutName) { - this.dsId = dsId; - this.dsName = dsName; - this.dsVersion = dsVersion; - this.actionStatusCount = actionStatusCount; - this.rolloutName = rolloutName; - - action = new JpaAction(); - action.setActionType(actionType); - action.setActive(active); - action.setForcedTime(forcedTime); - action.setStatus(status); - action.setId(actionId); - action.setActionType(actionType); - action.setCreatedAt(actionCreatedAt); - action.setLastModifiedAt(actionLastModifiedAt); - - } - - @Override - public Action getAction() { - return action; - } - - @Override - public Long getDsId() { - return dsId; - } - - @Override - public String getDsName() { - return dsName; - } - - @Override - public String getDsVersion() { - return dsVersion; - } - - @Override - public Long getActionStatusCount() { - return actionStatusCount; - } - - @Override - public String getRolloutName() { - return rolloutName; - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java index f8393d525..4c901ddfb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -35,7 +35,7 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; import org.eclipse.hawkbit.repository.model.Action; @@ -174,7 +174,6 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen this(name, version, description, type, moduleList, false); } - @Override public Set getTags() { if (tags == null) { return Collections.emptySet(); @@ -339,7 +338,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { publishEventWithEventPublisher( - new DistributionSetUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId())); + new DistributionSetUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); if (isSoftDeleted(descriptorEvent)) { publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), getClass().getName(), diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java index d24aac2ac..253138e02 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java @@ -20,7 +20,7 @@ import javax.persistence.UniqueConstraint; import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; @@ -64,7 +64,6 @@ public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag, // Default constructor for JPA. } - @Override public List getAssignedToDistributionSet() { if (assignedToDistributionSet == null) { return Collections.emptyList(); @@ -82,7 +81,7 @@ public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag, @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { EventPublisherHolder.getInstance().getEventPublisher().publishEvent( - new DistributionSetTagUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId())); + new DistributionSetTagUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index 576c8968e..95d2b338f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -130,7 +130,6 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event this.distributionSet = (JpaDistributionSet) distributionSet; } - @Override public List getRolloutGroups() { if (rolloutGroups == null) { return Collections.emptyList(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java index 4326bb312..722ffe262 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java @@ -20,7 +20,7 @@ import javax.persistence.UniqueConstraint; import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; @@ -61,7 +61,6 @@ public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity // Default constructor for JPA. } - @Override public List getAssignedToTargets() { if (assignedToTargets == null) { return Collections.emptyList(); @@ -80,7 +79,7 @@ public class JpaTargetTag extends JpaTag implements TargetTag, EventAwareEntity @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { EventPublisherHolder.getInstance().getEventPublisher() - .publishEvent(new TargetTagUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId())); + .publishEvent(new TargetTagUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java index c27bd2077..914a2c2ca 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java @@ -8,12 +8,9 @@ */ package org.eclipse.hawkbit.repository.jpa.rollout; -import java.util.List; - import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; -import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; @@ -29,8 +26,6 @@ public class RolloutScheduler { private static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.rollout.scheduler.fixedDelay:2000}"; - private final TenantAware tenantAware; - private final SystemManagement systemManagement; private final RolloutManagement rolloutManagement; @@ -40,8 +35,6 @@ public class RolloutScheduler { /** * Constructor. * - * @param tenantAware - * to run as specific tenant * @param systemManagement * to find all tenants * @param rolloutManagement @@ -49,9 +42,8 @@ public class RolloutScheduler { * @param systemSecurityContext * to run as system */ - public RolloutScheduler(final TenantAware tenantAware, final SystemManagement systemManagement, - final RolloutManagement rolloutManagement, final SystemSecurityContext systemSecurityContext) { - this.tenantAware = tenantAware; + public RolloutScheduler(final SystemManagement systemManagement, final RolloutManagement rolloutManagement, + final SystemSecurityContext systemSecurityContext) { this.systemManagement = systemManagement; this.rolloutManagement = rolloutManagement; this.systemSecurityContext = systemSecurityContext; @@ -76,22 +68,9 @@ public class RolloutScheduler { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So // iterate through all tenants and execute the rollout check for // each tenant seperately. - final List tenants = systemManagement.findTenants(); - LOGGER.info("Checking rollouts for {} tenants", tenants.size()); - for (final String tenant : tenants) { - tenantAware.runAsTenant(tenant, () -> { - try { - rolloutManagement.handleRollouts(); - // We catch all potential runtime exceptions here to - // ensure that not all tenants are blocked if we have a - // problem with a rollout. - } catch (@SuppressWarnings("squid:S1166") final RuntimeException e) { - LOGGER.error("Failed to handle rollouts for tenant {}. I will move on to next tenant.", tenant, - e); - } - return null; - }); - } + + systemManagement.forEachTenant(tenant -> rolloutManagement.handleRollouts()); + return null; }); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java index 764f8c26f..67356ed05 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java @@ -78,7 +78,6 @@ public final class DistributionSetSpecification { return (targetRoot, query, cb) -> { final Predicate predicate = cb.equal(targetRoot. get(JpaDistributionSet_.id), distid); targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT); - targetRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT); targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT); query.distinct(true); @@ -218,4 +217,20 @@ public final class DistributionSetSpecification { }; } + /** + * {@link Specification} for retrieving {@link DistributionSet}s by tag. + * + * @param tagId + * the ID of the distribution set which must be assigned + * @return the {@link DistributionSet} {@link Specification} + */ + public static Specification hasTag(final Long tagId) { + + return (targetRoot, query, cb) -> { + final SetJoin tags = targetRoot.join(JpaDistributionSet_.tags, + JoinType.LEFT); + return cb.equal(tags.get(JpaDistributionSetTag_.id), tagId); + }; + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java index 6b303607c..676dd0003 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java @@ -8,9 +8,6 @@ */ package org.eclipse.hawkbit.repository.jpa.specifications; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.Predicate; - import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_; @@ -28,24 +25,6 @@ public final class SoftwareModuleSpecification { // utility class } - /** - * {@link Specification} for retrieving {@link SoftwareModule}s by its ID - * attribute. - * - * @param moduleId - * to search for - * @return the {@link SoftwareModule} {@link Specification} - */ - public static Specification byId(final Long moduleId) { - return (targetRoot, query, cb) -> { - final Predicate predicate = cb.equal(targetRoot. get(JpaSoftwareModule_.id), moduleId); - targetRoot.fetch(JpaSoftwareModule_.type); - targetRoot.fetch(JpaSoftwareModule_.metadata, JoinType.LEFT); - query.distinct(true); - return predicate; - }; - } - /** * {@link Specification} for retrieving {@link SoftwareModule}s where its * DELETED attribute is false. @@ -57,8 +36,8 @@ public final class SoftwareModuleSpecification { } /** - * {@link Specification} for retrieving {@link SoftwareModule}s by - * "like name or like version". + * {@link Specification} for retrieving {@link SoftwareModule}s by "like + * name or like version". * * @param subString * to be filtered on @@ -71,8 +50,8 @@ public final class SoftwareModuleSpecification { } /** - * {@link Specification} for retrieving {@link SoftwareModule}s by - * "like name or like version". + * {@link Specification} for retrieving {@link SoftwareModule}s by "like + * name or like version". * * @param type * to be filtered on diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TagSpecification.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TagSpecification.java index cbaa99a1e..e30260013 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TagSpecification.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TagSpecification.java @@ -10,11 +10,18 @@ package org.eclipse.hawkbit.repository.jpa.specifications; import javax.persistence.criteria.Join; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.data.jpa.domain.Specification; /** @@ -28,13 +35,13 @@ public final class TagSpecification { } /** - * {@link Specification} for retrieving {@link DistributionSet}s by its - * DELETED attribute. + * {@link Specification} for retrieving {@link TargetTag}s by assigned + * {@link Target}. * - * @param isDeleted - * TRUE/FALSE are compared to the attribute DELETED. If NULL the - * attribute is ignored - * @return the {@link DistributionSet} {@link Specification} + * @param controllerId + * of the target + * + * @return the {@link JpaTargetTag} {@link Specification} */ public static Specification ofTarget(final String controllerId) { return (targetRoot, query, criteriaBuilder) -> { @@ -47,4 +54,25 @@ public final class TagSpecification { } + /** + * {@link Specification} for retrieving {@link DistributionSetTag}s by + * assigned {@link DistributionSet}. + * + * @param dsId + * of the distribution set + * + * @return the {@link JpaDistributionSetTag} {@link Specification} + */ + public static Specification ofDistributionSet(final Long dsId) { + return (dsRoot, query, criteriaBuilder) -> { + final Join tagJoin = dsRoot + .join(JpaDistributionSetTag_.assignedToDistributionSet); + + query.distinct(true); + + return criteriaBuilder.equal(tagJoin.get(JpaDistributionSet_.id), dsId); + }; + + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java index 2f3f2aa73..c67b89921 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java @@ -287,4 +287,19 @@ public final class TargetSpecifications { return (targetRoot, query, cb) -> cb.equal( targetRoot.get(JpaTarget_.installedDistributionSet).get(JpaDistributionSet_.id), distributionSetId); } + + /** + * {@link Specification} for retrieving {@link Target}s by tag. + * + * @param tagId + * the ID of the distribution set which must be assigned + * @return the {@link Target} {@link Specification} + */ + public static Specification hasTag(final Long tagId) { + + return (targetRoot, query, cb) -> { + final SetJoin tags = targetRoot.join(JpaTarget_.tags, JoinType.LEFT); + return cb.equal(tags.get(JpaTargetTag_.id), tagId); + }; + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java index 59a6b5d8e..2bd8f0d48 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java @@ -31,7 +31,7 @@ public class DistributionSetEventTest extends AbstractRemoteEntityEventTest @Test @Description("Verifies that the target tag entity reloading by remote updated event works") public void testTargetTagUpdateEventt() { - assertAndCreateRemoteEvent(TargetTagUpdateEvent.class); + assertAndCreateRemoteEvent(TargetTagUpdatedEvent.class); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index c2d8d03ee..affdf6842 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -98,7 +98,7 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest @Transactional(readOnly = true) protected List findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) { - return Lists.newArrayList(actionRepository.findByRolloutIdAndStatus(pageReq, rollout.getId(), actionStatus)); + return Lists.newArrayList(actionRepository.findByRolloutIdAndStatus(PAGE, rollout.getId(), actionStatus)); } protected static void verifyThrownExceptionBy(final ThrowingCallable tc, final String objectType) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index a613703f7..379c1a646 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -76,7 +76,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> artifactManagement.deleteArtifact(NOT_EXIST_IDL), "Artifact"); - verifyThrownExceptionBy(() -> artifactManagement.findArtifactBySoftwareModule(pageReq, NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> artifactManagement.findArtifactBySoftwareModule(PAGE, NOT_EXIST_IDL), "SoftwareModule"); assertThat(artifactManagement.findArtifactByFilename(NOT_EXIST_ID).isPresent()).isFalse(); @@ -260,12 +260,12 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest { public void findArtifactBySoftwareModule() { final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); - assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty(); + assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).isEmpty(); final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); - assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1); + assertThat(artifactManagement.findArtifactBySoftwareModule(PAGE, sm.getId())).hasSize(1); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java index a7262be71..53c25ba73 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java @@ -138,7 +138,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.FINISHED, Action.Status.FINISHED, false); assertThat(actionStatusRepository.count()).isEqualTo(6); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(6); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(6); } @Test @@ -161,7 +161,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.FINISHED, Action.Status.FINISHED, false); assertThat(actionStatusRepository.count()).isEqualTo(3); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(3); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3); } @Test @@ -186,7 +186,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.RUNNING, Action.Status.RUNNING, true); assertThat(actionStatusRepository.count()).isEqualTo(1); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(1); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(1); } @@ -214,7 +214,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.CANCELED, Action.Status.FINISHED, false); assertThat(actionStatusRepository.count()).isEqualTo(7); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7); } @Test @@ -241,7 +241,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.CANCELED, Action.Status.CANCELED, false); assertThat(actionStatusRepository.count()).isEqualTo(7); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7); } @Test @@ -269,7 +269,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.RUNNING, Action.Status.CANCEL_REJECTED, true); assertThat(actionStatusRepository.count()).isEqualTo(7); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7); } @Test @@ -297,7 +297,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.RUNNING, Action.Status.ERROR, true); assertThat(actionStatusRepository.count()).isEqualTo(7); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(7); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(7); } @Step @@ -308,7 +308,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get() .getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - return deploymentManagement.findActiveActionsByTarget(TestdataFactory.DEFAULT_CONTROLLER_ID).get(0).getId(); + return deploymentManagement.findActiveActionsByTarget(PAGE, TestdataFactory.DEFAULT_CONTROLLER_ID) + .getContent().get(0).getId(); } @Step @@ -366,7 +367,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { final Action action = deploymentManagement.findAction(actionId).get(); assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus); assertThat(action.isActive()).isEqualTo(actionActive); - final List actionStatusList = deploymentManagement.findActionStatusByAction(pageReq, actionId) + final List actionStatusList = deploymentManagement.findActionStatusByAction(PAGE, actionId) .getContent(); assertThat(actionStatusList.get(actionStatusList.size() - 1).getStatus()).isEqualTo(expectedActionStatus); if (actionActive) { @@ -472,7 +473,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.ERROR, Action.Status.ERROR, false); assertThat(actionStatusRepository.count()).isEqualTo(3); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(3); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3); } @@ -507,7 +508,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { Action.Status.FINISHED, Action.Status.FINISHED, false); assertThat(actionStatusRepository.count()).isEqualTo(3); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, actionId).getNumberOfElements()).isEqualTo(3); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, actionId).getNumberOfElements()).isEqualTo(3); } @@ -533,7 +534,7 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { .getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(actionStatusRepository.count()).isEqualTo(3); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements()) + assertThat(deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getNumberOfElements()) .isEqualTo(3); } @@ -558,8 +559,8 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest { .getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC); // however, additional action status has been stored - assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(4); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getNumberOfElements()) + assertThat(actionStatusRepository.findAll(PAGE).getNumberOfElements()).isEqualTo(4); + assertThat(deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getNumberOfElements()) .isEqualTo(4); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index 9a63cf71f..c8bb45678 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -36,6 +36,7 @@ import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedExcepti import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; @@ -122,16 +123,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget(NOT_EXIST_ID), "Target"); verifyThrownExceptionBy(() -> deploymentManagement.countActionsByTarget("xxx", NOT_EXIST_ID), "Target"); - verifyThrownExceptionBy(() -> deploymentManagement.findActionsByDistributionSet(pageReq, NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> deploymentManagement.findActionsByDistributionSet(PAGE, NOT_EXIST_IDL), "DistributionSet"); - verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget(NOT_EXIST_ID, pageReq), "Target"); - verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, pageReq), + verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget(NOT_EXIST_ID, PAGE), "Target"); + verifyThrownExceptionBy(() -> deploymentManagement.findActionsByTarget("id==*", NOT_EXIST_ID, PAGE), "Target"); - verifyThrownExceptionBy( - () -> deploymentManagement.findActionsWithStatusCountByTargetOrderByIdDesc(NOT_EXIST_ID), "Target"); - verifyThrownExceptionBy(() -> deploymentManagement.findActiveActionsByTarget(NOT_EXIST_ID), "Target"); - verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(NOT_EXIST_ID), "Target"); + verifyThrownExceptionBy(() -> deploymentManagement.findActiveActionsByTarget(PAGE, NOT_EXIST_ID), "Target"); + verifyThrownExceptionBy(() -> deploymentManagement.findInActiveActionsByTarget(PAGE, NOT_EXIST_ID), + "Target"); verifyThrownExceptionBy(() -> deploymentManagement.forceQuitAction(NOT_EXIST_IDL), "Action"); verifyThrownExceptionBy(() -> deploymentManagement.forceTargetAction(NOT_EXIST_IDL), "Action"); } @@ -164,7 +164,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // act final Slice actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(), - pageReq); + PAGE); final Long count = deploymentManagement.countActionsByTarget(testTarget.get(0).getControllerId()); assertThat(count).as("One Action for target").isEqualTo(1L).isEqualTo(actions.getContent().size()); @@ -180,11 +180,11 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // one action with one action status is generated final Long actionId = assignDistributionSet(testDs, testTarget).getActions().get(0); final Slice actions = deploymentManagement.findActionsByTarget(testTarget.get(0).getControllerId(), - pageReq); - final ActionStatus expectedActionStatus = actions.getContent().get(0).getActionStatus().get(0); + PAGE); + final ActionStatus expectedActionStatus = ((JpaAction) actions.getContent().get(0)).getActionStatus().get(0); // act - final Page actionStates = deploymentManagement.findActionStatusByAction(pageReq, actionId); + final Page actionStates = deploymentManagement.findActionStatusByAction(PAGE, actionId); assertThat(actionStates.getContent()).hasSize(1); assertThat(actionStates.getContent().get(0)).as("Action-status of action").isEqualTo(expectedActionStatus); @@ -201,14 +201,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // create action-status entry with one message controllerManagement.addUpdateActionStatus(entityFactory.actionStatus().create(actionId) .status(Action.Status.FINISHED).messages(Lists.newArrayList("finished message"))); - final Page actionStates = deploymentManagement.findActionStatusByAction(pageReq, actionId); + final Page actionStates = deploymentManagement.findActionStatusByAction(PAGE, actionId); + // find newly created action-status entry with message - final ActionStatus actionStatusWithMessage = actionStates.getContent().stream() + final JpaActionStatus actionStatusWithMessage = actionStates.getContent().stream().map(c -> (JpaActionStatus) c) .filter(entry -> entry.getMessages() != null && entry.getMessages().size() > 0).findFirst().get(); final String expectedMsg = actionStatusWithMessage.getMessages().get(0); // act - final Page messages = deploymentManagement.findMessagesByActionStatusId(pageReq, + final Page messages = deploymentManagement.findMessagesByActionStatusId(PAGE, actionStatusWithMessage.getId()); assertThat(actionStates.getTotalElements()).as("Two action-states in total").isEqualTo(2L); @@ -425,7 +426,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()) .as("wrong assigned ds").isEqualTo(ds); final JpaAction action = actionRepository - .findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent() + .findByTargetAndDistributionSet(PAGE, (JpaTarget) target, (JpaDistributionSet) ds).getContent() .get(0); assertThat(action).as("action should not be null").isNotNull(); return action; @@ -455,12 +456,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assignDistributionSet(ds, savedDeployedTargets); // verify that one Action for each assignDistributionSet - assertThat(actionRepository.findAll(pageReq).getNumberOfElements()).as("wrong size of actions").isEqualTo(20); + assertThat(actionRepository.findAll(PAGE).getNumberOfElements()).as("wrong size of actions").isEqualTo(20); - final Iterable allFoundTargets = targetManagement.findTargetsAll(pageReq).getContent(); + final Iterable allFoundTargets = targetManagement.findTargetsAll(PAGE).getContent(); // get final updated version of targets - savedDeployedTargets = targetManagement.findTargetByControllerID( + savedDeployedTargets = targetManagement.findTargetsByControllerID( savedDeployedTargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets) @@ -479,7 +480,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { for (final Target myt : savedDeployedTargets) { final Target t = targetManagement.findTargetByControllerID(myt.getControllerId()).get(); final List activeActionsByTarget = deploymentManagement - .findActiveActionsByTarget(t.getControllerId()); + .findActiveActionsByTarget(PAGE, t.getControllerId()).getContent(); assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty(); assertThat(t.getUpdateStatus()).as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING); for (final Action ua : activeActionsByTarget) { @@ -558,7 +559,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final Collection savedDeployedTargets = (Collection) deploymentResult.getDeployedTargets(); // retrieving all Actions created by the assignDistributionSet call - final Page page = actionRepository.findAll(pageReq); + final Page page = actionRepository.findAll(PAGE); // and verify the number assertThat(page.getTotalElements()).as("wrong size of actions") .isEqualTo(noOfDeployedTargets * noOfDistributionSets); @@ -653,7 +654,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { .as("installed ds is wrong").isEqualTo(dsA); assertThat(targetManagement.findTargetByControllerID(t.getControllerId()).get().getUpdateStatus()) .as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC); - assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId())) + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, t.getControllerId())) .as("no actions should be active").hasSize(0); } @@ -666,7 +667,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { actionRepository.findByDistributionSetId(pageRequest, dsA.getId()).getContent().get(1); // get final updated version of targets - final List deployResWithDsBTargets = targetManagement.findTargetByControllerID(deployResWithDsB + final List deployResWithDsBTargets = targetManagement.findTargetsByControllerID(deployResWithDsB .getDeployedTargets().stream().map(Target::getControllerId).collect(Collectors.toList())); assertThat(deployed2DS).as("deployed ds is wrong").containsAll(deployResWithDsBTargets); @@ -724,7 +725,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // verify that deleted attribute is used correctly List allFoundDS = distributionSetManagement - .findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true).getContent(); + .findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true).getContent(); assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0); allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, true, true) .getContent(); @@ -798,28 +799,28 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).get().getOptLockRevision()); // verifying that the assignment is correct - assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size()) + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()) .as("Active target actions are wrong").isEqualTo(1); assertThat(deploymentManagement.countActionsByTarget(targ.getControllerId())).as("Target actions are wrong") .isEqualTo(1); assertThat(targ.getUpdateStatus()).as("UpdateStatus of target is wrong").isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get()) .as("Assigned distribution set of target is wrong").isEqualTo(dsA); - assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet()) - .as("Distribution set of actionn is wrong").isEqualTo(dsA); - assertThat(deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet()) - .as("Installed distribution set of action should be null").isNotNull(); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0) + .getDistributionSet()).as("Distribution set of actionn is wrong").isEqualTo(dsA); + assertThat(deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0) + .getDistributionSet()).as("Installed distribution set of action should be null").isNotNull(); - final Page updAct = actionRepository.findByDistributionSetId(pageReq, dsA.getId()); + final Page updAct = actionRepository.findByDistributionSetId(PAGE, dsA.getId()); controllerManagement.addUpdateActionStatus( entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED)); targ = targetManagement.findTargetByControllerID(targ.getControllerId()).get(); assertEquals("active target actions are wrong", 0, - deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size()); + deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()); assertEquals("active actions are wrong", 1, - deploymentManagement.findInActiveActionsByTarget(targ.getControllerId()).size()); + deploymentManagement.findInActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()); assertEquals("tagret update status is not correct", TargetUpdateStatus.IN_SYNC, targ.getUpdateStatus()); assertEquals("wrong assigned ds", dsA, @@ -832,15 +833,15 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { targ = targs.iterator().next(); assertEquals("active actions are wrong", 1, - deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).size()); + deploymentManagement.findActiveActionsByTarget(PAGE, targ.getControllerId()).getTotalElements()); assertEquals("target status is wrong", TargetUpdateStatus.PENDING, targetManagement.findTargetByControllerID(targ.getControllerId()).get().getUpdateStatus()); assertEquals("wrong assigned ds", dsB, deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get()); assertEquals("Installed ds is wrong", dsA.getId(), deploymentManagement.getInstalledDistributionSet(targ.getControllerId()).get().getId()); - assertEquals("Active ds is wrong", dsB, - deploymentManagement.findActiveActionsByTarget(targ.getControllerId()).get(0).getDistributionSet()); + assertEquals("Active ds is wrong", dsB, deploymentManagement + .findActiveActionsByTarget(PAGE, targ.getControllerId()).getContent().get(0).getDistributionSet()); } @@ -972,7 +973,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { if (event.getControllerId().equals(myt.getControllerId())) { found = true; final List activeActionsByTarget = deploymentManagement - .findActiveActionsByTarget(myt.getControllerId()); + .findActiveActionsByTarget(PAGE, myt.getControllerId()).getContent(); assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty(); assertThat(event.getActionId()).as("Action id in database and event do not match") .isEqualTo(activeActionsByTarget.get(0).getId()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java index 6e2e162d2..20ef846dc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java @@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -121,6 +122,12 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { () -> distributionSetManagement.assignTag(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getId()), "DistributionSet"); + verifyThrownExceptionBy(() -> distributionSetManagement.findDistributionSetsByTag(PAGE, NOT_EXIST_IDL), + "DistributionSetTag"); + verifyThrownExceptionBy( + () -> distributionSetManagement.findDistributionSetsByTag(PAGE, "name==*", NOT_EXIST_IDL), + "DistributionSetTag"); + verifyThrownExceptionBy( () -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_IDL), dsTag.getName()), "DistributionSet"); @@ -128,9 +135,6 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { () -> distributionSetManagement.toggleTagAssignment(Lists.newArrayList(set.getId()), NOT_EXIST_ID), "DistributionSetTag"); - verifyThrownExceptionBy(() -> distributionSetManagement.unAssignAllDistributionSetsByTag(NOT_EXIST_IDL), - "DistributionSetTag"); - verifyThrownExceptionBy(() -> distributionSetManagement.unAssignTag(set.getId(), NOT_EXIST_IDL), "DistributionSetTag"); @@ -168,11 +172,11 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { "DistributionSet"); verifyThrownExceptionBy( - () -> distributionSetManagement.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, pageReq), + () -> distributionSetManagement.findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, PAGE), "DistributionSet"); verifyThrownExceptionBy(() -> distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, "name==*", pageReq), "DistributionSet"); + .findDistributionSetMetadataByDistributionSetId(NOT_EXIST_IDL, "name==*", PAGE), "DistributionSet"); assertThatThrownBy(() -> distributionSetManagement.isDistributionSetInUse(NOT_EXIST_IDL)) .isInstanceOf(EntityNotFoundException.class).hasMessageContaining(NOT_EXIST_ID) @@ -390,28 +394,28 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { final List assignedDS = distributionSetManagement.assignTag(assignDS, tag.getId()); assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4); - assignedDS.forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1)); + assignedDS.stream().map(c -> (JpaDistributionSet) c) + .forEach(ds -> assertThat(ds.getTags().size()).as("ds has wrong tag size").isEqualTo(1)); DistributionSetTag findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get(); - assertThat(assignedDS.size()).as("assigned ds has wrong size") - .isEqualTo(findDistributionSetTag.getAssignedToDistributionSet().size()); - final DistributionSet unAssignDS = distributionSetManagement.unAssignTag(assignDS.get(0), - findDistributionSetTag.getId()); + assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo( + distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()).getNumberOfElements()); + + final JpaDistributionSet unAssignDS = (JpaDistributionSet) distributionSetManagement + .unAssignTag(assignDS.get(0), findDistributionSetTag.getId()); assertThat(unAssignDS.getId()).as("unassigned ds is wrong").isEqualTo(assignDS.get(0)); assertThat(unAssignDS.getTags().size()).as("unassigned ds has wrong tag size").isEqualTo(0); findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get(); - assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag ds has wrong ds size") - .isEqualTo(3); + assertThat(distributionSetManagement.findDistributionSetsByTag(PAGE, tag.getId()).getNumberOfElements()) + .as("ds tag ds has wrong ds size").isEqualTo(3); - final List unAssignTargets = distributionSetManagement - .unAssignAllDistributionSetsByTag(findDistributionSetTag.getId()); - findDistributionSetTag = tagManagement.findDistributionSetTag("Tag1").get(); - assertThat(findDistributionSetTag.getAssignedToDistributionSet().size()).as("ds tag has wrong ds size") - .isEqualTo(0); - assertThat(unAssignTargets.size()).as("unassigned target has wrong size").isEqualTo(3); - unAssignTargets - .forEach(target -> assertThat(target.getTags().size()).as("target has wrong tag size").isEqualTo(0)); + assertThat(distributionSetManagement + .findDistributionSetsByTag(PAGE, "name==" + unAssignDS.getName(), tag.getId()).getNumberOfElements()) + .as("ds tag ds has wrong ds size").isEqualTo(0); + assertThat(distributionSetManagement + .findDistributionSetsByTag(PAGE, "name!=" + unAssignDS.getName(), tag.getId()).getNumberOfElements()) + .as("ds tag ds has wrong ds size").isEqualTo(3); } @Test @@ -559,14 +563,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // target first only has an assigned DS-three so check order correct final List tFirstPin = distributionSetManagement.findDistributionSetsAllOrderedByLinkTarget( - pageReq, distributionSetFilterBuilder, tFirst.getControllerId()).getContent(); + PAGE, distributionSetFilterBuilder, tFirst.getControllerId()).getContent(); assertThat(tFirstPin.get(0)).isEqualTo(dsThree); assertThat(tFirstPin).hasSize(10); // target second has installed DS-2 and assigned DS-4 so check order // correct final List tSecondPin = distributionSetManagement.findDistributionSetsAllOrderedByLinkTarget( - pageReq, distributionSetFilterBuilder, tSecond.getControllerId()).getContent(); + PAGE, distributionSetFilterBuilder, tSecond.getControllerId()).getContent(); assertThat(tSecondPin.get(0)).isEqualTo(dsSecond); assertThat(tSecondPin.get(1)).isEqualTo(dsFour); assertThat(tFirstPin).hasSize(10); @@ -624,7 +628,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { expected.add(dsNewType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, getDistributionSetFilterBuilder().build()).getContent()) + .findDistributionSetsByFilters(PAGE, getDistributionSetFilterBuilder().build()).getContent()) .hasSize(203).containsOnly(expected.toArray(new DistributionSet[0])); DistributionSetFilterBuilder distributionSetFilterBuilder; @@ -632,11 +636,11 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // search for not deleted distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(false); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(202); // search for completed @@ -648,61 +652,61 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(202) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(202) .containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE); expected = new ArrayList<>(); expected.add(dsInComplete); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1) .containsOnly(expected.toArray(new DistributionSet[0])); // search for type distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(202); // search for text distributionSetFilterBuilder = getDistributionSetFilterBuilder().setSearchText("%test2"); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(100); // search for tags distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Lists.newArrayList(dsTagA.getName())); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(200); distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Lists.newArrayList(dsTagB.getName())); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(100); distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Lists.newArrayList(dsTagA.getName(), dsTagB.getName())); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(200); distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Lists.newArrayList(dsTagC.getName(), dsTagB.getName())); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()) .hasSize(100); distributionSetFilterBuilder = getDistributionSetFilterBuilder() .setTagNames(Lists.newArrayList(dsTagC.getName())); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); // combine deleted and complete expected = new ArrayList<>(); @@ -713,14 +717,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setIsDeleted(Boolean.FALSE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(201) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(201) .containsOnly(expected.toArray(new DistributionSet[0])); expected = new ArrayList<>(); expected.add(dsInComplete); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.FALSE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1) .containsOnly(expected.toArray(new DistributionSet[0])); expected = new ArrayList<>(); @@ -728,13 +732,13 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setIsDeleted(Boolean.TRUE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1) .containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE) .setIsComplete(Boolean.FALSE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); // combine deleted and complete and type expected = new ArrayList<>(); @@ -743,7 +747,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.FALSE) .setIsComplete(Boolean.TRUE).setType(standardDsType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(200) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(200) .containsOnly(expected.toArray(new DistributionSet[0])); expected = new ArrayList<>(); @@ -751,19 +755,19 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setType(standardDsType).setIsDeleted(Boolean.TRUE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1) .containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsDeleted(Boolean.TRUE) .setIsComplete(Boolean.FALSE).setType(standardDsType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); expected = new ArrayList<>(); expected.add(dsNewType); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE).setType(newType); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(1) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(1) .containsOnly(expected.toArray(new DistributionSet[0])); // combine deleted and complete and type and text @@ -772,23 +776,23 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setType(standardDsType).setSearchText("%test2"); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(100) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(100) .containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setIsDeleted(Boolean.TRUE).setType(standardDsType).setSearchText("%test2"); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2") .setIsComplete(false).setIsDeleted(false); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(newType).setSearchText("%test2") .setIsComplete(Boolean.TRUE).setIsDeleted(false); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); // combine deleted and complete and type and text and tag expected = new ArrayList<>(); @@ -796,14 +800,14 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true).setType(standardDsType) .setSearchText("%test2").setTagNames(Lists.newArrayList(dsTagA.getName())); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(100) + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(100) .containsOnly(expected.toArray(new DistributionSet[0])); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setType(standardDsType).setSearchText("%test2") .setTagNames(Lists.newArrayList(dsTagA.getName())).setIsComplete(Boolean.FALSE) .setIsDeleted(Boolean.FALSE); assertThat(distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getContent()).hasSize(0); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getContent()).hasSize(0); } @@ -816,7 +820,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { public void findDistributionSetsWithoutLazy() { testdataFactory.createDistributionSets(20); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)) .hasSize(20); } @@ -832,7 +836,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // not assigned so not marked as deleted but fully deleted assertThat(distributionSetRepository.findAll()).hasSize(1); assertThat(distributionSetManagement - .findDistributionSetsByDeletedAndOrCompleted(pageReq, Boolean.FALSE, Boolean.TRUE).getTotalElements()) + .findDistributionSetsByDeletedAndOrCompleted(PAGE, Boolean.FALSE, Boolean.TRUE).getTotalElements()) .isEqualTo(1); } @@ -892,7 +896,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { // not assigned so not marked as deleted assertThat(distributionSetRepository.findAll()).hasSize(4); assertThat(distributionSetManagement - .findDistributionSetsByDeletedAndOrCompleted(pageReq, Boolean.FALSE, Boolean.TRUE).getTotalElements()) + .findDistributionSetsByDeletedAndOrCompleted(PAGE, Boolean.FALSE, Boolean.TRUE).getTotalElements()) .isEqualTo(2); } @@ -926,7 +930,7 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createDistributionSet("test" + i); } - final List foundDs = distributionSetManagement.findDistributionSetAllById(searchIds); + final List foundDs = distributionSetManagement.findDistributionSetsById(searchIds); assertThat(foundDs).hasSize(3); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java new file mode 100644 index 000000000..a3e1c9db5 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupManagementTest.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.eclipse.hawkbit.repository.event.remote.RolloutDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.test.matcher.Expect; +import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Component Tests - Repository") +@Stories("Rollout Management") +public class RolloutGroupManagementTest extends AbstractJpaIntegrationTest { + + @Test + @Description("Verifies that management get access reacts as specfied on calls for non existing entities by means " + + "of Optional not present.") + @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) + public void nonExistingEntityAccessReturnsNotPresent() { + assertThat(rolloutGroupManagement.findRolloutGroupById(NOT_EXIST_IDL)).isNotPresent(); + assertThat(rolloutGroupManagement.findRolloutGroupWithDetailedStatus(NOT_EXIST_IDL)).isNotPresent(); + + } + + @Test + @Description("Verifies that management queries react as specfied on calls for non existing entities " + + " by means of throwing EntityNotFoundException.") + @ExpectEvents({ @Expect(type = RolloutDeletedEvent.class, count = 0), + @Expect(type = RolloutGroupCreatedEvent.class, count = 10), + @Expect(type = RolloutGroupUpdatedEvent.class, count = 10), + @Expect(type = DistributionSetCreatedEvent.class, count = 1), + @Expect(type = SoftwareModuleCreatedEvent.class, count = 3), + @Expect(type = RolloutUpdatedEvent.class, count = 1), + @Expect(type = TargetCreatedEvent.class, count = 10) }) + public void entityQueriesReferringToNotExistingEntitiesThrowsException() { + testdataFactory.createRollout("xxx"); + + verifyThrownExceptionBy(() -> rolloutGroupManagement.countRolloutGroupsByRolloutId(NOT_EXIST_IDL), "Rollout"); + verifyThrownExceptionBy(() -> rolloutGroupManagement.countTargetsOfRolloutsGroup(NOT_EXIST_IDL), + "RolloutGroup"); + verifyThrownExceptionBy( + () -> rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(NOT_EXIST_IDL, PAGE), "Rollout"); + verifyThrownExceptionBy(() -> rolloutGroupManagement.findAllTargetsWithActionStatus(PAGE, NOT_EXIST_IDL), + "RolloutGroup"); + verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupsAll(NOT_EXIST_IDL, "name==*", PAGE), + "Rollout"); + + verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupTargets(NOT_EXIST_IDL, PAGE), + "RolloutGroup"); + verifyThrownExceptionBy(() -> rolloutGroupManagement.findRolloutGroupTargets(NOT_EXIST_IDL, "name==*", PAGE), + "RolloutGroup"); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java index 805af5da8..9c535e8de 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java @@ -10,9 +10,9 @@ package org.eclipse.hawkbit.repository.jpa; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.Assertions.fail; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -36,7 +36,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; import org.eclipse.hawkbit.repository.exception.ConstraintViolationException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; @@ -103,7 +102,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // verify that manually created action is still running and action // created from rollout is finished - final List actionsByKnownTarget = deploymentManagement.findActionsByTarget(knownControllerId, pageReq) + final List actionsByKnownTarget = deploymentManagement.findActionsByTarget(knownControllerId, PAGE) .getContent(); // should be 2 actions, one manually and one from the rollout assertThat(actionsByKnownTarget).hasSize(2); @@ -164,7 +163,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // verify the split of the target and targetGroup final Page rolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), pageReq); + .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE); // we have total of #amountTargetsForRollout in rollouts splitted in // group size #groupSize assertThat(rolloutGroups).hasSize(amountGroups); @@ -279,7 +278,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { @Step("Finish three actions of the rollout group and delete two targets") private void finishActionAndDeleteTargetsOfFirstRunningGroup(final Rollout createdRollout) { // finish group one by finishing targets and deleting targets - final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(pageReq, + final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE, createdRollout.getId(), Status.RUNNING); final List runningActions = Lists.newArrayList(runningActionsSlice.iterator()); finishAction(runningActions.get(0)); @@ -301,7 +300,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { @Step("Finish one action of the rollout group and delete four targets") private void finishActionAndDeleteTargetsOfSecondRunningGroup(final Rollout createdRollout) { - final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(pageReq, + final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE, createdRollout.getId(), Status.RUNNING); final List runningActions = Lists.newArrayList(runningActionsSlice.iterator()); finishAction(runningActions.get(0)); @@ -313,7 +312,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { @Step("Delete all targets of the rollout group") private void deleteAllTargetsFromThirdGroup(final Rollout createdRollout) { - final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(pageReq, + final Slice runningActionsSlice = actionRepository.findByRolloutIdAndStatus(PAGE, createdRollout.getId(), Status.SCHEDULED); final List runningActions = Lists.newArrayList(runningActionsSlice.iterator()); targetManagement.deleteTargets(Lists.newArrayList(runningActions.get(0).getTarget().getId(), @@ -325,7 +324,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { private void verifyRolloutAndAllGroupsAreFinished(final Rollout createdRollout) { rolloutManagement.handleRollouts(); final List runningRolloutGroups = rolloutGroupManagement - .findRolloutGroupsByRolloutId(createdRollout.getId(), pageReq).getContent(); + .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent(); assertThat(runningRolloutGroups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); assertThat(runningRolloutGroups.get(2).getStatus()).isEqualTo(RolloutGroupStatus.FINISHED); @@ -589,7 +588,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { // round(5/2)=3 targets SCHEDULED (Group 3) // round(2/1)=2 targets SCHEDULED (Group 4) createdRollout = rolloutManagement.findRolloutById(createdRollout.getId()).get(); - final List rolloutGroups = createdRollout.getRolloutGroups(); + final List rolloutGroups = rolloutGroupManagement + .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent(); Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 2L); @@ -628,9 +628,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(runningActions.size()).isEqualTo(5); // 5 targets are in the group and the DS has been assigned - final List rolloutGroups = createdRollout.getRolloutGroups(); + final List rolloutGroups = rolloutGroupManagement + .findRolloutGroupsByRolloutId(createdRollout.getId(), PAGE).getContent(); final Page targets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(), - pageReq); + PAGE); final List targetList = targets.getContent(); assertThat(targetList.size()).isEqualTo(5); @@ -742,7 +743,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { expectedTargetCountStatus.put(TotalTargetCountStatus.Status.FINISHED, 9L); validateRolloutActionStatus(rolloutTwo.getId(), expectedTargetCountStatus); changeStatusForAllRunningActions(rolloutTwo, Status.FINISHED); - final Page targetPage = targetManagement.findTargetByUpdateStatus(pageReq, TargetUpdateStatus.IN_SYNC); + final Page targetPage = targetManagement.findTargetByUpdateStatus(PAGE, TargetUpdateStatus.IN_SYNC); final List targetList = targetPage.getContent(); // 15 targets in finished/IN_SYNC status and same DS assigned assertThat(targetList.size()).isEqualTo(amountTargetsForRollout); @@ -767,7 +768,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { changeStatusForRunningActions(rolloutOne, Status.FINISHED, 3); rolloutManagement.handleRollouts(); // verify: 40% error but 60% finished -> should move to next group - final List rolloutGruops = rolloutOne.getRolloutGroups(); + final List rolloutGruops = rolloutGroupManagement + .findRolloutGroupsByRolloutId(rolloutOne.getId(), PAGE).getContent(); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.RUNNING, 5L); validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus); @@ -792,8 +794,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); // verify: 40% error and 60% finished -> should not move to next group // because successCondition 80% - rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()).get(); - final List rolloutGruops = rolloutOne.getRolloutGroups(); + final List rolloutGruops = rolloutGroupManagement + .findRolloutGroupsByRolloutId(rolloutOne.getId(), PAGE).getContent(); final Map expectedTargetCountStatus = createInitStatusMap(); expectedTargetCountStatus.put(TotalTargetCountStatus.Status.SCHEDULED, 5L); validateRolloutGroupActionStatus(rolloutGruops.get(1), expectedTargetCountStatus); @@ -1000,14 +1002,17 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); float percent = rolloutGroupManagement - .findRolloutGroupWithDetailedStatus(myRollout.getRolloutGroups().get(0).getId()).get() - .getTotalTargetCountStatus().getFinishedPercent(); + .findRolloutGroupWithDetailedStatus(rolloutGroupManagement + .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(0).getId()) + .get().getTotalTargetCountStatus().getFinishedPercent(); assertThat(percent).isEqualTo(40); changeStatusForRunningActions(myRollout, Status.FINISHED, 3); rolloutManagement.handleRollouts(); - percent = rolloutGroupManagement.findRolloutGroupWithDetailedStatus(myRollout.getRolloutGroups().get(0).getId()) + percent = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupManagement + .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(0).getId()) .get().getTotalTargetCountStatus().getFinishedPercent(); assertThat(percent).isEqualTo(100); @@ -1015,7 +1020,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { changeStatusForAllRunningActions(myRollout, Status.ERROR); rolloutManagement.handleRollouts(); - percent = rolloutGroupManagement.findRolloutGroupWithDetailedStatus(myRollout.getRolloutGroups().get(1).getId()) + percent = rolloutGroupManagement + .findRolloutGroupWithDetailedStatus(rolloutGroupManagement + .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent().get(1).getId()) .get().getTotalTargetCountStatus().getFinishedPercent(); assertThat(percent).isEqualTo(80); } @@ -1043,7 +1050,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); - final List rolloutGroups = myRollout.getRolloutGroups(); + final List rolloutGroups = rolloutGroupManagement + .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent(); Page targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0).getId(), rsqlParam, new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId"))); @@ -1075,13 +1083,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName); - try { - testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==notExisting", - distributionSet, successCondition, errorCondition); - fail("Was able to create a Rollout without targets."); - } catch (final ConstraintViolationException e) { - // OK - } + assertThatExceptionOfType(ConstraintViolationException.class) + .isThrownBy(() -> testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, + "id==notExisting", distributionSet, successCondition, errorCondition)) + .withMessageContaining("does not match any existing"); } @@ -1100,14 +1105,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet, successCondition, errorCondition); - try { - testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, "id==dup-ro-*", distributionSet, - successCondition, errorCondition); - fail("Was able to create a duplicate Rollout."); - } catch (final EntityAlreadyExistsException e) { - // OK - } - + assertThatExceptionOfType(EntityAlreadyExistsException.class) + .isThrownBy(() -> testdataFactory.createRolloutByVariables(rolloutName, "desc", amountGroups, + "id==dup-ro-*", distributionSet, successCondition, errorCondition)) + .withMessageContaining("already exists in database"); } @Test @@ -1127,7 +1128,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); - final List groups = myRollout.getRolloutGroups(); + final List groups = rolloutGroupManagement + .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent(); + assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY); assertThat(groups.get(0).getTotalTargets()).isEqualTo(1); assertThat(groups.get(1).getStatus()).isEqualTo(RolloutGroupStatus.READY); @@ -1282,7 +1285,8 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { myRollout = rolloutManagement.findRolloutById(myRollout.getId()).get(); assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING); - for (final RolloutGroup group : myRollout.getRolloutGroups()) { + for (final RolloutGroup group : rolloutGroupManagement.findRolloutGroupsByRolloutId(myRollout.getId(), PAGE) + .getContent()) { assertThat(group.getStatus()).isEqualTo(RolloutGroupStatus.CREATING); } @@ -1297,7 +1301,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY); assertThat(myRollout.getTotalTargets()).isEqualTo(amountTargetsInGroup1and2 + amountTargetsInGroup1); - final List groups = myRollout.getRolloutGroups(); + final List groups = rolloutGroupManagement + .findRolloutGroupsByRolloutId(myRollout.getId(), PAGE).getContent(); + ; assertThat(groups.get(0).getStatus()).isEqualTo(RolloutGroupStatus.READY); assertThat(groups.get(0).getTotalTargets()).isEqualTo(amountTargetsInGroup1); @@ -1324,12 +1330,9 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null)); rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null)); - try { - rolloutManagement.createRollout(myRollout, rolloutGroups, conditions); - fail("Was able to create a Rollout with groups that are not addressing all targets"); - } catch (final ConstraintViolationException e) { - // OK - } + assertThatExceptionOfType(ConstraintViolationException.class) + .isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions)) + .withMessageContaining("groups don't match"); } @@ -1344,16 +1347,13 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build(); final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout); - final List rolloutGroups = new ArrayList<>(2); - rolloutGroups.add(generateRolloutGroup(0, percentTargetsInGroup1, null)); - rolloutGroups.add(generateRolloutGroup(1, percentTargetsInGroup2, null)); + final List rolloutGroups = Arrays.asList( + generateRolloutGroup(0, percentTargetsInGroup1, null), + generateRolloutGroup(1, percentTargetsInGroup2, null)); - try { - rolloutManagement.createRollout(myRollout, rolloutGroups, conditions); - fail("Was able to create a Rollout with groups that have illegal percentages"); - } catch (final ConstraintViolationException e) { - // OK - } + assertThatExceptionOfType(ConstraintViolationException.class) + .isThrownBy(() -> rolloutManagement.createRollout(myRollout, rolloutGroups, conditions)) + .withMessageContaining("percentage has to be between 1 and 100"); } @@ -1367,59 +1367,12 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder().withDefaults().build(); final RolloutCreate myRollout = generateTargetsAndRollout(rolloutName, amountTargetsForRollout); - try { - rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions); - fail("Was able to create a Rollout with too many groups"); - } catch (final ConstraintViolationException e) { - // OK - } + assertThatExceptionOfType(ConstraintViolationException.class) + .isThrownBy(() -> rolloutManagement.createRollout(myRollout, illegalGroupAmount, conditions)) + .withMessageContaining("not be greater than " + quotaManagement.getMaxRolloutGroupsPerRollout()); } - @Test - @Description("Verify Exception when a Rollout groups are queried for rollout that does not exist.") - public void findRolloutGroupsForRolloutThatDoesNotExist() throws Exception { - try { - rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(1234L, pageReq); - fail("Was able to get Rollout group for rollout that does not exist."); - } catch (final EntityNotFoundException e) { - // OK - } - } - - @Test - @Description("Verify Exception when targets are queried for rollout group that does not exist.") - public void findRolloutGroupTargetsForGroupThatDoesNotExist() throws Exception { - try { - rolloutGroupManagement.findRolloutGroupTargets(1234L, pageReq); - fail("Was able to get Rollout group targets for rollout group that does not exist."); - } catch (final EntityNotFoundException e) { - // OK - } - } - - @Test - @Description("Verify Exception when targets are queried for rollout group that does not exist.") - public void findRolloutGroupTargetWithActionsForGroupThatDoesNotExist() throws Exception { - try { - rolloutGroupManagement.findAllTargetsWithActionStatus(pageReq, 1234L); - fail("Was able to get Rollout group targets for rollout group that does not exist."); - } catch (final EntityNotFoundException e) { - // OK - } - } - - @Test - @Description("Verify Exception when targets are counted for rollout group that does not exist.") - public void countRolloutGroupTargetWithActionsForGroupThatDoesNotExist() throws Exception { - try { - rolloutGroupManagement.countTargetsOfRolloutsGroup(1234L); - fail("Was able to count Rollout group targets for rollout group that does not exist."); - } catch (final EntityNotFoundException e) { - // OK - } - } - @Test @Description("Verify the start of a Rollout does not work during creation phase.") public void createAndStartRolloutDuringCreationFails() throws Exception { @@ -1445,12 +1398,10 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.CREATING); - try { - rolloutManagement.startRollout(myRollout.getId()); - fail("Was able to start a Rollout in CREATING status"); - } catch (final RolloutIllegalStateException e) { - // OK - } + final Long rolloutId = myRollout.getId(); + assertThatExceptionOfType(RolloutIllegalStateException.class) + .isThrownBy(() -> rolloutManagement.startRollout(rolloutId)) + .withMessageContaining("can only be started in state ready"); } @@ -1506,7 +1457,7 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { rolloutManagement.handleRollouts(); // verify we have running actions - assertThat(actionRepository.findByRolloutIdAndStatus(pageReq, createdRollout.getId(), Status.RUNNING) + assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, createdRollout.getId(), Status.RUNNING) .getNumberOfElements()).isEqualTo(2); // test @@ -1523,16 +1474,16 @@ public class RolloutManagementTest extends AbstractJpaIntegrationTest { .updateRollout(entityFactory.rollout().update(createdRollout.getId()).description("test"))) .withMessageContaining("" + createdRollout.getId()); - assertThat(rolloutManagement.findAll(pageReq, true).getContent()).hasSize(1); - assertThat(rolloutManagement.findAll(pageReq, false).getContent()).hasSize(0); - assertThat(rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(createdRollout.getId(), pageReq) + assertThat(rolloutManagement.findAll(PAGE, true).getContent()).hasSize(1); + assertThat(rolloutManagement.findAll(PAGE, false).getContent()).hasSize(0); + assertThat(rolloutGroupManagement.findAllRolloutGroupsWithDetailedStatus(createdRollout.getId(), PAGE) .getContent()).hasSize(amountGroups); // verify that all scheduled actions are deleted - assertThat(actionRepository.findByRolloutIdAndStatus(pageReq, deletedRollout.getId(), Status.SCHEDULED) + assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.SCHEDULED) .getNumberOfElements()).isEqualTo(0); // verify that all running actions keep running - assertThat(actionRepository.findByRolloutIdAndStatus(pageReq, deletedRollout.getId(), Status.RUNNING) + assertThat(actionRepository.findByRolloutIdAndStatus(PAGE, deletedRollout.getId(), Status.RUNNING) .getNumberOfElements()).isEqualTo(2); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java index 6eaaebf53..8a40824a8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java @@ -112,7 +112,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> softwareManagement.deleteSoftwareModuleType(NOT_EXIST_IDL), "SoftwareModuleType"); - verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleByAssignedTo(pageReq, NOT_EXIST_IDL), + verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleByAssignedTo(PAGE, NOT_EXIST_IDL), "DistributionSet"); verifyThrownExceptionBy( @@ -122,11 +122,12 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadata(NOT_EXIST_IDL, NOT_EXIST_ID), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL), + verifyThrownExceptionBy( + () -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(PAGE, NOT_EXIST_IDL), "SoftwareModule"); verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(NOT_EXIST_IDL, - "name==*", pageReq), "SoftwareModule"); - verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModulesByType(pageReq, NOT_EXIST_IDL), + "name==*", PAGE), "SoftwareModule"); + verifyThrownExceptionBy(() -> softwareManagement.findSoftwareModulesByType(PAGE, NOT_EXIST_IDL), "SoftwareModule"); verifyThrownExceptionBy( @@ -241,29 +242,29 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet(); // standard searches - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent()) .hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent().get(0)) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "poky", osType.getId()).getContent().get(0)) .isEqualTo(os); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent()) .hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent() + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "oracle%", runtimeType.getId()).getContent() .get(0)).isEqualTo(jvm); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent()) .hasSize(1); assertThat( - softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent().get(0)) + softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0.1", appType.getId()).getContent().get(0)) .isEqualTo(ah); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent()) .hasSize(2); // no we search with on entity marked as deleted softwareManagement.deleteSoftwareModule( - softwareModuleRepository.findByAssignedToAndType(pageReq, ds, appType).getContent().get(0).getId()); + softwareModuleRepository.findByAssignedToAndType(PAGE, ds, appType).getContent().get(0).getId()); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent()) .hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent().get(0)) + assertThat(softwareManagement.findSoftwareModuleByFilters(PAGE, "1.0%", appType.getId()).getContent().get(0)) .isEqualTo(ah); } @@ -272,7 +273,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).get().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(ds); - final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0); + final Action action = actionRepository.findByTargetAndDistributionSet(PAGE, target, ds).getContent().get(0); assertThat(action).isNotNull(); return action; } @@ -297,7 +298,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { softwareManagement.deleteSoftwareModule(testdataFactory.createSoftwareModuleOs("deleted").getId()); testdataFactory.createSoftwareModuleApp(); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModulesByType(PAGE, osType.getId()).getContent()) .as("Expected to find the following number of modules:").hasSize(2).as("with the following elements") .contains(two, one); } @@ -319,18 +320,18 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).") public void deleteAssignedAndUnassignedSoftwareModuleTypes() { - assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType, + assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType); SoftwareModuleType type = softwareManagement.createSoftwareModuleType( entityFactory.softwareModuleType().create().key("bundle").name("OSGi Bundle")); - assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType, + assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type); // delete unassigned softwareManagement.deleteSoftwareModuleType(type.getId()); - assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType, + assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType); assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType, (JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType); @@ -338,7 +339,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { type = softwareManagement.createSoftwareModuleType( entityFactory.softwareModuleType().create().key("bundle2").name("OSGi Bundle2")); - assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType, + assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(4).contains(osType, runtimeType, appType, type); softwareManagement.createSoftwareModule( @@ -346,7 +347,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { // delete assigned softwareManagement.deleteSoftwareModuleType(type.getId()); - assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType, + assertThat(softwareManagement.findSoftwareModuleTypesAll(PAGE)).hasSize(3).contains(osType, runtimeType, appType); assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType, @@ -397,7 +398,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { // verify: assignedModule is marked as deleted assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get(); assertTrue("The module should be flagged as deleted", assignedModule.isDeleted()); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(1); // verify: binary data is deleted @@ -437,7 +438,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { // verify: assignedModule is marked as deleted assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()).get(); assertTrue("The found module should be flagged deleted", assignedModule.isDeleted()); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(1); // verify: binary data is deleted @@ -538,7 +539,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { assertThat(moduleY).isNotNull(); assertTrue("The module should be flagged deleted", moduleX.isDeleted()); assertTrue("The module should be flagged deleted", moduleY.isDeleted()); - assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); + assertThat(softwareManagement.findSoftwareModulesAll(PAGE)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(2); // verify: binary data of artifact is deleted @@ -621,21 +622,21 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { softwareManagement.deleteSoftwareModule(deleted.getId()); // with filter on name, version and module type - assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, + assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), "%found%", testType.getId()).getContent()) .as("Found modules with given name, given module type and the assigned ones first") .containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); // with filter on module type only - assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, + assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, testType.getId()).getContent()) .as("Found modules with given module type and the assigned ones first").containsExactly( new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); // without any filter - assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, + assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(PAGE, set.getId(), null, null).getContent()).as("Found modules with the assigned ones first").containsExactly( new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(four, true), @@ -773,7 +774,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { .create().name("set").version("1").modules(Lists.newArrayList(one.getId(), deleted.getId()))); softwareManagement.deleteSoftwareModule(deleted.getId()); - assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set.getId()).getContent()) + assertThat(softwareManagement.findSoftwareModuleByAssignedTo(PAGE, set.getId()).getContent()) .as("Found this number of modules").hasSize(2); } @@ -882,13 +883,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTest { .createSoftwareModuleMetadata(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1)) .getSoftwareModule(); - assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId())) - .as("Contains the created metadata element") - .containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); + assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId()) + .getContent()).as("Contains the created metadata element") + .containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1); - assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId())) - .as("Metadata elemenets are").isEmpty(); + assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(new PageRequest(0, 100), ah.getId()) + .getContent()).as("Metadata elemenets are").isEmpty(); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java index ee4457bf1..9c6ecf74d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java @@ -33,11 +33,11 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in") public void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception { - assertThat(systemManagement.findTenants()).hasSize(1); + assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(1); createTestTenantsForSystemStatistics(2, 0, 0, 0); - assertThat(systemManagement.findTenants()).hasSize(3); + assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(3); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java index 354af3a2a..4d1cb295f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java @@ -19,9 +19,9 @@ import java.util.List; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -64,16 +64,21 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Verifies that management queries react as specfied on calls for non existing entities " + " by means of throwing EntityNotFoundException.") - @ExpectEvents({ @Expect(type = DistributionSetTagUpdateEvent.class, count = 0), - @Expect(type = TargetTagUpdateEvent.class, count = 0) }) + @ExpectEvents({ @Expect(type = DistributionSetTagUpdatedEvent.class, count = 0), + @Expect(type = TargetTagUpdatedEvent.class, count = 0) }) public void entityQueriesReferringToNotExistingEntitiesThrowsException() { verifyThrownExceptionBy(() -> tagManagement.deleteDistributionSetTag(NOT_EXIST_ID), "DistributionSetTag"); verifyThrownExceptionBy(() -> tagManagement.deleteTargetTag(NOT_EXIST_ID), "TargetTag"); + verifyThrownExceptionBy(() -> tagManagement.findDistributionSetTagsByDistributionSet(PAGE, NOT_EXIST_IDL), + "DistributionSet"); + verifyThrownExceptionBy(() -> tagManagement.updateDistributionSetTag(entityFactory.tag().update(NOT_EXIST_IDL)), "DistributionSetTag"); verifyThrownExceptionBy(() -> tagManagement.updateTargetTag(entityFactory.tag().update(NOT_EXIST_IDL)), "TargetTag"); + + verifyThrownExceptionBy(() -> tagManagement.findAllTargetTags(PAGE, NOT_EXIST_ID), "Target"); } @Test @@ -118,7 +123,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()) + distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true) @@ -126,7 +131,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsBs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown() + dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()) + distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true) @@ -134,13 +139,13 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()) + distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(true) .setTagNames(Lists.newArrayList(tagX.getName())); assertEquals("filter works not correct", 0, distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getTotalElements()); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements()); assertEquals("wrong tag size", 5, distributionSetTagRepository.findAll().spliterator().getExactSizeIfKnown()); @@ -157,20 +162,20 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertEquals("filter works not correct", dsAs.spliterator().getExactSizeIfKnown() + dsABs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()) + distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setTagNames(Lists.newArrayList(tagB.getName())); assertEquals("filter works not correct", 0, distributionSetManagement - .findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()).getTotalElements()); + .findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()).getTotalElements()); distributionSetFilterBuilder = getDistributionSetFilterBuilder().setIsComplete(Boolean.TRUE) .setTagNames(Lists.newArrayList(tagC.getName())); assertEquals("filter works not correct", dsCs.spliterator().getExactSizeIfKnown() + dsACs.spliterator().getExactSizeIfKnown() + dsBCs.spliterator().getExactSizeIfKnown() + dsABCs.spliterator().getExactSizeIfKnown(), - distributionSetManagement.findDistributionSetsByFilters(pageReq, distributionSetFilterBuilder.build()) + distributionSetManagement.findDistributionSetsByFilters(PAGE, distributionSetFilterBuilder.build()) .getTotalElements()); } @@ -193,7 +198,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(20); assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement - .findDistributionSetsAll(groupA.stream().map(set -> set.getId()).collect(Collectors.toList()))); + .findDistributionSetsById(groupA.stream().map(DistributionSet::getId).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -203,7 +208,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertThat(result.getAlreadyAssigned()).isEqualTo(20); assertThat(result.getAssigned()).isEqualTo(20); assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement - .findDistributionSetsAll(groupB.stream().map(set -> set.getId()).collect(Collectors.toList()))); + .findDistributionSetsById(groupB.stream().map(DistributionSet::getId).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -214,8 +219,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertThat(result.getAssigned()).isEqualTo(0); assertThat(result.getAssignedEntity()).isEmpty(); assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetsAll( - concat(groupB, groupA).stream().map(set -> set.getId()).collect(Collectors.toList()))); + assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetsById( + concat(groupB, groupA).stream().map(DistributionSet::getId).collect(Collectors.toList()))); assertThat(result.getDistributionSetTag()).isEqualTo(tag); } @@ -234,7 +239,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { TargetTagAssignmentResult result = toggleTagAssignment(groupA, tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID( + assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerID( groupA.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); @@ -244,7 +249,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { result = toggleTagAssignment(concat(groupA, groupB), tag); assertThat(result.getAlreadyAssigned()).isEqualTo(20); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetByControllerID( + assertThat(result.getAssignedEntity()).containsAll(targetManagement.findTargetsByControllerID( groupB.stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); @@ -256,7 +261,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { assertThat(result.getAssigned()).isEqualTo(0); assertThat(result.getAssignedEntity()).isEmpty(); assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetByControllerID( + assertThat(result.getUnassignedEntity()).containsAll(targetManagement.findTargetsByControllerID( concat(groupB, groupA).stream().map(target -> target.getControllerId()).collect(Collectors.toList()))); assertThat(result.getTargetTag()).isEqualTo(tag); @@ -300,7 +305,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final TargetTag toDelete = tags.iterator().next(); for (final Target target : targetRepository.findAll()) { - assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent()) + assertThat(tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getContent()) .contains(toDelete); } @@ -309,7 +314,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { // check for (final Target target : targetRepository.findAll()) { - assertThat(tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getContent()) + assertThat(tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getContent()) .doesNotContain(toDelete); } assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull(); @@ -365,8 +370,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final DistributionSetTag toDelete = tags.iterator().next(); for (final DistributionSet set : distributionSetRepository.findAll()) { - assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags()) - .as("Wrong tag found").contains(toDelete); + assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong tag found") + .contains(toDelete); } // delete @@ -374,10 +379,12 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { // check assertThat(distributionSetTagRepository.findOne(toDelete.getId())).as("Deleted tag should be null").isNull(); - assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of tags after deletion").hasSize(19); + assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()) + .as("Wrong size of tags after deletion").hasSize(19); + for (final DistributionSet set : distributionSetRepository.findAll()) { - assertThat(distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()).get().getTags()) - .as("Wrong found tags").doesNotContain(toDelete); + assertThat(distributionSetRepository.findOne(set.getId()).getTags()).as("Wrong found tags") + .doesNotContain(toDelete); } } @@ -448,7 +455,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { tagManagement.updateDistributionSetTag(entityFactory.tag().update(savedAssigned.getId()).name("test123")); // check data - assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of ds tags").hasSize(tags.size()); + assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()).as("Wrong size of ds tags") + .hasSize(tags.size()); assertThat(distributionSetTagRepository.findOne(savedAssigned.getId()).getName()).as("Wrong ds tag found") .isEqualTo("test123"); } @@ -459,7 +467,8 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { final List tags = createDsSetsWithTags(); // test - assertThat(tagManagement.findAllDistributionSetTags()).as("Wrong size of tags").hasSize(tags.size()); + assertThat(tagManagement.findAllDistributionSetTags(PAGE).getContent()).as("Wrong size of tags") + .hasSize(tags.size()); assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags").hasSize(20); } @@ -479,6 +488,6 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { tags.forEach(tag -> toggleTagAssignment(sets, tag)); - return tagManagement.findAllDistributionSetTags(); + return tagManagement.findAllDistributionSetTags(PAGE).getContent(); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java index e2742f0d5..60c363242 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagementTest.java @@ -68,7 +68,7 @@ public class TargetFilterQueryManagementTest extends AbstractJpaIntegrationTest verifyThrownExceptionBy(() -> targetFilterQueryManagement.deleteTargetFilterQuery(NOT_EXIST_IDL), "TargetFilterQuery"); - verifyThrownExceptionBy(() -> targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(pageReq, + verifyThrownExceptionBy(() -> targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(PAGE, NOT_EXIST_IDL, "name==*"), "DistributionSet"); verifyThrownExceptionBy( diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java index a3c38dc1a..cfe13d0ff 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java @@ -107,11 +107,11 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { // get final updated version of targets targAs = targetManagement - .findTargetByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList())); + .findTargetsByControllerID(targAs.stream().map(Target::getControllerId).collect(Collectors.toList())); targBs = targetManagement - .findTargetByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList())); + .findTargetsByControllerID(targBs.stream().map(Target::getControllerId).collect(Collectors.toList())); targCs = targetManagement - .findTargetByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList())); + .findTargetsByControllerID(targCs.stream().map(Target::getControllerId).collect(Collectors.toList())); // try to find several targets with different filter settings verifyThat1TargetHasNameAndId("targ-A-special", targSpecialName.getControllerId()); @@ -123,14 +123,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA); verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA); verifyThat3TargetsHaveDSAssigned(setA, - targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.findTargetByControllerID(assignedA).get()); List expected = concat(targAs, targBs, targCs, targDs); expected.removeAll( - targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); verifyThat397TargetsAreInStatusUnknown(unknown, expected); expected = concat(targBs, targCs); - expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + expected.removeAll(targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC))); verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected); verfyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown); expected = concat(targAs); @@ -140,23 +140,23 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { expected.remove(targetManagement.findTargetByControllerID(assignedB).get()); verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected); verifyThat3TargetsAreInStatusPending(pending, - targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); verifyThat3TargetsWithGivenDSAreInPending(setA, pending, - targetManagement.findTargetByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); + targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedA, assignedB, assignedC))); verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending, targetManagement.findTargetByControllerID(assignedA).get()); verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending, targetManagement.findTargetByControllerID(assignedB).get()); verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending, - targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC))); verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending, - targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC))); verifyThat200targetsWithGivenTagAreInStatusPendingorUnknown(targTagW, both, concat(targBs, targCs)); verfiyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending, targetManagement.findTargetByControllerID(installedC).get()); expected = concat(targBs, targCs); - expected.removeAll(targetManagement.findTargetByControllerID(Lists.newArrayList(assignedB, assignedC))); + expected.removeAll(targetManagement.findTargetsByControllerID(Lists.newArrayList(assignedB, assignedC))); verifyThat198TargetsAreInStatusUnknownAndOverdue(unknown, expected); } @@ -165,14 +165,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final List pending, final Target expected) { final String query = "updatestatus==pending and installedds.name==" + installedSet.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, installedSet.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @@ -182,13 +182,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(updatestatus==pending or updatestatus==unknown) and tag==" + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, both, null, null, null, Boolean.FALSE, targTagW.getName()).getContent()) + .findTargetByFilters(PAGE, both, null, null, null, Boolean.FALSE, targTagW.getName()).getContent()) .as("has number of elements").hasSize(200).as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(both, null, null, null, Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -197,14 +197,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==pending and tag==" + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, pending, null, null, null, Boolean.FALSE, targTagW.getName()) + .findTargetByFilters(PAGE, pending, null, null, null, Boolean.FALSE, targTagW.getName()) .getContent()).as("has number of elements").hasSize(2) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, null, Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -214,14 +214,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ") and tag==" + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName()) + .findTargetByFilters(PAGE, pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName()) .getContent()).as("has number of elements").hasSize(2) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -230,14 +230,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==pending and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ") and (name==*targ-B* or description==*targ-B*) and tag==" + targTagW.getName(); - assertThat(targetManagement.findTargetByFilters(pageReq, pending, null, "%targ-B%", setA.getId(), Boolean.FALSE, + assertThat(targetManagement.findTargetByFilters(PAGE, pending, null, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName()).getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -247,14 +247,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ") and (name==*targ-A* or description==*targ-A*)"; assertThat(targetManagement - .findTargetByFilters(pageReq, pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -264,14 +264,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(pageReq, pending, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, pending, null, null, setA.getId(), Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(3) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, setA.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -280,13 +280,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==pending"; assertThat(targetManagement - .findTargetByFilters(pageReq, pending, null, null, null, Boolean.FALSE, new String[0]).getContent()) + .findTargetByFilters(PAGE, pending, null, null, null, Boolean.FALSE, new String[0]).getContent()) .as("has number of elements").hasSize(3).as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(pending, null, null, null, Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -296,14 +296,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + targTagW.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName()) + .findTargetByFilters(PAGE, unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName()) .getContent()).as("has number of elements").hasSize(99) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-B%", null, Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -312,14 +312,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==unknown and (name==*targ-A* or description==*targ-A*)"; assertThat(targetManagement - .findTargetByFilters(pageReq, unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(99) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, "%targ-A%", null, Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @@ -330,13 +330,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(pageReq, unknown, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, unknown, null, null, setA.getId(), Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(0) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, setA.getId(), Boolean.FALSE, new String[0]))) .as("and filter query returns the same result") - .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()); + .hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size()); } @Step @@ -345,14 +345,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==unknown and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName() + ")"; - assertThat(targetManagement.findTargetByFilters(pageReq, unknown, null, null, null, Boolean.FALSE, + assertThat(targetManagement.findTargetByFilters(PAGE, unknown, null, null, null, Boolean.FALSE, targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(198) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, null, Boolean.FALSE, targTagY.getName(), targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -361,13 +361,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "updatestatus==unknown"; assertThat(targetManagement - .findTargetByFilters(pageReq, unknown, null, null, null, Boolean.FALSE, new String[0]).getContent()) + .findTargetByFilters(PAGE, unknown, null, null, null, Boolean.FALSE, new String[0]).getContent()) .as("has number of elements").hasSize(397).as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, null, null, null, Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @@ -378,14 +378,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "lastcontrollerrequestat=le=${overdue_ts};updatestatus==UNKNOWN"; assertThat(targetManagement - .findTargetByFilters(pageReq, unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(198) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(unknown, Boolean.TRUE, null, null, Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step @@ -394,14 +394,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(pageReq, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @@ -410,14 +410,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, null, null, null, setA.getId(), Boolean.FALSE, new String[0]) + .findTargetByFilters(PAGE, null, null, null, setA.getId(), Boolean.FALSE, new String[0]) .getContent()).as("has number of elements").hasSize(3) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null, setA.getId(), Boolean.FALSE, new String[0]))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @@ -426,13 +426,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(name==*targ-C* or description==*targ-C*) and tag==" + targTagX.getName() + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(pageReq, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName()) + .findTargetByFilters(PAGE, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName()) .getContent()).as("has number of elements").hasSize(0) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName()))) .as("and filter query returns the same result") - .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()); + .hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size()); } @@ -441,13 +441,13 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(name==*targ-A* or description==*targ-A*) and tag==" + targTagW.getName() + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(pageReq, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .findTargetByFilters(PAGE, null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName()) .getContent()).as("has number of elements").hasSize(0) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and filter query returns the same result") - .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()); + .hasSize(targetManagement.findTargetsAll(query, PAGE).getContent().size()); } @@ -457,24 +457,24 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final String query = "(name==*targ-c* or description==*targ-C*) and tag==" + targTagW.getName() + " and (assignedds.name==" + setA.getName() + " or installedds.name==" + setA.getName() + ")"; assertThat(targetManagement - .findTargetByFilters(pageReq, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName()) + .findTargetByFilters(PAGE, null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName()) .getContent()).as("has number of elements").hasSize(1) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName()))) .as("and contains the following elements").containsExactly(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step private void verifyThat1TargetHasNameAndId(final String name, final String controllerId) { - assertThat(targetManagement.findTargetByFilters(pageReq, null, null, name, null, Boolean.FALSE).getContent()) + assertThat(targetManagement.findTargetByFilters(PAGE, null, null, name, null, Boolean.FALSE).getContent()) .as("has number of elements").hasSize(1).as("that number is also returned by count query").hasSize(Ints .saturatedCast(targetManagement.countTargetByFilters(null, null, name, null, Boolean.FALSE))); - assertThat(targetManagement.findTargetByFilters(pageReq, null, null, controllerId, null, Boolean.FALSE) + assertThat(targetManagement.findTargetByFilters(PAGE, null, null, controllerId, null, Boolean.FALSE) .getContent()).as("has number of elements").hasSize(1).as("that number is also returned by count query") .hasSize(Ints.saturatedCast( targetManagement.countTargetByFilters(null, null, controllerId, null, Boolean.FALSE))); @@ -485,14 +485,14 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { final TargetTag targTagW, final List expected) { final String query = "(name==*targ-B* or description==*targ-B*) and (tag==" + targTagY.getName() + " or tag==" + targTagW.getName() + ")"; - assertThat(targetManagement.findTargetByFilters(pageReq, null, null, "%targ-B%", null, Boolean.FALSE, + assertThat(targetManagement.findTargetByFilters(PAGE, null, null, "%targ-B%", null, Boolean.FALSE, targTagY.getName(), targTagW.getName()).getContent()).as("has number of elements").hasSize(100) .as("that number is also returned by count query") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, "%targ-B%", null, Boolean.FALSE, targTagY.getName(), targTagW.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @@ -507,26 +507,26 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { private void verifyThat200TargetsHaveTagD(final TargetTag targTagD, final List expected) { final String query = "tag==" + targTagD.getName(); assertThat(targetManagement - .findTargetByFilters(pageReq, null, null, null, null, Boolean.FALSE, targTagD.getName()).getContent()) + .findTargetByFilters(PAGE, null, null, null, null, Boolean.FALSE, targTagD.getName()).getContent()) .as("Expected number of results is").hasSize(200) .as("and is expected number of results is equal to ") .hasSize(Ints.saturatedCast(targetManagement.countTargetByFilters(null, null, null, null, Boolean.FALSE, targTagD.getName()))) .as("and contains the following elements").containsAll(expected) .as("and filter query returns the same result") - .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(query, PAGE).getContent()); } @Step private void verifyThatRepositoryContains400Targets() { assertThat( - targetManagement.findTargetByFilters(pageReq, null, null, null, null, null, new String[0]).getContent()) + targetManagement.findTargetByFilters(PAGE, null, null, null, null, null, new String[0]).getContent()) .as("Overall we expect that many targets in the repository").hasSize(400) .as("which is also reflected by repository count") .hasSize(Ints.saturatedCast(targetManagement.countTargetsAll())) .as("which is also reflected by call without specification") - .containsAll(targetManagement.findTargetsAll(pageReq).getContent()); + .containsAll(targetManagement.findTargetsAll(PAGE).getContent()); } @@ -546,7 +546,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { .sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed")) .stream().map(Action::getTarget).collect(Collectors.toList()); - final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(), + final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(PAGE, ds.getId(), new FilterParams(null, null, null, null, Boolean.FALSE, new String[0])); final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); @@ -594,9 +594,9 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { targInstalled = assignDistributionSet(ds, targInstalled).getAssignedEntity(); targInstalled = testdataFactory .sendUpdateActionStatusToTargets(targInstalled, Status.FINISHED, Collections.singletonList("installed")) - .stream().map(action -> action.getTarget()).collect(Collectors.toList()); + .stream().map(Action::getTarget).collect(Collectors.toList()); - final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(pageReq, ds.getId(), + final Slice result = targetManagement.findTargetsAllOrderByLinkedDistributionSet(PAGE, ds.getId(), new FilterParams(null, null, Boolean.TRUE, null, Boolean.FALSE, new String[0])); final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); @@ -627,10 +627,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { assignDistributionSet(assignedSet, assignedtargets); // get final updated version of targets - assignedtargets = targetManagement.findTargetByControllerID( + assignedtargets = targetManagement.findTargetsByControllerID( assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); - assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), pageReq)) + assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), PAGE)) .as("Contains the assigned targets").containsAll(assignedtargets) .as("and that means the following expected amount").hasSize(10); @@ -648,7 +648,7 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { assignDistributionSet(assignedSet, assignedTargets); final List result = targetManagement - .findAllTargetsByTargetFilterQueryAndNonDS(pageReq, assignedSet.getId(), tfq.getQuery()).getContent(); + .findAllTargetsByTargetFilterQueryAndNonDS(PAGE, assignedSet.getId(), tfq.getQuery()).getContent(); assertThat(result).as("count of targets").hasSize(unassignedTargets.size()).as("contains all targets") .containsAll(unassignedTargets); @@ -668,10 +668,10 @@ public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { assignDistributionSet(assignedSet, installedtargets); // get final updated version of targets - installedtargets = targetManagement.findTargetByControllerID( + installedtargets = targetManagement.findTargetsByControllerID( installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); - assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), pageReq)) + assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), PAGE)) .as("Contains the assigned targets").containsAll(installedtargets) .as("and that means the following expected amount").hasSize(10); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java index 2a8f51d11..46963d5c2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java @@ -84,6 +84,10 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> targetManagement.assignTag(Lists.newArrayList(NOT_EXIST_ID), tag.getId()), "Target"); + verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, NOT_EXIST_IDL), "TargetTag"); + verifyThrownExceptionBy(() -> targetManagement.findTargetsByTag(PAGE, "name==*", NOT_EXIST_IDL), + "TargetTag"); + verifyThrownExceptionBy(() -> targetManagement.countTargetByAssignedDistributionSet(NOT_EXIST_IDL), "DistributionSet"); verifyThrownExceptionBy(() -> targetManagement.countTargetByInstalledDistributionSet(NOT_EXIST_IDL), @@ -99,21 +103,21 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy(() -> targetManagement.deleteTargets(Lists.newArrayList(NOT_EXIST_IDL)), "Target"); verifyThrownExceptionBy( - () -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(pageReq, NOT_EXIST_IDL, "name==*"), + () -> targetManagement.findAllTargetsByTargetFilterQueryAndNonDS(PAGE, NOT_EXIST_IDL, "name==*"), "DistributionSet"); verifyThrownExceptionBy( - () -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageReq, NOT_EXIST_IDL), + () -> targetManagement.findAllTargetsInRolloutGroupWithoutAction(PAGE, NOT_EXIST_IDL), "RolloutGroup"); - verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, pageReq), + verifyThrownExceptionBy(() -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, PAGE), "DistributionSet"); verifyThrownExceptionBy( - () -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, "name==*", pageReq), + () -> targetManagement.findTargetByAssignedDistributionSet(NOT_EXIST_IDL, "name==*", PAGE), "DistributionSet"); - verifyThrownExceptionBy(() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, pageReq), + verifyThrownExceptionBy(() -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, PAGE), "DistributionSet"); verifyThrownExceptionBy( - () -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, "name==*", pageReq), + () -> targetManagement.findTargetByInstalledDistributionSet(NOT_EXIST_IDL, "name==*", PAGE), "DistributionSet"); verifyThrownExceptionBy( @@ -122,7 +126,6 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { verifyThrownExceptionBy( () -> targetManagement.toggleTagAssignment(Lists.newArrayList(NOT_EXIST_ID), tag.getName()), "Target"); - verifyThrownExceptionBy(() -> targetManagement.unAssignAllTargetsByTag(NOT_EXIST_IDL), "TargetTag"); verifyThrownExceptionBy(() -> targetManagement.unAssignTag(NOT_EXIST_ID, tag.getId()), "Target"); verifyThrownExceptionBy(() -> targetManagement.unAssignTag(target.getControllerId(), NOT_EXIST_IDL), "TargetTag"); @@ -255,7 +258,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { @Description("Ensures that targets can assigned and unassigned to a target tag. Not exists target will be ignored for the assignment.") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 4), @Expect(type = TargetTagCreatedEvent.class, count = 1), - @Expect(type = TargetUpdatedEvent.class, count = 8) }) + @Expect(type = TargetUpdatedEvent.class, count = 5) }) public void assignAndUnassignTargetsToTag() { final List assignTarget = new ArrayList<>(); assignTarget.add(targetManagement.createTarget(entityFactory.target().create().controllerId("targetId123")) @@ -272,26 +275,24 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final List assignedTargets = targetManagement.assignTag(assignTarget, targetTag.getId()); assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4); assignedTargets.forEach(target -> assertThat( - tagManagement.findAllTargetTags(pageReq, target.getControllerId()).getNumberOfElements()).isEqualTo(1)); + tagManagement.findAllTargetTags(PAGE, target.getControllerId()).getNumberOfElements()).isEqualTo(1)); TargetTag findTargetTag = tagManagement.findTargetTag("Tag1").get(); assertThat(assignedTargets.size()).as("Assigned targets are wrong") - .isEqualTo(findTargetTag.getAssignedToTargets().size()); + .isEqualTo(targetManagement.findTargetsByTag(PAGE, targetTag.getId()).getNumberOfElements()); final Target unAssignTarget = targetManagement.unAssignTag("targetId123", findTargetTag.getId()); assertThat(unAssignTarget.getControllerId()).as("Controller id is wrong").isEqualTo("targetId123"); - assertThat(tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId())).as("Tag size is wrong") + assertThat(tagManagement.findAllTargetTags(PAGE, unAssignTarget.getControllerId())).as("Tag size is wrong") .isEmpty(); findTargetTag = tagManagement.findTargetTag("Tag1").get(); - assertThat(findTargetTag.getAssignedToTargets()).as("Assigned targets are wrong").hasSize(3); + assertThat(targetManagement.findTargetsByTag(PAGE, targetTag.getId())).as("Assigned targets are wrong") + .hasSize(3); + assertThat(targetManagement.findTargetsByTag(PAGE, "controllerId==targetId123", targetTag.getId())) + .as("Assigned targets are wrong").isEmpty(); + assertThat(targetManagement.findTargetsByTag(PAGE, "controllerId==targetId1234", targetTag.getId())) + .as("Assigned targets are wrong").hasSize(1); - final List unAssignTargets = targetManagement.unAssignAllTargetsByTag(findTargetTag.getId()); - findTargetTag = tagManagement.findTargetTag("Tag1").get(); - assertThat(findTargetTag.getAssignedToTargets()).as("Unassigned targets are wrong").isEmpty(); - assertThat(unAssignTargets).as("Unassigned targets are wrong").hasSize(3); - unAssignTargets.forEach(target -> assertThat( - tagManagement.findAllTargetTags(pageReq, unAssignTarget.getControllerId()).getNumberOfElements()) - .isEqualTo(0)); } @Test @@ -426,7 +427,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { _target: for (final Target tl : targets) { final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get(); - for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) { + for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) { for (final Tag tag : tags) { if (tag.getName().equals(tt.getName())) { continue _target; @@ -445,7 +446,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final Target t = targetManagement.findTargetByControllerID(tl.getControllerId()).get(); for (final Tag tag : tags) { - for (final Tag tt : tagManagement.findAllTargetTags(pageReq, tl.getControllerId())) { + for (final Tag tt : tagManagement.findAllTargetTags(PAGE, tl.getControllerId())) { if (tag.getName().equals(tt.getName())) { fail("Target should have no tags"); } @@ -577,15 +578,15 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { t2Tags.forEach(tag -> targetManagement.assignTag(Lists.newArrayList(t2.getControllerId()), tag.getId())); final Target t11 = targetManagement.findTargetByControllerID(t1.getControllerId()).get(); - assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong") + assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong") .hasSize(noT1Tags).containsAll(t1Tags); - assertThat(tagManagement.findAllTargetTags(pageReq, t11.getControllerId()).getContent()).as("Tag size is wrong") + assertThat(tagManagement.findAllTargetTags(PAGE, t11.getControllerId()).getContent()).as("Tag size is wrong") .hasSize(noT1Tags).doesNotContain(Iterables.toArray(t2Tags, TargetTag.class)); final Target t21 = targetManagement.findTargetByControllerID(t2.getControllerId()).get(); - assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong") + assertThat(tagManagement.findAllTargetTags(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong") .hasSize(noT2Tags).containsAll(t2Tags); - assertThat(tagManagement.findAllTargetTags(pageReq, t21.getControllerId()).getContent()).as("Tag size is wrong") + assertThat(tagManagement.findAllTargetTags(PAGE, t21.getControllerId()).getContent()).as("Tag size is wrong") .hasSize(noT2Tags).doesNotContain(Iterables.toArray(t1Tags, TargetTag.class)); } @@ -731,7 +732,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { final String[] tagNames = null; final List targetsListWithNoTag = targetManagement - .findTargetByFilters(pageReq, null, null, null, null, Boolean.TRUE, tagNames).getContent(); + .findTargetByFilters(PAGE, null, null, null, null, Boolean.TRUE, tagNames).getContent(); assertThat(50L).as("Total targets").isEqualTo(targetManagement.countTargetsAll()); assertThat(25).as("Targets with no tag").isEqualTo(targetsListWithNoTag.size()); @@ -766,7 +767,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createTargets(25, "target-id-B", "first description"); - final Page foundTargets = targetManagement.findTargetsAll(rsqlFilter, pageReq); + final Page foundTargets = targetManagement.findTargetsAll(rsqlFilter, PAGE); assertThat(targetManagement.countTargetsAll()).as("Total targets").isEqualTo(50L); assertThat(foundTargets.getTotalElements()).as("Targets in RSQL filter").isEqualTo(27L); @@ -782,7 +783,7 @@ public class TargetManagementTest extends AbstractJpaIntegrationTest { testdataFactory.createTarget("test" + i); } - final List foundDs = targetManagement.findTargetAllById(searchIds); + final List foundDs = targetManagement.findTargetsById(searchIds); assertThat(foundDs).hasSize(3); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java index 511de601b..4bb041c8c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/autoassign/AutoAssignCheckerTest.java @@ -145,7 +145,7 @@ public class AutoAssignCheckerTest extends AbstractJpaIntegrationTest { final int count) { final List targetIds = targets.stream().map(Target::getId).collect(Collectors.toList()); - final Slice targetsAll = targetManagement.findTargetsAll(pageReq); + final Slice targetsAll = targetManagement.findTargetsAll(PAGE); assertThat(targetsAll).as("Count of targets").hasSize(count); for (final Target target : targetsAll) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java index 927d7c969..8a3f052e5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java @@ -40,7 +40,9 @@ public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest { final DistributionSet dsA = testdataFactory.createDistributionSet(""); rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); rollout = rolloutManagement.findRolloutById(rollout.getId()).get(); - this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId(); + + this.rolloutGroupId = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), PAGE).getContent() + .get(0).getId(); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java index 01050770c..854eb5a72 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java @@ -25,7 +25,6 @@ import org.eclipse.hawkbit.repository.test.util.TestdataFactory; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; @@ -181,7 +180,7 @@ public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) { - final Page findTargetPage = targetManagement.findTargetsAll(rsqlParam, new PageRequest(0, 100)); + final Page findTargetPage = targetManagement.findTargetsAll(rsqlParam, PAGE); final long countTargetsAll = findTargetPage.getTotalElements(); assertThat(findTargetPage).isNotNull(); assertThat(countTargetsAll).isEqualTo(expcetedTargets); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java index 56a223496..635264352 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java @@ -73,7 +73,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { createTargetForTenant(controllerAnotherTenant, anotherTenant); // find all targets for current tenant "mytenant" - final Slice findTargetsAll = targetManagement.findTargetsAll(pageReq); + final Slice findTargetsAll = targetManagement.findTargetsAll(PAGE); // no target has been created for "mytenant" assertThat(findTargetsAll).hasSize(0); @@ -92,11 +92,12 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { final String controllerAnotherTenant = "anotherController"; createTargetForTenant(controllerAnotherTenant, anotherTenant); - assertThat(systemManagement.findTenants()).as("Expected number if tenants before deletion is").hasSize(3); + assertThat(systemManagement.findTenants(PAGE)).as("Expected number if tenants before deletion is") + .hasSize(3); systemManagement.deleteTenant(anotherTenant); - assertThat(systemManagement.findTenants()).as("Expected number if tenants after deletion is").hasSize(2); + assertThat(systemManagement.findTenants(PAGE)).as("Expected number if tenants after deletion is").hasSize(2); } @Test @@ -106,9 +107,9 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { // logged in tenant mytenant - check if tenant default data is // autogenerated - assertThat(distributionSetManagement.findDistributionSetTypesAll(pageReq)).isEmpty(); + assertThat(distributionSetManagement.findDistributionSetTypesAll(PAGE)).isEmpty(); assertThat(systemManagement.getTenantMetadata().getTenant().toUpperCase()).isEqualTo("mytenant".toUpperCase()); - assertThat(distributionSetManagement.findDistributionSetTypesAll(pageReq)).isNotEmpty(); + assertThat(distributionSetManagement.findDistributionSetTypesAll(PAGE)).isNotEmpty(); // check that the cache is not getting in the way, i.e. "bumlux" results // in bumlux and not @@ -174,7 +175,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { private Slice findTargetsForTenant(final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), - () -> targetManagement.findTargetsAll(pageReq)); + () -> targetManagement.findTargetsAll(PAGE)); } private void deleteTargetsForTenant(final String tenant, final Collection targetIds) throws Exception { @@ -191,7 +192,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { private Page findDistributionSetForTenant(final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), - () -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)); + () -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(PAGE, false, true)); } } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 4ef020f1e..7a519b907 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -27,6 +27,7 @@ import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; @@ -100,7 +101,7 @@ import com.google.common.collect.Lists; public abstract class AbstractIntegrationTest implements EnvironmentAware { private static final Logger LOG = LoggerFactory.getLogger(AbstractIntegrationTest.class); - protected static final Pageable pageReq = new PageRequest(0, 400, new Sort(Direction.ASC, "id")); + protected static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id")); /** * Constant for MediaType HAL with encoding UTF-8. Necessary since Spring @@ -176,6 +177,9 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Autowired protected TenantAwareCacheManager cacheManager; + @Autowired + protected QuotaManagement quotaManagement; + protected MockMvc mvc; protected SoftwareModuleType osType; @@ -258,7 +262,8 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { Target savedTarget = testdataFactory.createTarget(controllerId); savedTarget = assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getAssignedEntity().iterator() .next(); - Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0); + Action savedAction = deploymentManagement.findActiveActionsByTarget(PAGE, savedTarget.getControllerId()) + .getContent().get(0); savedAction = controllerManagement.addUpdateActionStatus( entityFactory.actionStatus().create(savedAction.getId()).status(Action.Status.RUNNING)); diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java index 149050be0..59c640586 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java @@ -15,10 +15,15 @@ import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; public class JpaTestRepositoryManagement implements TestRepositoryManagement { private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class); + private static final Pageable PAGE = new PageRequest(0, 400, new Sort(Direction.ASC, "id")); private final TenantAwareCacheManager cacheManager; @@ -50,7 +55,8 @@ public class JpaTestRepositoryManagement implements TestRepositoryManagement { } public void deleteAllRepos() { - final List tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants()); + final List tenants = systemSecurityContext + .runAsSystem(() -> systemManagement.findTenants(PAGE).getContent()); tenants.forEach(tenant -> { try { systemSecurityContext.runAsSystem(() -> { diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index 7adcaa133..b0afb6d80 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -345,6 +345,26 @@ public class TestdataFactory { return createDistributionSets("", number); } + /** + * Create a list of {@link DistributionSet}s without modules, i.e. + * incomplete. + * + * @param number + * of {@link DistributionSet}s to create + * @return {@link List} of {@link DistributionSet} entities + */ + public List createDistributionSetsWithoutModules(final int number) { + + final List sets = Lists.newArrayListWithExpectedSize(number); + for (int i = 0; i < number; i++) { + sets.add(distributionSetManagement.createDistributionSet( + entityFactory.distributionSet().create().name("DS" + i).version(DEFAULT_VERSION + "." + i) + .description(LOREM.words(10)).type(findOrCreateDefaultTestDsType()))); + } + + return sets; + } + /** * Creates {@link DistributionSet}s in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java index 6791569aa..0a70f5a8a 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.rest.util; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -20,6 +21,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.json.JSONArray; import org.json.JSONException; @@ -33,21 +35,68 @@ import org.json.JSONObject; */ public abstract class JsonBuilder { + public static String ids(final Collection ids) { + final JSONArray list = new JSONArray(); + for (final Long smID : ids) { + list.put(new JSONObject().put("id", smID)); + } + + return list.toString(); + } + + public static String controllerIds(final Collection ids) { + final JSONArray list = new JSONArray(); + for (final String smID : ids) { + list.put(new JSONObject().put("controllerId", smID)); + } + + return list.toString(); + } + + public static String tags(final List tags) throws JSONException { + final StringBuilder builder = new StringBuilder(); + + builder.append("["); + int i = 0; + for (final Tag tag : tags) { + createTagLine(builder, tag); + + if (++i < tags.size()) { + builder.append(","); + } + } + + builder.append("]"); + + return builder.toString(); + + } + + private static void createTagLine(final StringBuilder builder, final Tag tag) { + builder.append(new JSONObject().put("name", tag.getName()).put("description", tag.getDescription()) + .put("colour", tag.getColour()).put("createdAt", "0").put("updatedAt", "0") + .put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString()); + } + + public static String tag(final Tag tag) throws JSONException { + final StringBuilder builder = new StringBuilder(); + + createTagLine(builder, tag); + + return builder.toString(); + + } + public static String softwareModules(final List modules) throws JSONException { final StringBuilder builder = new StringBuilder(); builder.append("["); int i = 0; for (final SoftwareModule module : modules) { - try { - builder.append(new JSONObject().put("name", module.getName()) - .put("description", module.getDescription()).put("type", module.getType().getKey()) - .put("id", Long.MAX_VALUE).put("vendor", module.getVendor()).put("version", module.getVersion()) - .put("createdAt", "0").put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh") - .put("updatedBy", "fghdfkjghdfkjh").toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) + .put("type", module.getType().getKey()).put("id", Long.MAX_VALUE).put("vendor", module.getVendor()) + .put("version", module.getVersion()).put("createdAt", "0").put("updatedAt", "0") + .put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString()); if (++i < modules.size()) { builder.append(","); @@ -66,13 +115,9 @@ public abstract class JsonBuilder { builder.append("["); int i = 0; for (final SoftwareModule module : modules) { - try { - builder.append(new JSONObject().put("name", module.getName()) - .put("description", module.getDescription()).put("type", module.getType().getKey()) - .put("vendor", module.getVendor()).put("version", module.getVersion()).toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) + .put("type", module.getType().getKey()).put("vendor", module.getVendor()) + .put("version", module.getVersion()).toString()); if (++i < modules.size()) { builder.append(","); @@ -101,15 +146,10 @@ public abstract class JsonBuilder { builder.append("["); int i = 0; for (final SoftwareModuleType module : types) { - try { - builder.append(new JSONObject().put("name", module.getName()) - .put("description", module.getDescription()).put("id", Long.MAX_VALUE) - .put("key", module.getKey()).put("maxAssignments", module.getMaxAssignments()) - .put("createdAt", "0").put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh") - .put("updatedBy", "fghdfkjghdfkjh").toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) + .put("id", Long.MAX_VALUE).put("key", module.getKey()) + .put("maxAssignments", module.getMaxAssignments()).put("createdAt", "0").put("updatedAt", "0") + .put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString()); if (++i < types.size()) { builder.append(","); @@ -129,13 +169,8 @@ public abstract class JsonBuilder { builder.append("["); int i = 0; for (final SoftwareModuleType module : types) { - try { - builder.append(new JSONObject().put("name", module.getName()) - .put("description", module.getDescription()).put("key", module.getKey()) - .put("maxAssignments", module.getMaxAssignments()).toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) + .put("key", module.getKey()).put("maxAssignments", module.getMaxAssignments()).toString()); if (++i < types.size()) { builder.append(","); @@ -249,22 +284,16 @@ public abstract class JsonBuilder { int i = 0; for (final DistributionSetType module : types) { - try { + final JSONArray osmTypes = new JSONArray(); + module.getOptionalModuleTypes().forEach(smt -> osmTypes.put(new JSONObject().put("id", smt.getId()))); - final JSONArray osmTypes = new JSONArray(); - module.getOptionalModuleTypes().forEach(smt -> osmTypes.put(new JSONObject().put("id", smt.getId()))); + final JSONArray msmTypes = new JSONArray(); + module.getMandatoryModuleTypes().forEach(smt -> msmTypes.put(new JSONObject().put("id", smt.getId()))); - final JSONArray msmTypes = new JSONArray(); - module.getMandatoryModuleTypes().forEach(smt -> msmTypes.put(new JSONObject().put("id", smt.getId()))); - - builder.append(new JSONObject().put("name", module.getName()) - .put("description", module.getDescription()).put("id", Long.MAX_VALUE) - .put("key", module.getKey()).put("createdAt", "0").put("updatedAt", "0") - .put("createdBy", "fghdfkjghdfkjh").put("optionalmodules", osmTypes) - .put("mandatorymodules", msmTypes).put("updatedBy", "fghdfkjghdfkjh").toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) + .put("id", Long.MAX_VALUE).put("key", module.getKey()).put("createdAt", "0").put("updatedAt", "0") + .put("createdBy", "fghdfkjghdfkjh").put("optionalmodules", osmTypes) + .put("mandatorymodules", msmTypes).put("updatedBy", "fghdfkjghdfkjh").toString()); if (++i < types.size()) { builder.append(","); @@ -283,20 +312,15 @@ public abstract class JsonBuilder { int i = 0; for (final DistributionSetType module : types) { - try { + final JSONArray osmTypes = new JSONArray(); + module.getOptionalModuleTypes().forEach(smt -> osmTypes.put(new JSONObject().put("id", smt.getId()))); - final JSONArray osmTypes = new JSONArray(); - module.getOptionalModuleTypes().forEach(smt -> osmTypes.put(new JSONObject().put("id", smt.getId()))); + final JSONArray msmTypes = new JSONArray(); + module.getMandatoryModuleTypes().forEach(smt -> msmTypes.put(new JSONObject().put("id", smt.getId()))); - final JSONArray msmTypes = new JSONArray(); - module.getMandatoryModuleTypes().forEach(smt -> msmTypes.put(new JSONObject().put("id", smt.getId()))); - - builder.append(new JSONObject().put("name", module.getName()) - .put("description", module.getDescription()).put("key", module.getKey()) - .put("optionalmodules", osmTypes).put("mandatorymodules", msmTypes).toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("name", module.getName()).put("description", module.getDescription()) + .put("key", module.getKey()).put("optionalmodules", osmTypes).put("mandatorymodules", msmTypes) + .toString()); if (++i < types.size()) { builder.append(","); @@ -314,11 +338,7 @@ public abstract class JsonBuilder { builder.append("["); int i = 0; for (final DistributionSet set : sets) { - try { - builder.append(distributionSet(set)); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(distributionSet(set)); if (++i < sets.size()) { builder.append(","); @@ -337,12 +357,7 @@ public abstract class JsonBuilder { builder.append("["); int i = 0; for (final DistributionSet set : sets) { - try { - builder.append(distributionSetCreateValidFieldsOnly(set)); - } catch (final Exception e) { - e.printStackTrace(); - } - + builder.append(distributionSetCreateValidFieldsOnly(set)); if (++i < sets.size()) { builder.append(","); } @@ -356,15 +371,8 @@ public abstract class JsonBuilder { public static String distributionSetCreateValidFieldsOnly(final DistributionSet set) throws JSONException { - final List modules = set.getModules().stream().map(module -> { - try { - return new JSONObject().put("id", module.getId()); - } catch (final Exception e) { - e.printStackTrace(); - } - - return null; - }).collect(Collectors.toList()); + final List modules = set.getModules().stream() + .map(module -> new JSONObject().put("id", module.getId())).collect(Collectors.toList()); return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) .put("type", set.getType() == null ? null : set.getType().getKey()).put("version", set.getVersion()) @@ -374,15 +382,8 @@ public abstract class JsonBuilder { public static String distributionSetUpdateValidFieldsOnly(final DistributionSet set) throws JSONException { - final List modules = set.getModules().stream().map(module -> { - try { - return new JSONObject().put("id", module.getId()); - } catch (final Exception e) { - e.printStackTrace(); - } - - return null; - }).collect(Collectors.toList()); + final List modules = set.getModules().stream() + .map(module -> new JSONObject().put("id", module.getId())).collect(Collectors.toList()); return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) .put("version", set.getVersion()).put("requiredMigrationStep", set.isRequiredMigrationStep()) @@ -392,15 +393,8 @@ public abstract class JsonBuilder { public static String distributionSet(final DistributionSet set) throws JSONException { - final List modules = set.getModules().stream().map(module -> { - try { - return new JSONObject().put("id", module.getId()); - } catch (final Exception e) { - e.printStackTrace(); - } - - return null; - }).collect(Collectors.toList()); + final List modules = set.getModules().stream() + .map(module -> new JSONObject().put("id", module.getId())).collect(Collectors.toList()); return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) .put("type", set.getType() == null ? null : set.getType().getKey()).put("id", Long.MAX_VALUE) @@ -416,18 +410,14 @@ public abstract class JsonBuilder { builder.append("["); int i = 0; for (final Target target : targets) { - try { - final String address = target.getAddress() != null ? target.getAddress().toString() : null; + final String address = target.getAddress() != null ? target.getAddress().toString() : null; - final String token = withToken ? target.getSecurityToken() : null; + final String token = withToken ? target.getSecurityToken() : null; - builder.append(new JSONObject().put("controllerId", target.getControllerId()) - .put("description", target.getDescription()).put("name", target.getName()).put("createdAt", "0") - .put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh") - .put("address", address).put("securityToken", token).toString()); - } catch (final Exception e) { - e.printStackTrace(); - } + builder.append(new JSONObject().put("controllerId", target.getControllerId()) + .put("description", target.getDescription()).put("name", target.getName()).put("createdAt", "0") + .put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh") + .put("address", address).put("securityToken", token).toString()); if (++i < targets.size()) { builder.append(","); diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java index 652002d57..47165a26b 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/HawkbitSecurityProperties.java @@ -92,6 +92,11 @@ public class HawkbitSecurityProperties { */ private int maxAttributeEntriesPerTarget = 100; + /** + * Maximum number of allowed groups per Rollout. + */ + private int maxRolloutGroupsPerRollout = 500; + private final Filter filter = new Filter(); public Filter getFilter() { @@ -114,6 +119,14 @@ public class HawkbitSecurityProperties { this.maxAttributeEntriesPerTarget = maxAttributeEntriesPerTarget; } + public int getMaxRolloutGroupsPerRollout() { + return maxRolloutGroupsPerRollout; + } + + public void setMaxRolloutGroupsPerRollout(final int maxRolloutGroupsPerRollout) { + this.maxRolloutGroupsPerRollout = maxRolloutGroupsPerRollout; + } + /** * Configuration for hawkBits DOS prevention filter. This is usually an * infrastructure topic but might be useful in some cases. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java index e284d4523..7e1eb886f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/ErrorView.java @@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui; import org.eclipse.hawkbit.ui.menu.DashboardMenu; import org.eclipse.hawkbit.ui.menu.DashboardMenuItem; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.navigator.Navigator; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java index 0bd7142e1..4a0dce1ff 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTableHeader.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import org.eclipse.hawkbit.ui.SpPermissionChecker; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.RefreshSoftwareModuleByFilterEvent; +import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.table.AbstractSoftwareModuleTableHeader; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java index be292f017..b2e129b1d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterHeader.java @@ -15,11 +15,11 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import com.vaadin.ui.Button.ClickEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java index b1a645f58..5f8bf526e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterLayout.java @@ -16,8 +16,8 @@ import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterLayout; import org.eclipse.hawkbit.ui.dd.criteria.UploadViewClientCriterion; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java index 24fc5d826..ceba51cda 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java @@ -15,11 +15,11 @@ import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import com.vaadin.data.Item; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 36b060a22..7afbcb06b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -21,10 +21,10 @@ import org.eclipse.hawkbit.ui.common.ConfirmationDialog; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java index b74505789..a9c3f3edf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractMetadataPopupLayout.java @@ -71,6 +71,8 @@ public abstract class AbstractMetadataPopupLayout swMetadataList = softwareManagement - .findSoftwareModuleMetadataBySoftwareModuleId(selectedSWModuleId); + .findSoftwareModuleMetadataBySoftwareModuleId(selectedSWModuleId, + new PageRequest(0, MAX_METADATA_QUERY)) + .getContent(); if (null != swMetadataList && !swMetadataList.isEmpty()) { swMetadataList.forEach(this::setSWMetadataProperties); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/TargetFilterQueryDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/TargetFilterQueryDetailsTable.java index f28033e5c..edc633ed7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/TargetFilterQueryDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/TargetFilterQueryDetailsTable.java @@ -12,8 +12,8 @@ import java.util.List; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import com.vaadin.data.Container; import com.vaadin.data.Item; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java index c086798d6..3caba27b7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/filterlayout/AbstractFilterHeader.java @@ -12,8 +12,8 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java index 47aba63f5..ef91e6ca7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridHeader.java @@ -14,9 +14,9 @@ import org.eclipse.hawkbit.ui.components.SPUIButton; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import com.google.common.base.Strings; import com.vaadin.server.FontAwesome; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java index 15eb736cf..af5179802 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java @@ -18,10 +18,10 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.tokenfield.TokenField; @@ -50,6 +50,8 @@ public abstract class AbstractTagToken implements Serializ private static final String NAME_PROPERTY = "name"; private static final String COLOR_PROPERTY = "color"; + protected static final int MAX_TAG_QUERY = 500; + private static final long serialVersionUID = 6599386705285184783L; protected TokenField tokenField; @@ -77,8 +79,8 @@ public abstract class AbstractTagToken implements Serializ @SuppressWarnings("squid:S1948") protected T selectedEntity; - protected AbstractTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, final UINotification uinotification, - final UIEventBus eventBus, final ManagementUIState managementUIState) { + protected AbstractTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, + final UINotification uinotification, final UIEventBus eventBus, final ManagementUIState managementUIState) { this.checker = checker; this.i18n = i18n; this.uinotification = uinotification; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index b475c4345..3c8e54a62 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -11,14 +11,14 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import java.util.List; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.push.TargetTagCreatedEventContainer; import org.eclipse.hawkbit.ui.push.TargetTagDeletedEventContainer; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -57,8 +57,8 @@ public abstract class AbstractTargetTagToken extends Abstr } @EventBusListenerMethod(scope = EventScope.UI) - void onTargetTagUpdateEvent(final List events) { - events.stream().map(TargetTagUpdateEvent::getEntity).forEach(entity -> { + void onTargetTagUpdateEvent(final List events) { + events.stream().map(TargetTagUpdatedEvent::getEntity).forEach(entity -> { final Item item = container.getItem(entity.getId()); if (item != null) { updateItem(entity.getName(), entity.getColour(), item); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index e9aaceb04..0ee3a10c4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -24,8 +24,9 @@ import org.eclipse.hawkbit.ui.push.DistributionSetTagCreatedEventContainer; import org.eclipse.hawkbit.ui.push.DistributionSetTagDeletedEventContainer; import org.eclipse.hawkbit.ui.push.DistributionSetTagUpdatedEventContainer; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; +import org.springframework.data.domain.PageRequest; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; @@ -48,9 +49,9 @@ public class DistributionTagToken extends AbstractTagToken { // To Be Done : have to set this value based on view??? private static final Boolean NOTAGS_SELECTED = Boolean.FALSE; - public DistributionTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, final UINotification uinotification, - final UIEventBus eventBus, final ManagementUIState managementUIState, final TagManagement tagManagement, - final DistributionSetManagement distributionSetManagement) { + public DistributionTagToken(final SpPermissionChecker checker, final VaadinMessageSource i18n, + final UINotification uinotification, final UIEventBus eventBus, final ManagementUIState managementUIState, + final TagManagement tagManagement, final DistributionSetManagement distributionSetManagement) { super(checker, i18n, uinotification, eventBus, managementUIState); this.tagManagement = tagManagement; this.distributionSetManagement = distributionSetManagement; @@ -103,9 +104,9 @@ public class DistributionTagToken extends AbstractTagToken { public void displayAlreadyAssignedTags() { removePreviouslyAddedTokens(); if (selectedEntity != null) { - for (final DistributionSetTag tag : selectedEntity.getTags()) { - addNewToken(tag.getId()); - } + tagManagement + .findDistributionSetTagsByDistributionSet(new PageRequest(0, MAX_TAG_QUERY), selectedEntity.getId()) + .getContent().stream().forEach(tag -> addNewToken(tag.getId())); } } @@ -113,9 +114,9 @@ public class DistributionTagToken extends AbstractTagToken { protected void populateContainer() { container.removeAllItems(); tagDetails.clear(); - for (final DistributionSetTag tag : tagManagement.findAllDistributionSetTags()) { - setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour()); - } + tagManagement.findAllDistributionSetTags(new PageRequest(0, MAX_TAG_QUERY)).getContent().stream() + .forEach(tag -> setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour())); + } @EventBusListenerMethod(scope = EventScope.UI) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/DistributionSetInfoPanel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/DistributionSetInfoPanel.java index 9d13c599a..75e0c85d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/DistributionSetInfoPanel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/DistributionSetInfoPanel.java @@ -10,8 +10,8 @@ package org.eclipse.hawkbit.ui.components; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java index 0b6e3b5cc..6cfd4a2bd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/HawkbitUIErrorHandler.java @@ -14,8 +14,8 @@ import java.util.stream.Collectors; import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/NotificationUnreadButton.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/NotificationUnreadButton.java index 5c24fa697..b959077f4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/NotificationUnreadButton.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/NotificationUnreadButton.java @@ -12,9 +12,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.hawkbit.ui.push.EventContainer; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.event.FieldEvents.BlurEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java index 53cdacab0..d2bb19644 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java @@ -13,7 +13,6 @@ import java.net.URI; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPTargetAttributesLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPTargetAttributesLayout.java index a057cdb3d..7651d7b34 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPTargetAttributesLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/SPTargetAttributesLayout.java @@ -11,9 +11,9 @@ package org.eclipse.hawkbit.ui.components; import java.util.Map; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.Label; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/GridButtonRenderer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/GridButtonRenderer.java index 8cab5d3c9..8c567147c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/GridButtonRenderer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/customrenderers/renderers/GridButtonRenderer.java @@ -9,7 +9,9 @@ package org.eclipse.hawkbit.ui.customrenderers.renderers; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.FontIconData; + import com.vaadin.ui.renderers.ClickableRenderer; + import elemental.json.JsonValue; /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java index 715554858..a5cd76cd1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterHeader.java @@ -17,10 +17,10 @@ import org.eclipse.hawkbit.ui.common.CommonDialogWindow; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import com.vaadin.ui.Button.ClickEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java index 6364f80e8..a51795a25 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/DSTypeFilterLayout.java @@ -17,8 +17,8 @@ import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterLayout; import org.eclipse.hawkbit.ui.dd.criteria.DistributionsViewClientCriterion; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 4b5ee50ae..87663c900 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -19,7 +19,7 @@ import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.SpPermissionChecker; @@ -118,7 +118,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable events) { + private void handleSelectedAndUpdatedDs(final List events) { manageDistUIState.getLastSelectedDistribution() .ifPresent(lastSelectedDsIdName -> events.stream() .filter(event -> event.getEntityId().equals(lastSelectedDsIdName)).findAny() @@ -126,7 +126,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable events, + private void updateVisableTableEntries(final List events, final List visibleItemIds) { events.stream().filter(event -> visibleItemIds.contains(event.getEntityId())) .filter(event -> event.getEntity().isComplete()) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DsMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DsMetadataPopupLayout.java index 040ab9904..1ac45fb41 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DsMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DsMetadataPopupLayout.java @@ -18,8 +18,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.MetaData; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.AbstractMetadataPopupLayout; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; import org.vaadin.spring.events.EventBus.UIEventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index c436f3fb6..4e1b3173d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -185,7 +185,7 @@ public class DSDeleteActionsLayout extends AbstractDeleteActionsLayout { final AbstractTable table = (AbstractTable) sourceTable; final Set ids = table.getDeletedEntityByTransferable(transferable); final List findDistributionSetAllById = distributionSetManagement - .findDistributionSetAllById(ids); + .findDistributionSetsById(ids); if (findDistributionSetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("distributionsets.not.exists")); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java index 08a2e313c..a763eaf4b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java @@ -20,8 +20,9 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.AbstractMetadataPopupLayout; import org.eclipse.hawkbit.ui.distributions.event.MetadataEvent; import org.eclipse.hawkbit.ui.distributions.event.MetadataEvent.MetadataUIEvent; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; +import org.springframework.data.domain.PageRequest; import org.vaadin.spring.events.EventBus.UIEventBus; /** @@ -35,8 +36,8 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout getMetadataList() { - return Collections.unmodifiableList( - softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(getSelectedEntity().getId())); + return Collections.unmodifiableList(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId( + new PageRequest(0, MAX_METADATA_QUERY), getSelectedEntity().getId()).getContent()); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java index a3247bfe1..f8bcf055f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTableHeader.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.distributions.smtable; import org.eclipse.hawkbit.ui.SpPermissionChecker; -import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.RefreshSoftwareModuleByFilterEvent; +import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.smtable.SoftwareModuleAddUpdateWindow; import org.eclipse.hawkbit.ui.common.table.AbstractSoftwareModuleTableHeader; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java index d3d806d88..dfc1b19e9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterHeader.java @@ -16,11 +16,11 @@ import org.eclipse.hawkbit.ui.artifacts.smtype.CreateUpdateSoftwareTypeLayout; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import com.vaadin.ui.Button.ClickEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java index 45339f927..1ce7ed820 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterLayout.java @@ -16,8 +16,8 @@ import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterLayout; import org.eclipse.hawkbit.ui.dd.criteria.DistributionsViewClientCriterion; import org.eclipse.hawkbit.ui.distributions.event.DistributionsUIEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index b56c92cc9..daf644b44 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -22,11 +22,11 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java index a614946fb..0d232a332 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterTable.java @@ -19,12 +19,12 @@ import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; import org.eclipse.hawkbit.ui.utils.AssignInstalledDSTooltipGenerator; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.TableColumn; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java index d48d38baa..6b25a8812 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java @@ -24,10 +24,10 @@ import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTarget; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java index 91039d564..9fd4ac81e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectWindow.java @@ -21,9 +21,9 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleNoBorderWithIcon; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java index a815c0123..8f77c3882 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java @@ -21,9 +21,9 @@ import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.footer.TargetFilterCountMessageLabel; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java index aefef7d7b..10a5921ae 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java @@ -22,12 +22,12 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.TableColumn; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/footer/TargetFilterCountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/footer/TargetFilterCountMessageLabel.java index 374c136f2..2356a917a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/footer/TargetFilterCountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/footer/TargetFilterCountMessageLabel.java @@ -11,10 +11,10 @@ package org.eclipse.hawkbit.ui.filtermanagement.footer; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java index b315220a6..cdb5f2bca 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/AbstractCreateUpdateTagLayout.java @@ -76,6 +76,8 @@ public abstract class AbstractCreateUpdateTagLayout exten protected static final String TAG_DYNAMIC_STYLE = "tag-color-preview"; protected static final String MESSAGE_ERROR_MISSING_TAGNAME = "message.error.missing.tagname"; + protected static final int MAX_TAGS = 500; + protected VaadinMessageSource i18n; protected transient TagManagement tagManagement; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java index 0edb122b9..39a07ede2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/layouts/CreateUpdateTypeLayout.java @@ -19,10 +19,10 @@ import org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import com.vaadin.data.Property.ValueChangeEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/login/LoginView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/login/LoginView.java index 03330ef7e..28ce89671 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/login/LoginView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/login/LoginView.java @@ -18,8 +18,8 @@ import org.eclipse.hawkbit.im.authentication.MultitenancyIndicator; import org.eclipse.hawkbit.im.authentication.TenantUserPasswordAuthenticationToken; import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ProxyActionStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ProxyActionStatus.java index 1296cca23..a772c4fcd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ProxyActionStatus.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ProxyActionStatus.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.actionhistory; import java.io.Serializable; import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.ActionStatus; /** * Proxy for {@link ActionStatus} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index d9fc68fb6..ad3030dd9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -19,8 +19,9 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; @@ -49,6 +50,9 @@ import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.view.filter.OnlyEventsFromDeploymentViewFilter; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; @@ -83,7 +87,9 @@ public class DistributionTable extends AbstractNamedVersionTable events, + private static boolean allOfThemAffectCompletedSetsThatAreNotVisible(final List events, final List visibleItemIds) { return events.stream() .allMatch(event -> !visibleItemIds.contains(event.getEntityId()) && event.getEntity().isComplete()); } - private void updateVisableTableEntries(final List events, + private void updateVisableTableEntries(final List events, final List visibleItemIds) { events.stream().filter(event -> visibleItemIds.contains(event.getEntityId())) .filter(event -> event.getEntity().isComplete()) @@ -150,10 +157,10 @@ public class DistributionTable extends AbstractNamedVersionTable events, final List visibleItemIds) { + final List events, final List visibleItemIds) { final List setsThatAreVisibleButNotCompleteAnymore = events.stream() .filter(event -> visibleItemIds.contains(event.getEntityId())) - .filter(event -> !event.getEntity().isComplete()).map(DistributionSetUpdateEvent::getEntityId) + .filter(event -> !event.getEntity().isComplete()).map(DistributionSetUpdatedEvent::getEntityId) .collect(Collectors.toList()); if (!setsThatAreVisibleButNotCompleteAnymore.isEmpty()) { @@ -387,13 +394,25 @@ public class DistributionTable extends AbstractNamedVersionTable assignedTargets = targetManagement.findTargetsByTag(targetTagName); - if (!assignedTargets.isEmpty()) { - assignTargetToDs(getItem(distItemId), assignedTargets); - } else { - notification.displaySuccess( - i18n.getMessage("message.no.targets.assiged.fortag", new Object[] { targetTagName })); - } + + tagManagement.findTargetTag(targetTagName).ifPresent(tag -> { + Pageable query = new PageRequest(0, 500); + Page assignedTargets; + boolean assigned = false; + do { + assignedTargets = targetManagement.findTargetsByTag(query, tag.getId()); + + if (assignedTargets.hasContent()) { + assignTargetToDs(getItem(distItemId), assignedTargets.getContent()); + assigned = true; + } + } while (assignedTargets.hasNext() && (query = assignedTargets.nextPageable()) != null); + + if (assigned) { + notification.displaySuccess( + i18n.getMessage("message.no.targets.assiged.fortag", new Object[] { targetTagName })); + } + }); } private void assignTargetToDs(final DragAndDropEvent event) { @@ -404,7 +423,7 @@ public class DistributionTable extends AbstractNamedVersionTable distTagNameList = tagManagement.findAllDistributionSetTags(); + final List distTagNameList = tagManagement + .findAllDistributionSetTags(new PageRequest(0, MAX_TAGS)).getContent(); distTagNameList.forEach(value -> tagNameComboBox.addItem(value.getName())); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java index a192c3e82..313a1f279 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagHeader.java @@ -15,9 +15,9 @@ import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.components.RefreshableContainer; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import com.vaadin.ui.Button.ClickEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java index 41d269adc..de25ac940 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagLayout.java @@ -22,8 +22,8 @@ import org.eclipse.hawkbit.ui.management.event.DistributionSetTagTableEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.DistributionTableFilters; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ActionTypeOptionGroupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ActionTypeOptionGroupLayout.java index e6d3b85ee..8a09d97e6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ActionTypeOptionGroupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ActionTypeOptionGroupLayout.java @@ -14,9 +14,9 @@ import java.util.TimeZone; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroup; import org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroupItemComponent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java index a20f82323..0c9bdb6d8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java @@ -22,10 +22,10 @@ import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.TargetTableFilters; import org.eclipse.hawkbit.ui.management.targettable.TargetTable; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index f51bb60f7..c59f37cf6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -286,7 +286,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { } final List findDistributionSetAllById = distributionSetManagement - .findDistributionSetAllById(ids); + .findDistributionSetsById(ids); if (findDistributionSetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("distributionsets.not.exists")); @@ -345,7 +345,7 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout { private void addInDeleteTargetList(final Table sourceTable, final TableTransferable transferable) { final TargetTable targetTable = (TargetTable) sourceTable; final Set targetIdSet = targetTable.getDeletedEntityByTransferable(transferable); - final Collection findTargetAllById = targetManagement.findTargetAllById(targetIdSet); + final Collection findTargetAllById = targetManagement.findTargetsById(targetIdSet); if (findTargetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("targets.not.exists")); return; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index e9360ea86..8701200d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -41,8 +41,8 @@ import org.eclipse.hawkbit.ui.management.event.TargetTableEvent.TargetComponentE import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.management.state.TargetBulkUpload; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.vaadin.spring.events.EventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java index 91388451d..93cb91fc1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkTokenTags.java @@ -15,8 +15,8 @@ import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.tagdetails.AbstractTargetTagToken; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; import org.vaadin.spring.events.EventBus.UIEventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 60861db83..2cad6c5eb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -519,7 +519,7 @@ public class TargetTable extends AbstractTable { * @return TagAssigmentResult with all meta data of the assignment outcome. */ public TargetTagAssignmentResult toggleTagAssignment(final Collection targetIds, final String targTagName) { - final List controllerIds = targetManagement.findTargetAllById(targetIds).stream() + final List controllerIds = targetManagement.findTargetsById(targetIds).stream() .map(Target::getControllerId).collect(Collectors.toList()); if (controllerIds.isEmpty()) { notification.displayWarning(i18n.getMessage("targets.not.exists")); @@ -588,7 +588,7 @@ public class TargetTable extends AbstractTable { final TargetIdName createTargetIdName = new TargetIdName(target.get()); final List findDistributionSetAllById = distributionSetManagement - .findDistributionSetAllById(ids); + .findDistributionSetsById(ids); if (findDistributionSetAllById.isEmpty()) { notification.displayWarning(i18n.getMessage("distributionsets.not.exists")); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java index 62f9927a3..d629abdd8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayoutWindow.java @@ -23,8 +23,8 @@ import org.eclipse.hawkbit.ui.components.RefreshableContainer; import org.eclipse.hawkbit.ui.layouts.AbstractCreateUpdateTagLayout; import org.eclipse.hawkbit.ui.management.event.TargetTagTableEvent; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -36,8 +36,6 @@ public class CreateUpdateTargetTagLayoutWindow extends AbstractCreateUpdateTagLa private static final long serialVersionUID = 2446682350481560235L; - private static final int MAX_TAGS = 500; - /** * Constructor for CreateUpdateTargetTagLayoutWindow * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/FilterByStatusLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/FilterByStatusLayout.java index f8b045b30..a4d04f25e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/FilterByStatusLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/FilterByStatusLayout.java @@ -15,9 +15,9 @@ import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmall; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.TargetFilterEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/MultipleTargetFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/MultipleTargetFilter.java index 0ef0924ac..f86f197a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/MultipleTargetFilter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/MultipleTargetFilter.java @@ -16,10 +16,10 @@ import org.eclipse.hawkbit.ui.dd.criteria.ManagementViewClientCriterion; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java index 1ee33e3d7..8e7a128f4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterHeader.java @@ -12,8 +12,8 @@ import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterHeader; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import com.vaadin.ui.Button.ClickEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterLayout.java index fd14ca6f1..f7a29ccfa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterLayout.java @@ -17,8 +17,8 @@ import org.eclipse.hawkbit.ui.dd.criteria.ManagementViewClientCriterion; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.TargetTagTableEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java index bef95d4c8..5f590bf8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java @@ -26,8 +26,8 @@ import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; -import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; -import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutChangedEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangedEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationEvent; @@ -295,10 +295,10 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy, Applicati return; } - offerEventIfNotContains(new RolloutChangeEvent(event.getTenant(), rolloutId)); + offerEventIfNotContains(new RolloutChangedEvent(event.getTenant(), rolloutId)); if (rolloutGroupId != null) { - offerEventIfNotContains(new RolloutGroupChangeEvent(event.getTenant(), rolloutId, rolloutGroupId)); + offerEventIfNotContains(new RolloutGroupChangedEvent(event.getTenant(), rolloutId, rolloutGroupId)); } } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java index cb1bff010..564e858b3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java @@ -10,22 +10,22 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; /** - * EventHolder for {@link DistributionSetTagUpdateEvent}s. + * EventHolder for {@link DistributionSetTagUpdatedEvent}s. * */ -public class DistributionSetTagUpdatedEventContainer implements EventContainer { +public class DistributionSetTagUpdatedEventContainer implements EventContainer { private static final String I18N_UNREAD_NOTIFICATION_UNREAD_MESSAGE = "distribution.set.tag.updated.event.container.notifcation.message"; - private final List events; + private final List events; - DistributionSetTagUpdatedEventContainer(final List events) { + DistributionSetTagUpdatedEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java index 0482bdcaf..4885c74bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java @@ -10,21 +10,21 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; /** - * EventHolder for {@link DistributionSetUpdateEvent}s. + * EventHolder for {@link DistributionSetUpdatedEvent}s. * */ -public class DistributionSetUpdatedEventContainer implements EventContainer { - private final List events; +public class DistributionSetUpdatedEventContainer implements EventContainer { + private final List events; - DistributionSetUpdatedEventContainer(final List events) { + DistributionSetUpdatedEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java index 10c543c78..ebd60a18e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java @@ -20,16 +20,16 @@ import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; -import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; -import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutChangedEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangedEvent; import com.google.common.collect.Maps; @@ -44,23 +44,23 @@ public class HawkbitEventProvider implements UIEventProvider { EVENTS.put(TargetTagDeletedEvent.class, TargetTagDeletedEventContainer.class); EVENTS.put(TargetTagCreatedEvent.class, TargetTagCreatedEventContainer.class); - EVENTS.put(TargetTagUpdateEvent.class, TargetTagUpdatedEventContainer.class); + EVENTS.put(TargetTagUpdatedEvent.class, TargetTagUpdatedEventContainer.class); EVENTS.put(DistributionSetTagCreatedEvent.class, DistributionSetTagCreatedEventContainer.class); EVENTS.put(DistributionSetTagDeletedEvent.class, DistributionSetTagDeletedEventContainer.class); - EVENTS.put(DistributionSetTagUpdateEvent.class, DistributionSetTagUpdatedEventContainer.class); + EVENTS.put(DistributionSetTagUpdatedEvent.class, DistributionSetTagUpdatedEventContainer.class); EVENTS.put(TargetCreatedEvent.class, TargetCreatedEventContainer.class); EVENTS.put(TargetDeletedEvent.class, TargetDeletedEventContainer.class); EVENTS.put(TargetUpdatedEvent.class, TargetUpdatedEventContainer.class); EVENTS.put(CancelTargetAssignmentEvent.class, CancelTargetAssignmentEventContainer.class); - EVENTS.put(DistributionSetUpdateEvent.class, DistributionSetUpdatedEventContainer.class); + EVENTS.put(DistributionSetUpdatedEvent.class, DistributionSetUpdatedEventContainer.class); EVENTS.put(DistributionSetDeletedEvent.class, DistributionDeletedEventContainer.class); EVENTS.put(DistributionSetCreatedEvent.class, DistributionCreatedEventContainer.class); - EVENTS.put(RolloutGroupChangeEvent.class, RolloutGroupChangeEventContainer.class); - EVENTS.put(RolloutChangeEvent.class, RolloutChangeEventContainer.class); + EVENTS.put(RolloutGroupChangedEvent.class, RolloutGroupChangedEventContainer.class); + EVENTS.put(RolloutChangedEvent.class, RolloutChangeEventContainer.class); EVENTS.put(RolloutDeletedEvent.class, RolloutDeletedEventContainer.class); EVENTS.put(SoftwareModuleCreatedEvent.class, SoftwareModuleCreatedEventContainer.class); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java index 6dea3fa15..81d62c183 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java @@ -10,21 +10,21 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutChangedEvent; /** - * EventHolder for {@link RolloutChangeEvent}s. + * EventHolder for {@link RolloutChangedEvent}s. * */ -public class RolloutChangeEventContainer implements EventContainer { - private final List events; +public class RolloutChangeEventContainer implements EventContainer { + private final List events; - RolloutChangeEventContainer(final List events) { + RolloutChangeEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangedEventContainer.java similarity index 53% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangedEventContainer.java index c3d9688e1..0a41a1a93 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangedEventContainer.java @@ -10,21 +10,21 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangedEvent; /** - * EventHolder for {@link RolloutGroupChangeEvent}s. + * EventHolder for {@link RolloutGroupChangedEvent}s. * */ -public class RolloutGroupChangeEventContainer implements EventContainer { - private final List events; +public class RolloutGroupChangedEventContainer implements EventContainer { + private final List events; - RolloutGroupChangeEventContainer(final List events) { + RolloutGroupChangedEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java index b11e739b4..032b049af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java @@ -10,22 +10,22 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent; /** - * EventHolder for {@link TargetTagUpdateEvent}s. + * EventHolder for {@link TargetTagUpdatedEvent}s. * */ -public class TargetTagUpdatedEventContainer implements EventContainer { +public class TargetTagUpdatedEventContainer implements EventContainer { private static final String I18N_UNREAD_NOTIFICATION_UNREAD_MESSAGE = "target.tag.updated.event.container.notifcation.message"; - private final List events; + private final List events; - TargetTagUpdatedEventContainer(final List events) { + TargetTagUpdatedEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangedEvent.java similarity index 89% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangedEvent.java index c97747dcc..6c7e4d672 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangedEvent.java @@ -13,7 +13,7 @@ package org.eclipse.hawkbit.ui.push.event; * been changed. * */ -public class RolloutChangeEvent extends TenantAwareUiEvent { +public class RolloutChangedEvent extends TenantAwareUiEvent { private final Long rolloutId; @@ -25,7 +25,7 @@ public class RolloutChangeEvent extends TenantAwareUiEvent { * @param rolloutId * the ID of the rollout which has been changed */ - public RolloutChangeEvent(final String tenant, final Long rolloutId) { + public RolloutChangedEvent(final String tenant, final Long rolloutId) { super(tenant); this.rolloutId = rolloutId; } @@ -58,7 +58,7 @@ public class RolloutChangeEvent extends TenantAwareUiEvent { if (getClass() != obj.getClass()) { return false; } - final RolloutChangeEvent other = (RolloutChangeEvent) obj; + final RolloutChangedEvent other = (RolloutChangedEvent) obj; if (rolloutId == null) { if (other.rolloutId != null) { return false; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangedEvent.java similarity index 90% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangedEvent.java index 27748481b..a582a5f00 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangedEvent.java @@ -14,7 +14,7 @@ package org.eclipse.hawkbit.ui.push.event; * * */ -public class RolloutGroupChangeEvent extends TenantAwareUiEvent { +public class RolloutGroupChangedEvent extends TenantAwareUiEvent { private final Long rolloutId; private final Long rolloutGroupId; @@ -29,7 +29,7 @@ public class RolloutGroupChangeEvent extends TenantAwareUiEvent { * @param rolloutGroupId * the ID of the rollout group which has been changed */ - public RolloutGroupChangeEvent(final String tenant, final Long rolloutId, final Long rolloutGroupId) { + public RolloutGroupChangedEvent(final String tenant, final Long rolloutId, final Long rolloutGroupId) { super(tenant); this.rolloutId = rolloutId; this.rolloutGroupId = rolloutGroupId; @@ -69,7 +69,7 @@ public class RolloutGroupChangeEvent extends TenantAwareUiEvent { if (getClass() != obj.getClass()) { return false; } - final RolloutGroupChangeEvent other = (RolloutGroupChangeEvent) obj; + final RolloutGroupChangedEvent other = (RolloutGroupChangedEvent) obj; if (rolloutGroupId == null) { if (other.rolloutGroupId != null) { return false; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java index 89ec9614e..07a03c565 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/RolloutView.java @@ -14,6 +14,7 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; @@ -27,8 +28,8 @@ import org.eclipse.hawkbit.ui.rollout.rollout.RolloutListView; import org.eclipse.hawkbit.ui.rollout.rolloutgroup.RolloutGroupsListView; import org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets.RolloutGroupTargetsListView; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -71,11 +72,13 @@ public class RolloutView extends VerticalLayout implements View { final UIEventBus eventBus, final RolloutManagement rolloutManagement, final RolloutGroupManagement rolloutGroupManagement, final TargetManagement targetManagement, final UINotification uiNotification, final UiProperties uiProperties, final EntityFactory entityFactory, - final VaadinMessageSource i18n, final TargetFilterQueryManagement targetFilterQueryManagement) { + final VaadinMessageSource i18n, final TargetFilterQueryManagement targetFilterQueryManagement, + final QuotaManagement quotaManagement) { this.permChecker = permissionChecker; this.rolloutManagement = rolloutManagement; this.rolloutListView = new RolloutListView(permissionChecker, rolloutUIState, eventBus, rolloutManagement, - targetManagement, uiNotification, uiProperties, entityFactory, i18n, targetFilterQueryManagement); + targetManagement, uiNotification, uiProperties, entityFactory, i18n, targetFilterQueryManagement, + rolloutGroupManagement, quotaManagement); this.rolloutGroupsListView = new RolloutGroupsListView(i18n, eventBus, rolloutGroupManagement, rolloutUIState, permissionChecker); this.rolloutGroupTargetsListView = new RolloutGroupTargetsListView(eventBus, i18n, rolloutUIState); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/groupschart/client/GroupsPieChartWidget.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/groupschart/client/GroupsPieChartWidget.java index 175ce0aa6..58b1b5a59 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/groupschart/client/GroupsPieChartWidget.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/groupschart/client/GroupsPieChartWidget.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.ui.rollout.groupschart.client; +import java.util.List; + import com.github.gwtd3.api.D3; import com.github.gwtd3.api.arrays.Array; import com.github.gwtd3.api.core.Selection; @@ -20,8 +22,6 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style; import com.google.gwt.user.client.ui.DockLayoutPanel; -import java.util.List; - /** * Draws a pie chart using D3. The slices are based on the list of Longs and on * the total target count. The total target count represents 100% of the pie. If diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index 5c68c2e44..617792c89 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -17,6 +17,8 @@ import java.util.Optional; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; @@ -105,6 +107,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { private final transient RolloutManagement rolloutManagement; + private final transient RolloutGroupManagement rolloutGroupManagement; + + private final transient QuotaManagement quotaManagement; + private final transient TargetManagement targetManagement; private final transient TargetFilterQueryManagement targetFilterQueryManagement; @@ -162,10 +168,13 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { AddUpdateRolloutWindowLayout(final RolloutManagement rolloutManagement, final TargetManagement targetManagement, final UINotification uiNotification, final UiProperties uiProperties, final EntityFactory entityFactory, final VaadinMessageSource i18n, final UIEventBus eventBus, - final TargetFilterQueryManagement targetFilterQueryManagement) { + final TargetFilterQueryManagement targetFilterQueryManagement, + final RolloutGroupManagement rolloutGroupManagement, final QuotaManagement quotaManagement) { actionTypeOptionGroupLayout = new ActionTypeOptionGroupLayout(i18n); autoStartOptionGroupLayout = new AutoStartOptionGroupLayout(i18n); this.rolloutManagement = rolloutManagement; + this.rolloutGroupManagement = rolloutGroupManagement; + this.quotaManagement = quotaManagement; this.targetManagement = targetManagement; this.uiNotification = uiNotification; this.uiProperties = uiProperties; @@ -174,8 +183,8 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { this.eventBus = eventBus; this.targetFilterQueryManagement = targetFilterQueryManagement; - defineGroupsLayout = new DefineGroupsLayout(i18n, entityFactory, rolloutManagement, - targetFilterQueryManagement); + defineGroupsLayout = new DefineGroupsLayout(i18n, entityFactory, rolloutManagement, targetFilterQueryManagement, + rolloutGroupManagement, quotaManagement); defaultRolloutGroupConditions = new RolloutGroupConditionBuilder().withDefaults().build(); @@ -927,7 +936,10 @@ public class AddUpdateRolloutWindowLayout extends GridLayout { window.updateAllComponents(this); window.setOrginaleValues(); - updateGroupsChart(rollout.getRolloutGroups(), rollout.getTotalTargets()); + updateGroupsChart( + rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), + new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout())).getContent(), + rollout.getTotalTargets()); } totalTargetsCount = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AutoStartOptionGroupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AutoStartOptionGroupLayout.java index f9587d48a..4aee13ed0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AutoStartOptionGroupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AutoStartOptionGroupLayout.java @@ -13,9 +13,9 @@ import java.util.Date; import java.util.TimeZone; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroup; import org.vaadin.hene.flexibleoptiongroup.FlexibleOptionGroupItemComponent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java index 9c1385aa4..ca53979a1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DefineGroupsLayout.java @@ -15,6 +15,8 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.builder.RolloutGroupCreate; @@ -75,6 +77,10 @@ public class DefineGroupsLayout extends GridLayout { private transient RolloutManagement rolloutManagement; + private transient RolloutGroupManagement rolloutGroupManagement; + + private final transient QuotaManagement quotaManagement; + private transient TargetFilterQueryManagement targetFilterQueryManagement; private String defaultTriggerThreshold; @@ -98,10 +104,13 @@ public class DefineGroupsLayout extends GridLayout { private final AtomicInteger runningValidationsCounter; DefineGroupsLayout(final VaadinMessageSource i18n, final EntityFactory entityFactory, - final RolloutManagement rolloutManagement, final TargetFilterQueryManagement targetFilterQueryManagement) { + final RolloutManagement rolloutManagement, final TargetFilterQueryManagement targetFilterQueryManagement, + final RolloutGroupManagement rolloutGroupManagement, final QuotaManagement quotaManagement) { this.i18n = i18n; this.entityFactory = entityFactory; this.rolloutManagement = rolloutManagement; + this.rolloutGroupManagement = rolloutGroupManagement; + this.quotaManagement = quotaManagement; this.targetFilterQueryManagement = targetFilterQueryManagement; runningValidationsCounter = new AtomicInteger(0); @@ -229,7 +238,8 @@ public class DefineGroupsLayout extends GridLayout { removeAllRows(); - final List groups = rollout.getRolloutGroups(); + final List groups = rolloutGroupManagement.findRolloutGroupsByRolloutId(rollout.getId(), + new PageRequest(0, quotaManagement.getMaxRolloutGroupsPerRollout())).getContent(); for (final RolloutGroup group : groups) { final GroupRow groupRow = addGroupRow(); groupRow.populateByGroup(group); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 4fd5348a1..43062b73c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -19,6 +19,8 @@ import java.util.Map; import java.util.Optional; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; @@ -37,7 +39,7 @@ import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.push.RolloutChangeEventContainer; import org.eclipse.hawkbit.ui.push.RolloutDeletedEventContainer; -import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutChangedEvent; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; @@ -84,6 +86,7 @@ public class RolloutListGrid extends AbstractGrid { private static final String ROLLOUT_RENDERER_DATA = "rolloutRendererData"; private final transient RolloutManagement rolloutManagement; + private final transient RolloutGroupManagement rolloutGroupManagement; private final AddUpdateRolloutWindowLayout addUpdateRolloutWindow; @@ -121,11 +124,14 @@ public class RolloutListGrid extends AbstractGrid { final RolloutManagement rolloutManagement, final UINotification uiNotification, final RolloutUIState rolloutUIState, final SpPermissionChecker permissionChecker, final TargetManagement targetManagement, final EntityFactory entityFactory, final UiProperties uiProperties, - final TargetFilterQueryManagement targetFilterQueryManagement) { + final TargetFilterQueryManagement targetFilterQueryManagement, + final RolloutGroupManagement rolloutGroupManagement, final QuotaManagement quotaManagement) { super(i18n, eventBus, permissionChecker); this.rolloutManagement = rolloutManagement; + this.rolloutGroupManagement = rolloutGroupManagement; this.addUpdateRolloutWindow = new AddUpdateRolloutWindowLayout(rolloutManagement, targetManagement, - uiNotification, uiProperties, entityFactory, i18n, eventBus, targetFilterQueryManagement); + uiNotification, uiProperties, entityFactory, i18n, eventBus, targetFilterQueryManagement, + rolloutGroupManagement, quotaManagement); this.uiNotification = uiNotification; this.rolloutUIState = rolloutUIState; @@ -172,7 +178,7 @@ public class RolloutListGrid extends AbstractGrid { eventContainer.getEvents().forEach(this::handleEvent); } - private void handleEvent(final RolloutChangeEvent rolloutChangeEvent) { + private void handleEvent(final RolloutChangedEvent rolloutChangeEvent) { if (!rolloutUIState.isShowRollOuts() || rolloutChangeEvent.getRolloutId() == null) { return; } @@ -196,16 +202,21 @@ public class RolloutListGrid extends AbstractGrid { final TotalTargetCountStatus totalTargetCountStatus = rollout.getTotalTargetCountStatus(); item.getItemProperty(SPUILabelDefinitions.VAR_STATUS).setValue(rollout.getStatus()); item.getItemProperty(SPUILabelDefinitions.VAR_TOTAL_TARGETS_COUNT_STATUS).setValue(totalTargetCountStatus); - final Integer groupCount = (Integer) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue(); + final Long groupCount = Long + .valueOf((Integer) item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).getValue()); final int groupsCreated = rollout.getRolloutGroupsCreated(); - if (groupsCreated != 0) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Integer.valueOf(groupsCreated)); - } else if (rollout.getRolloutGroups() != null && !groupCount.equals(rollout.getRolloutGroups().size())) { - item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS) - .setValue(Integer.valueOf(rollout.getRolloutGroups().size())); - } item.getItemProperty(ROLLOUT_RENDERER_DATA) .setValue(new RolloutRendererData(rollout.getName(), rollout.getStatus().toString())); + + if (groupsCreated != 0) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(Integer.valueOf(groupsCreated)); + return; + } + + final Long size = rolloutGroupManagement.countTargetsOfRolloutsGroup(rollout.getId()); + if (!size.equals(groupCount)) { + item.getItemProperty(SPUILabelDefinitions.VAR_NUMBER_OF_GROUPS).setValue(size.intValue()); + } } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java index 6837862fb..b469f89e2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListHeader.java @@ -9,6 +9,8 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; @@ -18,10 +20,10 @@ import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; import org.eclipse.hawkbit.ui.common.grid.AbstractGridHeader; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -45,11 +47,13 @@ public class RolloutListHeader extends AbstractGridHeader { final UIEventBus eventBus, final RolloutManagement rolloutManagement, final TargetManagement targetManagement, final UINotification uiNotification, final UiProperties uiProperties, final EntityFactory entityFactory, final VaadinMessageSource i18n, - final TargetFilterQueryManagement targetFilterQueryManagement) { + final TargetFilterQueryManagement targetFilterQueryManagement, + final RolloutGroupManagement rolloutGroupManagement, final QuotaManagement quotaManagement) { super(permissionChecker, rolloutUIState, i18n); this.eventBus = eventBus; this.addUpdateRolloutWindow = new AddUpdateRolloutWindowLayout(rolloutManagement, targetManagement, - uiNotification, uiProperties, entityFactory, i18n, eventBus, targetFilterQueryManagement); + uiNotification, uiProperties, entityFactory, i18n, eventBus, targetFilterQueryManagement, + rolloutGroupManagement, quotaManagement); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java index b61b8561a..85327b1eb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListView.java @@ -9,6 +9,8 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.QuotaManagement; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; @@ -17,8 +19,8 @@ import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.common.grid.AbstractGridComponentLayout; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.spring.events.EventBus.UIEventBus; @@ -31,25 +33,29 @@ public class RolloutListView extends AbstractGridComponentLayout { private static final long serialVersionUID = -2703552177439393208L; private final transient RolloutManagement rolloutManagement; + private final transient RolloutGroupManagement rolloutGroupManagement; private final transient TargetManagement targetManagement; private final transient EntityFactory entityFactory; private final transient TargetFilterQueryManagement targetFilterQueryManagement; + private final transient QuotaManagement quotaManagement; private final SpPermissionChecker permissionChecker; private final RolloutUIState rolloutUIState; private final UINotification uiNotification; private final UiProperties uiProperties; - public RolloutListView(final SpPermissionChecker permissionChecker, final RolloutUIState rolloutUIState, final UIEventBus eventBus, final RolloutManagement rolloutManagement, final TargetManagement targetManagement, final UINotification uiNotification, final UiProperties uiProperties, final EntityFactory entityFactory, final VaadinMessageSource i18n, - final TargetFilterQueryManagement targetFilterQueryManagement) { + final TargetFilterQueryManagement targetFilterQueryManagement, + final RolloutGroupManagement rolloutGroupManagement, final QuotaManagement quotaManagement) { super(i18n, eventBus); this.permissionChecker = permissionChecker; this.rolloutUIState = rolloutUIState; this.rolloutManagement = rolloutManagement; + this.rolloutGroupManagement = rolloutGroupManagement; + this.quotaManagement = quotaManagement; this.targetManagement = targetManagement; this.uiNotification = uiNotification; this.uiProperties = uiProperties; @@ -62,13 +68,15 @@ public class RolloutListView extends AbstractGridComponentLayout { @Override public AbstractOrderedLayout createGridHeader() { return new RolloutListHeader(permissionChecker, rolloutUIState, eventBus, rolloutManagement, targetManagement, - uiNotification, uiProperties, entityFactory, i18n, targetFilterQueryManagement); + uiNotification, uiProperties, entityFactory, i18n, targetFilterQueryManagement, rolloutGroupManagement, + quotaManagement); } @Override public AbstractGrid createGrid() { return new RolloutListGrid(i18n, eventBus, rolloutManagement, uiNotification, rolloutUIState, permissionChecker, - targetManagement, entityFactory, uiProperties, targetFilterQueryManagement); + targetManagement, entityFactory, uiProperties, targetFilterQueryManagement, rolloutGroupManagement, + quotaManagement); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index 7bfaf6349..f6d5e1322 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -25,17 +25,17 @@ import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; -import org.eclipse.hawkbit.ui.push.RolloutGroupChangeEventContainer; +import org.eclipse.hawkbit.ui.push.RolloutGroupChangedEventContainer; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; @@ -43,7 +43,6 @@ import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; -import com.vaadin.data.Container; import com.vaadin.data.util.converter.Converter; import com.vaadin.server.FontAwesome; import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent; @@ -125,7 +124,7 @@ public class RolloutGroupListGrid extends AbstractGrid { * change */ @EventBusListenerMethod(scope = EventScope.UI) - public void onRolloutGroupChangeEvent(final RolloutGroupChangeEventContainer eventContainer) { + public void onRolloutGroupChangeEvent(final RolloutGroupChangedEventContainer eventContainer) { if (!rolloutUIState.isShowRolloutGroups()) { return; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java index d77d1c393..05457cfdb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListHeader.java @@ -14,8 +14,8 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java index 37f637630..6e9b0c717 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupsListView.java @@ -17,8 +17,6 @@ import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.spring.events.EventBus.UIEventBus; -import com.vaadin.ui.Label; - /** * Groups List View. */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java index bebd2d039..c420c52f6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java @@ -11,10 +11,10 @@ package org.eclipse.hawkbit.ui.rollout.rolloutgrouptargets; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java index f70594e25..f6a1d5114 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListGrid.java @@ -23,11 +23,11 @@ import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition; @@ -35,7 +35,6 @@ import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; -import com.vaadin.data.Container; import com.vaadin.data.util.converter.Converter; import com.vaadin.server.FontAwesome; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java index b5de515d7..45f3c4cca 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsListHeader.java @@ -15,8 +15,8 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; import org.eclipse.hawkbit.ui.rollout.state.RolloutUIState; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventScope; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java index 94b374e73..6add8fa05 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/AuthenticationConfigurationView.java @@ -16,8 +16,8 @@ import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.AuthenticationC import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.CertificateAuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.GatewaySecurityTokenAuthenticationConfigurationItem; import org.eclipse.hawkbit.ui.tenantconfiguration.authentication.TargetSecurityTokenAuthenticationConfigurationItem; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java index 3232b6909..44d5dad94 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java @@ -14,8 +14,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java index 144edbd26..f6ed2850f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java @@ -16,8 +16,8 @@ import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey; import org.eclipse.hawkbit.ui.tenantconfiguration.polling.DurationConfigField; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java index 3a55c2bff..3f10d6a01 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/TenantConfigurationDashboardView.java @@ -25,9 +25,9 @@ import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.tenantconfiguration.ConfigurationItem.ConfigurationItemChangeListener; -import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.UINotification; +import org.eclipse.hawkbit.ui.utils.VaadinMessageSource; import org.springframework.beans.factory.annotation.Autowired; import com.google.common.collect.Lists;