trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arvi...@apache.org
Subject [1/2] incubator-trafodion git commit: Add new REST API to display DCS configuration summary
Date Thu, 04 Feb 2016 23:51:47 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 96ce1f35e -> 83983c7c3


Add new REST API to display DCS configuration summary


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/0f800cc6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/0f800cc6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/0f800cc6

Branch: refs/heads/master
Commit: 0f800cc60d0d5e92f74155b9508310fb4a791fee
Parents: 679efee
Author: Venkat Muthuswamy <venkat.muthuswamy@esgyn.com>
Authored: Tue Feb 2 09:55:48 2016 -0800
Committer: Venkat Muthuswamy <venkat.muthuswamy@esgyn.com>
Committed: Tue Feb 2 09:55:48 2016 -0800

----------------------------------------------------------------------
 core/rest/src/main/asciidoc/_chapters/apis.adoc | 20 +++++
 .../java/org/trafodion/rest/ServerResource.java | 94 ++++++++++++++++++++
 2 files changed, 114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/0f800cc6/core/rest/src/main/asciidoc/_chapters/apis.adoc
----------------------------------------------------------------------
diff --git a/core/rest/src/main/asciidoc/_chapters/apis.adoc b/core/rest/src/main/asciidoc/_chapters/apis.adoc
index 4ffb612..d561b85 100644
--- a/core/rest/src/main/asciidoc/_chapters/apis.adoc
+++ b/core/rest/src/main/asciidoc/_chapters/apis.adoc
@@ -284,6 +284,26 @@ curl  -X GET -H "Accept: application/json" http://{hostname}:4200/v1/servers/dcs
 }
 ----
 
+In this example the user wishes to see a summary of the Trafodion DCS configuration.
+The server retrieves this information by executing dcscheck script.
+
+.Http command
+----
+curl  -X GET -H "Accept: application/json" http://{hostname}:4200/v1/servers/dcs/summary
+----
+
+.Response
+----
+{
+  "Cluster Configuration": "HA",
+  "Zookeeper listen port": "2181",
+  "DcsMaster listen port": "23400",
+  "Configured Primary DcsMaster": "\"node1\"",
+  "Configured Backup DcsMasters": "\"node2 node3\"",
+  "Active DcsMaster": "\"node1\", pid 8526"
+}
+----
+
 In this example the user wishes to see the Trafodion DCS server/client connection information.
 The server retrieves this information from ZooKeeper.
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/0f800cc6/core/rest/src/main/java/org/trafodion/rest/ServerResource.java
----------------------------------------------------------------------
diff --git a/core/rest/src/main/java/org/trafodion/rest/ServerResource.java b/core/rest/src/main/java/org/trafodion/rest/ServerResource.java
index 40ab9e1..3f9490f 100644
--- a/core/rest/src/main/java/org/trafodion/rest/ServerResource.java
+++ b/core/rest/src/main/java/org/trafodion/rest/ServerResource.java
@@ -176,6 +176,52 @@ public class ServerResource extends ResourceBase {
 
 	    return jsonObject;
 	}
+	
+	private JSONObject dcscheck() throws IOException {
+	    ScriptContext scriptContext = new ScriptContext();
+	    scriptContext.setScriptName(Constants.SYS_SHELL_SCRIPT_NAME);
+	    scriptContext.setCommand("dcscheck");
+	    scriptContext.setStripStdOut(false);
+	    try {
+	        ScriptManager.getInstance().runScript(scriptContext);//This will block while script
is running
+	    } catch (Exception e) {
+	        e.printStackTrace();
+	        throw new IOException(e);
+	    }
+
+        if(LOG.isDebugEnabled()) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("exit code [" + scriptContext.getExitCode() + "]");
+            if(! scriptContext.getStdOut().toString().isEmpty()) 
+                sb.append(", stdout [" + scriptContext.getStdOut().toString() + "]");
+            if(! scriptContext.getStdErr().toString().isEmpty())
+                sb.append(", stderr [" + scriptContext.getStdErr().toString() + "]");
+            LOG.debug(sb.toString());
+        }
+
+	    JSONObject jsonObject = new JSONObject();
+	    try {
+	        Scanner scanner = new Scanner(scriptContext.getStdOut().toString());
+
+			while (scanner.hasNextLine()) {
+				String line = scanner.nextLine();
+				if(line.contains(":")){
+					String[] nameValue = line.split(":");
+					if(nameValue.length > 1){
+						jsonObject.put(nameValue[0].trim(), nameValue[1].trim());
+					}
+				}
+			}
+		
+			scanner.close();
+
+	    } catch (Exception e) {
+	        e.printStackTrace();
+	        throw new IOException(e);
+	    }
+
+	    return jsonObject;
+	}
 
 	private JSONArray pstack(String program) throws IOException {
 	    ScriptContext scriptContext = new ScriptContext();
@@ -574,6 +620,54 @@ public class ServerResource extends ResourceBase {
     }   
     
     @GET
+    @Path("/dcs/summary")
+    @Produces({MIMETYPE_JSON})
+    public Response getDcsSummary(
+            final @Context UriInfo uriInfo,
+            final @Context Request request) {
+        try {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("GET " + uriInfo.getAbsolutePath());
+
+                MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
+                String output = " Query Parameters :\n";
+                for (String key : queryParams.keySet()) {
+                    output += key + " : " + queryParams.getFirst(key) +"\n";
+                }
+                LOG.debug(output);
+
+                MultivaluedMap<String, String> pathParams = uriInfo.getPathParameters();
+                output = " Path Parameters :\n";
+                for (String key : pathParams.keySet()) {
+                    output += key + " : " + pathParams.getFirst(key) +"\n";
+                }
+                LOG.debug(output);
+            }
+
+            JSONObject jsonObject = dcscheck();
+            
+            if(jsonObject.length() == 0) {
+                String result = buildRemoteException(
+                        "org.trafodion.rest.NotFoundException",
+                        "NotFoundException",
+                        "No dcs resources found");
+                return Response.status(Response.Status.NOT_FOUND)
+                        .type(MIMETYPE_JSON).entity(result)
+                        .build();
+            }
+ 
+            ResponseBuilder response = Response.ok(jsonObject.toString());
+            response.cacheControl(cacheControl);
+            return response.build();
+        } catch (IOException e) {
+            e.printStackTrace();
+            return Response.status(Response.Status.SERVICE_UNAVAILABLE)
+                    .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
+                    .build();
+        }
+    } 
+    
+    @GET
     @Path("/dcs/connections")
     @Produces({MIMETYPE_JSON})
     public Response getConnections(


Mime
View raw message