You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/08/06 06:35:48 UTC
[incubator-streampipes] 01/03: Fix present exceptions of connenct
worker in ui
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch STREAMPIPES-145
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
commit 15d0c6211c8c9bd9c29e70f60d0a0ecf9668d499
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Wed Aug 5 13:40:26 2020 +0200
Fix present exceptions of connenct worker in ui
---
.../master/management/GuessManagement.java | 55 ++++++++--------------
.../container/master/rest/GuessResource.java | 23 ++-------
.../container/worker/rest/GuessResource.java | 5 +-
.../adapter/exception/WorkerAdapterException.java | 38 +++++++++++++++
.../streampipes/model/message/ErrorMessage.java | 4 ++
.../apache/streampipes/model/message/Message.java | 4 ++
.../streampipes/model/message/Notification.java | 4 ++
7 files changed, 75 insertions(+), 58 deletions(-)
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java
index 886fb60..aac8f65 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/management/GuessManagement.java
@@ -19,13 +19,18 @@
package org.apache.streampipes.connect.container.master.management;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
import org.apache.http.client.fluent.Request;
+import org.apache.http.client.fluent.Response;
import org.apache.http.entity.ContentType;
+import org.apache.http.util.EntityUtils;
import org.apache.streampipes.connect.adapter.exception.AdapterException;
import org.apache.streampipes.connect.adapter.exception.ParseException;
+import org.apache.streampipes.connect.adapter.exception.WorkerAdapterException;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.connect.guess.GuessSchema;
-import org.apache.streampipes.model.message.Message;
+import org.apache.streampipes.model.message.ErrorMessage;
import org.apache.streampipes.serializers.json.JacksonSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,17 +39,13 @@ import java.io.IOException;
public class GuessManagement {
- private String errorMessage = "Sorry, something went wrong! Hit the feedback button (top right corner) to ask for help. If you think you've found a bug, fill an issue on our Github Page";
-
private static Logger LOG = LoggerFactory.getLogger(GuessManagement.class);
- private WorkerAdministrationManagement workerAdministrationManagement;
-
public GuessManagement() {
- this.workerAdministrationManagement = new WorkerAdministrationManagement();
+
}
- public GuessSchema guessSchema(AdapterDescription adapterDescription) throws AdapterException, ParseException {
+ public GuessSchema guessSchema(AdapterDescription adapterDescription) throws AdapterException, ParseException, WorkerAdapterException {
String workerUrl = new Utils().getWorkerUrl(adapterDescription);
workerUrl = workerUrl + "api/v1/admin@streampipes.de/worker/guess/schema";
@@ -54,45 +55,29 @@ public class GuessManagement {
try {
String ad = mapper.writeValueAsString(adapterDescription);
LOG.info("Guess schema at: " + workerUrl);
- String responseString = Request.Post(workerUrl)
+ Response requestResponse = Request.Post(workerUrl)
.bodyString(ad, ContentType.APPLICATION_JSON)
.connectTimeout(1000)
.socketTimeout(100000)
- .execute().returnContent().asString();
+ .execute();
- GuessSchema guessSchema = mapper.readValue(responseString, GuessSchema.class);
+ HttpResponse httpResponse = requestResponse.returnResponse();
+ String responseString = EntityUtils.toString(httpResponse.getEntity());
- if (guessSchema.getEventSchema() != null) {
+ if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
+ GuessSchema guessSchema = mapper.readValue(responseString, GuessSchema.class);
return guessSchema;
- } else {
- Message errorMessage = mapper.readValue(responseString, Message.class);
- if (errorMessage.getNotifications() != null && errorMessage.getNotifications().get(0) != null) {
- throw new AdapterException(errorMessage.getNotifications().get(0).getTitle());
- } else {
- throw new AdapterException("There was an error while guessing the schema in the worker with the URL: " + workerUrl + "\n" +
- errorMessage);
- }
-
+ } else {
+ ErrorMessage errorMessage = mapper.readValue(responseString, ErrorMessage.class);
+ LOG.error(errorMessage.getElementName());
+ throw new WorkerAdapterException(errorMessage);
}
-
} catch (IOException e) {
- e.printStackTrace();
- throw new AdapterException("Connect Worker: " + workerUrl + " is currently not available.\n" +
- errorMessage);
+ LOG.error(e.getMessage());
+ throw new AdapterException("Error in connect worker: " + workerUrl, e);
}
}
- public void guessFormat() {
- // TODO implement
- }
-
-
- public void guessFormatDescription() {
- // TODO implement
- }
-
-
-
}
diff --git a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/GuessResource.java b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/GuessResource.java
index da2eeed..0e78560 100644
--- a/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/GuessResource.java
+++ b/streampipes-connect-container-master/src/main/java/org/apache/streampipes/connect/container/master/rest/GuessResource.java
@@ -19,6 +19,7 @@
package org.apache.streampipes.connect.container.master.rest;
import org.apache.streampipes.connect.adapter.exception.ParseException;
+import org.apache.streampipes.connect.adapter.exception.WorkerAdapterException;
import org.apache.streampipes.connect.container.master.management.GuessManagement;
import org.apache.streampipes.connect.rest.AbstractContainerResource;
import org.apache.streampipes.model.message.Notifications;
@@ -55,13 +56,14 @@ public class GuessResource extends AbstractContainerResource {
public Response guessSchema(AdapterDescription adapterDescription, @PathParam("username") String userName) {
try {
- //AdapterDescription adapterDescription = AdapterDeserializer.getAdapterDescription(s);
GuessSchema result = guessManagement.guessSchema(adapterDescription);
return ok(result);
} catch (ParseException e) {
logger.error("Error while parsing events: ", e);
return error(Notifications.error(e.getMessage()));
+ } catch (WorkerAdapterException e) {
+ return error(e.getContent());
} catch (Exception e) {
logger.error("Error while guess schema for AdapterDescription: ", e);
return error(Notifications.error(e.getMessage()));
@@ -69,25 +71,6 @@ public class GuessResource extends AbstractContainerResource {
}
- @GET
- @JacksonSerialized
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/format")
- public Response guessFormat() {
- //TODO
- return ok(true);
- }
-
-
- @GET
- @JacksonSerialized
- @Produces(MediaType.APPLICATION_JSON)
- @Path("/formatdescription")
- public Response guessFormatDescription() {
- //TODO
- return ok(true);
- }
-
public void setGuessManagement(GuessManagement guessManagement) {
this.guessManagement = guessManagement;
}
diff --git a/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/GuessResource.java b/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/GuessResource.java
index c88b162..f29596f 100644
--- a/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/GuessResource.java
+++ b/streampipes-connect-container-worker/src/main/java/org/apache/streampipes/connect/container/worker/rest/GuessResource.java
@@ -58,16 +58,15 @@ public class GuessResource extends AbstractContainerResource {
public Response guessSchema(AdapterDescription adapterDescription, @PathParam("username") String userName) {
try {
- //AdapterDescription adapterDescription = AdapterDeserializer.getAdapterDescription(s);
GuessSchema result = guessManagement.guessSchema(adapterDescription);
return ok(result);
} catch (ParseException e) {
logger.error("Error while parsing events: ", e);
- return ok(Notifications.error(e.getMessage()));
+ return error(Notifications.error(e.getMessage()));
} catch (Exception e) {
logger.error("Error while guess schema for AdapterDescription: " + adapterDescription.getAdapterId(), e);
- return ok(Notifications.error(e.getMessage()));
+ return error(Notifications.error(e.getMessage()));
}
}
diff --git a/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/exception/WorkerAdapterException.java b/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/exception/WorkerAdapterException.java
new file mode 100644
index 0000000..d3173aa
--- /dev/null
+++ b/streampipes-connect/src/main/java/org/apache/streampipes/connect/adapter/exception/WorkerAdapterException.java
@@ -0,0 +1,38 @@
+/*
+Copyright 2020 FZI Forschungszentrum Informatik
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package org.apache.streampipes.connect.adapter.exception;
+
+import org.apache.streampipes.model.message.Message;
+
+public class WorkerAdapterException extends Exception {
+ private Message content;
+ public WorkerAdapterException() {}
+
+ public WorkerAdapterException(Message message)
+ {
+ super(message.getElementName());
+ this.content = message;
+ }
+
+ public WorkerAdapterException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public Message getContent() {
+ return content;
+ }
+}
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/message/ErrorMessage.java b/streampipes-model/src/main/java/org/apache/streampipes/model/message/ErrorMessage.java
index 4faf560..890043f 100644
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/message/ErrorMessage.java
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/message/ErrorMessage.java
@@ -25,6 +25,10 @@ import java.util.List;
@TsModel
public class ErrorMessage extends Message {
+ public ErrorMessage() {
+ super();
+
+ }
public ErrorMessage(Notification...notifications) {
super(false, notifications);
}
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/message/Message.java b/streampipes-model/src/main/java/org/apache/streampipes/model/message/Message.java
index 0a5ae50..a3c2740 100644
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/message/Message.java
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/message/Message.java
@@ -39,6 +39,10 @@ public abstract class Message {
private List<Notification> notifications;
+ public Message(){
+
+ }
+
public Message(boolean success){
this.success = success;
this.notifications = null;
diff --git a/streampipes-model/src/main/java/org/apache/streampipes/model/message/Notification.java b/streampipes-model/src/main/java/org/apache/streampipes/model/message/Notification.java
index cea965f..e73e524 100644
--- a/streampipes-model/src/main/java/org/apache/streampipes/model/message/Notification.java
+++ b/streampipes-model/src/main/java/org/apache/streampipes/model/message/Notification.java
@@ -24,6 +24,10 @@ public class Notification {
private String description;
private String additionalInformation;
+ public Notification() {
+
+ }
+
public Notification(String title, String description) {
super();
this.title = title;