From 97f099d1946c493999a5794a6cd0ee6674d03d36 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Tue, 19 Apr 2016 09:10:27 +0200 Subject: [PATCH] Move DDI resources and annotation to module hawkbit-ddi-resource - added missing pathVaraible - added port to download urls and adjusted tests - extended feign management API client - fixed pom test artifacts dependencies Signed-off-by: Jonathan Philip Knoblauch --- .../builder/DistributionSetBuilder.java | 10 +++++ .../api/ArtifactUrlHandlerProperties.java | 2 +- hawkbit-ddi-resource/pom.xml | 11 ++--- .../ddi/resource/ArtifactStoreController.java | 15 ++++--- .../ddi/resource/DataConversionHelper.java | 2 +- .../hawkbit/ddi/resource/RootController.java | 8 ++-- .../ddi/resource/DeploymentBaseTest.java | 44 +++++++++---------- 7 files changed, 48 insertions(+), 44 deletions(-) diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java index 358cff0db..2e2d91928 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost; +import org.eclipse.hawkbit.rest.resource.model.softwaremodule.SoftwareModuleAssigmentRest; import com.google.common.collect.Lists; @@ -23,6 +24,7 @@ public class DistributionSetBuilder { private String name; private String version; private String type; + private final List modules = new ArrayList<>(); /** * @param name @@ -34,6 +36,13 @@ public class DistributionSetBuilder { return this; } + public DistributionSetBuilder moduleByID(final Long id) { + final SoftwareModuleAssigmentRest softwareModuleAssigmentRest = new SoftwareModuleAssigmentRest(); + softwareModuleAssigmentRest.setId(id); + modules.add(softwareModuleAssigmentRest); + return this; + } + /** * @param version * the version of the distribution set @@ -89,6 +98,7 @@ public class DistributionSetBuilder { body.setName(prefixName); body.setVersion(version); body.setType(type); + body.setModules(modules); return body; } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java index 33fe8651e..a1cb8bbd9 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java @@ -17,7 +17,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("hawkbit.artifact.url") public class ArtifactUrlHandlerProperties { private static final String DEFAULT_IP_LOCALHOST = "127.0.0.1"; - private static final String LOCALHOST = "localhost"; + private static final String LOCALHOST = "localhost:8080"; private final Http http = new Http(); private final Https https = new Https(); diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml index 08cd03828..bcc1b4932 100644 --- a/hawkbit-ddi-resource/pom.xml +++ b/hawkbit-ddi-resource/pom.xml @@ -26,11 +26,6 @@ hawkbit-repository ${project.version} - @@ -38,7 +33,7 @@ hawkbit-rest-resource ${project.version} test - tests + tests org.springframework.boot @@ -139,11 +134,11 @@ allure-junit-adaptor test - + org.springframework spring-context-support test - + diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/ArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/ArtifactStoreController.java index 5709c08d3..ec8a994b0 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/ArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/ArtifactStoreController.java @@ -32,16 +32,16 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; /** - * The {@link ArtifactStoreController} of the Rollouts server controller API - * that is queried by the SP target in order to download artifacts independent + * The {@link ArtifactStoreController} of the HawkBit server controller API that + * is queried by the HawkBit target in order to download artifacts independent * of their own individual resource. This is offered in addition to the * {@link RootController#downloadArtifact(String, Long, Long, javax.servlet.http.HttpServletResponse)} * for legacy controllers that can not be fed with a download URI at runtime. - * - * TODO */ @RestController public class ArtifactStoreController implements ArtifactStoreControllerDdiApi { @@ -61,8 +61,9 @@ public class ArtifactStoreController implements ArtifactStoreControllerDdiApi { private HawkbitSecurityProperties securityProperties; @Override - public ResponseEntity downloadArtifactByFilename(final String fileName, final HttpServletResponse response, - final HttpServletRequest request, final String targetid) { + public ResponseEntity downloadArtifactByFilename(@PathVariable("fileName") final String fileName, + final HttpServletResponse response, final HttpServletRequest request, + @AuthenticationPrincipal final String targetid) { ResponseEntity result; final List foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); @@ -99,7 +100,7 @@ public class ArtifactStoreController implements ArtifactStoreControllerDdiApi { } @Override - public ResponseEntity downloadArtifactMD5ByFilename(final String fileName, + public ResponseEntity downloadArtifactMD5ByFilename(@PathVariable("fileName") final String fileName, final HttpServletResponse response) { final List foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/DataConversionHelper.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/DataConversionHelper.java index dd88e7cee..75adebb45 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/DataConversionHelper.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/DataConversionHelper.java @@ -38,7 +38,7 @@ import org.springframework.hateoas.Link; import com.google.common.base.Charsets; /** - * Utility class for the Controller API. + * Utility class for the DDI API. */ public final class DataConversionHelper { diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/RootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/RootController.java index baadc5c42..9fb0fca1d 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/RootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/resource/RootController.java @@ -56,13 +56,11 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** - * The {@link RootController} of the hawkBit server controller API that is - * queried by the hawkBit controller in order to pull {@link Action}s that have - * to be fulfilled and report status updates concerning the {@link Action} - * processing. + * The {@link RootController} of the hawkBit server DDI API that is queried by + * the hawkBit controller in order to pull {@link Action}s that have to be + * fulfilled and report status updates concerning the {@link Action} processing. * * Transactional (read-write) as all queries at least update the last poll time. - * */ @RestController public class RootController implements RootControllerDdiApi { diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/resource/DeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/resource/DeploymentBaseTest.java index 714866274..4b985f5ba 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/resource/DeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/resource/DeploymentBaseTest.java @@ -170,23 +170,23 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) @@ -200,22 +200,22 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", equalTo(artifactSignature.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) @@ -315,12 +315,12 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) @@ -333,22 +333,22 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", equalTo(artifactSignature.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) @@ -445,22 +445,22 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.download-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[0]._links.md5sum-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.MD5SUM"))) @@ -473,23 +473,23 @@ public class DeploymentBaseTest extends AbstractIntegrationTestWithMongoDB { jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1].hashes.sha1", equalTo(artifactSignature.getSha1Hash()))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum.href", - equalTo("https://localhost/" + tenantAware.getCurrentTenant() + equalTo("https://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.download-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature"))) .andExpect(jsonPath("$deployment.chunks[?(@.part==os)][0].artifacts[1]._links.md5sum-http.href", - equalTo("http://localhost/" + tenantAware.getCurrentTenant() + equalTo("http://localhost:8080/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/softwaremodules/" + findDistributionSetByAction.findFirstModuleByType(osType).getId() + "/artifacts/test1.signature.MD5SUM")))