New names for persistenceArtifactStrategy interfaces and implementations
Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -19,7 +19,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
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.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.DdiActionFeedback;
|
||||||
import org.eclipse.hawkbit.ddi.json.model.DdiArtifact;
|
import org.eclipse.hawkbit.ddi.json.model.DdiArtifact;
|
||||||
import org.eclipse.hawkbit.ddi.json.model.DdiChunk;
|
import org.eclipse.hawkbit.ddi.json.model.DdiChunk;
|
||||||
@@ -45,12 +45,12 @@ public class DdiExampleClient implements Runnable {
|
|||||||
private final String controllerId;
|
private final String controllerId;
|
||||||
private Long actionIdOfLastInstalltion;
|
private Long actionIdOfLastInstalltion;
|
||||||
private final RootControllerResourceClient rootControllerResourceClient;
|
private final RootControllerResourceClient rootControllerResourceClient;
|
||||||
private final PersistenceStrategy persistenceStrategy;
|
private final ArtifactsPersistenceStrategy persistenceStrategy;
|
||||||
private DdiClientStatus clientStatus;
|
private DdiClientStatus clientStatus;
|
||||||
|
|
||||||
private FinalResult finalResultOfCurrentUpdate;
|
private FinalResult finalResultOfCurrentUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the DDI example client.
|
* Constructor for the DDI example client.
|
||||||
*
|
*
|
||||||
* @param baseUrl
|
* @param baseUrl
|
||||||
@@ -63,7 +63,7 @@ public class DdiExampleClient implements Runnable {
|
|||||||
* the persistence strategy for downloading artifacts
|
* the persistence strategy for downloading artifacts
|
||||||
*/
|
*/
|
||||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
||||||
final PersistenceStrategy persistenceStrategy) {
|
final ArtifactsPersistenceStrategy persistenceStrategy) {
|
||||||
this(baseUrl, controllerId, tenant, persistenceStrategy, null);
|
this(baseUrl, controllerId, tenant, persistenceStrategy, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ 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 PersistenceStrategy 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();
|
||||||
@@ -129,26 +129,32 @@ 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, Long.valueOf(actionId), Integer.valueOf(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();
|
final List<DdiArtifact> artifactList = chunk.getArtifacts();
|
||||||
final Link downloadLink = ddiDeploymentBase.getDeployment().getChunks().get(0).getArtifacts().get(0)
|
if (artifactList.isEmpty()) {
|
||||||
.getLink("download-http");
|
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
||||||
final String[] downloadLinkSep = downloadLink.getHref().split(Pattern.quote("/"));
|
"No artifacts to download for softwaremodule " + chunk.getName());
|
||||||
final Long softwareModuleId = Long.valueOf(downloadLinkSep[8]);
|
} else {
|
||||||
for (final DdiArtifact ddiArtifact : artifactList) {
|
for (final DdiArtifact ddiArtifact : artifactList) {
|
||||||
if (finalResultOfCurrentUpdate != FinalResult.FAILURE) {
|
if (finalResultOfCurrentUpdate != FinalResult.FAILURE) {
|
||||||
downloadArtifact(actionId, softwareModuleId, ddiArtifact.getFilename());
|
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,
|
sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE,
|
||||||
"Starting download of artifact " + artifact);
|
"Starting download of artifact " + artifact);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.io.InputStream;
|
|||||||
/**
|
/**
|
||||||
* Interface of persistence strategy.
|
* Interface of persistence strategy.
|
||||||
*/
|
*/
|
||||||
public interface PersistenceStrategy {
|
public interface ArtifactsPersistenceStrategy {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method handling the artifact download.
|
* Method handling the artifact download.
|
||||||
@@ -12,10 +12,10 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link PersistenceStrategy} for not downloading any
|
* Implementation of {@link ArtifactsPersistenceStrategy} for not downloading any
|
||||||
* artifacts.
|
* artifacts.
|
||||||
*/
|
*/
|
||||||
public class DoNotSaveArtifactsStrategy implements PersistenceStrategy {
|
public class DoNotSaveArtifacts implements ArtifactsPersistenceStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInputStream(final InputStream in, final String artifactName) throws IOException {
|
public void handleInputStream(final InputStream in, final String artifactName) throws IOException {
|
||||||
@@ -18,10 +18,10 @@ import com.google.common.io.ByteStreams;
|
|||||||
import com.google.common.io.Files;
|
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.
|
* the temp directory.
|
||||||
*/
|
*/
|
||||||
public class SaveArtifactsStrategy implements PersistenceStrategy {
|
public class SaveArtifactsToLocalTempDirectories implements ArtifactsPersistenceStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleInputStream(final InputStream in, final String artifactName) throws IOException {
|
public void handleInputStream(final InputStream in, final String artifactName) throws IOException {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.eclipse.hawkbit.example.ddi.client;
|
package org.eclipse.hawkbit.example.ddi.client;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.ddi.client.DdiExampleClient;
|
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;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,8 +11,8 @@ public class AppTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void AppTest() {
|
public void AppTest() {
|
||||||
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "Einstein15", "DEFAULT",
|
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "Einstein17", "DEFAULT",
|
||||||
new SaveArtifactsStrategy());
|
new SaveArtifactsToLocalTempDirectories());
|
||||||
final Thread thread = new Thread(ddiClient);
|
final Thread thread = new Thread(ddiClient);
|
||||||
thread.run();
|
thread.run();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user