ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject incubator-ignite git commit: IGNITE-1201 Refactoring: make agent testable
Date Wed, 05 Aug 2015 13:33:55 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1201 [created] 0a31799b4


IGNITE-1201 Refactoring: make agent testable


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

Branch: refs/heads/ignite-1201
Commit: 0a31799b4a55973dfb0288b40c8b5de35c241fb5
Parents: ed47b34
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Wed Aug 5 16:33:32 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Wed Aug 5 16:33:32 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/agent/AgentConfiguration.java | 18 +++++
 .../org/apache/ignite/agent/AgentLauncher.java  | 83 +++++++++++---------
 .../org/apache/ignite/agent/AgentSocket.java    | 15 ++--
 .../ignite/agent/handlers/RestExecutor.java     | 10 +--
 .../ignite/agent/remote/RemoteHandler.java      |  4 +-
 5 files changed, 79 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a31799b/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 48b9d2d..33725be 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
@@ -18,6 +18,7 @@
 package org.apache.ignite.agent;
 
 import com.beust.jcommander.*;
+import org.eclipse.jetty.util.ssl.*;
 
 import java.io.*;
 import java.net.*;
@@ -56,6 +57,9 @@ public class AgentConfiguration {
     @Parameter(names = { "-h", "--help" }, description = "Print this help message")
     private boolean help;
 
+    /** */
+    private SslContextFactory sslCtxFactory;
+
     /**
      * @return Login.
      */
@@ -200,4 +204,18 @@ public class AgentConfiguration {
     public boolean help() {
         return help;
     }
+
+    /**
+     * @return SSL context factory.
+     */
+    public synchronized SslContextFactory sslContextFactory() {
+        if (sslCtxFactory == null) {
+            sslCtxFactory = new SslContextFactory();
+
+            if (Boolean.TRUE.equals(Boolean.getBoolean("trust.all")))
+                sslCtxFactory.setTrustAll(true);
+        }
+
+        return sslCtxFactory;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a31799b/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 35223de..2b43a79 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
@@ -19,7 +19,6 @@ package org.apache.ignite.agent;
 
 import com.beust.jcommander.*;
 import org.apache.ignite.agent.handlers.*;
-import org.eclipse.jetty.util.ssl.*;
 import org.eclipse.jetty.websocket.client.*;
 
 import java.io.*;
@@ -41,6 +40,51 @@ public class AgentLauncher {
     /** */
     private static final int RECONNECT_INTERVAL = 3000;
 
+    /** */
+    private final AgentConfiguration cfg;
+
+    /**
+     * @param cfg Config.
+     */
+    public AgentLauncher(AgentConfiguration cfg) {
+        this.cfg = cfg;
+    }
+
+    /**
+     *
+     */
+    public void run() throws Exception {
+        RestExecutor restExecutor = new RestExecutor(cfg);
+
+        try {
+            WebSocketClient client = new WebSocketClient(cfg.sslContextFactory());
+
+            client.setMaxIdleTimeout(Long.MAX_VALUE);
+
+            client.start();
+
+            try {
+                while (!Thread.interrupted()) {
+                    AgentSocket agentSock = new AgentSocket(cfg, restExecutor, new DatabaseMetadataExtractor(cfg));
+
+                    log.log(Level.INFO, "Connecting to: " + cfg.getServerUri());
+
+                    client.connect(agentSock, URI.create(cfg.getServerUri()));
+
+                    agentSock.waitForClose();
+
+                    Thread.sleep(RECONNECT_INTERVAL);
+                }
+            }
+            finally {
+                client.stop();
+            }
+        }
+        finally {
+            restExecutor.stop();
+        }
+    }
+
     /**
      * @param args Args.
      */
@@ -76,41 +120,8 @@ public class AgentLauncher {
             cfg.setPassword(new String(System.console().readPassword()));
         }
 
-        RestExecutor restExecutor = new RestExecutor(cfg);
-
-        restExecutor.start();
-
-        try {
-            SslContextFactory sslCtxFactory = new SslContextFactory();
-
-            if (Boolean.TRUE.equals(Boolean.getBoolean("trust.all")))
-                sslCtxFactory.setTrustAll(true);
-
-            WebSocketClient client = new WebSocketClient(sslCtxFactory);
-
-            client.setMaxIdleTimeout(Long.MAX_VALUE);
-
-            client.start();
-
-            try {
-                while (!Thread.interrupted()) {
-                    AgentSocket agentSock = new AgentSocket(cfg, restExecutor);
+        AgentLauncher agentLauncher = new AgentLauncher(cfg);
 
-                    log.log(Level.INFO, "Connecting to: " + cfg.getServerUri());
-
-                    client.connect(agentSock, URI.create(cfg.getServerUri()));
-
-                    agentSock.waitForClose();
-
-                    Thread.sleep(RECONNECT_INTERVAL);
-                }
-            }
-            finally {
-                client.stop();
-            }
-        }
-        finally {
-            restExecutor.stop();
-        }
+        agentLauncher.run();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a31799b/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 bab149f..a1f23f2 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
@@ -18,13 +18,13 @@
 package org.apache.ignite.agent;
 
 import com.google.gson.*;
-import org.apache.ignite.agent.handlers.*;
 import org.apache.ignite.agent.remote.*;
 import org.eclipse.jetty.websocket.api.*;
 import org.eclipse.jetty.websocket.api.annotations.*;
 
 import java.io.*;
 import java.net.*;
+import java.util.*;
 import java.util.concurrent.*;
 import java.util.logging.*;
 
@@ -49,7 +49,7 @@ public class AgentSocket implements WebSocketSender {
     private final AgentConfiguration cfg;
 
     /** */
-    private final RestExecutor restExecutor;
+    private final Object[] rmtCallHandlers;
 
     /** */
     private RemoteHandler remote;
@@ -60,9 +60,9 @@ public class AgentSocket implements WebSocketSender {
     /**
      * @param cfg Config.
      */
-    public AgentSocket(AgentConfiguration cfg, RestExecutor restExecutor) {
+    public AgentSocket(AgentConfiguration cfg, Object ... rmtCallHandlers) {
         this.cfg = cfg;
-        this.restExecutor = restExecutor;
+        this.rmtCallHandlers = rmtCallHandlers;
     }
 
     /**
@@ -88,7 +88,12 @@ public class AgentSocket implements WebSocketSender {
 
         this.ses = ses;
 
-        remote = RemoteHandler.wrap(this, this, restExecutor, new DatabaseMetadataExtractor(cfg));
+        Collection<Object> hnds = new ArrayList<>();
+
+        hnds.addAll(Arrays.asList(rmtCallHandlers));
+        hnds.add(this);
+
+        remote = RemoteHandler.wrap(this, hnds);
 
         JsonObject authMsg = new JsonObject();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a31799b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/RestExecutor.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/RestExecutor.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/RestExecutor.java
index 6531ad9..ea3b111 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/RestExecutor.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/handlers/RestExecutor.java
@@ -44,19 +44,14 @@ public class RestExecutor {
     private final AgentConfiguration cfg;
 
     /** */
-    private CloseableHttpClient httpClient;
+    private final CloseableHttpClient httpClient;
 
     /**
      * @param cfg Config.
      */
     public RestExecutor(AgentConfiguration cfg) {
         this.cfg = cfg;
-    }
 
-    /**
-     *
-     */
-    public void start() {
         httpClient = HttpClientBuilder.create().build();
     }
 
@@ -64,8 +59,7 @@ public class RestExecutor {
      *
      */
     public void stop() throws IOException {
-        if (httpClient != null)
-            httpClient.close();
+        httpClient.close();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0a31799b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java
index 8199ff5..4b1527e 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java
@@ -53,7 +53,7 @@ public class RemoteHandler implements AutoCloseable {
      * @param snd Session.
      * @param hnds Handlers.
      */
-    private RemoteHandler(WebSocketSender snd, Object ... hnds) {
+    private RemoteHandler(WebSocketSender snd, Collection<Object> hnds) {
         this.snd = snd;
 
         for (Object hnd : hnds) {
@@ -202,7 +202,7 @@ public class RemoteHandler implements AutoCloseable {
      * @param hnds Handler.
      * @param snd Sender.
      */
-    public static RemoteHandler wrap(WebSocketSender snd, Object ... hnds) {
+    public static RemoteHandler wrap(WebSocketSender snd, Collection<Object> hnds)
{
         return new RemoteHandler(snd, hnds);
     }
 


Mime
View raw message