From 8addb05f090f687b0847df861ebd0b8c24d53018 Mon Sep 17 00:00:00 2001 From: Jonathan Philip Knoblauch Date: Tue, 26 Apr 2016 14:57:39 +0200 Subject: [PATCH] Added javadoc and logger to ddi client Signed-off-by: Jonathan Philip Knoblauch --- .../ddi/client/DdiDefaultFeignClient.java | 13 ++++- .../hawkbit/ddi/client/DdiExampleClient.java | 54 ++++++++++++------- .../strategy/DoNotSaveArtifactsStrategy.java | 7 +-- .../client/strategy/PersistenceStrategy.java | 12 ++++- .../strategy/SaveArtifactsStrategy.java | 4 +- 5 files changed, 61 insertions(+), 29 deletions(-) diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java index 7a042d7eb..7c4c87708 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java @@ -18,8 +18,7 @@ import feign.Logger.Level; import feign.jackson.JacksonEncoder; /** - * TODO - * + * Default implementation of DDI client. */ public class DdiDefaultFeignClient { @@ -39,10 +38,20 @@ public class DdiDefaultFeignClient { this.tenant = tenant; } + /** + * Get the feign builder. + * + * @return the feign builder + */ public Builder getFeignBuilder() { return feignBuilder; } + /** + * Get the rootController resource client. + * + * @return the rootController resource client + */ public RootControllerResourceClient getRootControllerResourceClient() { if (rootControllerResourceClient == null) { diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java index ae33f1c39..ad9f086bb 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ddi.client; import java.io.IOException; import java.io.InputStream; +import java.time.LocalDateTime; import java.time.LocalTime; import java.util.ArrayList; import java.util.List; @@ -31,6 +32,9 @@ import org.springframework.hateoas.Link; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +/** + * DDI example client based on defualt DDI feign client. + */ public class DdiExampleClient implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(DdiExampleClient.class); @@ -38,17 +42,26 @@ public class DdiExampleClient implements Runnable { private final String controllerId; private Long actionIdOfLastInstalltion; private final DdiDefaultFeignClient ddiDefaultFeignClient; - private long pollingIntervalInMillis; private final PersistenceStrategy persistenceStrategy; - private STATUS clientStatus; + /** + * Constructor for the DDI example client. + * + * @param baseUrl + * the base url of the hawkBit server + * @param controllerId + * the controller id that will be simulated + * @param tenant + * the tenant + * @param persistenceStrategy + * the persistence strategy for downloading artifacts + */ public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant, - final long pollingIntervalInMillis, final PersistenceStrategy persistenceStrategy) { + final PersistenceStrategy persistenceStrategy) { this.controllerId = controllerId; this.ddiDefaultFeignClient = new DdiDefaultFeignClient(baseUrl, tenant); this.actionIdOfLastInstalltion = null; - this.pollingIntervalInMillis = pollingIntervalInMillis; this.persistenceStrategy = persistenceStrategy; this.clientStatus = STATUS.DOWN; } @@ -56,15 +69,13 @@ public class DdiExampleClient implements Runnable { @Override public void run() { clientStatus = STATUS.UP; - ResponseEntity response = ddiDefaultFeignClient.getRootControllerResourceClient() - .getControllerBase(controllerId); - final String pollingTime = response.getBody().getConfig().getPolling().getSleep(); - final LocalTime localtime = LocalTime.parse(pollingTime); - pollingIntervalInMillis = localtime.toNanoOfDay(); - + ResponseEntity response; while (clientStatus == STATUS.UP) { + LOGGER.info(" Controller {} polling from hawkBit server", controllerId); response = ddiDefaultFeignClient.getRootControllerResourceClient().getControllerBase(controllerId); - // final DdiControllerBase controllerBase = response.getBody(); + final String pollingTime = response.getBody().getConfig().getPolling().getSleep(); + final LocalTime localtime = LocalTime.parse(pollingTime); + final long pollingIntervalInMillis = localtime.toNanoOfDay(); final Link controllerDeploymentBaseLink = response.getBody().getLink("deploymentBase"); if (controllerDeploymentBaseLink != null) { @@ -78,14 +89,15 @@ public class DdiExampleClient implements Runnable { try { Thread.sleep(pollingIntervalInMillis); - System.out.println("polling ..."); } catch (final InterruptedException e) { LOGGER.error("Error during sleep"); } } - } + /** + * Stop the DDI example client + */ public void stop() { clientStatus = STATUS.DOWN; } @@ -112,12 +124,12 @@ public class DdiExampleClient implements Runnable { sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, "Starting download of artifact " + artifact); - System.out.println("Starting download for artifact " + artifact); + LOGGER.info("Starting download of artifact " + artifact); final ResponseEntity responseDownloadArtifact = ddiDefaultFeignClient .getRootControllerResourceClient().downloadArtifact(controllerId, softwareModuleId, artifact); final HttpStatus statsuCode = responseDownloadArtifact.getStatusCode(); - System.out.println("Finished download with stataus " + statsuCode); + LOGGER.info("Finished download with stataus {}", statsuCode); try { persistenceStrategy.handleInputStream(responseDownloadArtifact.getBody(), artifact); @@ -138,12 +150,11 @@ public class DdiExampleClient implements Runnable { final List details = new ArrayList<>(); details.add(message); final DdiStatus ddiStatus = new DdiStatus(executionStatus, result, details); - final String time = null; + final String time = String.valueOf(LocalDateTime.now()); final DdiActionFeedback feedback = new DdiActionFeedback(actionId, time, ddiStatus); - final ResponseEntity response = ddiDefaultFeignClient.getRootControllerResourceClient() - .postBasedeploymentActionFeedback(feedback, controllerId, actionId); - final HttpStatus statsuCode = response.getStatusCode(); - System.out.println("Message send with stataus " + statsuCode); + ddiDefaultFeignClient.getRootControllerResourceClient().postBasedeploymentActionFeedback(feedback, controllerId, + actionId); + LOGGER.info("Sent feedback message to HaktBit"); } private void simulateSuccessfulInstallation(final Long actionId) { @@ -166,6 +177,9 @@ public class DdiExampleClient implements Runnable { return segments[8].split(Pattern.quote("?")); } + /** + * Enum for DDI running status. + */ public enum STATUS { UP, DOWN; diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java index 0e9ea82e1..80743c99e 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java @@ -8,16 +8,17 @@ */ package org.eclipse.hawkbit.ddi.client.strategy; +import java.io.IOException; import java.io.InputStream; /** - * @author Jonathan Knoblauch - * + * Implementation of {@link PersistenceStrategy} for not downloading any + * artifacts. */ public class DoNotSaveArtifactsStrategy implements PersistenceStrategy { @Override - public void handleInputStream(final InputStream in, final String artifactName) { + public void handleInputStream(final InputStream in, final String artifactName) throws IOException { // do nothing } diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java index c8080a1d6..e5a3a60d0 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java @@ -12,11 +12,19 @@ import java.io.IOException; import java.io.InputStream; /** - * @author Jonathan Knoblauch - * + * Interface of persistence strategy. */ public interface PersistenceStrategy { + /** + * Method handling the artifact download. + * + * @param in + * the input stream + * @param artifactName + * the name of the artifact + * @throws IOException + */ public void handleInputStream(InputStream in, String artifactName) throws IOException; } diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java index dbf13ef9c..2ae7987cb 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java @@ -18,8 +18,8 @@ import com.google.common.io.ByteStreams; import com.google.common.io.Files; /** - * @author Jonathan Knoblauch - * + * Implementation of {@link PersistenceStrategy} for downloading artifacts to + * the temp directory. */ public class SaveArtifactsStrategy implements PersistenceStrategy {