From 889d1492fbae6fbb7455438329d8632cf35b5342 Mon Sep 17 00:00:00 2001
From: Kai Zimmermann
Date: Wed, 11 Jan 2017 14:32:55 +0100
Subject: [PATCH] Repository API query signatures Entity free (#403)
* Migrated target management queries to IDs inetsead of full entities
Signed-off-by: kaizimmerm
* Added missing comment.
Signed-off-by: kaizimmerm
* refactored target,DS,cont,deploy,rg mangement.
Signed-off-by: kaizimmerm
* Adde versioning documentation.
Signed-off-by: kaizimmerm
* Rollout, Dist and Software mgmt refactored
Signed-off-by: kaizimmerm
* Readded line that was remove by incident.
Signed-off-by: kaizimmerm
* Fixed broken tests.
Signed-off-by: kaizimmerm
* Query management refactored
Signed-off-by: kaizimmerm
* Fix bug of auto assign DS delete
Signed-off-by: kaizimmerm
* Switch to collection
Signed-off-by: kaizimmerm
* Fixed compile error
Signed-off-by: kaizimmerm
* Small glitches
Signed-off-by: kaizimmerm
* Fixed test after merge
Signed-off-by: kaizimmerm
---
README.md | 6 +
hawkbit-ddi-api/README.md | 6 +-
hawkbit-ddi-dl-api/README.md | 6 +-
.../resource/DdiArtifactStoreController.java | 2 +-
.../ddi/rest/resource/DdiRootController.java | 13 +-
.../resource/DdiArtifactDownloadTest.java | 10 +-
.../rest/resource/DdiCancelActionTest.java | 72 +++----
.../rest/resource/DdiDeploymentBaseTest.java | 113 ++++++-----
.../rest/resource/DdiRootControllerTest.java | 6 +-
.../ddi/rest/resource/DosFilterTest.java | 4 +-
.../AmqpAuthenticationMessageHandler.java | 37 ++--
.../amqp/AmqpMessageHandlerService.java | 5 +-
.../AmqpControllerAuthenticationTest.java | 10 +-
.../amqp/AmqpMessageHandlerServiceTest.java | 17 +-
hawkbit-dmf-api/README.md | 10 +-
hawkbit-mgmt-api/README.md | 5 +-
.../resource/MgmtDistributionSetResource.java | 23 +--
.../MgmtDistributionSetTagResource.java | 14 +-
.../MgmtDistributionSetTypeResource.java | 3 +-
.../MgmtDownloadArtifactResource.java | 2 +-
.../rest/resource/MgmtRolloutResource.java | 8 +-
.../MgmtSoftwareModuleTypeResource.java | 5 +-
.../rest/resource/MgmtTargetResource.java | 30 +--
.../rest/resource/MgmtTargetTagResource.java | 16 +-
.../MgmtSoftwareModuleResourceTest.java | 6 +-
.../rest/resource/MgmtTargetResourceTest.java | 21 +-
.../repository/ArtifactManagement.java | 11 +-
.../repository/ControllerManagement.java | 64 ++----
.../repository/DeploymentManagement.java | 151 +++-----------
.../repository/DistributionSetManagement.java | 65 +++---
.../repository/RolloutGroupManagement.java | 16 +-
.../hawkbit/repository/RolloutManagement.java | 7 +-
.../repository/SoftwareManagement.java | 23 +--
.../TargetFilterQueryManagement.java | 36 ++--
.../hawkbit/repository/TargetManagement.java | 138 +++++++------
.../repository/jpa/ActionRepository.java | 26 +--
.../jpa/ActionStatusRepository.java | 8 +-
.../jpa/DistributionSetRepository.java | 14 +-
.../repository/jpa/JpaArtifactManagement.java | 24 ++-
.../jpa/JpaControllerManagement.java | 52 ++---
.../jpa/JpaDeploymentManagement.java | 145 ++++----------
.../jpa/JpaDistributionSetManagement.java | 123 ++++++------
.../jpa/JpaRolloutGroupManagement.java | 27 ++-
.../repository/jpa/JpaRolloutManagement.java | 62 +++++-
.../repository/jpa/JpaSoftwareManagement.java | 24 +--
.../repository/jpa/JpaTagManagement.java | 2 +-
.../jpa/JpaTargetFilterQueryManagement.java | 46 ++---
.../repository/jpa/JpaTargetManagement.java | 108 +++++-----
.../RepositoryApplicationConfiguration.java | 16 +-
.../hawkbit/repository/jpa/RolloutHelper.java | 4 +-
.../jpa/SoftwareModuleRepository.java | 8 +-
.../repository/jpa/TargetRepository.java | 12 +-
.../jpa/autoassign/AutoAssignChecker.java | 30 +--
.../specifications/ActionSpecifications.java | 7 +-
.../specifications/TargetSpecifications.java | 40 ++--
.../jpa/AbstractJpaIntegrationTest.java | 24 ++-
.../jpa/ArtifactManagementTest.java | 4 +-
.../jpa/ControllerManagementTest.java | 13 +-
.../jpa/DeploymentManagementTest.java | 86 ++++----
.../jpa/DistributionSetManagementTest.java | 15 +-
.../repository/jpa/ReportManagementTest.java | 6 +-
.../repository/jpa/RolloutManagementTest.java | 36 ++--
.../jpa/SoftwareManagementTest.java | 8 +-
.../repository/jpa/TagManagementTest.java | 40 ++--
.../jpa/TargetFilterQueryManagementTest.java | 10 +-
.../jpa/TargetManagementSearchTest.java | 189 ++++++------------
.../repository/jpa/TargetManagementTest.java | 90 ++++-----
.../jpa/autoassign/AutoAssignCheckerTest.java | 2 +-
.../jpa/event/RepositoryEntityEventTest.java | 4 +-
.../model/EntityInterceptorListenerTest.java | 2 +-
.../jpa/rsql/RSQLActionFieldsTest.java | 4 +-
.../rsql/RSQLDistributionSetFieldTest.java | 2 +-
.../jpa/rsql/RSQLTargetFieldTest.java | 3 +-
.../jpa/tenancy/MultiTenancyEntityTest.java | 10 +-
.../test/util/AbstractIntegrationTest.java | 2 +-
.../repository/test/util/TestdataFactory.java | 10 +-
.../UploadViewConfirmationWindowLayout.java | 4 +-
.../SoftwareModuleAddUpdateWindow.java | 2 +-
.../state/SoftwareModuleFilters.java | 4 +-
.../SoftwareModuleDetailsTable.java | 2 +-
.../CreateUpdateDistSetTypeLayout.java | 4 +-
.../dstable/DistributionSetTable.java | 2 +-
...DistributionsConfirmationWindowLayout.java | 10 +-
.../state/ManageDistFilters.java | 2 +-
.../state/ManageSoftwareModuleFilters.java | 4 +-
.../DistributionSetSelectWindow.java | 2 +-
.../state/FilterManagementUIState.java | 4 +-
.../actionhistory/ActionHistoryTable.java | 12 +-
.../ManangementConfirmationWindowLayout.java | 10 +-
.../state/DistributionTableFilters.java | 6 +-
.../management/state/TargetTableFilters.java | 21 +-
.../targettable/TargetBeanQuery.java | 4 +-
.../CustomTargetTagFilterButtonClick.java | 2 +-
.../targettag/TargetFilterQueryButtons.java | 3 +-
.../rolloutgroup/RolloutGroupBeanQuery.java | 2 +-
.../RolloutGroupTargetsBeanQuery.java | 6 +-
.../ui/rollout/state/RolloutUIState.java | 10 +-
97 files changed, 1126 insertions(+), 1289 deletions(-)
diff --git a/README.md b/README.md
index 2d97de456..c5e74c706 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,12 @@ https://hawkbit.eu-gb.mybluemix.net/UI/
We are not providing an off the shelf installation ready hawkBit update server. However, we recommend to check out the [Example Application](examples/hawkbit-example-app) for a runtime ready Spring Boot based update server that is empowered by hawkBit. In addition we have [guide](https://github.com/eclipse/hawkbit/wiki/Run-hawkBit) for setting up a complete landscape.
+# API stability
+
+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-api) are on major version 'v1' and will be kept stable.
+
# hawkBit (Spring boot) starters
Next to the [Example Application](examples/hawkbit-example-app) we are also providing a set of [Spring Boot Starters](hawkbit-starters) to quick start your own [Spring Boot](https://projects.spring.io/spring-boot/) based application.
diff --git a/hawkbit-ddi-api/README.md b/hawkbit-ddi-api/README.md
index b47b74895..3f2aa1fbb 100644
--- a/hawkbit-ddi-api/README.md
+++ b/hawkbit-ddi-api/README.md
@@ -1,7 +1,11 @@
-# Eclipse.IoT hawkBit - DDI API
+# Eclipse.IoT hawkBit - Direct Device Integration API - Model and Resources
The Direct Device Integration (DDI) API is used by devices for communicating with the HawkBit Update Server through HTTP.
+# Version 1
+
+The model follows [semantic versioning](http://semver.org) with MAJOR version, i.e. breaking changes will result in a new MAJOR version.
+
# Compile
#### Build hawkbit-ddi-api
diff --git a/hawkbit-ddi-dl-api/README.md b/hawkbit-ddi-dl-api/README.md
index 703ef2916..ae8c9542e 100644
--- a/hawkbit-ddi-dl-api/README.md
+++ b/hawkbit-ddi-dl-api/README.md
@@ -1,7 +1,11 @@
-# Eclipse.IoT hawkBit - DDI Download API
+# Eclipse.IoT hawkBit - DDI Artifact Download API - Resources
This module is part of the Direct Device Integration (DDI) API and is used by devices/targets for downloading artifacts through HTTP.
+# Version 1
+
+The model follows [semantic versioning](http://semver.org) with MAJOR version, i.e. breaking changes will result in a new MAJOR version.
+
# Compile
#### Build hawkbit-ddi-dl-api
diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java
index b5beb1d39..2d4086055 100644
--- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java
+++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java
@@ -89,7 +89,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
} else {
- final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
+ final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getId());
// we set a download status only if we are aware of the
// targetid, i.e. authenticated and not anonymous
diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
index b91298a47..42491ff0a 100644
--- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
+++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
@@ -131,10 +131,9 @@ public class DdiRootController implements DdiRootControllerRestApi {
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotexist(controllerId, IpUtil
.getClientIpFromRequest(requestResponseContextHolder.getHttpServletRequest(), securityProperties));
- return new ResponseEntity<>(
- DataConversionHelper.fromTarget(target, controllerManagement.findOldestActiveActionByTarget(target),
- controllerManagement.getPollingTime(), tenantAware),
- HttpStatus.OK);
+ return new ResponseEntity<>(DataConversionHelper.fromTarget(target,
+ controllerManagement.findOldestActiveActionByTarget(controllerId),
+ controllerManagement.getPollingTime(), tenantAware), HttpStatus.OK);
}
@Override
@@ -158,7 +157,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
@SuppressWarnings("squid:S3655")
final Artifact artifact = module.getArtifactByFilename(fileName).get();
- final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
+ final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getId());
final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
@@ -254,7 +253,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
LOG.debug("Found an active UpdateAction for target {}. returning deyploment: {}", controllerId, base);
- controllerManagement.registerRetrieved(action, RepositoryConstants.SERVER_MESSAGE_PREFIX
+ controllerManagement.registerRetrieved(action.getId(), RepositoryConstants.SERVER_MESSAGE_PREFIX
+ "Target retrieved update action and should start now the download.");
return new ResponseEntity<>(base, HttpStatus.OK);
@@ -388,7 +387,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
LOG.debug("Found an active CancelAction for target {}. returning cancel: {}", controllerId, cancel);
- controllerManagement.registerRetrieved(action, RepositoryConstants.SERVER_MESSAGE_PREFIX
+ controllerManagement.registerRetrieved(action.getId(), RepositoryConstants.SERVER_MESSAGE_PREFIX
+ "Target retrieved cancel action and should start now the cancelation.");
return new ResponseEntity<>(cancel, HttpStatus.OK);
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 68541b960..adb04f03f 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
@@ -379,13 +379,15 @@ public class DdiArtifactDownloadTest extends AbstractDDiApiIntegrationTest {
Arrays.equals(result.getResponse().getContentAsByteArray(), random));
// one (update) action
- assertThat(deploymentManagement.findActionsByTarget(target)).hasSize(1);
- final Action action = deploymentManagement.findActionsByTarget(target).get(0);
+ assertThat(deploymentManagement.countActionsByTarget(target.getControllerId())).isEqualTo(1);
+ final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent()
+ .get(0);
// one status - download
assertThat(action.getActionStatus()).hasSize(2);
- assertThat(deploymentManagement.findActionStatusByAction(new PageRequest(0, 400, Direction.DESC, "id"), action)
- .getContent().get(0).getStatus()).isEqualTo(Status.DOWNLOAD);
+ assertThat(deploymentManagement
+ .findActionStatusByAction(new PageRequest(0, 400, Direction.DESC, "id"), action.getId()).getContent()
+ .get(0).getStatus()).isEqualTo(Status.DOWNLOAD);
// download complete
assertThat(downLoadProgress).isEqualTo(10);
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 b299ec4c6..666396d3d 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
@@ -54,8 +54,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
final Action updateAction = deploymentManagement.findActionWithDetails(
assignDistributionSet(ds.getId(), savedTarget.getControllerId()).getActions().get(0));
- final Action cancelAction = deploymentManagement.cancelAction(updateAction,
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
+ final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId());
// controller rejects cancelation
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
@@ -125,14 +124,14 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
// Retrieved is reported
- List activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget);
+ List activeActionsByTarget = deploymentManagement
+ .findActiveActionsByTarget(savedTarget.getControllerId());
assertThat(activeActionsByTarget).hasSize(1);
assertThat(activeActionsByTarget.get(0).getStatus()).isEqualTo(Status.RUNNING);
- final Action cancelAction = deploymentManagement.cancelAction(updateAction,
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
+ final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId());
- activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget);
+ activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId());
// the canceled action should still be active!
assertThat(cancelAction.isActive()).isTrue();
@@ -176,7 +175,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
- activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget);
+ activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId());
assertThat(activeActionsByTarget).hasSize(0);
final Action canceledAction = deploymentManagement.findAction(cancelAction.getId());
assertThat(canceledAction.isActive()).isFalse();
@@ -223,8 +222,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
final Action updateAction = deploymentManagement
.findActionWithDetails(assignDistributionSet(ds, toAssign).getActions().get(0));
- return deploymentManagement.cancelAction(updateAction,
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
+ return deploymentManagement.cancelAction(updateAction.getId());
}
@Test
@@ -239,11 +237,10 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assignDistributionSet(ds.getId(), TestdataFactory.DEFAULT_CONTROLLER_ID).getActions().get(0));
// cancel action manually
- final Action cancelAction = deploymentManagement.cancelAction(updateAction,
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
+ final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId());
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
long current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
@@ -253,7 +250,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3);
current = System.currentTimeMillis();
@@ -264,7 +261,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4);
current = System.currentTimeMillis();
@@ -276,10 +273,10 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
// cancelation canceled -> should remove the action from active
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
@@ -289,12 +286,12 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
// cancelation rejected -> action still active until controller close it
// with finished or
// error
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
+ cancelAction.getId() + "/feedback", tenantAware.getCurrentTenant())
@@ -304,7 +301,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
// cancelaction closed -> should remove the action from active
current = System.currentTimeMillis();
@@ -316,7 +313,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).getTargetInfo()
.getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(0);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0);
}
@Test
@@ -338,15 +335,13 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3);
// 3 update actions, 0 cancel actions
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(3);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(3);
- final Action cancelAction = deploymentManagement.cancelAction(updateAction,
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
- final Action cancelAction2 = deploymentManagement.cancelAction(updateAction2,
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(3);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(3);
+ final Action cancelAction = deploymentManagement.cancelAction(updateAction.getId());
+ final Action cancelAction2 = deploymentManagement.cancelAction(updateAction2.getId());
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(3);
- assertThat(deploymentManagement.findActionsByTarget(savedTarget)).hasSize(3);
+ assertThat(deploymentManagement.findActiveActionsByTarget(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))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -372,8 +367,8 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
// 1 update actions, 1 cancel actions
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
- assertThat(deploymentManagement.findActionsByTarget(savedTarget)).hasSize(3);
+ assertThat(deploymentManagement.findActiveActionsByTarget(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))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -406,15 +401,13 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10);
// 1 update actions, 0 cancel actions
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
- final Action cancelAction3 = deploymentManagement.cancelAction(
- deploymentManagement.findAction(updateAction3.getId()),
- targetManagement.findTargetByControllerID(savedTarget.getControllerId()));
+ final Action cancelAction3 = deploymentManagement.cancelAction(updateAction3.getId());
// action is in cancelling state
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1);
- assertThat(deploymentManagement.findActionsByTarget(savedTarget)).hasSize(3);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
+ assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3);
assertThat(targetManagement.findTargetByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID)
.getAssignedDistributionSet()).isEqualTo(ds3);
@@ -435,8 +428,8 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(13);
// final status
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(0);
- assertThat(deploymentManagement.findActionsByTarget(savedTarget)).hasSize(3);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(0);
+ assertThat(deploymentManagement.countActionsByTarget(savedTarget.getControllerId())).isEqualTo(3);
}
@Test
@@ -448,8 +441,7 @@ public class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
final Action action = deploymentManagement.findActionWithDetails(
assignDistributionSet(ds.getId(), TestdataFactory.DEFAULT_CONTROLLER_ID).getActions().get(0));
- final Action cancelAction = deploymentManagement.cancelAction(action,
- targetManagement.findTargetByControllerID(target.getControllerId()));
+ final Action cancelAction = deploymentManagement.cancelAction(action.getId());
final String feedback = JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "proceeding");
// assignDistributionSet creates an ActionStatus and cancel action
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 9f50d4043..888679242 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
@@ -30,6 +30,7 @@ import org.apache.commons.lang3.RandomUtils;
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent;
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;
@@ -118,24 +119,24 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final Target savedTarget = testdataFactory.createTarget("4712");
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty();
+ assertThat(deploymentManagement.findActiveActionsByTarget(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)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
- final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
assertThat(deploymentManagement.countActionsAll()).isEqualTo(1);
saved = assignDistributionSet(ds2, saved).getAssignedEntity();
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2);
assertThat(deploymentManagement.countActionsAll()).isEqualTo(2);
- final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
assertThat(uaction.getDistributionSet()).isEqualTo(ds);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2);
// Run test
long current = System.currentTimeMillis();
@@ -154,7 +155,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
current = System.currentTimeMillis();
final DistributionSet findDistributionSetByAction = distributionSetManagement
- .findDistributionSetByAction(action);
+ .findDistributionSetByAction(action.getId());
mvc.perform(
get("/{tenant}/controller/v1/4712/deploymentBase/" + uaction.getId(), tenantAware.getCurrentTenant())
@@ -221,7 +222,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
// Retrieved is reported
final Iterable actionStatusMessages = deploymentManagement
- .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction);
+ .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction.getId());
assertThat(actionStatusMessages).hasSize(2);
final ActionStatus actionStatusMessage = actionStatusMessages.iterator().next();
assertThat(actionStatusMessage.getStatus()).isEqualTo(Status.RETRIEVED);
@@ -238,7 +239,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
ActionType.TIMEFORCED, System.currentTimeMillis() + 1_000,
Lists.newArrayList(target.getControllerId()));
- final Action action = deploymentManagement.findActiveActionsByTarget(result.getAssignedEntity().get(0)).get(0);
+ final Action action = deploymentManagement
+ .findActiveActionsByTarget(result.getAssignedEntity().get(0).getControllerId()).get(0);
MvcResult mvcResult = mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
@@ -282,24 +284,24 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final Target savedTarget = testdataFactory.createTarget("4712");
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty();
+ assertThat(deploymentManagement.findActiveActionsByTarget(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)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
- final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
assertThat(deploymentManagement.countActionsAll()).isEqualTo(1);
saved = assignDistributionSet(ds2, saved).getAssignedEntity();
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2);
assertThat(deploymentManagement.countActionsAll()).isEqualTo(2);
- final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
assertThat(uaction.getDistributionSet()).isEqualTo(ds);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2);
// Run test
@@ -319,7 +321,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
current = System.currentTimeMillis();
final DistributionSet findDistributionSetByAction = distributionSetManagement
- .findDistributionSetByAction(action);
+ .findDistributionSetByAction(action.getId());
mvc.perform(
get("/{tenant}/controller/v1/4712/deploymentBase/" + uaction.getId(), tenantAware.getCurrentTenant())
@@ -378,7 +380,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
// Retrieved is reported
final List actionStatusMessages = deploymentManagement
- .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction).getContent();
+ .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction.getId()).getContent();
assertThat(actionStatusMessages).hasSize(2);
final ActionStatus actionStatusMessage = actionStatusMessages.iterator().next();
assertThat(actionStatusMessage.getStatus()).isEqualTo(Status.RETRIEVED);
@@ -399,23 +401,23 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final Target savedTarget = testdataFactory.createTarget("4712");
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty();
+ assertThat(deploymentManagement.findActiveActionsByTarget(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)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(1);
- final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
assertThat(deploymentManagement.countActionsAll()).isEqualTo(1);
saved = assignDistributionSet(ds2, saved).getAssignedEntity();
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2);
- final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).get(0);
assertThat(uaction.getDistributionSet()).isEqualTo(ds);
- assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())).hasSize(2);
// Run test
@@ -435,7 +437,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
current = System.currentTimeMillis();
final DistributionSet findDistributionSetByAction = distributionSetManagement
- .findDistributionSetByAction(action);
+ .findDistributionSetByAction(action.getId());
mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/{actionId}", tenantAware.getCurrentTenant(),
uaction.getId()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
@@ -501,7 +503,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
// Retrieved is reported
final Iterable actionStatusMessages = deploymentManagement
- .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction).getContent();
+ .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction.getId()).getContent();
assertThat(actionStatusMessages).hasSize(2);
final ActionStatus actionStatusMessage = actionStatusMessages.iterator().next();
assertThat(actionStatusMessage.getStatus()).isEqualTo(Status.RETRIEVED);
@@ -554,7 +556,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("");
assignDistributionSet(ds.getId(), "4712");
- final Action action = deploymentManagement.findActionsByTarget(target).get(0);
+ final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent()
+ .get(0);
final String feedback = JsonBuilder.deploymentActionFeedback(action.getId().toString(), "proceeding");
// assign distribution set creates an action status, so only 99 left
@@ -594,7 +597,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
Target myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(3);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(3);
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
assertThat(myT.getTargetInfo().getInstalledDistributionSet()).isNull();
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.UNKNOWN))
@@ -612,7 +615,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(2);
assertThat(myT.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds1.getId());
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
@@ -633,7 +636,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(myT.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds2.getId());
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id"))
@@ -652,7 +655,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(myT.getTargetInfo().getLastTargetQuery()).isLessThanOrEqualTo(System.currentTimeMillis());
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
assertThat(myT.getTargetInfo().getInstalledDistributionSet()).isEqualTo(ds3);
assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3);
actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id"))
@@ -674,7 +677,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.UNKNOWN);
assignDistributionSet(ds, toAssign);
- final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds).getContent().get(0);
+ final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent()
+ .get(0);
long current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback",
@@ -694,8 +698,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.hasSize(1);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0);
- assertThat(deploymentManagement.findActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
+ assertThat(deploymentManagement.countActionsByTarget(myT.getControllerId())).isEqualTo(1);
final Iterable actionStatusMessages = deploymentManagement
.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")).getContent();
assertThat(actionStatusMessages).hasSize(2);
@@ -706,7 +710,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
toAssign.add(targetManagement.findTargetByControllerID("4712"));
ds = distributionSetManagement.findDistributionSetByIdWithDetails(ds.getId());
assignDistributionSet(ds, toAssign);
- final Action action2 = deploymentManagement.findActiveActionsByTarget(myT).get(0);
+ final Action action2 = deploymentManagement.findActiveActionsByTarget(myT.getControllerId()).get(0);
current = System.currentTimeMillis();
mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action2.getId() + "/feedback",
@@ -725,12 +729,12 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.hasSize(0);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(1);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0);
- assertThat(deploymentManagement.findInActiveActionsByTarget(myT)).hasSize(2);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(0);
+ assertThat(deploymentManagement.findInActiveActionsByTarget(myT.getControllerId())).hasSize(2);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4);
- assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getContent()).haveAtLeast(1,
+ assertThat(deploymentManagement.findActionStatusByAction(pageReq, action.getId()).getContent()).haveAtLeast(1,
new ActionStatusCondition(Status.ERROR));
- assertThat(deploymentManagement.findActionStatusByAction(pageReq, action2).getContent()).haveAtLeast(1,
+ assertThat(deploymentManagement.findActionStatusByAction(pageReq, action2.getId()).getContent()).haveAtLeast(1,
new ActionStatusCondition(Status.FINISHED));
}
@@ -747,7 +751,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
Target myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
assignDistributionSet(ds, toAssign);
- final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds).getContent().get(0);
+ final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds.getId()).getContent()
+ .get(0);
myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
@@ -775,7 +780,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.hasSize(0);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5);
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5,
new ActionStatusCondition(Status.RUNNING));
@@ -795,7 +800,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.hasSize(0);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6);
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5,
new ActionStatusCondition(Status.RUNNING));
@@ -815,7 +820,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
.hasSize(0);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC))
.hasSize(0);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7);
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6,
new ActionStatusCondition(Status.RUNNING));
@@ -829,7 +834,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.PENDING))
.hasSize(1);
assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.ERROR))
@@ -852,7 +857,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId())).hasSize(1);
assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9);
assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6,
new ActionStatusCondition(Status.RUNNING));
@@ -870,7 +875,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
myT = targetManagement.findTargetByControllerID("4712");
assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current);
assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
- assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0);
+ assertThat(deploymentManagement.findActiveActionsByTarget(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))
@@ -917,7 +922,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
savedTarget = assignDistributionSet(savedSet, toAssign).getAssignedEntity().iterator().next();
assignDistributionSet(savedSet2, toAssign2);
- final Action updateAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0);
+ final Action updateAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId())
+ .get(0);
// action exists but is not assigned to this target
mvc.perform(post("/{tenant}/controller/v1/4713/deploymentBase/" + updateAction.getId() + "/feedback",
@@ -942,6 +948,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
@Description("Ensures that an invalid id in feedback body returns a bad request.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
+ @Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1) })
public void invalidIdInFeedbackReturnsBadRequest() throws Exception {
@@ -949,7 +956,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("");
assignDistributionSet(ds.getId(), "1080");
- final Action action = deploymentManagement.findActionsByTarget(target).get(0);
+ final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent()
+ .get(0);
mvc.perform(post("/{tenant}/controller/v1/1080/deploymentBase/" + action.getId() + "/feedback",
tenantAware.getCurrentTenant()).content(JsonBuilder.deploymentActionInProgressFeedback("AAAA"))
@@ -961,6 +969,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
@Description("Ensures that a missing feedback result in feedback body returns a bad request.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
+ @Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1) })
public void missingResultAttributeInFeedbackReturnsBadRequest() throws Exception {
@@ -969,7 +978,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("");
assignDistributionSet(ds.getId(), "1080");
- final Action action = deploymentManagement.findActionsByTarget(target).get(0);
+ final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent()
+ .get(0);
final String missingResultInFeedback = JsonBuilder.missingResultInFeedback(action.getId().toString(), "closed",
"test");
mvc.perform(post("/{tenant}/controller/v1/1080/deploymentBase/" + action.getId() + "/feedback",
@@ -983,6 +993,7 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
@Description("Ensures that a missing finished result in feedback body returns a bad request.")
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
@Expect(type = DistributionSetCreatedEvent.class, count = 1),
+ @Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
@Expect(type = TargetAssignDistributionSetEvent.class, count = 1),
@Expect(type = ActionCreatedEvent.class, count = 1), @Expect(type = TargetUpdatedEvent.class, count = 1) })
public void missingFinishedAttributeInFeedbackReturnsBadRequest() throws Exception {
@@ -991,7 +1002,8 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
final DistributionSet ds = testdataFactory.createDistributionSet("");
assignDistributionSet(ds.getId(), "1080");
- final Action action = deploymentManagement.findActionsByTarget(target).get(0);
+ final Action action = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq).getContent()
+ .get(0);
final String missingFinishedResultInFeedback = JsonBuilder
.missingFinishedResultInFeedback(action.getId().toString(), "closed", "test");
mvc.perform(post("/{tenant}/controller/v1/1080/deploymentBase/" + action.getId() + "/feedback",
@@ -1003,9 +1015,6 @@ public class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
private class ActionStatusCondition extends Condition {
private final Status status;
- /**
- * @param status
- */
public ActionStatusCondition(final Status status) {
this.status = status;
}
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 26bb256c4..e7f84f88c 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
@@ -199,7 +199,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
assignDistributionSet(ds.getId(), "4711");
- final Action updateAction = deploymentManagement.findActiveActionsByTarget(target).get(0);
+ final Action updateAction = deploymentManagement.findActiveActionsByTarget(target.getControllerId()).get(0);
final String etagWithFirstUpdate = mvc
.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())
.header("If-None-Match", etag).accept(MediaType.APPLICATION_JSON))
@@ -232,7 +232,7 @@ public class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
assignDistributionSet(ds2.getId(), "4711");
- final Action updateAction2 = deploymentManagement.findActiveActionsByTarget(target).get(0);
+ final Action updateAction2 = deploymentManagement.findActiveActionsByTarget(target.getControllerId()).get(0);
mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())
.header("If-None-Match", etagWithFirstUpdate).accept(MediaType.APPLICATION_JSON))
@@ -319,7 +319,7 @@ 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).get(0);
+ final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget.getControllerId()).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 59141320e..d2d4c5c80 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,9 @@ public class DosFilterTest extends AbstractDDiApiIntegrationTest {
final List toAssign = Lists.newArrayList(target);
final Iterable saved = assignDistributionSet(ds, toAssign).getAssignedEntity();
- assertThat(deploymentManagement.findActiveActionsByTarget(target)).hasSize(1);
+ assertThat(deploymentManagement.findActiveActionsByTarget(target.getControllerId())).hasSize(1);
- final Action uaction = deploymentManagement.findActiveActionsByTarget(target).get(0);
+ final Action uaction = deploymentManagement.findActiveActionsByTarget(target.getControllerId()).get(0);
return uaction.getId();
}
diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java
index d123bdbc7..828645875 100644
--- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java
+++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java
@@ -116,46 +116,43 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
*
* @param secruityToken
* the security token which holds the target ID to check on
- * @param artifact
+ * @param artifactId
* the artifact to verify if the given target is allowed to
* download it
*/
- private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken,
- final org.eclipse.hawkbit.repository.model.Artifact artifact) {
+ private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, final Long artifactId) {
if (secruityToken.getControllerId() != null) {
- checkByControllerId(artifact, secruityToken.getControllerId());
+ checkByControllerId(artifactId, secruityToken.getControllerId());
} else if (secruityToken.getTargetId() != null) {
- checkByTargetId(artifact, secruityToken.getTargetId());
+ checkByTargetId(artifactId, secruityToken.getTargetId());
} else {
- LOG.info("anonymous download no authentication check for artifact {}", artifact);
+ LOG.info("anonymous download no authentication check for artifact {}", artifactId);
return;
}
}
- private void checkByTargetId(final org.eclipse.hawkbit.repository.model.Artifact localArtifact,
- final Long targetId) {
+ private void checkByTargetId(final Long artifactId, final Long targetId) {
LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", targetId,
- localArtifact);
- if (!controllerManagement.hasTargetArtifactAssigned(targetId, localArtifact)) {
+ artifactId);
+ if (!controllerManagement.hasTargetArtifactAssigned(targetId, artifactId)) {
LOG.info("target {} tried to download artifact {} which is not assigned to the target", targetId,
- localArtifact);
+ artifactId);
throw new EntityNotFoundException();
}
- LOG.info("download security check for target {} and artifact {} granted", targetId, localArtifact);
+ LOG.info("download security check for target {} and artifact {} granted", targetId, artifactId);
}
- private void checkByControllerId(final org.eclipse.hawkbit.repository.model.Artifact localArtifact,
- final String controllerId) {
+ private void checkByControllerId(final Long artifactId, final String controllerId) {
LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}",
- controllerId, localArtifact);
- if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) {
+ controllerId, artifactId);
+ if (!controllerManagement.hasTargetArtifactAssigned(controllerId, artifactId)) {
LOG.info("target {} tried to download artifact {} which is not assigned to the target", controllerId,
- localArtifact);
+ artifactId);
throw new EntityNotFoundException();
}
- LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact);
+ LOG.info("download security check for target {} and artifact {} granted", controllerId, artifactId);
}
private org.eclipse.hawkbit.repository.model.Artifact findArtifactByFileResource(final FileResource fileResource) {
@@ -201,9 +198,9 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService {
throw new EntityNotFoundException();
}
- checkIfArtifactIsAssignedToTarget(secruityToken, localArtifact);
+ checkIfArtifactIsAssignedToTarget(secruityToken, localArtifact.getId());
- final Artifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(localArtifact));
+ final Artifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(localArtifact.getId()));
if (artifact == null) {
throw new EntityNotFoundException();
}
diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java
index 35551d49f..7593029bf 100644
--- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java
+++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java
@@ -180,7 +180,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
}
private void lookIfUpdateAvailable(final Target target) {
- final Optional actionOptional = controllerManagement.findOldestActiveActionByTarget(target);
+ final Optional actionOptional = controllerManagement
+ .findOldestActiveActionByTarget(target.getControllerId());
if (!actionOptional.isPresent()) {
return;
}
@@ -286,7 +287,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
}
private void updateLastPollTime(final Target target) {
- controllerManagement.updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), null);
+ controllerManagement.updateLastTargetQuery(target.getControllerId(), null);
}
private static String convertCorrelationId(final Message message) {
diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java
index d6fb164f9..f7f57537b 100644
--- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java
+++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java
@@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.jpa.JpaEntityFactory;
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
-import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
@@ -153,8 +152,9 @@ public class AmqpControllerAuthenticationTest {
authenticationManager.postConstruct();
- final Artifact testArtifact = new JpaArtifact("afilename", "afilename", new JpaSoftwareModule(
+ final JpaArtifact testArtifact = new JpaArtifact("afilename", "afilename", new JpaSoftwareModule(
new JpaSoftwareModuleType("a key", "a name", null, 1), "a name", null, null, null));
+ testArtifact.setId(1L);
when(artifactManagementMock.findArtifact(ARTIFACT_ID)).thenReturn(testArtifact);
when(artifactManagementMock.findFirstArtifactBySHA1(SHA1)).thenReturn(testArtifact);
@@ -162,7 +162,7 @@ public class AmqpControllerAuthenticationTest {
final DbArtifact artifact = new DbArtifact();
artifact.setSize(ARTIFACT_SIZE);
artifact.setHashes(new DbArtifactHash("sha1 test", "md5 test"));
- when(artifactManagementMock.loadArtifactBinary(testArtifact)).thenReturn(artifact);
+ when(artifactManagementMock.loadArtifactBinary(1L)).thenReturn(artifact);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate,
mock(AmqpMessageDispatcherService.class), controllerManagementMock, new JpaEntityFactory());
@@ -173,8 +173,8 @@ public class AmqpControllerAuthenticationTest {
when(hostnameResolverMock.resolveHostname()).thenReturn(new URL("http://localhost"));
- when(controllerManagementMock.hasTargetArtifactAssigned(TARGET_ID, testArtifact)).thenReturn(true);
- when(controllerManagementMock.hasTargetArtifactAssigned(CONTROLLER_ID, testArtifact)).thenReturn(true);
+ when(controllerManagementMock.hasTargetArtifactAssigned(TARGET_ID, 1L)).thenReturn(true);
+ when(controllerManagementMock.hasTargetArtifactAssigned(CONTROLLER_ID, 1L)).thenReturn(true);
}
@Test
diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java
index c1d8ba35b..4e50be107 100644
--- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java
+++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.amqp;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
@@ -49,9 +50,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.Target;
-import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo;
-import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.junit.Before;
import org.junit.Test;
@@ -149,10 +148,12 @@ public class AmqpMessageHandlerServiceTest {
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
+ final Target targetMock = mock(Target.class);
+
final ArgumentCaptor targetIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor uriCaptor = ArgumentCaptor.forClass(URI.class);
when(controllerManagementMock.findOrRegisterTargetIfItDoesNotexist(targetIdCaptor.capture(),
- uriCaptor.capture())).thenReturn(null);
+ uriCaptor.capture())).thenReturn(targetMock);
when(controllerManagementMock.findOldestActiveActionByTarget(Matchers.any())).thenReturn(Optional.empty());
amqpMessageHandlerService.onMessage(message, MessageType.THING_CREATED.name(), TENANT, "vHost");
@@ -326,11 +327,14 @@ public class AmqpMessageHandlerServiceTest {
// mock
final Artifact localArtifactMock = mock(Artifact.class);
+ final Long mockedArtifactId = 1L;
+ when(localArtifactMock.getId()).thenReturn(mockedArtifactId);
+
final DbArtifact dbArtifactMock = mock(DbArtifact.class);
when(artifactManagementMock.findFirstArtifactBySHA1(anyString())).thenReturn(localArtifactMock);
- when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), localArtifactMock))
+ when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), mockedArtifactId))
.thenReturn(true);
- when(artifactManagementMock.loadArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock);
+ when(artifactManagementMock.loadArtifactBinary(anyLong())).thenReturn(dbArtifactMock);
when(dbArtifactMock.getArtifactId()).thenReturn("artifactId");
when(dbArtifactMock.getSize()).thenReturn(1L);
when(dbArtifactMock.getHashes()).thenReturn(new DbArtifactHash("sha1", "md5"));
@@ -377,8 +381,7 @@ public class AmqpMessageHandlerServiceTest {
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
// verify
- verify(controllerManagementMock).updateTargetStatus(Matchers.any(TargetInfo.class),
- Matchers.isNull(TargetUpdateStatus.class), Matchers.isNotNull(Long.class), Matchers.isNull(URI.class));
+ verify(controllerManagementMock).updateLastTargetQuery(Matchers.any(String.class), Matchers.isNull(URI.class));
final ArgumentCaptor tenantCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor targetCaptor = ArgumentCaptor.forClass(Target.class);
diff --git a/hawkbit-dmf-api/README.md b/hawkbit-dmf-api/README.md
index cdb6f8d50..8d8463acc 100644
--- a/hawkbit-dmf-api/README.md
+++ b/hawkbit-dmf-api/README.md
@@ -1,4 +1,8 @@
-# HawkBit Software Provisioning device management federation API
+# hawkBit device management federation API - model definition
-This API is used for communicating with the HawkBit Software Provisioning server through AMQP.
-It is used to integrate other device management system through a high performance protocol.
\ No newline at end of file
+This API is used for communicating with the hawkBit Update Server through AMQP.
+It is used to integrate other device management system through a high throughput protocol optimized for service to service communication.
+
+# Version 1
+
+The model follows [semantic versioning](http://semver.org) with MAJOR version, i.e. breaking changes will result in a new MAJOR version.
\ No newline at end of file
diff --git a/hawkbit-mgmt-api/README.md b/hawkbit-mgmt-api/README.md
index eeb51c145..4c59cac89 100644
--- a/hawkbit-mgmt-api/README.md
+++ b/hawkbit-mgmt-api/README.md
@@ -1,7 +1,10 @@
-# Eclipse.IoT hawkBit - Mgmt API
+# Eclipse.IoT hawkBit - Management API - Model and Resources
This Management (Mgmt) API is used to manage and monitor the HawkBit Update Server via HTTP. This API allows Create/Read/Update/Delete operations for provisioning targets (i.e. devices) and repository content (i.e. software).
+# Version 1
+
+The model follows [semantic versioning](http://semver.org) with MAJOR version, i.e. breaking changes will result in a new MAJOR version.
# Compile
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
index 9f7baad5a..4b14a2e5b 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
@@ -137,10 +137,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@Override
public ResponseEntity deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId) {
- final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
-
- distributionSetManagement.deleteDistributionSet(set);
-
+ distributionSetManagement.deleteDistributionSet(distributionSetId);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -222,21 +219,13 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@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 DistributionSet distributionSet = findDistributionSetWithExceptionIfNotFound(distributionSetId);
-
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetFilterQuerySortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
- final Page targetFilterQueries;
- if (rsqlParam != null) {
- targetFilterQueries = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(pageable,
- distributionSet, rsqlParam);
- } else {
- targetFilterQueries = targetFilterQueryManagement.findTargetFilterQueryByAutoAssignDS(pageable,
- distributionSet);
- }
+ final Page targetFilterQueries = targetFilterQueryManagement
+ .findTargetFilterQueryByAutoAssignDS(pageable, distributionSetId, rsqlParam);
return new ResponseEntity<>(
new PagedList<>(MgmtTargetFilterQueryMapper.toResponse(targetFilterQueries.getContent()),
@@ -340,7 +329,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@RequestBody final List softwareModuleIDs) {
distributionSetManagement.assignSoftwareModules(distributionSetId,
- softwareModuleIDs.stream().map(module -> module.getId()).collect(Collectors.toList()));
+ softwareModuleIDs.stream().map(MgmtSoftwareModuleAssigment::getId).collect(Collectors.toList()));
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -360,13 +349,13 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam) {
// check if distribution set exists otherwise throw exception
// immediately
- final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId);
+ findDistributionSetWithExceptionIfNotFound(distributionSetId);
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page softwaremodules = softwareManagement.findSoftwareModuleByAssignedTo(pageable,
- foundDs);
+ distributionSetId);
return new ResponseEntity<>(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(softwaremodules.getContent()),
softwaremodules.getTotalElements()), HttpStatus.OK);
}
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 9e6b19471..28814bbbe 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
@@ -167,10 +167,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@PathVariable("distributionsetTagId") final Long distributionsetTagId,
@RequestBody final List assignedDSRequestBodies) {
LOG.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId);
- final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
-
final List assignedDs = this.distributionSetManagement
- .assignTag(findDistributionSetIds(assignedDSRequestBodies), tag);
+ .assignTag(findDistributionSetIds(assignedDSRequestBodies), distributionsetTagId);
LOG.debug("Assignd DistributionSet {}", assignedDs.size());
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs), HttpStatus.OK);
}
@@ -179,14 +177,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
public ResponseEntity unassignDistributionSets(
@PathVariable("distributionsetTagId") final Long distributionsetTagId) {
LOG.debug("Unassign all DS for ds tag {}", distributionsetTagId);
- final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
- if (tag.getAssignedToDistributionSet() == null) {
- LOG.debug("No assigned ds founded");
- return new ResponseEntity<>(HttpStatus.OK);
- }
final List distributionSets = this.distributionSetManagement
- .unAssignAllDistributionSetsByTag(tag);
+ .unAssignAllDistributionSetsByTag(distributionsetTagId);
LOG.debug("Unassigned ds {}", distributionSets.size());
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -196,8 +189,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
@PathVariable("distributionsetTagId") final Long distributionsetTagId,
@PathVariable("distributionsetId") final Long distributionsetId) {
LOG.debug("Unassign ds {} for ds tag {}", distributionsetId, distributionsetTagId);
- final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
- this.distributionSetManagement.unAssignTag(distributionsetId, tag);
+ this.distributionSetManagement.unAssignTag(distributionsetId, distributionsetTagId);
return new ResponseEntity<>(HttpStatus.OK);
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
index e1591b8b6..7a83318c5 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
@@ -101,8 +101,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
public ResponseEntity deleteDistributionSetType(
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
- final DistributionSetType module = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
- distributionSetManagement.deleteDistributionSetType(module);
+ distributionSetManagement.deleteDistributionSetType(distributionSetTypeId);
return ResponseEntity.ok().build();
}
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java
index a187e6769..10513d568 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java
@@ -67,7 +67,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
}
final Artifact artifact = module.getArtifact(artifactId).get();
- final DbArtifact file = artifactManagement.loadArtifactBinary(artifact);
+ final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getId());
final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest();
final String ifMatch = request.getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
index 59f76b27c..c5b80c3aa 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
@@ -188,8 +188,6 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
findRolloutOrThrowException(rolloutId);
- final RolloutGroup rolloutGroup = findRolloutGroupOrThrowException(groupId);
-
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeTargetSortParam(sortParam);
@@ -198,11 +196,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
final Page rolloutGroupTargets;
if (rsqlParam != null) {
- rolloutGroupTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, rsqlParam,
- pageable);
+ rolloutGroupTargets = this.rolloutGroupManagement.findRolloutGroupTargets(groupId, rsqlParam, pageable);
} else {
- final Page pageTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup,
- pageable);
+ final Page pageTargets = this.rolloutGroupManagement.findRolloutGroupTargets(groupId, pageable);
rolloutGroupTargets = pageTargets;
}
final List rest = MgmtTargetMapper.toResponse(rolloutGroupTargets.getContent());
diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
index 704bf72da..1c249089c 100644
--- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
+++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
@@ -87,10 +87,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
@Override
public ResponseEntity deleteSoftwareModuleType(
@PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId) {
- final SoftwareModuleType module = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
-
- softwareManagement.deleteSoftwareModuleType(module);
-
+ softwareManagement.deleteSoftwareModuleType(softwareModuleTypeId);
return new ResponseEntity<>(HttpStatus.OK);
}
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 5a1e9471d..a5b3e0a91 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
@@ -130,8 +130,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity deleteTarget(@PathVariable("controllerId") final String controllerId) {
- final Target target = findTargetWithExceptionIfNotFound(controllerId);
- this.targetManagement.deleteTargets(target.getId());
+ this.targetManagement.deleteTarget(controllerId);
LOG.debug("{} target deleted, return status {}", controllerId, HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -158,7 +157,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
- final Target foundTarget = findTargetWithExceptionIfNotFound(controllerId);
+ findTargetWithExceptionIfNotFound(controllerId);
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -168,11 +167,11 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
final Slice activeActions;
final Long totalActionCount;
if (rsqlParam != null) {
- activeActions = this.deploymentManagement.findActionsByTarget(rsqlParam, foundTarget, pageable);
- totalActionCount = this.deploymentManagement.countActionsByTarget(rsqlParam, foundTarget);
+ activeActions = this.deploymentManagement.findActionsByTarget(rsqlParam, controllerId, pageable);
+ totalActionCount = this.deploymentManagement.countActionsByTarget(rsqlParam, controllerId);
} else {
- activeActions = this.deploymentManagement.findActionsByTarget(foundTarget, pageable);
- totalActionCount = this.deploymentManagement.countActionsByTarget(foundTarget);
+ activeActions = this.deploymentManagement.findActionsByTarget(controllerId, pageable);
+ totalActionCount = this.deploymentManagement.countActionsByTarget(controllerId);
}
return new ResponseEntity<>(
@@ -184,11 +183,10 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
@Override
public ResponseEntity getAction(@PathVariable("controllerId") final String controllerId,
@PathVariable("actionId") final Long actionId) {
- final Target target = findTargetWithExceptionIfNotFound(controllerId);
final Action action = findActionWithExceptionIfNotFound(actionId);
- if (!action.getTarget().getId().equals(target.getId())) {
- LOG.warn("given action ({}) is not assigned to given target ({}).", action.getId(), target.getId());
+ if (!action.getTarget().getControllerId().equals(controllerId)) {
+ LOG.warn("given action ({}) is not assigned to given target ({}).", action.getId(), controllerId);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
@@ -215,13 +213,17 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity cancelAction(@PathVariable("controllerId") final String controllerId,
@PathVariable("actionId") final Long actionId,
@RequestParam(value = "force", required = false, defaultValue = "false") final boolean force) {
- final Target target = findTargetWithExceptionIfNotFound(controllerId);
final Action action = findActionWithExceptionIfNotFound(actionId);
+ if (!action.getTarget().getControllerId().equals(controllerId)) {
+ LOG.warn("given action ({}) is not assigned to given target ({}).", actionId, controllerId);
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
+
if (force) {
- this.deploymentManagement.forceQuitAction(action);
+ this.deploymentManagement.forceQuitAction(actionId);
} else {
- this.deploymentManagement.cancelAction(action, target);
+ this.deploymentManagement.cancelAction(actionId);
}
// both functions will throw an exception, when action is in wrong
// state, which is mapped by MgmtResponseExceptionHandler.
@@ -249,7 +251,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam);
final Page statusList = this.deploymentManagement.findActionStatusByActionWithMessages(
- new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action);
+ new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action.getId());
return new ResponseEntity<>(
new PagedList<>(MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent()),
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 23fd45c9f..f4ab1c96f 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
@@ -152,21 +152,16 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
public ResponseEntity> assignTargets(@PathVariable("targetTagId") final Long targetTagId,
@RequestBody final List assignedTargetRequestBodies) {
LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
- final TargetTag targetTag = findTargetTagById(targetTagId);
final List assignedTarget = this.targetManagement
- .assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTag);
+ .assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTagId);
return new ResponseEntity<>(MgmtTargetMapper.toResponseWithLinksAndPollStatus(assignedTarget), HttpStatus.OK);
}
@Override
public ResponseEntity unassignTargets(@PathVariable("targetTagId") final Long targetTagId) {
LOG.debug("Unassign all Targets for target tag {}", targetTagId);
- final TargetTag targetTag = findTargetTagById(targetTagId);
- if (targetTag.getAssignedToTargets() == null) {
- LOG.debug("No assigned targets found");
- return new ResponseEntity<>(HttpStatus.OK);
- }
- this.targetManagement.unAssignAllTargetsByTag(targetTag);
+
+ this.targetManagement.unAssignAllTargetsByTag(targetTagId);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -174,8 +169,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
public ResponseEntity unassignTarget(@PathVariable("targetTagId") final Long targetTagId,
@PathVariable("controllerId") final String controllerId) {
LOG.debug("Unassign target {} for target tag {}", controllerId, targetTagId);
- final TargetTag targetTag = findTargetTagById(targetTagId);
- this.targetManagement.unAssignTag(controllerId, targetTag);
+ this.targetManagement.unAssignTag(controllerId, targetTagId);
return new ResponseEntity<>(HttpStatus.OK);
}
@@ -189,7 +183,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
private List findTargetControllerIds(
final List assignedTargetRequestBodies) {
- return assignedTargetRequestBodies.stream().map(request -> request.getControllerId())
+ return assignedTargetRequestBodies.stream().map(MgmtAssignedTargetRequestBody::getControllerId)
.collect(Collectors.toList());
}
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 0e27312d0..b0e85bbb4 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
@@ -163,7 +163,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
// binary
try (InputStream fileInputStream = artifactManagement
- .loadArtifactBinary(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts().get(0))
+ .loadArtifactBinary(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts().get(0).getId())
.getFileInputStream()) {
assertTrue("Wrong artifact content",
IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream));
@@ -689,9 +689,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
.andExpect(jsonPath("[1].createdAt", not(equalTo(0)))).andReturn();
final SoftwareModule osCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name1", "version1",
- osType);
+ osType.getId());
final SoftwareModule appCreated = softwareManagement.findSoftwareModuleByNameAndVersion("name3", "version3",
- appType);
+ appType.getId());
assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())
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 ca0a23145..cc84769e8 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,8 +110,7 @@ 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(pageRequest, targetManagement.findTargetByControllerID(knownTargetId)).getContent()
+ 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);
@@ -247,10 +246,10 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
final Target tA = createTargetAndStartAction();
// cancel the active action
- deploymentManagement.cancelAction(tA.getActions().get(0), tA);
+ deploymentManagement.cancelAction(tA.getActions().get(0).getId());
// find the current active action
- final List cancelActions = deploymentManagement.findActionsByTarget(new PageRequest(0, 100), tA)
+ final List cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq)
.getContent().stream().filter(action -> action.isCancelingOrCanceled()).collect(Collectors.toList());
assertThat(cancelActions).hasSize(1);
@@ -267,11 +266,11 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
final Target tA = createTargetAndStartAction();
// cancel the active action
- deploymentManagement.cancelAction(tA.getActions().get(0), tA);
+ deploymentManagement.cancelAction(tA.getActions().get(0).getId());
// find the current active action
- final List cancelActions = deploymentManagement.findActionsByTarget(pageReq, tA).getContent().stream()
- .filter(Action::isCancelingOrCanceled).collect(Collectors.toList());
+ final List cancelActions = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq)
+ .getContent().stream().filter(Action::isCancelingOrCanceled).collect(Collectors.toList());
assertThat(cancelActions).hasSize(1);
assertThat(cancelActions.get(0).isCancelingOrCanceled()).isTrue();
@@ -1045,7 +1044,8 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
assignDistributionSet(two, updatedTargets);
// two updates, one cancellation
- final List actions = deploymentManagement.findActionsByTarget(target);
+ final List actions = deploymentManagement.findActionsByTarget(target.getControllerId(), pageReq)
+ .getContent();
assertThat(actions).hasSize(2);
return actions;
@@ -1096,7 +1096,8 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- final List findActiveActionsByTarget = deploymentManagement.findActiveActionsByTarget(target);
+ final List findActiveActionsByTarget = deploymentManagement
+ .findActiveActionsByTarget(target.getControllerId());
assertThat(findActiveActionsByTarget).hasSize(1);
assertThat(findActiveActionsByTarget.get(0).getActionType()).isEqualTo(ActionType.TIMEFORCED);
assertThat(findActiveActionsByTarget.get(0).getForcedTime()).isEqualTo(forceTime);
@@ -1276,7 +1277,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(new PageRequest(0, 100), tA);
+ final Slice actionsByTarget = deploymentManagement.findActionsByTarget(tA.getControllerId(), pageReq);
assertThat(actionsByTarget.getContent()).hasSize(1);
return targetManagement.findTargetByControllerID(tA.getControllerId());
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
index a1740c879..5b5a91796 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
@@ -104,13 +104,13 @@ public interface ArtifactManagement {
* Garbage collects local artifact binary file if only referenced by given
* {@link Artifact} metadata object.
*
- * @param onlyByThisReferenced
+ * @param artifactId
* the related local artifact
*
* @return true if an binary was actually garbage collected
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
- boolean clearArtifactBinary(@NotNull Artifact onlyByThisReferenced);
+ boolean clearArtifactBinary(@NotNull Long artifactId);
/**
* Deletes {@link Artifact} based on given id.
@@ -186,15 +186,18 @@ public interface ArtifactManagement {
/**
* Loads {@link DbArtifact} from store for given {@link Artifact}.
*
- * @param artifact
+ * @param artifactId
* to search for
* @return loaded {@link DbArtifact}
*
* @throws GridFSDBFileNotFoundException
* if file could not be found in store
+ *
+ * @throws EntityNotFoundException
+ * is artifact with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD)
- DbArtifact loadArtifactBinary(@NotNull Artifact artifact);
+ DbArtifact loadArtifactBinary(@NotNull Long artifactId);
}
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
index 752164b45..63b6b1523 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
@@ -24,10 +24,8 @@ import org.eclipse.hawkbit.repository.exception.TooManyStatusEntriesException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
-import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
-import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
import org.hibernate.validator.constraints.NotEmpty;
@@ -116,12 +114,15 @@ public interface ControllerManagement {
* Retrieves oldest {@link Action} that is active and assigned to a
* {@link Target}.
*
- * @param target
- * the target to retrieve the actions from
+ * @param controllerId
+ * identifies the target to retrieve the actions from
* @return a list of actions assigned to given target which are active
+ *
+ * @throws EntityNotFoundException
+ * if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
- Optional findOldestActiveActionByTarget(@NotNull Target target);
+ Optional findOldestActiveActionByTarget(@NotNull String controllerId);
/**
* Get the {@link Action} entity for given actionId with all lazy
@@ -177,7 +178,7 @@ public interface ControllerManagement {
*
* @param controllerId
* the ID of the target to check
- * @param localArtifact
+ * @param artifactId
* the artifact to verify if the given target had even been
* assigned to
* @return {@code true} if the given target has currently or had ever a
@@ -185,7 +186,7 @@ public interface ControllerManagement {
* otherwise {@code false}
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
- boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull Artifact localArtifact);
+ boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull Long artifactId);
/**
* Checks if a given target has currently or has even been assigned to the
@@ -196,7 +197,7 @@ public interface ControllerManagement {
*
* @param targetId
* the ID of the target to check
- * @param localArtifact
+ * @param artifactId
* the artifact to verify if the given target had even been
* assigned to
* @return {@code true} if the given target has currently or had ever a
@@ -204,21 +205,24 @@ public interface ControllerManagement {
* otherwise {@code false}
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
- boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull Artifact localArtifact);
+ boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull Long artifactId);
/**
* Registers retrieved status for given {@link Target} and {@link Action} if
* it does not exist yet.
*
- * @param action
+ * @param actionId
* to the handle status for
* @param message
* for the status
* @return the update action in case the status has been changed to
* {@link Status#RETRIEVED}
+ *
+ * @throws EntityNotFoundException
+ * if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
- Action registerRetrieved(@NotNull Action action, String message);
+ Action registerRetrieved(@NotNull Long actionId, String message);
/**
* Updates attributes of the controller.
@@ -255,40 +259,6 @@ public interface ControllerManagement {
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
Target updateLastTargetQuery(@NotEmpty String controllerId, URI address);
- /**
- * Refreshes the time of the last time the controller has been connected to
- * the server.
- *
- * @param target
- * to update
- * @param address
- * the client address of the target, might be {@code null}
- * @return the updated target
- *
- */
- @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
- TargetInfo updateLastTargetQuery(@NotNull TargetInfo target, @NotNull URI address);
-
- /**
- * Update selective the target status of a given {@code target}.
- *
- * @param targetInfo
- * the target to update the target status
- * @param status
- * the status to be set of the target. Might be {@code null} if
- * the target status should not be updated
- * @param lastTargetQuery
- * the last target query to be set of the target. Might be
- * {@code null} if the target lastTargetQuery should not be
- * updated
- * @param address
- * the client address of the target, might be {@code null}
- * @return the updated TargetInfo
- */
- @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
- TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery,
- URI address);
-
/**
* Finds {@link Target} based on given controller ID returns found Target
* without details, i.e. NO {@link Target#getTags()} and
@@ -301,7 +271,7 @@ public interface ControllerManagement {
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
- Target findByControllerId(@NotEmpty final String controllerId);
+ Target findByControllerId(@NotEmpty String controllerId);
/**
* Finds {@link Target} based on given ID returns found Target without
@@ -315,6 +285,6 @@ public interface ControllerManagement {
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_SYSTEM_CODE)
- Target findByTargetId(final long targetId);
+ Target findByTargetId(@NotNull Long targetId);
}
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 53f3a07b3..d3675ea49 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
@@ -114,57 +114,33 @@ public interface DeploymentManagement {
DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID,
@NotEmpty Collection targets, String actionMessage);
- /**
- * method assigns the {@link DistributionSet} to all {@link Target}s by
- * their IDs with a specific {@link ActionType} and {@code forcetime}.
- *
- * @param dsID
- * the ID of the distribution set to assign
- * @param targets
- * a list of all targets and their action type
- * @param rollout
- * the rollout for this assignment
- * @param rolloutGroup
- * the rollout group for this assignment
- * @return the assignment result
- *
- * @throw IncompleteDistributionSetException if mandatory
- * {@link SoftwareModuleType} are not assigned as define by the
- * {@link DistributionSetType}.
- *
- * @throw {@link EntityNotFoundException} if either provided
- * {@link DistributionSet} or {@link Target}s do not exist
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET)
- DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID,
- @NotEmpty Collection targets, Rollout rollout, RolloutGroup rolloutGroup);
-
/**
* Cancels given {@link Action} for given {@link Target}. The method will
* immediately add a {@link Status#CANCELED} status to the action. However,
* it might be possible that the controller will continue to work on the
* cancellation.
*
- * @param action
+ * @param actionId
* to be canceled
- * @param target
- * for which the action needs cancellation
*
* @return generated {@link Action} or null if not active on
* given {@link Target}.
* @throws CancelActionNotAllowedException
* in case the given action is not active or is already a cancel
* action
+ *
+ * @throws EntityNotFoundException
+ * if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- Action cancelAction(@NotNull Action action, @NotNull Target target);
+ Action cancelAction(@NotNull Long actionId);
/**
* counts all actions associated to a specific target.
*
* @param rsqlParam
* rsql query string
- * @param target
+ * @param controllerId
* the target associated to the actions to count
* @return the count value of found actions associated to the target
*
@@ -175,7 +151,7 @@ public interface DeploymentManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target);
+ Long countActionsByTarget(@NotNull String rsqlParam, @NotEmpty String controllerId);
/**
* @return the total amount of stored action status
@@ -192,35 +168,12 @@ public interface DeploymentManagement {
/**
* counts all actions associated to a specific target.
*
- * @param target
+ * @param controllerId
* the target associated to the actions to count
* @return the count value of found actions associated to the target
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Long countActionsByTarget(@NotNull Target target);
-
- /**
- * Creates an action entry into the action repository. In case of existing
- * scheduled actions the scheduled actions gets canceled. A scheduled action
- * is created in-active.
- *
- * @param targets
- * the targets to create scheduled actions for
- * @param distributionSet
- * the distribution set for the actions
- * @param actionType
- * the action type for the action
- * @param forcedTime
- * the forcedTime of the action
- * @param rollout
- * the roll out for this action
- * @param rolloutGroup
- * the roll out group for this action
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- void createScheduledAction(@NotEmpty Collection targets, @NotNull DistributionSet distributionSet,
- @NotNull ActionType actionType, Long forcedTime, @NotNull Rollout rollout,
- @NotNull RolloutGroup rolloutGroup);
+ Long countActionsByTarget(@NotEmpty String controllerId);
/**
* Get the {@link Action} entity for given actionId.
@@ -232,30 +185,6 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Action findAction(@NotNull Long actionId);
- /**
- * Retrieves all actions for a specific rollout and in a specific status.
- *
- * @param rollout
- * the rollout the actions beglong to
- * @param actionStatus
- * the status of the actions
- * @return the actions referring a specific rollout an in a specific status
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findActionsByRolloutAndStatus(@NotNull Rollout rollout, @NotNull Action.Status actionStatus);
-
- /**
- * Retrieves all {@link Action}s of a specific target.
- *
- * @param pageable
- * pagination parameter
- * @param target
- * of which the actions have to be searched
- * @return a paged list of actions associated with the given target
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Slice findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target);
-
/**
* Retrieves all {@link Action}s from repository.
*
@@ -272,14 +201,14 @@ public interface DeploymentManagement {
*
* @param pageable
* the page request parameter for paging and sorting the result
- * @param distributionSet
+ * @param distributionSetId
* the distribution set which should be assigned to the actions
* in the result
* @return a list of {@link Action} which are assigned to a specific
* {@link DistributionSet}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Slice findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull DistributionSet distributionSet);
+ Slice findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull Long distributionSetId);
/**
* Retrieves all {@link Action}s assigned to a specific {@link Target} and a
@@ -287,7 +216,7 @@ public interface DeploymentManagement {
*
* @param rsqlParam
* rsql query string
- * @param target
+ * @param controllerId
* the target which must be assigned to the actions
* @param pageable
* the page request
@@ -301,31 +230,21 @@ public interface DeploymentManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Slice findActionsByTarget(@NotNull String rsqlParam, @NotNull Target target, @NotNull Pageable pageable);
-
- /**
- * Retrieves all {@link Action}s of a specific target ordered by action ID.
- *
- * @param target
- * the target associated with the actions
- * @return a list of actions associated with the given target ordered by
- * action ID
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findActionsByTarget(@NotNull Target target);
+ Slice findActionsByTarget(@NotNull String rsqlParam, @NotEmpty String controllerId,
+ @NotNull Pageable pageable);
/**
* Retrieves all {@link Action}s which are referring the given
* {@link Target}.
*
- * @param foundTarget
+ * @param controllerId
* the target to find actions for
* @param pageable
* the pageable request to limit, sort the actions
* @return a slice of actions found for a specific target
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Slice findActionsByTarget(@NotNull Target foundTarget, @NotNull Pageable pageable);
+ Slice findActionsByTarget(@NotEmpty String controllerId, @NotNull Pageable pageable);
/**
* Retrieves all the {@link ActionStatus} entries of the given
@@ -333,12 +252,12 @@ public interface DeploymentManagement {
*
* @param pageReq
* pagination parameter
- * @param action
+ * @param actionId
* to be filtered on
* @return the corresponding {@link Page} of {@link ActionStatus}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Action action);
+ Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Long actionId);
/**
* Retrieves all {@link ActionStatus} inclusive their messages by a specific
@@ -346,23 +265,23 @@ public interface DeploymentManagement {
*
* @param pageable
* the page request parameter for paging and sorting the result
- * @param action
+ * @param actionId
* the {@link Action} to retrieve the {@link ActionStatus} from
* @return a page of {@link ActionStatus} by a speciifc {@link Action}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Action action);
+ Page findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Long actionId);
/**
* Retrieves all {@link Action}s of a specific target ordered by action ID.
*
- * @param target
+ * @param controllerId
* the target associated with the actions
* @return a list of actions associated with the given target ordered by
* action ID
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findActionsWithStatusCountByTargetOrderByIdDesc(@NotNull Target target);
+ List findActionsWithStatusCountByTargetOrderByIdDesc(@NotNull String controllerId);
/**
* Get the {@link Action} entity for given actionId with all lazy attributes
@@ -379,23 +298,23 @@ public interface DeploymentManagement {
* Retrieves all active {@link Action}s of a specific target ordered by
* action ID.
*
- * @param target
+ * @param controllerId
* the target associated with the actions
* @return a list of actions associated with the given target
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findActiveActionsByTarget(@NotNull Target target);
+ List findActiveActionsByTarget(@NotEmpty String controllerId);
/**
* Retrieves all inactive {@link Action}s of a specific target ordered by
* action ID.
*
- * @param target
+ * @param controllerId
* the target associated with the actions
* @return a list of actions associated with the given target
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findInActiveActionsByTarget(@NotNull Target target);
+ List findInActiveActionsByTarget(@NotEmpty String controllerId);
/**
* Force cancels given {@link Action} for given {@link Target}. Force
@@ -403,16 +322,19 @@ public interface DeploymentManagement {
* and a cancel request is sent to the target. But however it's not tracked,
* if the targets handles the cancel request or not.
*
- * @param action
+ * @param actionId
* to be canceled
*
* @return generated {@link Action} or null if not active on
* {@link Target}.
* @throws CancelActionNotAllowedException
* in case the given action is not active
+ *
+ * @throws EntityNotFoundException
+ * if action with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- Action forceQuitAction(@NotNull Action action);
+ Action forceQuitAction(@NotNull Long actionId);
/**
* Updates a {@link Action} and forces the {@link Action} if it's not
@@ -425,17 +347,6 @@ public interface DeploymentManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
Action forceTargetAction(@NotNull Long actionId);
- /**
- * Starting an action which is scheduled, e.g. in case of roll out a
- * scheduled action must be started now.
- *
- * @param actionId
- * the the ID of the action to start now.
- * @return the action which has been started
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Action startScheduledAction(@NotNull Long actionId);
-
/**
* Starts all scheduled actions of an RolloutGroup parent.
*
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 6744ce5d5..18c312ac8 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
@@ -81,12 +81,15 @@ public interface DistributionSetManagement {
*
* @param dsIds
* to assign for
- * @param tag
+ * @param tagId
* to assign
* @return list of assigned ds
+ *
+ * @throws EntityNotFoundException
+ * if tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
- List assignTag(@NotEmpty Collection dsIds, @NotNull DistributionSetTag tag);
+ List assignTag(@NotEmpty Collection dsIds, @NotNull Long tagId);
/**
* Count all {@link DistributionSet}s in the repository that are not marked
@@ -101,13 +104,13 @@ public interface DistributionSetManagement {
* Count all {@link DistributionSet}s in the repository that are not marked
* as deleted.
*
- * @param type
+ * @param typeId
* to look for
*
* @return number of {@link DistributionSet}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
- Long countDistributionSetsByType(@NotNull DistributionSetType type);
+ Long countDistributionSetsByType(@NotNull Long typeId);
/**
* @return number of {@link DistributionSetType}s in the repository.
@@ -212,22 +215,22 @@ public interface DistributionSetManagement {
* e.g. findByDeletedFalse())
*
*
- * @param set
+ * @param setId
* to delete
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
- void deleteDistributionSet(@NotNull DistributionSet set);
+ void deleteDistributionSet(@NotNull Long setId);
/**
* Deleted {@link DistributionSet}s by their IDs. That is either a soft
* delete of the entities have been linked to an {@link Action} before or a
* hard delete if not.
*
- * @param distributionSetIDs
+ * @param dsIds
* to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
- void deleteDistributionSet(@NotEmpty Long... distributionSetIDs);
+ void deleteDistributionSet(@NotEmpty Collection dsIds);
/**
* deletes a distribution set meta data entry.
@@ -246,21 +249,24 @@ public interface DistributionSetManagement {
/**
* Deletes or mark as delete in case the type is in use.
*
- * @param type
+ * @param typeId
* to delete
+ *
+ * @throws EntityNotFoundException
+ * if given set does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
- void deleteDistributionSetType(@NotNull DistributionSetType type);
+ void deleteDistributionSetType(@NotNull Long typeId);
/**
* retrieves the distribution set for a given action.
*
- * @param action
+ * @param actionId
* the action associated with the distribution set
* @return the distribution set which is associated with the action
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
- DistributionSet findDistributionSetByAction(@NotNull Action action);
+ DistributionSet findDistributionSetByAction(@NotNull Long actionId);
/**
* Find {@link DistributionSet} based on given ID without details, e.g.
@@ -510,28 +516,13 @@ public interface DistributionSetManagement {
* Checks if a {@link DistributionSet} is currently in use by a target in
* the repository.
*
- * @param distributionSet
+ * @param setId
* to check
*
* @return true if in use
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
- boolean isDistributionSetInUse(@NotNull DistributionSet distributionSet);
-
- /**
- * entity based method call for
- * {@link #toggleTagAssignment(Collection, String)}.
- *
- * @param sets
- * to toggle for
- * @param tag
- * to toggle
- * @return {@link DistributionSetTagAssignmentResult} with all meta data of
- * the assignment outcome.
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
- DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection sets,
- @NotNull DistributionSetTag tag);
+ boolean isDistributionSetInUse(@NotNull Long setId);
/**
* Toggles {@link DistributionSetTag} assignment to given
@@ -553,12 +544,15 @@ public interface DistributionSetManagement {
* Unassign all {@link DistributionSet} from a given
* {@link DistributionSetTag} .
*
- * @param tag
+ * @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 DistributionSetTag tag);
+ List unAssignAllDistributionSetsByTag(@NotNull Long tagId);
/**
* Unassigns a {@link SoftwareModule} form an existing
@@ -571,7 +565,7 @@ public interface DistributionSetManagement {
* @return the updated {@link DistributionSet}.
*
* @throws EntityNotFoundException
- * if given module does not exist
+ * if given module or DS does not exist
*
* @throws EntityReadOnlyException
* if use tries to change the {@link DistributionSet} s while
@@ -586,12 +580,15 @@ public interface DistributionSetManagement {
*
* @param dsId
* to unassign for
- * @param distributionSetTag
+ * @param tagId
* to unassign
* @return the unassigned ds or if no ds is unassigned
+ *
+ * @throws EntityNotFoundException
+ * if set or tag with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
- DistributionSet unAssignTag(@NotNull Long dsId, @NotNull DistributionSetTag distributionSetTag);
+ DistributionSet unAssignTag(@NotNull Long dsId, @NotNull Long tagId);
/**
* Updates existing {@link DistributionSet}.
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 c8d4533d3..8823c00f9 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
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
+import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.model.Rollout;
@@ -51,13 +52,13 @@ public interface RolloutGroupManagement {
*
* @param pageRequest
* the page request to sort and limit the result
- * @param rolloutGroup
+ * @param rolloutGroupId
* rollout group
* @return {@link TargetWithActionStatus} target with action status
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
Page findAllTargetsWithActionStatus(@NotNull PageRequest pageRequest,
- @NotNull RolloutGroup rolloutGroup);
+ @NotNull Long rolloutGroupId);
/**
* Retrieves a single {@link RolloutGroup} by its ID.
@@ -109,20 +110,23 @@ public interface RolloutGroupManagement {
/**
* Get targets of specified rollout group.
*
- * @param rolloutGroup
+ * @param rolloutGroupId
* rollout group
* @param page
* the page request to sort and limit the result
*
* @return Page list of targets of a rollout group
+ *
+ * @throws EntityNotFoundException
+ * if group with ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
- Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page);
+ Page findRolloutGroupTargets(@NotNull Long rolloutGroupId, @NotNull Pageable page);
/**
* Get targets of specified rollout group.
*
- * @param rolloutGroup
+ * @param rolloutGroupId
* rollout group
* @param rsqlParam
* the specification for filtering the targets of a rollout group
@@ -138,7 +142,7 @@ public interface RolloutGroupManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ)
- Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull String rsqlParam,
+ Page findRolloutGroupTargets(@NotNull Long rolloutGroupId, @NotNull String rsqlParam,
@NotNull Pageable pageable);
/**
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
index 738f2ff21..68108622d 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
@@ -290,12 +290,12 @@ public interface RolloutManagement {
*
* @param rolloutId
* the ID of the {@link Rollout}
- * @param rolloutGroup
+ * @param rolloutGroupId
* the ID of the {@link RolloutGroup}
* @return percentage finished
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ)
- float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup);
+ float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull Long rolloutGroupId);
/**
* Pauses a rollout which is currently running. The Rollout switches
@@ -313,10 +313,11 @@ public interface RolloutManagement {
* the rollout to be paused.
*
* @throws EntityNotFoundException
- * if rollout with given ID does not exist
+ * if rollout or group with given ID does not exist
* @throws RolloutIllegalStateException
* if given rollout is not in {@link RolloutStatus#RUNNING}.
* Only running rollouts can be paused.
+ *
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE)
void pauseRollout(@NotNull Long rollout);
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 20cf7e7bd..5307e6f55 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
@@ -175,22 +175,25 @@ public interface SoftwareManagement {
/**
* Deletes or marks as delete in case the type is in use.
*
- * @param type
+ * @param typeId
* to delete
+ *
+ * @throws EntityNotFoundException
+ * not found is type with giben ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
- void deleteSoftwareModuleType(@NotNull SoftwareModuleType type);
+ void deleteSoftwareModuleType(@NotNull Long typeId);
/**
* @param pageable
* the page request to page the result set
- * @param set
+ * @param setId
* to search for
* @return all {@link SoftwareModule}s that are assigned to given
* {@link DistributionSet}.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
- Page findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull DistributionSet set);
+ Page findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull Long setId);
/**
* Filter {@link SoftwareModule}s with given
@@ -238,13 +241,13 @@ public interface SoftwareManagement {
* of the {@link SoftwareModule}
* @param version
* of the {@link SoftwareModule}
- * @param type
+ * @param typeId
* of the {@link SoftwareModule}
* @return the found {@link SoftwareModule} or null
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version,
- @NotNull SoftwareModuleType type);
+ @NotNull Long typeId);
/**
* finds a single software module meta data by its id.
@@ -433,12 +436,8 @@ public interface SoftwareManagement {
* {@link SoftwareModule#getDescription()}
* {@link SoftwareModule#getVendor()}.
*
- * @param moduleId
- * to update
- * @param description
- * to update or null
- * @param vendor
- * to update or null
+ * @param update
+ * contains properties to update
*
* @throws EntityNotFoundException
* if given module does not exist
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java
index 8429e4215..17c92bf03 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java
@@ -16,7 +16,6 @@ import org.eclipse.hawkbit.repository.builder.TargetFilterQueryUpdate;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
-import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -62,7 +61,7 @@ public interface TargetFilterQueryManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- boolean verifyTargetFilterQuerySyntax(String query);
+ boolean verifyTargetFilterQuerySyntax(@NotNull String query);
/**
*
@@ -94,7 +93,7 @@ public interface TargetFilterQueryManagement {
* @return the page with the found {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findTargetFilterQueryByName(@NotNull Pageable pageable, String name);
+ Page findTargetFilterQueryByName(@NotNull Pageable pageable, @NotNull String name);
/**
* Retrieves all target filter query which {@link TargetFilterQuery}.
@@ -107,7 +106,7 @@ public interface TargetFilterQueryManagement {
* @return the page with the found {@link TargetFilterQuery}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findTargetFilterQueryByFilter(@NotNull Pageable pageable, String rsqlFilter);
+ Page findTargetFilterQueryByFilter(@NotNull Pageable pageable, @NotNull String rsqlFilter);
/**
* Retrieves all target filter query which {@link TargetFilterQuery}.
@@ -115,29 +114,18 @@ public interface TargetFilterQueryManagement {
*
* @param pageable
* pagination parameter
- * @param distributionSet
- * the auto assign distribution set
- * @return the page with the found {@link TargetFilterQuery}
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findTargetFilterQueryByAutoAssignDS(@NotNull Pageable pageable,
- DistributionSet distributionSet);
-
- /**
- * Retrieves all target filter query which {@link TargetFilterQuery}.
- *
- *
- * @param pageable
- * pagination parameter
- * @param distributionSet
+ * @param setId
* the auto assign distribution set
* @param rsqlParam
* RSQL filter
* @return the page with the found {@link TargetFilterQuery}
+ *
+ * @throws EntityNotFoundException
+ * if DS with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findTargetFilterQueryByAutoAssignDS(@NotNull Pageable pageable,
- DistributionSet distributionSet, String rsqlParam);
+ Page findTargetFilterQueryByAutoAssignDS(@NotNull Pageable pageable, @NotNull Long setId,
+ String rsqlParam);
/**
* Retrieves all target filter query with auto assign DS which
@@ -185,7 +173,7 @@ public interface TargetFilterQueryManagement {
* provided but not found
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- TargetFilterQuery updateTargetFilterQuery(TargetFilterQueryUpdate update);
+ TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQueryUpdate update);
/**
* updates the {@link TargetFilterQuery#getAutoAssignDistributionSet()}.
@@ -193,7 +181,7 @@ public interface TargetFilterQueryManagement {
* @param queryId
* to be updated
* @param dsId
- * to be updated or null
+ * to be updated or null in order to remove it
* @return the updated {@link TargetFilterQuery}
*
* @throws EntityNotFoundException
@@ -201,6 +189,6 @@ public interface TargetFilterQueryManagement {
* provided but not found
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- TargetFilterQuery updateTargetFilterQueryAutoAssignDS(Long queryId, Long dsId);
+ TargetFilterQuery updateTargetFilterQueryAutoAssignDS(@NotNull Long queryId, Long dsId);
}
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 6befca853..34b1727c9 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
@@ -45,14 +45,17 @@ public interface TargetManagement {
/**
* Assign a {@link TargetTag} assignment to given {@link Target}s.
*
- * @param targetIds
+ * @param controllerIds
* to assign for
- * @param tag
+ * @param tagId
* to assign
* @return list of assigned targets
+ *
+ * @throws EntityNotFoundException
+ * if given tagId does not exist
*/
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- List assignTag(@NotEmpty Collection targetIds, @NotNull TargetTag tag);
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET)
+ List assignTag(@NotEmpty Collection controllerIds, @NotNull Long tagId);
/**
* Counts number of targets with given
@@ -112,22 +115,25 @@ public interface TargetManagement {
/**
* Count {@link TargetFilterQuery}s for given target filter query.
*
- * @param targetFilterQuery
- * {link TargetFilterQuery}
- * @return the found number {@link TargetFilterQuery}s
+ * @param rsqlParam
+ * filter definition in RSQL syntax
+ * @return the found number {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Long countTargetByTargetFilterQuery(@NotEmpty String targetFilterQuery);
+ Long countTargetByTargetFilterQuery(@NotEmpty String rsqlParam);
/**
- * Count {@link TargetFilterQuery}s for given filter parameter.
+ * Count {@link TargetFilterQuery}s for given target filter query.
*
- * @param targetFilterQuery
- * {link TargetFilterQuery}
- * @return the found number {@link TargetFilterQuery}s
+ * @param targetFilterQueryId
+ * {@link TargetFilterQuery#getId()}
+ * @return the found number {@link Target}s
+ *
+ * @throws EntityNotFoundException
+ * if {@link TargetFilterQuery} with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Long countTargetByTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery);
+ Long countTargetByTargetFilterQuery(@NotNull Long targetFilterQueryId);
/**
* Counts all {@link Target}s in the repository.
@@ -169,28 +175,22 @@ public interface TargetManagement {
* Deletes all targets with the given IDs.
*
* @param targetIDs
- * the technical IDs of the targets to be deleted
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
- void deleteTargets(@NotEmpty Long... targetIDs);
-
- /**
- * Deletes all targets with the given IDs.
- *
- * @param targetIDs
- * the technical IDs of the targets to be deleted
+ * the IDs of the targets to be deleted
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
void deleteTargets(@NotEmpty Collection targetIDs);
/**
- * finds all {@link Target#getControllerId()} which are currently in the
- * database.
+ * Deletes target with the given IDs.
*
- * @return all IDs of all {@link Target} in the system
+ * @param controllerID
+ * the ID of the targets to be deleted
+ *
+ * @throws EntityNotFoundException
+ * if target with given ID does not exist
*/
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findAllTargetIds();
+ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET)
+ void deleteTarget(@NotEmpty String controllerID);
/**
* Finds all targets for all the given parameters but returns not the full
@@ -231,13 +231,12 @@ public interface TargetManagement {
*
* @param pageRequest
* the pageRequest to enhance the query for paging and sorting
- * @param targetFilterQuery
- * {@link TargetFilterQuery}
+ * @param rsqlParam
+ * filter definition in RSQL syntax
* @return the found {@link TargetIdName}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- List findAllTargetIdsByTargetFilterQuery(@NotNull Pageable pageRequest,
- @NotNull TargetFilterQuery targetFilterQuery);
+ List findAllTargetIdsByTargetFilterQuery(@NotNull Pageable pageRequest, @NotNull String rsqlParam);
/**
* Finds all targets for all the given parameter {@link TargetFilterQuery}
@@ -248,13 +247,13 @@ public interface TargetManagement {
* the pageRequest to enhance the query for paging and sorting
* @param distributionSetId
* id of the {@link DistributionSet}
- * @param targetFilterQuery
- * {@link TargetFilterQuery}
+ * @param rsqlParam
+ * filter definition in RSQL syntax
* @return a page of the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page findAllTargetsByTargetFilterQueryAndNonDS(@NotNull Pageable pageRequest, Long distributionSetId,
- @NotNull TargetFilterQuery targetFilterQuery);
+ @NotNull String rsqlParam);
/**
* Counts all targets for all the given parameter {@link TargetFilterQuery}
@@ -263,12 +262,12 @@ public interface TargetManagement {
*
* @param distributionSetId
* id of the {@link DistributionSet}
- * @param targetFilterQuery
- * {@link TargetFilterQuery}
+ * @param rsqlParam
+ * filter definition in RSQL syntax
* @return the count of found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Long countTargetsByTargetFilterQueryAndNonDS(Long distributionSetId, @NotNull TargetFilterQuery targetFilterQuery);
+ Long countTargetsByTargetFilterQueryAndNonDS(@NotNull Long distributionSetId, @NotNull String rsqlParam);
/**
* Finds all targets for all the given parameter {@link TargetFilterQuery}
@@ -278,13 +277,13 @@ public interface TargetManagement {
* the pageRequest to enhance the query for paging and sorting
* @param groups
* the list of {@link RolloutGroup}s
- * @param targetFilterQuery
- * RSQL filter
+ * @param rsqlParam
+ * filter definition in RSQL syntax
* @return a page of the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(@NotNull Pageable pageRequest,
- List groups, @NotNull String targetFilterQuery);
+ @NotEmpty Collection groups, @NotNull String rsqlParam);
/**
* Counts all targets for all the given parameter {@link TargetFilterQuery}
@@ -292,13 +291,13 @@ public interface TargetManagement {
*
* @param groups
* the list of {@link RolloutGroup}s
- * @param targetFilterQuery
- * RSQL filter
+ * @param rsqlParam
+ * filter definition in RSQL syntax
* @return count of the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(List groups,
- @NotNull String targetFilterQuery);
+ Long countAllTargetsByTargetFilterQueryAndNotInRolloutGroups(@NotEmpty Collection groups,
+ @NotNull String rsqlParam);
/**
* Finds all targets of the provided {@link RolloutGroup} that have no
@@ -311,7 +310,7 @@ public interface TargetManagement {
* @return the found {@link Target}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findAllTargetsInRolloutGroupWithoutAction(@NotNull Pageable pageRequest, @NotNull RolloutGroup group);
+ Page findAllTargetsInRolloutGroupWithoutAction(@NotNull Pageable pageRequest, @NotNull Long group);
/**
* retrieves {@link Target}s by the assigned {@link DistributionSet} without
@@ -490,13 +489,15 @@ public interface TargetManagement {
* and {@link Target#getActions()} possible based on
* {@link TargetFilterQuery#getQuery()}
*
- * @param targetFilterQuery
- * in string notation
+ * @param rsqlParam
+ * in RSQL notation
+ *
* @param pageable
* pagination parameter
*
* @return the found {@link Target}s, never {@code null}
- *
+ *
+ *
* @throws RSQLParameterUnsupportedFieldException
* if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
@@ -504,20 +505,22 @@ public interface TargetManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Page findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable);
+ Page findTargetsAll(@NotNull String rsqlParam, @NotNull Pageable pageable);
/**
* Retrieves all targets without details, i.e. NO {@link Target#getTags()}
* and {@link Target#getActions()} possible based on
* {@link TargetFilterQuery#getQuery()}
*
- * @param targetFilterQuery
- * the specification for the query
+ * @param targetFilterQueryId
+ * {@link TargetFilterQuery#getId()}
* @param pageable
* pagination parameter
*
* @return the found {@link Target}s, never {@code null}
*
+ * @throws EntityNotFoundException
+ * if {@link TargetFilterQuery} 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}
@@ -525,7 +528,7 @@ public interface TargetManagement {
* if the RSQL syntax is wrong
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
- Slice findTargetsAll(@NotNull TargetFilterQuery targetFilterQuery, @NotNull Pageable pageable);
+ Slice findTargetsByTargetFilterQuery(@NotNull Long targetFilterQueryId, @NotNull Pageable pageable);
/**
* method retrieves all {@link Target}s from the repo in the following
@@ -594,40 +597,33 @@ public interface TargetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection targetIds, @NotEmpty String tagName);
- /**
- * {@link Target} based method call for
- * {@link #toggleTagAssignment(Collection, String)}.
- *
- * @param targets
- * to toggle for
- * @param tag
- * to toggle
- * @return TagAssigmentResult with all meta data of the assignment outcome.
- */
- @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection targets, @NotNull TargetTag tag);
-
/**
* Un-assign all {@link Target} from a given {@link TargetTag} .
*
- * @param tag
+ * @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 TargetTag tag);
+ List unAssignAllTargetsByTag(@NotNull Long targetTagId);
/**
* Un-assign a {@link TargetTag} assignment to given {@link Target}.
*
* @param controllerID
* to un-assign for
- * @param targetTag
+ * @param targetTagId
* to un-assign
* @return the unassigned target or if no target is unassigned
+ *
+ * @throws EntityNotFoundException
+ * if TAG with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
- Target unAssignTag(@NotEmpty String controllerID, @NotNull TargetTag targetTag);
+ Target unAssignTag(@NotEmpty String controllerID, @NotNull Long targetTagId);
/**
* updates the {@link Target}.
@@ -642,5 +638,5 @@ public interface TargetManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR
+ SpringEvalExpressions.IS_CONTROLLER)
- Target updateTarget(TargetUpdate update);
+ Target updateTarget(@NotNull TargetUpdate update);
}
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 b2d54263e..532b55b94 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
@@ -61,11 +61,11 @@ public interface ActionRepository extends BaseEntityRepository,
*
* @param pageable
* page parameters
- * @param ds
+ * @param dsId
* the {@link DistributionSet} on which will be filtered
* @return the found {@link Action}s
*/
- Page findByDistributionSet(final Pageable pageable, final JpaDistributionSet ds);
+ Page findByDistributionSetId(final Pageable pageable, final Long dsId);
/**
* Retrieves all {@link Action}s which are referring the given
@@ -73,11 +73,11 @@ public interface ActionRepository extends BaseEntityRepository,
*
* @param pageable
* page parameters
- * @param target
+ * @param controllerId
* the target to find assigned actions
* @return the found {@link Action}s
*/
- Slice findByTarget(Pageable pageable, JpaTarget target);
+ Slice findByTargetControllerId(Pageable pageable, String controllerId);
/**
* Retrieves all {@link Action}s which are active and referring to the given
@@ -97,7 +97,7 @@ public interface ActionRepository extends BaseEntityRepository,
*
* @param sort
* order
- * @param target
+ * @param controllerId
* the target to find assigned actions
* @param active
* the action active flag
@@ -105,7 +105,7 @@ public interface ActionRepository extends BaseEntityRepository,
* @return the found {@link Action}
*/
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
- Optional findFirstByTargetAndActive(final Sort sort, final JpaTarget target, boolean active);
+ Optional findFirstByTargetControllerIdAndActive(final Sort sort, final String controllerId, boolean active);
/**
* Retrieves latest {@link Action} for given target and
@@ -162,8 +162,8 @@ public interface ActionRepository extends BaseEntityRepository,
* @return a list of actions ordered by action ID
*/
@EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD)
- @Query("Select a from JpaAction a where a.target = :target and a.active= :active order by a.id")
- List findByActiveAndTarget(@Param("target") JpaTarget target, @Param("active") boolean active);
+ @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);
/**
* Switches the status of actions from one specific status into another,
@@ -203,11 +203,11 @@ public interface ActionRepository extends BaseEntityRepository,
/**
* Counts all {@link Action}s referring to the given target.
*
- * @param target
+ * @param controllerId
* the target to count the {@link Action}s
* @return the count of actions referring to the given target
*/
- Long countByTarget(JpaTarget target);
+ Long countByTargetControllerId(String controllerId);
/**
* Counts all {@link Action}s referring to the given DistributionSet.
@@ -216,7 +216,7 @@ public interface ActionRepository extends BaseEntityRepository,
* DistributionSet to count the {@link Action}s from
* @return the count of actions referring to the given distributionSet
*/
- Long countByDistributionSet(JpaDistributionSet distributionSet);
+ Long countByDistributionSetId(Long distributionSet);
/**
* Counts all actions referring to a given rollout and rolloutgroup which
@@ -303,13 +303,13 @@ public interface ActionRepository extends BaseEntityRepository,
/**
* Retrieves all actions for a specific rollout and in a specific status.
*
- * @param rollout
+ * @param rolloutId
* the rollout the actions beglong to
* @param actionStatus
* the status of the actions
* @return the actions referring a specific rollout an in a specific status
*/
- List findByRolloutAndStatus(JpaRollout rollout, Status actionStatus);
+ List findByRolloutIdAndStatus(Long rolloutId, Status actionStatus);
/**
* Get list of objects which has details of status and count of targets in
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java
index d9c282c19..00af2653a 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java
@@ -44,11 +44,11 @@ public interface ActionStatusRepository
*
* @param pageReq
* parameters
- * @param action
+ * @param actionId
* of the status entries
* @return pages list of {@link ActionStatus} entries
*/
- Page findByAction(Pageable pageReq, JpaAction action);
+ Page findByActionId(Pageable pageReq, Long actionId);
/**
* Finds all status updates for the defined action and target including
@@ -58,11 +58,11 @@ public interface ActionStatusRepository
* for page configuration
* @param target
* to look for
- * @param action
+ * @param actionId
* to look for
* @return Page with found targets
*/
@EntityGraph(value = "ActionStatus.withMessages", type = EntityGraphType.LOAD)
- Page getByAction(Pageable pageReq, JpaAction action);
+ Page getByActionId(Pageable pageReq, Long actionId);
}
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 1908af1f9..e31aa209a 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
@@ -11,10 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
import java.util.Collection;
import java.util.List;
-import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
-import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -89,7 +87,7 @@ public interface DistributionSetRepository
* @return list of {@link DistributionSet#getId()}
*/
@Query("select ac.distributionSet.id from JpaAction ac where ac.distributionSet.id in :ids")
- List findAssignedToTargetDistributionSetsById(@Param("ids") Long... ids);
+ List findAssignedToTargetDistributionSetsById(@Param("ids") Collection ids);
/**
* Finds {@link DistributionSet}s based on given ID that are assigned yet to
@@ -100,7 +98,7 @@ public interface DistributionSetRepository
* @return list of {@link DistributionSet#getId()}
*/
@Query("select ra.distributionSet.id from JpaRollout ra where ra.distributionSet.id in :ids")
- List findAssignedToRolloutDistributionSetsById(@Param("ids") Long... ids);
+ List findAssignedToRolloutDistributionSetsById(@Param("ids") Collection ids);
/**
* Finds the distribution set for a specific action.
@@ -109,17 +107,17 @@ public interface DistributionSetRepository
* the action associated with the distribution set to find
* @return the distribution set associated with the given action
*/
- @Query("select DISTINCT d from JpaDistributionSet d join fetch d.modules m join d.actions a where a = :action")
- JpaDistributionSet findByAction(@Param("action") JpaAction action);
+ @Query("select DISTINCT d from JpaDistributionSet d join fetch d.modules m join d.actions a where a.id = :action")
+ JpaDistributionSet findByActionId(@Param("action") Long action);
/**
* Counts {@link DistributionSet} instances of given type in the repository.
*
- * @param type
+ * @param typeId
* to search for
* @return number of found {@link DistributionSet}s
*/
- long countByType(JpaDistributionSetType type);
+ long countByTypeId(Long typeId);
/**
* Counts {@link DistributionSet} with given
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java
index 35a5c8311..bade56ab3 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa;
import java.io.InputStream;
import java.util.List;
+import java.util.Optional;
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
import org.eclipse.hawkbit.artifact.repository.ArtifactStoreException;
@@ -104,10 +105,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
- public boolean clearArtifactBinary(final Artifact existing) {
+ public boolean clearArtifactBinary(final Long existing) {
+ return clearArtifactBinary(Optional.ofNullable(localArtifactRepository.findOne(existing))
+ .orElseThrow(() -> new EntityNotFoundException("Artifact with given ID" + existing + " not found.")));
+ }
- for (final Artifact lArtifact : localArtifactRepository
- .findByGridFsFileName(((JpaArtifact) existing).getGridFsFileName())) {
+ private boolean clearArtifactBinary(final JpaArtifact existing) {
+
+ for (final Artifact lArtifact : localArtifactRepository.findByGridFsFileName(existing.getGridFsFileName())) {
if (!lArtifact.getSoftwareModule().isDeleted()
&& Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) {
return false;
@@ -115,8 +120,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
try {
- LOG.debug("deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName());
- artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName());
+ LOG.debug("deleting artifact from repository {}", existing.getGridFsFileName());
+ artifactRepository.deleteBySha1(existing.getGridFsFileName());
return true;
} catch (final ArtifactStoreException e) {
throw new ArtifactDeleteFailedException(e);
@@ -166,10 +171,13 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
@Override
- public DbArtifact loadArtifactBinary(final Artifact artifact) {
- final DbArtifact result = artifactRepository.getArtifactBySha1(((JpaArtifact) artifact).getGridFsFileName());
+ public DbArtifact loadArtifactBinary(final Long artifactId) {
+ final JpaArtifact artifact = Optional.ofNullable(localArtifactRepository.findOne(artifactId))
+ .orElseThrow(() -> new EntityNotFoundException("Artifact with given id " + artifactId + " not found."));
+
+ final DbArtifact result = artifactRepository.getArtifactBySha1(artifact.getGridFsFileName());
if (result == null) {
- throw new GridFSDBFileNotFoundException(((JpaArtifact) artifact).getGridFsFileName());
+ throw new GridFSDBFileNotFoundException(artifact.getGridFsFileName());
}
return result;
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 2ad7ef23c..c98d65834 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
@@ -36,6 +36,7 @@ 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.JpaAction_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
@@ -45,7 +46,6 @@ import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus;
-import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo;
@@ -135,12 +135,10 @@ public class JpaControllerManagement implements ControllerManagement {
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public Target updateLastTargetQuery(final String controllerId, final URI address) {
- final Target target = targetRepository.findByControllerId(controllerId);
- if (target == null) {
- throw new EntityNotFoundException(controllerId);
- }
+ final Target target = Optional.ofNullable(targetRepository.findByControllerId(controllerId))
+ .orElseThrow(() -> new EntityNotFoundException("Target with given ID " + controllerId + " not found"));
- return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
+ return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
}
@Override
@@ -158,7 +156,7 @@ public class JpaControllerManagement implements ControllerManagement {
}
@Override
- public boolean hasTargetArtifactAssigned(final String controllerId, final Artifact localArtifact) {
+ public boolean hasTargetArtifactAssigned(final String controllerId, final Long localArtifact) {
final Target target = targetRepository.findByControllerId(controllerId);
if (target == null) {
return false;
@@ -167,7 +165,7 @@ public class JpaControllerManagement implements ControllerManagement {
}
@Override
- public boolean hasTargetArtifactAssigned(final Long targetId, final Artifact localArtifact) {
+ public boolean hasTargetArtifactAssigned(final Long targetId, final Long localArtifact) {
final Target target = targetRepository.findOne(targetId);
if (target == null) {
return false;
@@ -176,10 +174,11 @@ public class JpaControllerManagement implements ControllerManagement {
}
@Override
- public Optional findOldestActiveActionByTarget(final Target target) {
+ public Optional findOldestActiveActionByTarget(final String controllerId) {
// used in favorite to findFirstByTargetAndActiveOrderByIdAsc due to
// DATAJPA-841 issue.
- return actionRepository.findFirstByTargetAndActive(new Sort(Direction.ASC, "id"), (JpaTarget) target, true);
+ return actionRepository.findFirstByTargetControllerIdAndActive(new Sort(Direction.ASC, "id"), controllerId,
+ true);
}
@Override
@@ -208,13 +207,10 @@ public class JpaControllerManagement implements ControllerManagement {
return result;
}
- return updateLastTargetQuery(target.getTargetInfo(), address).getTarget();
+ return updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), address).getTarget();
}
- @Override
- @Modifying
- @Transactional(isolation = Isolation.READ_UNCOMMITTED)
- public TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status,
+ private TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status,
final Long lastTargetQuery, final URI address) {
final JpaTargetInfo mtargetInfo = (JpaTargetInfo) entityManager.merge(targetInfo);
if (status != null) {
@@ -431,22 +427,24 @@ public class JpaControllerManagement implements ControllerManagement {
@Override
@Modifying
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
- public Action registerRetrieved(final Action action, final String message) {
- return handleRegisterRetrieved((JpaAction) action, message);
+ public Action registerRetrieved(final Long actionId, final String message) {
+ return handleRegisterRetrieved(actionId, message);
}
/**
* Registers retrieved status for given {@link Target} and {@link Action} if
* it does not exist yet.
*
- * @param action
+ * @param actionId
* to the handle status for
* @param message
* for the status
* @return the updated action in case the status has been changed to
* {@link Status#RETRIEVED}
*/
- private Action handleRegisterRetrieved(final JpaAction action, final String message) {
+ private Action handleRegisterRetrieved(final Long actionId, final String message) {
+ final JpaAction action = Optional.ofNullable(actionRepository.findById(actionId)).orElseThrow(
+ () -> new EntityNotFoundException("Actionw ith given ID " + actionId + " doesn not exist."));
// do a manual query with CriteriaBuilder to avoid unnecessary field
// queries and an extra
// count query made by spring-data when using pageable requests, we
@@ -458,7 +456,7 @@ public class JpaControllerManagement implements ControllerManagement {
final Root actionStatusRoot = queryActionStatus.from(JpaActionStatus.class);
final CriteriaQuery