Fixed sonar issues and added javadoc
Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -73,16 +73,14 @@
|
|||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
<artifactId>commons-lang</artifactId>
|
<artifactId>commons-lang</artifactId>
|
||||||
<version>2.3</version>
|
<version>2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
|
||||||
*
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*/
|
|
||||||
package org.eclipse.hawkbit.ddi.client;
|
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
|
|
||||||
import feign.RequestInterceptor;
|
|
||||||
import feign.RequestTemplate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class DdiAcceptedRequestInterceptor implements RequestInterceptor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(final RequestTemplate template) {
|
|
||||||
template.header("Accept", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE,
|
|
||||||
MediaType.TEXT_PLAIN_VALUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,9 +20,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import feign.FeignException;
|
|
||||||
import feign.Response;
|
import feign.Response;
|
||||||
import feign.codec.DecodeException;
|
|
||||||
import feign.codec.Decoder;
|
import feign.codec.Decoder;
|
||||||
import feign.jackson.JacksonDecoder;
|
import feign.jackson.JacksonDecoder;
|
||||||
|
|
||||||
@@ -32,8 +30,9 @@ import feign.jackson.JacksonDecoder;
|
|||||||
*/
|
*/
|
||||||
public class DdiDecoder implements Decoder {
|
public class DdiDecoder implements Decoder {
|
||||||
|
|
||||||
ObjectMapper mapper;
|
private static final String OCTET_STREAM = "[application/octet-stream]";
|
||||||
private final String octentTypeOctetStream = "[application/octet-stream]";
|
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
public DdiDecoder() {
|
public DdiDecoder() {
|
||||||
mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
@@ -41,11 +40,11 @@ public class DdiDecoder implements Decoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object decode(final Response response, final Type type) throws IOException, DecodeException, FeignException {
|
public Object decode(final Response response, final Type type) throws IOException {
|
||||||
|
|
||||||
final Map<String, Collection<String>> header = response.headers();
|
final Map<String, Collection<String>> header = response.headers();
|
||||||
final String contentType = String.valueOf(header.get("Content-Type"));
|
final String contentType = String.valueOf(header.get("Content-Type"));
|
||||||
if (contentType.equals(octentTypeOctetStream)) {
|
if (contentType.equals(OCTET_STREAM)) {
|
||||||
return ResponseEntity.ok(response.body().asInputStream());
|
return ResponseEntity.ok(response.body().asInputStream());
|
||||||
}
|
}
|
||||||
final ResponseEntityDecoder responseEntityDecoder = new ResponseEntityDecoder(new JacksonDecoder(mapper));
|
final ResponseEntityDecoder responseEntityDecoder = new ResponseEntityDecoder(new JacksonDecoder(mapper));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ddi.client;
|
|||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor;
|
import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor;
|
||||||
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||||
|
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClientConstants;
|
||||||
import org.eclipse.hawkbit.feign.core.client.ApplicationJsonRequestHeaderInterceptor;
|
import org.eclipse.hawkbit.feign.core.client.ApplicationJsonRequestHeaderInterceptor;
|
||||||
import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract;
|
import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract;
|
||||||
|
|
||||||
@@ -26,26 +27,39 @@ import feign.jackson.JacksonEncoder;
|
|||||||
public class DdiDefaultFeignClient {
|
public class DdiDefaultFeignClient {
|
||||||
|
|
||||||
private RootControllerResourceClient rootControllerResourceClient;
|
private RootControllerResourceClient rootControllerResourceClient;
|
||||||
|
|
||||||
private final Builder feignBuilder;
|
private final Builder feignBuilder;
|
||||||
private final String baseUrl;
|
private final String baseUrl;
|
||||||
private final String tenant;
|
private final String tenant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for default DDI feign client with no authentication.
|
||||||
|
*
|
||||||
|
* @param baseUrl
|
||||||
|
* the base url of the client
|
||||||
|
* @param tenant
|
||||||
|
* the tenant
|
||||||
|
*/
|
||||||
public DdiDefaultFeignClient(final String baseUrl, final String tenant) {
|
public DdiDefaultFeignClient(final String baseUrl, final String tenant) {
|
||||||
this(baseUrl, tenant, null);
|
this(baseUrl, tenant, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for default DDI feign client with authentication.
|
||||||
|
*
|
||||||
|
* @param baseUrl
|
||||||
|
* the base url of the client
|
||||||
|
* @param tenant
|
||||||
|
* the tenant
|
||||||
|
* @param authenticationInterceptor
|
||||||
|
*/
|
||||||
public DdiDefaultFeignClient(final String baseUrl, final String tenant,
|
public DdiDefaultFeignClient(final String baseUrl, final String tenant,
|
||||||
final AuthenticationInterceptor authenticationInterceptor) {
|
final AuthenticationInterceptor authenticationInterceptor) {
|
||||||
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||||
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor())
|
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL)
|
||||||
.requestInterceptor(new DdiAcceptedRequestInterceptor()).logLevel(Level.FULL)
|
|
||||||
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder()).decoder(new DdiDecoder());
|
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder()).decoder(new DdiDecoder());
|
||||||
|
|
||||||
if (authenticationInterceptor != null) {
|
if (authenticationInterceptor != null) {
|
||||||
feignBuilder.requestInterceptor(authenticationInterceptor);
|
feignBuilder.requestInterceptor(authenticationInterceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
Validate.notNull(baseUrl, "A baseUrl has to be set");
|
Validate.notNull(baseUrl, "A baseUrl has to be set");
|
||||||
Validate.notNull(tenant, "A tenant has to be set");
|
Validate.notNull(tenant, "A tenant has to be set");
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
@@ -69,7 +83,7 @@ public class DdiDefaultFeignClient {
|
|||||||
public RootControllerResourceClient getRootControllerResourceClient() {
|
public RootControllerResourceClient getRootControllerResourceClient() {
|
||||||
|
|
||||||
if (rootControllerResourceClient == null) {
|
if (rootControllerResourceClient == null) {
|
||||||
String rootControllerResourcePath = this.baseUrl + RootControllerResourceClient.PATH;
|
String rootControllerResourcePath = this.baseUrl + RootControllerResourceClientConstants.PATH;
|
||||||
rootControllerResourcePath = rootControllerResourcePath.replace("{tenant}", tenant);
|
rootControllerResourcePath = rootControllerResourcePath.replace("{tenant}", tenant);
|
||||||
rootControllerResourceClient = feignBuilder.target(RootControllerResourceClient.class,
|
rootControllerResourceClient = feignBuilder.target(RootControllerResourceClient.class,
|
||||||
rootControllerResourcePath);
|
rootControllerResourcePath);
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ public class DdiExampleClient implements Runnable {
|
|||||||
private final RootControllerResourceClient rootControllerResourceClient;
|
private final RootControllerResourceClient rootControllerResourceClient;
|
||||||
private final ArtifactsPersistenceStrategy persistenceStrategy;
|
private final ArtifactsPersistenceStrategy persistenceStrategy;
|
||||||
private DdiClientStatus clientStatus;
|
private DdiClientStatus clientStatus;
|
||||||
|
|
||||||
private FinalResult finalResultOfCurrentUpdate;
|
private FinalResult finalResultOfCurrentUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +82,8 @@ public class DdiExampleClient implements Runnable {
|
|||||||
* might be {@code null}
|
* might be {@code null}
|
||||||
*/
|
*/
|
||||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
||||||
final ArtifactsPersistenceStrategy persistenceStrategy, final AuthenticationInterceptor authenticationInterceptor) {
|
final ArtifactsPersistenceStrategy persistenceStrategy,
|
||||||
|
final AuthenticationInterceptor authenticationInterceptor) {
|
||||||
this.controllerId = controllerId;
|
this.controllerId = controllerId;
|
||||||
this.rootControllerResourceClient = new DdiDefaultFeignClient(baseUrl, tenant, authenticationInterceptor)
|
this.rootControllerResourceClient = new DdiDefaultFeignClient(baseUrl, tenant, authenticationInterceptor)
|
||||||
.getRootControllerResourceClient();
|
.getRootControllerResourceClient();
|
||||||
@@ -130,22 +130,25 @@ public class DdiExampleClient implements Runnable {
|
|||||||
|
|
||||||
private void startDownload(final Long actionId, final Integer resource) {
|
private void startDownload(final Long actionId, final Integer resource) {
|
||||||
final ResponseEntity<DdiDeploymentBase> respone = rootControllerResourceClient
|
final ResponseEntity<DdiDeploymentBase> respone = rootControllerResourceClient
|
||||||
.getControllerBasedeploymentAction(controllerId, Long.valueOf(actionId), Integer.valueOf(resource));
|
.getControllerBasedeploymentAction(controllerId, actionId, resource);
|
||||||
final DdiDeploymentBase ddiDeploymentBase = respone.getBody();
|
final DdiDeploymentBase ddiDeploymentBase = respone.getBody();
|
||||||
final List<DdiChunk> chunks = ddiDeploymentBase.getDeployment().getChunks();
|
final List<DdiChunk> chunks = ddiDeploymentBase.getDeployment().getChunks();
|
||||||
for (final DdiChunk chunk : chunks) {
|
for (final DdiChunk chunk : chunks) {
|
||||||
final List<DdiArtifact> artifactList = chunk.getArtifacts();
|
downloadArtifacts(chunk, actionId);
|
||||||
if (artifactList.isEmpty()) {
|
}
|
||||||
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
}
|
||||||
"No artifacts to download for softwaremodule " + chunk.getName());
|
|
||||||
} else {
|
|
||||||
for (final DdiArtifact ddiArtifact : artifactList) {
|
|
||||||
if (finalResultOfCurrentUpdate != FinalResult.FAILURE) {
|
|
||||||
downloadArtifact(actionId, ddiArtifact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private void downloadArtifacts(final DdiChunk chunk, final Long actionId) {
|
||||||
|
final List<DdiArtifact> artifactList = chunk.getArtifacts();
|
||||||
|
if (artifactList.isEmpty()) {
|
||||||
|
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
||||||
|
"No artifacts to download for softwaremodule " + chunk.getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (final DdiArtifact ddiArtifact : artifactList) {
|
||||||
|
if (finalResultOfCurrentUpdate != FinalResult.FAILURE) {
|
||||||
|
downloadArtifact(actionId, ddiArtifact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,8 +173,9 @@ public class DdiExampleClient implements Runnable {
|
|||||||
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
||||||
"Downloaded artifact " + artifact);
|
"Downloaded artifact " + artifact);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
|
LOGGER.error("Download of artifact failed", e);
|
||||||
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
||||||
"Downloaded of artifact " + artifact + "failed");
|
"Download of artifact " + artifact + "failed");
|
||||||
finalResultOfCurrentUpdate = FinalResult.FAILURE;
|
finalResultOfCurrentUpdate = FinalResult.FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
|
|||||||
/**
|
/**
|
||||||
* Client binding for the Rootcontroller resource of the DDI API.
|
* Client binding for the Rootcontroller resource of the DDI API.
|
||||||
*/
|
*/
|
||||||
|
@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClientConstants.PATH)
|
||||||
@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClient.PATH)
|
|
||||||
public interface RootControllerResourceClient extends DdiRootControllerRestApi {
|
public interface RootControllerResourceClient extends DdiRootControllerRestApi {
|
||||||
|
|
||||||
static String PATH = "{tenant}/controller/v1";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.ddi.client.resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Constants for RootController resource client.
|
||||||
|
*/
|
||||||
|
public class RootControllerResourceClientConstants {
|
||||||
|
|
||||||
|
public static final String PATH = "{tenant}/controller/v1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
private RootControllerResourceClientConstants() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import java.io.InputStream;
|
|||||||
/**
|
/**
|
||||||
* Interface of persistence strategy.
|
* Interface of persistence strategy.
|
||||||
*/
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
public interface ArtifactsPersistenceStrategy {
|
public interface ArtifactsPersistenceStrategy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user