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 190ea622b..5945fef5d 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 @@ -19,7 +19,7 @@ import java.util.regex.Pattern; import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor; import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient; -import org.eclipse.hawkbit.ddi.client.strategy.PersistenceStrategy; +import org.eclipse.hawkbit.ddi.client.strategy.ArtifactsPersistenceStrategy; import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback; import org.eclipse.hawkbit.ddi.json.model.DdiArtifact; import org.eclipse.hawkbit.ddi.json.model.DdiChunk; @@ -45,12 +45,12 @@ public class DdiExampleClient implements Runnable { private final String controllerId; private Long actionIdOfLastInstalltion; private final RootControllerResourceClient rootControllerResourceClient; - private final PersistenceStrategy persistenceStrategy; + private final ArtifactsPersistenceStrategy persistenceStrategy; private DdiClientStatus clientStatus; - + private FinalResult finalResultOfCurrentUpdate; - /** + /** * Constructor for the DDI example client. * * @param baseUrl @@ -63,7 +63,7 @@ public class DdiExampleClient implements Runnable { * the persistence strategy for downloading artifacts */ public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant, - final PersistenceStrategy persistenceStrategy) { + final ArtifactsPersistenceStrategy persistenceStrategy) { this(baseUrl, controllerId, tenant, persistenceStrategy, null); } @@ -83,7 +83,7 @@ public class DdiExampleClient implements Runnable { * might be {@code null} */ public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant, - final PersistenceStrategy persistenceStrategy, final AuthenticationInterceptor authenticationInterceptor) { + final ArtifactsPersistenceStrategy persistenceStrategy, final AuthenticationInterceptor authenticationInterceptor) { this.controllerId = controllerId; this.rootControllerResourceClient = new DdiDefaultFeignClient(baseUrl, tenant, authenticationInterceptor) .getRootControllerResourceClient(); @@ -129,26 +129,32 @@ public class DdiExampleClient implements Runnable { } private void startDownload(final Long actionId, final Integer resource) { - final ResponseEntity respone = rootControllerResourceClient .getControllerBasedeploymentAction(controllerId, Long.valueOf(actionId), Integer.valueOf(resource)); final DdiDeploymentBase ddiDeploymentBase = respone.getBody(); final List chunks = ddiDeploymentBase.getDeployment().getChunks(); for (final DdiChunk chunk : chunks) { final List artifactList = chunk.getArtifacts(); - final Link downloadLink = ddiDeploymentBase.getDeployment().getChunks().get(0).getArtifacts().get(0) - .getLink("download-http"); - final String[] downloadLinkSep = downloadLink.getHref().split(Pattern.quote("/")); - final Long softwareModuleId = Long.valueOf(downloadLinkSep[8]); - for (final DdiArtifact ddiArtifact : artifactList) { - if (finalResultOfCurrentUpdate != FinalResult.FAILURE) { - downloadArtifact(actionId, softwareModuleId, ddiArtifact.getFilename()); + 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 downloadArtifact(final Long actionId, final Long softwareModuleId, final String artifact) { + private void downloadArtifact(final Long actionId, final DdiArtifact ddiArtifact) { + + final String artifact = ddiArtifact.getFilename(); + final Link downloadLink = ddiArtifact.getLink("download-http"); + final String[] downloadLinkSep = downloadLink.getHref().split(Pattern.quote("/")); + final Long softwareModuleId = Long.valueOf(downloadLinkSep[8]); sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, "Starting download of artifact " + artifact); 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/ArtifactsPersistenceStrategy.java similarity index 94% rename from examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java rename to examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java index e5a3a60d0..347b01bcc 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/ArtifactsPersistenceStrategy.java @@ -14,7 +14,7 @@ import java.io.InputStream; /** * Interface of persistence strategy. */ -public interface PersistenceStrategy { +public interface ArtifactsPersistenceStrategy { /** * Method handling the artifact download. 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/DoNotSaveArtifacts.java similarity index 80% rename from examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java rename to examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifacts.java index 447885715..7e5d72c4a 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/DoNotSaveArtifacts.java @@ -12,10 +12,10 @@ import java.io.IOException; import java.io.InputStream; /** - * Implementation of {@link PersistenceStrategy} for not downloading any + * Implementation of {@link ArtifactsPersistenceStrategy} for not downloading any * artifacts. */ -public class DoNotSaveArtifactsStrategy implements PersistenceStrategy { +public class DoNotSaveArtifacts implements ArtifactsPersistenceStrategy { @Override public void handleInputStream(final InputStream in, final 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/SaveArtifactsToLocalTempDirectories.java similarity index 84% rename from examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java rename to examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsToLocalTempDirectories.java index 2908ee29f..11ac5698b 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/SaveArtifactsToLocalTempDirectories.java @@ -18,10 +18,10 @@ import com.google.common.io.ByteStreams; import com.google.common.io.Files; /** - * Implementation of {@link PersistenceStrategy} for downloading artifacts to + * Implementation of {@link ArtifactsPersistenceStrategy} for downloading artifacts to * the temp directory. */ -public class SaveArtifactsStrategy implements PersistenceStrategy { +public class SaveArtifactsToLocalTempDirectories implements ArtifactsPersistenceStrategy { @Override public void handleInputStream(final InputStream in, final String artifactName) throws IOException { diff --git a/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java b/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java index 2644f9d28..13eaa66d3 100644 --- a/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java +++ b/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java @@ -1,7 +1,7 @@ package org.eclipse.hawkbit.example.ddi.client; import org.eclipse.hawkbit.ddi.client.DdiExampleClient; -import org.eclipse.hawkbit.ddi.client.strategy.SaveArtifactsStrategy; +import org.eclipse.hawkbit.ddi.client.strategy.SaveArtifactsToLocalTempDirectories; import org.junit.Test; /** @@ -11,8 +11,8 @@ public class AppTest { @Test public void AppTest() { - final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "Einstein15", "DEFAULT", - new SaveArtifactsStrategy()); + final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "Einstein17", "DEFAULT", + new SaveArtifactsToLocalTempDirectories()); final Thread thread = new Thread(ddiClient); thread.run();