This is an automated email from the ASF dual-hosted git repository.

imesha pushed a commit to branch development
in repository https://gitbox.apache.org/repos/asf/oodt.git


The following commit(s) were added to refs/heads/development by this push:
     new 6d629df  Added a REST endpoint to check workflow manager status
6d629df is described below

commit 6d629df8eaef930494752b4783db26e6d379e88e
Author: Imesha Sudasingha <[email protected]>
AuthorDate: Sun Sep 22 14:31:59 2019 +0530

    Added a REST endpoint to check workflow manager status
---
 .../resources/WorkflowManagerStatus.java           | 52 ++++++++++++++++++++++
 .../cas/wmservices/services/WMJaxrsServiceV2.java  | 23 ++++++++++
 .../cas/wmservices/servlets/WmServicesServlet.java |  7 +--
 3 files changed, 79 insertions(+), 3 deletions(-)

diff --git 
a/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/resources/WorkflowManagerStatus.java
 
b/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/resources/WorkflowManagerStatus.java
new file mode 100644
index 0000000..bf650b3
--- /dev/null
+++ 
b/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/resources/WorkflowManagerStatus.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.oodt.cas.wmservices.resources;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement(name = "WorkflowManagerStatus")
+@XmlType(propOrder = {"url", "serverUp"})
+public class WorkflowManagerStatus {
+
+  private String url;
+  private boolean serverUp;
+
+  public WorkflowManagerStatus() {}
+
+  public WorkflowManagerStatus(String url, boolean serverUp) {
+    this.url = url;
+    this.serverUp = serverUp;
+  }
+
+  public String getUrl() {
+    return url;
+  }
+
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  public boolean isServerUp() {
+    return serverUp;
+  }
+
+  public void setServerUp(boolean serverUp) {
+    this.serverUp = serverUp;
+  }
+}
diff --git 
a/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/services/WMJaxrsServiceV2.java
 
b/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/services/WMJaxrsServiceV2.java
index 3c8c4ef..8fc78b5 100644
--- 
a/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/services/WMJaxrsServiceV2.java
+++ 
b/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/services/WMJaxrsServiceV2.java
@@ -13,10 +13,12 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import org.apache.oodt.cas.wmservices.enums.ErrorType;
+import org.apache.oodt.cas.wmservices.exceptions.InternalServerErrorException;
 import org.apache.oodt.cas.wmservices.exceptions.NotFoundException;
 import org.apache.oodt.cas.wmservices.resources.WMRequestStatusResource;
 import org.apache.oodt.cas.wmservices.resources.WorkflowInstancePageResource;
 import org.apache.oodt.cas.wmservices.resources.WorkflowInstanceResource;
+import org.apache.oodt.cas.wmservices.resources.WorkflowManagerStatus;
 import org.apache.oodt.cas.workflow.exceptions.WorkflowException;
 import org.apache.oodt.cas.workflow.structs.WorkflowInstance;
 import org.apache.oodt.cas.workflow.structs.WorkflowInstancePage;
@@ -56,6 +58,27 @@ public class WMJaxrsServiceV2 {
   }
 
   /**
+   * Checks if workflow manager is alive
+   *
+   * @return status
+   */
+  @GET
+  @Path("status")
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+  public WorkflowManagerStatus getWorkflowManagerStatus() {
+    try {
+      WorkflowManagerClient client = getContextClient();
+      WorkflowManagerStatus status = new WorkflowManagerStatus();
+      status.setServerUp(client.isAlive());
+      status.setUrl(client.getWorkflowManagerUrl().toString());
+      return status;
+    } catch (WorkflowException e) {
+      logger.error("Error occurred when getting WM client", e);
+      throw new InternalServerErrorException("Unable to get WM client");
+    }
+  }
+
+  /**
    * Gets an HTTP response that represents a {@link WorkflowInstance} from the 
workflow manager.
    *
    * @param workflowInstId the ID of the workflow Instance
diff --git 
a/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/servlets/WmServicesServlet.java
 
b/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/servlets/WmServicesServlet.java
index 065611f..6f1b928 100644
--- 
a/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/servlets/WmServicesServlet.java
+++ 
b/webapp/wmservices/src/main/java/org/apache/oodt/cas/wmservices/servlets/WmServicesServlet.java
@@ -132,11 +132,12 @@ public class WmServicesServlet extends 
CXFNonSpringJaxrsServlet {
     String message;
     try {
       URL url;
-      String urlParameter = context.getInitParameter(DEFAULT_WM_URL);
+      String urlParameter = context.getInitParameter(PARAM_NAME_URL);
 
       /* Get the workflow manager URL from the context parameter. */
-      if (urlParameter != null) url = new 
URL(PathUtils.replaceEnvVariables(urlParameter));
-      else {
+      if (urlParameter != null) {
+        url = new URL(PathUtils.replaceEnvVariables(urlParameter));
+      } else {
         message = "Unable to find a servlet context parameter for the workflow 
manager URL.";
         /* Try the default URL for the Workflow manager. */
         logger.debug("WARNING Exception Thrown: {}", message);

Reply via email to