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>
|
<groupId>com.netflix.feign</groupId>
|
||||||
<artifactId>feign-core</artifactId>
|
<artifactId>feign-core</artifactId>
|
||||||
<!-- need to overwrite for the interface inheritance feature of feign-core -->
|
<!-- 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>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.netflix.feign</groupId>
|
<groupId>com.netflix.feign</groupId>
|
||||||
<artifactId>feign-jackson</artifactId>
|
<artifactId>feign-jackson</artifactId>
|
||||||
<!-- need to overwrite for the interface inheritance feature of feign-core -->
|
<!-- 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>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<!-- <scope>provided</scope> -->
|
<!-- <scope>provided</scope> -->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.plugin</groupId>
|
||||||
|
<artifactId>spring-plugin-core</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public class ApplicationJsonRequestHeaderInterceptor implements RequestIntercept
|
|||||||
@Override
|
@Override
|
||||||
public void apply(final RequestTemplate template) {
|
public void apply(final RequestTemplate template) {
|
||||||
template.header("Accept", MediaType.APPLICATION_JSON_VALUE);
|
template.header("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
// template.header("Accept",
|
||||||
|
// EnableHypermediaSupport.HypermediaType.HAL);
|
||||||
template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
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.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||||
import org.springframework.cloud.netflix.feign.support.ResponseEntityDecoder;
|
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;
|
||||||
import feign.Feign.Builder;
|
import feign.Feign.Builder;
|
||||||
@@ -26,12 +30,18 @@ public class DdiDefaultFeignClient {
|
|||||||
private final String tenant;
|
private final String tenant;
|
||||||
|
|
||||||
public DdiDefaultFeignClient(final String baseUrl, 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())
|
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||||
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL)
|
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL)
|
||||||
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder())
|
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder())
|
||||||
.decoder(new ResponseEntityDecoder(new JacksonDecoder()));
|
.decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)));
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.tenant = tenant;
|
this.tenant = tenant;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder getFeignBuilder() {
|
public Builder getFeignBuilder() {
|
||||||
|
|||||||
@@ -3,36 +3,55 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ddi.client;
|
package org.eclipse.hawkbit.ddi.client;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Component
|
import org.eclipse.hawkbit.ddi.json.model.DdiControllerBase;
|
||||||
public class DdiExampleClient {
|
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 controllerId;
|
||||||
private final String name;
|
|
||||||
private final String description;
|
|
||||||
private final String baseUrl;
|
|
||||||
final DdiDefaultFeignClient ddiDefaultFeignClient;
|
final DdiDefaultFeignClient ddiDefaultFeignClient;
|
||||||
|
|
||||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String name,
|
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant) {
|
||||||
final String description, final String tenant) {
|
|
||||||
super();
|
super();
|
||||||
this.controllerId = controllerId;
|
this.controllerId = controllerId;
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
this.baseUrl = baseUrl;
|
|
||||||
ddiDefaultFeignClient = new DdiDefaultFeignClient(baseUrl, tenant);
|
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() {
|
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
|
// 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.
|
* Client binding for the Rootcontroller resource of the DDI API.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClient.PATH)
|
@FeignClient(url = "${hawkbit.url:localhost:8080}/" + RootControllerResourceClient.PATH)
|
||||||
public interface RootControllerResourceClient extends DdiRootControllerRestApi {
|
public interface RootControllerResourceClient extends DdiRootControllerRestApi {
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ public class AppTest {
|
|||||||
@Test
|
@Test
|
||||||
public void AppTest() {
|
public void AppTest() {
|
||||||
|
|
||||||
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "mytest", "mytest", "desc",
|
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "jktest", "DEFAULT");
|
||||||
"DEFAULT");
|
ddiClient.run();
|
||||||
ddiClient.startDdiClient();
|
|
||||||
|
System.out.println("next steps........................");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,15 +18,19 @@ import javax.validation.constraints.NotNull;
|
|||||||
public class DdiChunk {
|
public class DdiChunk {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String part;
|
private String part;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String version;
|
private String version;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String name;
|
private String name;
|
||||||
|
|
||||||
private final List<DdiArtifact> artifacts;
|
private List<DdiArtifact> artifacts;
|
||||||
|
|
||||||
|
public DdiChunk() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|||||||
@@ -8,12 +8,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ddi.json.model;
|
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.
|
* Standard configuration for the target.
|
||||||
*/
|
*/
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class DdiConfig {
|
public class DdiConfig {
|
||||||
|
|
||||||
private final DdiPolling polling;
|
@JsonProperty
|
||||||
|
private DdiPolling polling;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -26,6 +34,10 @@ public class DdiConfig {
|
|||||||
this.polling = polling;
|
this.polling = polling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DdiConfig() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DdiPolling getPolling() {
|
public DdiPolling getPolling() {
|
||||||
return polling;
|
return polling;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,20 @@ package org.eclipse.hawkbit.ddi.json.model;
|
|||||||
|
|
||||||
import org.springframework.hateoas.ResourceSupport;
|
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.
|
* {@link DdiControllerBase} resource content.
|
||||||
*/
|
*/
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class DdiControllerBase extends ResourceSupport {
|
public class DdiControllerBase extends ResourceSupport {
|
||||||
|
|
||||||
private final DdiConfig config;
|
@JsonProperty
|
||||||
|
private DdiConfig config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -28,6 +36,10 @@ public class DdiControllerBase extends ResourceSupport {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DdiControllerBase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DdiConfig getConfig() {
|
public DdiConfig getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,15 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
|||||||
*/
|
*/
|
||||||
public class DdiDeployment {
|
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.
|
* Constructor.
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ public class DdiDeploymentBase extends ResourceSupport {
|
|||||||
|
|
||||||
@JsonProperty("id")
|
@JsonProperty("id")
|
||||||
@NotNull
|
@NotNull
|
||||||
private final String deplyomentId;
|
private String deplyomentId;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final DdiDeployment deployment;
|
private DdiDeployment deployment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -39,6 +39,10 @@ public class DdiDeploymentBase extends ResourceSupport {
|
|||||||
this.deployment = deployment;
|
this.deployment = deployment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DdiDeploymentBase() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public DdiDeployment getDeployment() {
|
public DdiDeployment getDeployment() {
|
||||||
return deployment;
|
return deployment;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ddi.json.model;
|
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.
|
* Polling interval for the SP target.
|
||||||
*/
|
*/
|
||||||
|
@JsonInclude(Include.NON_NULL)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class DdiPolling {
|
public class DdiPolling {
|
||||||
|
|
||||||
private final String sleep;
|
@JsonProperty
|
||||||
|
private String sleep;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -26,6 +34,9 @@ public class DdiPolling {
|
|||||||
this.sleep = sleep;
|
this.sleep = sleep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DdiPolling() {
|
||||||
|
}
|
||||||
|
|
||||||
public String getSleep() {
|
public String getSleep() {
|
||||||
return sleep;
|
return sleep;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user