Implementation of controller example client
Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -37,19 +37,25 @@
|
||||
<groupId>com.netflix.feign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
<!-- need to overwrite for the interface inheritance feature of feign-core -->
|
||||
<version>8.16.0</version>
|
||||
<!-- <version>8.16.0</version> -->
|
||||
<version>8.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.feign</groupId>
|
||||
<artifactId>feign-jackson</artifactId>
|
||||
<!-- need to overwrite for the interface inheritance feature of feign-core -->
|
||||
<version>8.16.0</version>
|
||||
<!-- <version>8.16.0</version> -->
|
||||
<version>8.14.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<!-- <scope>provided</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.plugin</groupId>
|
||||
<artifactId>spring-plugin-core</artifactId>
|
||||
</dependency>
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -22,6 +22,8 @@ public class ApplicationJsonRequestHeaderInterceptor implements RequestIntercept
|
||||
@Override
|
||||
public void apply(final RequestTemplate template) {
|
||||
template.header("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
// template.header("Accept",
|
||||
// EnableHypermediaSupport.HypermediaType.HAL);
|
||||
template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,10 @@ package org.eclipse.hawkbit.ddi.client;
|
||||
|
||||
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||
import org.springframework.cloud.netflix.feign.support.ResponseEntityDecoder;
|
||||
import org.springframework.hateoas.hal.Jackson2HalModule;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Feign.Builder;
|
||||
@@ -26,12 +30,18 @@ public class DdiDefaultFeignClient {
|
||||
private final String tenant;
|
||||
|
||||
public DdiDefaultFeignClient(final String baseUrl, final String tenant) {
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper()
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
.registerModule(new Jackson2HalModule());
|
||||
|
||||
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL)
|
||||
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder())
|
||||
.decoder(new ResponseEntityDecoder(new JacksonDecoder()));
|
||||
.decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)));
|
||||
this.baseUrl = baseUrl;
|
||||
this.tenant = tenant;
|
||||
|
||||
}
|
||||
|
||||
public Builder getFeignBuilder() {
|
||||
|
||||
@@ -3,36 +3,55 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.client;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Component
|
||||
public class DdiExampleClient {
|
||||
import org.eclipse.hawkbit.ddi.json.model.DdiControllerBase;
|
||||
import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
//@Component
|
||||
public class DdiExampleClient implements Runnable {
|
||||
|
||||
private final String controllerId;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String baseUrl;
|
||||
|
||||
final DdiDefaultFeignClient ddiDefaultFeignClient;
|
||||
|
||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String name,
|
||||
final String description, final String tenant) {
|
||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant) {
|
||||
super();
|
||||
this.controllerId = controllerId;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.baseUrl = baseUrl;
|
||||
ddiDefaultFeignClient = new DdiDefaultFeignClient(baseUrl, tenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
ResponseEntity<DdiControllerBase> response;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
|
||||
response = ddiDefaultFeignClient.getRootControllerResourceClient().getControllerBase(controllerId);
|
||||
final DdiControllerBase controllerBase = response.getBody();
|
||||
final Link controllerDeploymentBaseLink = controllerBase.getLink("deploymentBase");
|
||||
|
||||
if (controllerDeploymentBaseLink != null) {
|
||||
// TOD actung download nur einmal starten
|
||||
startDownload(controllerDeploymentBaseLink);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (final InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void startDdiClient() {
|
||||
|
||||
// final ResponseEntity<DdiControllerBase> response =
|
||||
|
||||
ddiDefaultFeignClient.getRootControllerResourceClient().getControllerBase(controllerId);
|
||||
|
||||
// final DdiControllerBase controllerBase = response.getBody();
|
||||
|
||||
System.out.println("test");
|
||||
//
|
||||
|
||||
// TODO notify every 10 seconds on the rollout server
|
||||
|
||||
@@ -42,4 +61,32 @@ public class DdiExampleClient {
|
||||
|
||||
}
|
||||
|
||||
private void startDownload(final Link controllerDeploymentBaseLink) {
|
||||
|
||||
// controllerDeploymentBaseLink.
|
||||
|
||||
// final List<String> varibles = controllerDeploymentBaseLink.get
|
||||
|
||||
final String link = controllerDeploymentBaseLink.getHref();
|
||||
final String[] segs = link.split(Pattern.quote("/"));
|
||||
final String[] ending = segs[8].split(Pattern.quote("?"));
|
||||
final String actionId = ending[0];
|
||||
final String resource = ending[1].substring(2);
|
||||
|
||||
final ResponseEntity<DdiDeploymentBase> respone = ddiDefaultFeignClient.getRootControllerResourceClient()
|
||||
.getControllerBasedeploymentAction(controllerId, Long.valueOf(actionId), Integer.valueOf(resource));
|
||||
|
||||
final DdiDeploymentBase ddiDeploymentBase = respone.getBody();
|
||||
|
||||
final Link downloadLink = ddiDeploymentBase.getDeployment().getChunks().get(0).getArtifacts().get(0)
|
||||
.getLink("download");
|
||||
|
||||
System.out.println("download startet ....");
|
||||
|
||||
}
|
||||
|
||||
private void startSimulatedInstalltion() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
/**
|
||||
* Client binding for the Rootcontroller resource of the DDI API.
|
||||
*/
|
||||
|
||||
@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClient.PATH)
|
||||
public interface RootControllerResourceClient extends DdiRootControllerRestApi {
|
||||
|
||||
|
||||
@@ -11,9 +11,10 @@ public class AppTest {
|
||||
@Test
|
||||
public void AppTest() {
|
||||
|
||||
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "mytest", "mytest", "desc",
|
||||
"DEFAULT");
|
||||
ddiClient.startDdiClient();
|
||||
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "jktest", "DEFAULT");
|
||||
ddiClient.run();
|
||||
|
||||
System.out.println("next steps........................");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,15 +18,19 @@ import javax.validation.constraints.NotNull;
|
||||
public class DdiChunk {
|
||||
|
||||
@NotNull
|
||||
private final String part;
|
||||
private String part;
|
||||
|
||||
@NotNull
|
||||
private final String version;
|
||||
private String version;
|
||||
|
||||
@NotNull
|
||||
private final String name;
|
||||
private String name;
|
||||
|
||||
private final List<DdiArtifact> artifacts;
|
||||
private List<DdiArtifact> artifacts;
|
||||
|
||||
public DdiChunk() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -8,12 +8,20 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Standard configuration for the target.
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiConfig {
|
||||
|
||||
private final DdiPolling polling;
|
||||
@JsonProperty
|
||||
private DdiPolling polling;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -26,6 +34,10 @@ public class DdiConfig {
|
||||
this.polling = polling;
|
||||
}
|
||||
|
||||
public DdiConfig() {
|
||||
|
||||
}
|
||||
|
||||
public DdiPolling getPolling() {
|
||||
return polling;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,20 @@ package org.eclipse.hawkbit.ddi.json.model;
|
||||
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* {@link DdiControllerBase} resource content.
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiControllerBase extends ResourceSupport {
|
||||
|
||||
private final DdiConfig config;
|
||||
@JsonProperty
|
||||
private DdiConfig config;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -28,6 +36,10 @@ public class DdiControllerBase extends ResourceSupport {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public DdiControllerBase() {
|
||||
|
||||
}
|
||||
|
||||
public DdiConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
*/
|
||||
public class DdiDeployment {
|
||||
|
||||
private final HandlingType download;
|
||||
private HandlingType download;
|
||||
|
||||
private final HandlingType update;
|
||||
private HandlingType update;
|
||||
|
||||
private final List<DdiChunk> chunks;
|
||||
private List<DdiChunk> chunks;
|
||||
|
||||
public DdiDeployment() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -21,10 +21,10 @@ public class DdiDeploymentBase extends ResourceSupport {
|
||||
|
||||
@JsonProperty("id")
|
||||
@NotNull
|
||||
private final String deplyomentId;
|
||||
private String deplyomentId;
|
||||
|
||||
@NotNull
|
||||
private final DdiDeployment deployment;
|
||||
private DdiDeployment deployment;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -39,6 +39,10 @@ public class DdiDeploymentBase extends ResourceSupport {
|
||||
this.deployment = deployment;
|
||||
}
|
||||
|
||||
public DdiDeploymentBase() {
|
||||
|
||||
}
|
||||
|
||||
public DdiDeployment getDeployment() {
|
||||
return deployment;
|
||||
}
|
||||
|
||||
@@ -8,12 +8,20 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Polling interval for the SP target.
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class DdiPolling {
|
||||
|
||||
private final String sleep;
|
||||
@JsonProperty
|
||||
private String sleep;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -26,6 +34,9 @@ public class DdiPolling {
|
||||
this.sleep = sleep;
|
||||
}
|
||||
|
||||
public DdiPolling() {
|
||||
}
|
||||
|
||||
public String getSleep() {
|
||||
return sleep;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user