You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/07/16 22:40:19 UTC

incubator-ignite git commit: # IGNITE-1121 Add AgentConfiguration.serverUri and AgentConfiguration.nodeUri parameters.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1121 386c223f5 -> 0dfb521a7


# IGNITE-1121 Add AgentConfiguration.serverUri and AgentConfiguration.nodeUri parameters.


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

Branch: refs/heads/ignite-1121
Commit: 0dfb521a71246625c550347fdb1c06da99ad1d09
Parents: 386c223
Author: sevdokimov <se...@jetbrains.com>
Authored: Thu Jul 16 23:34:42 2015 +0300
Committer: sevdokimov <se...@jetbrains.com>
Committed: Thu Jul 16 23:40:06 2015 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/agent/Agent.java     | 34 ++++++++-----
 .../apache/ignite/agent/AgentConfiguration.java | 37 +++++++++++---
 .../org/apache/ignite/agent/AgentLauncher.java  | 20 +++++---
 .../org/apache/ignite/agent/AgentSocket.java    |  2 +-
 .../ignite/agent/messages/RestRequest.java      | 12 ++---
 .../nodejs/agents/agentManager.js               | 52 ++++++++++++++------
 .../web-control-center/nodejs/routes/test.js    |  8 +--
 7 files changed, 113 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/Agent.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/Agent.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/Agent.java
index f8e95a5..49f45f5a 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/Agent.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/Agent.java
@@ -21,11 +21,13 @@ import org.apache.commons.codec.*;
 import org.apache.http.*;
 import org.apache.http.client.entity.*;
 import org.apache.http.client.methods.*;
+import org.apache.http.client.utils.*;
 import org.apache.http.impl.client.*;
 import org.apache.http.message.*;
 import org.apache.ignite.agent.messages.*;
 
 import java.io.*;
+import java.net.*;
 import java.nio.charset.*;
 import java.util.*;
 
@@ -64,26 +66,36 @@ public class Agent {
     /**
      * @param restReq Request.
      */
-    public RestResult executeRest(RestRequest restReq) throws IOException {
+    public RestResult executeRest(RestRequest restReq) throws IOException, URISyntaxException {
         HttpRequestBase httpReq;
 
-        if ("GET".equalsIgnoreCase(restReq.getMethod())) {
-            httpReq = new HttpGet(restReq.getUrl());
+        URIBuilder builder = new URIBuilder(cfg.getNodeUri());
 
-            if (restReq.getParams() != null)
-                throw new IOException("Parameters of GET method should be passed in URL");
+        String path = restReq.getPath();
+
+        if (path != null) {
+            if (!path.startsWith("/") && !cfg.getNodeUri().toString().endsWith("/"))
+                path = '/' +  path;
+
+            builder.setPath(path);
+        }
+
+        if (restReq.getParams() != null) {
+            for (Map.Entry<String, String> entry : restReq.getParams().entrySet())
+                builder.addParameter(entry.getKey(), entry.getValue());
         }
+
+        if ("GET".equalsIgnoreCase(restReq.getMethod()))
+            httpReq = new HttpGet(builder.build());
         else if ("POST".equalsIgnoreCase(restReq.getMethod())) {
-            HttpPost post = new HttpPost(restReq.getUrl());
+            List<NameValuePair> nvps = builder.getQueryParams();
 
-            if (restReq.getParams() != null) {
-                List<NameValuePair> nvps = new ArrayList<>();
+            builder.clearParameters();
 
-                for (Map.Entry<String, String> entry : restReq.getParams().entrySet())
-                    nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+            HttpPost post = new HttpPost(builder.build());
 
+            if (nvps.size() > 0)
                 post.setEntity(new UrlEncodedFormEntity(nvps));
-            }
 
             httpReq = post;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
index 06a21f3..05246e3 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
@@ -17,18 +17,29 @@
 
 package org.apache.ignite.agent;
 
+import java.net.*;
+
 /**
  *
  */
 public class AgentConfiguration {
     /** */
+    public static final URI DFLT_NODE_URI = URI.create("http://localhost:8080");
+
+    /** todo set something like wss://control-center.gridgain.com */
+    public static final URI DFLT_SERVER_URI = URI.create("wss://localhost:3001");
+
+    /** */
     private String login;
 
     /** */
     private String pwd;
 
     /** */
-    private String uri;
+    private URI serverUri = DFLT_SERVER_URI;
+
+    /** */
+    private URI nodeUri = DFLT_NODE_URI;
 
     /**
      *
@@ -61,14 +72,28 @@ public class AgentConfiguration {
     /**
      *
      */
-    public String getUri() {
-        return uri;
+    public URI getServerUri() {
+        return serverUri;
+    }
+
+    /**
+     * @param srvUri Uri.
+     */
+    public void setServerUri(URI srvUri) {
+        this.serverUri = srvUri;
+    }
+
+    /**
+     *
+     */
+    public URI getNodeUri() {
+        return nodeUri;
     }
 
     /**
-     * @param uri Uri.
+     * @param nodeUri Node uri.
      */
-    public void setUri(String uri) {
-        this.uri = uri;
+    public void setNodeUri(URI nodeUri) {
+        this.nodeUri = nodeUri;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
index 9f76b9d..0ac1a63 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
@@ -31,7 +31,8 @@ public class AgentLauncher {
     private static final Options options = new Options()
         .addOption("l", "login", true, "User's login (email) on web-control-center")
         .addOption("p", "password", true, "User's password")
-        .addOption("u", "url", true, "web-control-center URL");
+        .addOption("s", "serverUrl", true, "web-control-center URL")
+        .addOption("n", "nodeUrl", true, "ignite REST server");
 
     /**
      *
@@ -75,12 +76,15 @@ public class AgentLauncher {
         cfg.setLogin(login);
         cfg.setPassword(pwd);
 
-        String uri = cmd.getOptionValue('u');
+        String srvUri = cmd.getOptionValue('s');
 
-        if (uri == null)
-            cfg.setUri("wss://localhost:3001"); // todo set something like wss://control-center.gridgain.com
-        else
-            cfg.setUri(uri);
+        if (srvUri != null)
+            cfg.setServerUri(URI.create(srvUri));
+
+        String nodeUri = cmd.getOptionValue('n');
+
+        if (nodeUri != null)
+            cfg.setNodeUri(URI.create(nodeUri));
 
         Agent agent = new Agent(cfg);
 
@@ -99,9 +103,9 @@ public class AgentLauncher {
             client.start();
 
             try {
-                client.connect(agentSock, new URI(cfg.getUri()));
+                client.connect(agentSock, cfg.getServerUri());
 
-                System.out.printf("Connecting to : %s%n", cfg.getUri());
+                System.out.printf("Connecting to : %s%n", cfg.getServerUri());
 
                 agentSock.waitForClose();
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
index 7603ed9..5cb5f36 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
@@ -110,7 +110,7 @@ public class AgentSocket {
             try {
                 restRes = agent.executeRest(restReq);
             }
-            catch (IOException e) {
+            catch (Throwable e) {
                 restRes = new RestResult();
 
                 restRes.setCode(500);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/RestRequest.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/RestRequest.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/RestRequest.java
index e2517b6..ed7304b 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/RestRequest.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/RestRequest.java
@@ -27,7 +27,7 @@ public class RestRequest extends AbstractMessage {
     private int id;
 
     /** */
-    private String url;
+    private String path;
 
     /** */
     private Map<String, String> params;
@@ -52,15 +52,15 @@ public class RestRequest extends AbstractMessage {
     /**
      *
      */
-    public String getUrl() {
-        return url;
+    public String getPath() {
+        return path;
     }
 
     /**
-     * @param url Url.
+     * @param path Url.
      */
-    public void setUrl(String url) {
-        this.url = url;
+    public void setPath(String path) {
+        this.path = path;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/web-control-center/nodejs/agents/agentManager.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/agents/agentManager.js b/modules/web-control-center/nodejs/agents/agentManager.js
index 97a0bb1..1050a47 100644
--- a/modules/web-control-center/nodejs/agents/agentManager.js
+++ b/modules/web-control-center/nodejs/agents/agentManager.js
@@ -113,7 +113,21 @@ function Client(ws) {
 
     this.cbMap = {};
 
-    this.invokeRest = function(url, method, params, cb) {
+    this.invokeRest = function(path, params, cb, method) {
+        if (typeof(params) != 'object')
+            throw "'params' argument must be an object";
+
+        if (typeof(cb) != 'function')
+            throw "callback must be a function";
+
+        if (!method)
+            method = 'GET';
+        else
+            method = method.toUpperCase();
+
+        if (method != 'GET' && method != 'POST')
+            throw "Unknown HTTP method: " + method;
+
         var reqId = this.restCounter++;
 
         this.cbMap[reqId] = cb;
@@ -123,7 +137,7 @@ function Client(ws) {
             type: 'RestRequest',
             method: method,
             params: params,
-            url: url
+            path: path
         }, function(err) {
             if (err) {
                 delete this.cbMap[reqId];
@@ -133,22 +147,12 @@ function Client(ws) {
         })
     };
 
-
-    this.restGet = function(url, cb) {
-        this.invokeRest(url, 'GET', null, cb);
+    this.restGet = function(path, params, cb) {
+        this.invokeRest(path, params, cb, 'GET');
     };
 
-    this.restPost = function(url, params, cb) {
-        if (typeof(params) == 'function' && !cb) {
-            cb = params;
-
-            params = undefined
-        }
-
-        if (params && typeof(params) != 'object')
-            throw "'params' argument must be an object";
-
-        this.invokeRest(url, 'POST', params, cb);
+    this.restPost = function(path, params, cb) {
+        this.invokeRest(path, params, cb, 'POST');
     }
 }
 
@@ -188,3 +192,19 @@ exports.findClient = function(userId) {
 
     return clientsList[0];
 };
+
+/**
+ * For tests only!!!
+ */
+exports.getOneClient = function() {
+    for (var userId in clients) {
+        if (clients.hasOwnProperty(userId)) {
+            var m = clients[userId];
+
+            if (m.length > 0)
+                return m[0];
+        }
+    }
+
+    return null;
+};

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0dfb521a/modules/web-control-center/nodejs/routes/test.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/test.js b/modules/web-control-center/nodejs/routes/test.js
index f842c8b..4c066ca 100644
--- a/modules/web-control-center/nodejs/routes/test.js
+++ b/modules/web-control-center/nodejs/routes/test.js
@@ -22,13 +22,13 @@ var bridge = require('../agents/agentManager');
 
 /* GET summary page. */
 router.get('/testGet', function(req, res) {
-    var c = bridge.findClient("55a2ca51eef88f6c775ed9d0");
+    var c = bridge.getOneClient();
 
     if (!c) {
         return res.send("Client not found");
     }
 
-    c.restGet("http://ya.ru/", function(error, code, message) {
+    c.restGet("ignite", {cmd: 'version'}, function(error, code, message) {
         if (error) {
             res.send("Failed to execute REST query: " + error);
 
@@ -41,13 +41,13 @@ router.get('/testGet', function(req, res) {
 
 /* GET summary page. */
 router.get('/testPost', function(req, res) {
-    var c = bridge.findClient("55a2ca51eef88f6c775ed9d0");
+    var c = bridge.getOneClient();
 
     if (!c) {
         return res.send("Client not found");
     }
 
-    c.restPost("http://localhost:3000/configuration/caches/save", {_id: 555}, function(error, code, message) {
+    c.restPost("ignite", {cmd: 'version'}, function(error, code, message) {
         if (error) {
             res.send("Failed to execute REST query: " + error);