You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2020/06/28 21:41:27 UTC
[incubator-streampipes] 05/06: [STREAMPIPES-145] Migrate
runtime-resolvable static property
This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch STREAMPIPES-145
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
commit 85c826aa03634985f3624e1c92e5bf1b3db95c88
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Sun Jun 28 15:42:51 2020 +0200
[STREAMPIPES-145] Migrate runtime-resolvable static property
---
.../master/management/WorkerRestClient.java | 10 ++---
.../master/rest/RuntimeResolvableResource.java | 21 +++++-----
.../worker/rest/RuntimeResolvableResource.java | 47 ++++++++--------------
ui/src/app/connect/rest.service.ts | 22 +++++-----
...c-runtime-resolvable-oneof-input.component.html | 6 +--
5 files changed, 43 insertions(+), 63 deletions(-)
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java
index 9d6d4c1..7d0c843 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/WorkerRestClient.java
@@ -24,6 +24,7 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.streampipes.model.connect.grounding.ProtocolDescription;
+import org.apache.streampipes.model.runtime.RuntimeOptionsRequest;
import org.apache.streampipes.serializers.json.JacksonSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -130,20 +131,19 @@ public class WorkerRestClient {
}
- public static RuntimeOptionsResponse getConfiguration(String workerEndpoint, String elementId, String username, String runtimeOptionsRequest) throws AdapterException {
+ public static RuntimeOptionsResponse getConfiguration(String workerEndpoint, String elementId, String username, RuntimeOptionsRequest runtimeOptionsRequest) throws AdapterException {
String element = encodeValue(elementId);
String url = workerEndpoint + "api/v1/" + username + "/worker/resolvable/" + element + "/configurations";
-// url = encodeValue(url);
-// String url = workerEndpoint + "/api/v1/" + username + "/worker/resolvable/abc/configurations";
try {
+ String payload = JacksonSerializer.getObjectMapper().writeValueAsString(runtimeOptionsRequest);
String responseString = Request.Post(url)
- .bodyString(runtimeOptionsRequest, ContentType.APPLICATION_JSON)
+ .bodyString(payload, ContentType.APPLICATION_JSON)
.connectTimeout(1000)
.socketTimeout(100000)
.execute().returnContent().asString();
- return JsonLdUtils.fromJsonLd(responseString, RuntimeOptionsResponse.class);
+ return JacksonSerializer.getObjectMapper().readValue(responseString, RuntimeOptionsResponse.class);
} catch (IOException e) {
e.printStackTrace();
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/RuntimeResolvableResource.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/RuntimeResolvableResource.java
index fa6b2b9..60e3566 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/RuntimeResolvableResource.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/RuntimeResolvableResource.java
@@ -22,15 +22,12 @@ import org.apache.streampipes.connect.adapter.exception.AdapterException;
import org.apache.streampipes.connect.container.master.management.WorkerAdministrationManagement;
import org.apache.streampipes.connect.container.master.management.WorkerRestClient;
import org.apache.streampipes.connect.rest.AbstractContainerResource;
+import org.apache.streampipes.model.runtime.RuntimeOptionsRequest;
import org.apache.streampipes.model.runtime.RuntimeOptionsResponse;
-import org.apache.streampipes.rest.shared.annotation.JsonLdSerialized;
-import org.apache.streampipes.rest.shared.util.SpMediaType;
+import org.apache.streampipes.rest.shared.annotation.JacksonSerialized;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/api/v1/{username}/master/resolvable")
@@ -45,12 +42,12 @@ public class RuntimeResolvableResource extends AbstractContainerResource {
@POST
@Path("{id}/configurations")
- @JsonLdSerialized
- @Produces(SpMediaType.JSONLD)
- @Consumes(SpMediaType.JSONLD)
+ @JacksonSerialized
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
public Response fetchConfigurations(@PathParam("id") String elementId,
@PathParam("username") String username,
- String payload) {
+ RuntimeOptionsRequest runtimeOptionsRequest) {
// TODO add solution for formats
// ResolvesContainerProvidedOptions runtimeResolvableOptions = RuntimeResovable.getRuntimeResolvableFormat(elementId);
@@ -60,7 +57,7 @@ public class RuntimeResolvableResource extends AbstractContainerResource {
try {
- RuntimeOptionsResponse result = WorkerRestClient.getConfiguration(workerEndpoint, elementId, username, payload);
+ RuntimeOptionsResponse result = WorkerRestClient.getConfiguration(workerEndpoint, elementId, username, runtimeOptionsRequest);
return ok(result);
} catch (AdapterException e) {
diff --git a/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/RuntimeResolvableResource.java b/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/RuntimeResolvableResource.java
index 722c660..b686e6a 100644
--- a/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/RuntimeResolvableResource.java
+++ b/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/RuntimeResolvableResource.java
@@ -24,49 +24,36 @@ import org.apache.streampipes.container.api.ResolvesContainerProvidedOptions;
import org.apache.streampipes.model.runtime.RuntimeOptionsRequest;
import org.apache.streampipes.model.runtime.RuntimeOptionsResponse;
import org.apache.streampipes.model.staticproperty.Option;
-import org.apache.streampipes.rest.shared.annotation.JsonLdSerialized;
-import org.apache.streampipes.rest.shared.util.SpMediaType;
+import org.apache.streampipes.rest.shared.annotation.JacksonSerialized;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
-import org.apache.streampipes.serializers.jsonld.JsonLdTransformer;
-import java.io.IOException;
-import java.util.List;
-
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
+import javax.ws.rs.*;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.util.List;
@Path("/api/v1/{username}/worker/resolvable")
public class RuntimeResolvableResource extends AbstractContainerResource {
@POST
@Path("{id}/configurations")
- @JsonLdSerialized
- @Produces(SpMediaType.JSONLD)
+ @JacksonSerialized
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.APPLICATION_JSON)
public Response fetchConfigurations(@PathParam("id") String elementId,
- String payload) {
-
- try {
- RuntimeOptionsRequest runtimeOptionsRequest = new JsonLdTransformer().fromJsonLd(payload,
- RuntimeOptionsRequest.class);
+ RuntimeOptionsRequest runtimeOptionsRequest) {
- ResolvesContainerProvidedOptions adapterClass =
- RuntimeResovable.getRuntimeResolvableAdapter(elementId);
+ ResolvesContainerProvidedOptions adapterClass =
+ RuntimeResovable.getRuntimeResolvableAdapter(elementId);
- List<Option> availableOptions =
- adapterClass.resolveOptions(runtimeOptionsRequest.getRequestId(),
- StaticPropertyExtractor.from(runtimeOptionsRequest.getStaticProperties(),
- runtimeOptionsRequest.getInputStreams(),
- runtimeOptionsRequest.getAppId()));
+ List<Option> availableOptions =
+ adapterClass.resolveOptions(runtimeOptionsRequest.getRequestId(),
+ StaticPropertyExtractor.from(runtimeOptionsRequest.getStaticProperties(),
+ runtimeOptionsRequest.getInputStreams(),
+ runtimeOptionsRequest.getAppId()));
- return ok(new RuntimeOptionsResponse(runtimeOptionsRequest,
- availableOptions));
- } catch (IOException e) {
- e.printStackTrace();
- return fail();
- }
+ return ok(new RuntimeOptionsResponse(runtimeOptionsRequest,
+ availableOptions));
}
}
diff --git a/ui/src/app/connect/rest.service.ts b/ui/src/app/connect/rest.service.ts
index 08cf1ce..d156808 100644
--- a/ui/src/app/connect/rest.service.ts
+++ b/ui/src/app/connect/rest.service.ts
@@ -54,19 +54,15 @@ export class RestService {
}
fetchRemoteOptions(resolvableOptionsParameterRequest: any, adapterId: string): Observable<RuntimeOptionsResponse> {
- let promise = new Promise<RuntimeOptionsResponse>((resolve, reject) => {
- this.http.post("/streampipes-connect/api/v1/"
- + this.authStatusService.email
- + "/master/resolvable/"
- + encodeURIComponent(adapterId)
- + "/configurations", resolvableOptionsParameterRequest)
- .pipe(map(response => {
- let resp = response as RuntimeOptionsResponse;
- resolve(resp);
- })).subscribe();
- });
- return from(promise);
-
+ resolvableOptionsParameterRequest["@class"] = "org.apache.streampipes.model.runtime.RuntimeOptionsRequest";
+ return this.http.post("/streampipes-connect/api/v1/"
+ + this.authStatusService.email
+ + "/master/resolvable/"
+ + encodeURIComponent(adapterId)
+ + "/configurations", resolvableOptionsParameterRequest)
+ .pipe(map(response => {
+ return RuntimeOptionsResponse.fromData(response as RuntimeOptionsResponse);
+ }));
}
addAdapterDescription(adapter: AdapterDescription, url: String): Observable<Message> {
diff --git a/ui/src/app/connect/static-properties/static-runtime-resolvable-oneof-input/static-runtime-resolvable-oneof-input.component.html b/ui/src/app/connect/static-properties/static-runtime-resolvable-oneof-input/static-runtime-resolvable-oneof-input.component.html
index ea17ad5..26bf91d 100644
--- a/ui/src/app/connect/static-properties/static-runtime-resolvable-oneof-input/static-runtime-resolvable-oneof-input.component.html
+++ b/ui/src/app/connect/static-properties/static-runtime-resolvable-oneof-input/static-runtime-resolvable-oneof-input.component.html
@@ -27,7 +27,7 @@
<div fxFlex fxLayout="row">
<div fxLayout="column" *ngIf="showOptions || staticProperty.options" style="margin-left: 10px">
<mat-radio-button *ngFor="let option of staticProperty.options"
- (click)="select(option.id)" [checked]="option.selected">
+ (click)="select(option.elementId)" [checked]="option.selected">
<label style="font-weight: normal">
{{option.name}}
</label>
@@ -47,8 +47,8 @@
<mat-label>{{staticProperty.label}}</mat-label>
<span matPrefix *ngIf="loading"><mat-spinner style="top:5px" [diameter]="20"></mat-spinner></span>
<mat-select>
- <mat-option *ngFor="let option of staticProperty.options" [value]="option.id"
- (click)="select(option.id)">
+ <mat-option *ngFor="let option of staticProperty.options" [value]="option.elementId"
+ (click)="select(option.elementId)">
<label style="font-weight: normal">
{{option.name}}
</label>