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/22 15:10:19 UTC

incubator-ignite git commit: # IGNITE-1121 Refactoring agent configuration.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1121 aef4919a9 -> 3a9580d2d


# IGNITE-1121 Refactoring agent configuration.


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

Branch: refs/heads/ignite-1121
Commit: 3a9580d2d5dc4bf2f07f9539fc8e6f54c27d21b0
Parents: aef4919
Author: sevdokimov <se...@jetbrains.com>
Authored: Wed Jul 22 16:09:55 2015 +0300
Committer: sevdokimov <se...@jetbrains.com>
Committed: Wed Jul 22 16:09:55 2015 +0300

----------------------------------------------------------------------
 modules/control-center-agent/pom.xml            |  19 +++-
 .../apache/ignite/agent/AgentCommandLine.java   | 113 +++++++++++++++++++
 .../apache/ignite/agent/AgentConfiguration.java |  60 ++++++++--
 .../org/apache/ignite/agent/AgentLauncher.java  |  70 ++++--------
 .../src/main/resources/config.properties        |   2 +
 5 files changed, 208 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a9580d2/modules/control-center-agent/pom.xml
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/pom.xml b/modules/control-center-agent/pom.xml
index 9e711a2..d4ae0d6 100644
--- a/modules/control-center-agent/pom.xml
+++ b/modules/control-center-agent/pom.xml
@@ -51,9 +51,9 @@
         </dependency>
 
         <dependency>
-            <groupId>commons-cli</groupId>
-            <artifactId>commons-cli</artifactId>
-            <version>1.2</version>
+            <groupId>com.beust</groupId>
+            <artifactId>jcommander</artifactId>
+            <version>1.32</version>
         </dependency>
 
         <dependency>
@@ -66,6 +66,19 @@
     <build>
         <plugins>
             <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.5</version>
+
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <mainClass>org.apache.ignite.agent.AgentLauncher</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
                 <version>2.4</version>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a9580d2/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java
new file mode 100644
index 0000000..849c94b
--- /dev/null
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java
@@ -0,0 +1,113 @@
+package org.apache.ignite.agent;/*
+ * 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.
+ */
+
+import com.beust.jcommander.*;
+
+/**
+ *
+ */
+public class AgentCommandLine {
+    /** */
+    @Parameter(names = {"-l", "--login"}, description = "User's login (email) on web-control-center")
+    private String login;
+
+    /** */
+    @Parameter(names = {"-p", "--password"}, description = "User's password")
+    private String pwd;
+
+    /** */
+    @Parameter(names = {"-s", "--serverUri"}, description = "Link to web-control-center web-socket server, for example: wss://control-center.gridgain.com")
+    private String serverUri;
+
+    /** */
+    @Parameter(names = {"-n", "--nodeUri"}, description = "ignite REST server, for example: http://localhost:8080")
+    private String nodeUri;
+
+    /** */
+    @Parameter(names = {"-c", "--config"}, description = "Path to configuration file")
+    private String cfgPath;
+
+    /**
+     *
+     */
+    public String getLogin() {
+        return login;
+    }
+
+    /**
+     * @param login Login.
+     */
+    public void setLogin(String login) {
+        this.login = login;
+    }
+
+    /**
+     *
+     */
+    public String getPassword() {
+        return pwd;
+    }
+
+    /**
+     * @param pwd Password.
+     */
+    public void setPassword(String pwd) {
+        this.pwd = pwd;
+    }
+
+    /**
+     *
+     */
+    public String getServerUri() {
+        return serverUri;
+    }
+
+    /**
+     * @param srvUri Server uri.
+     */
+    public void setServerUri(String srvUri) {
+        this.serverUri = srvUri;
+    }
+
+    /**
+     *
+     */
+    public String getNodeUri() {
+        return nodeUri;
+    }
+
+    /**
+     * @param nodeUri Node uri.
+     */
+    public void setNodeUri(String nodeUri) {
+        this.nodeUri = nodeUri;
+    }
+
+    /**
+     *
+     */
+    public String getConfigFile() {
+        return cfgPath;
+    }
+
+    /**
+     * @param cfgPath Config path.
+     */
+    public void setConfigPath(String cfgPath) {
+        this.cfgPath = cfgPath;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a9580d2/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 05246e3..4b73a90 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,29 +17,25 @@
 
 package org.apache.ignite.agent;
 
+import java.io.*;
 import java.net.*;
+import java.util.*;
 
 /**
  *
  */
 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 URI serverUri = DFLT_SERVER_URI;
+    private URI serverUri;
 
     /** */
-    private URI nodeUri = DFLT_NODE_URI;
+    private URI nodeUri;
 
     /**
      *
@@ -96,4 +92,52 @@ public class AgentConfiguration {
     public void setNodeUri(URI nodeUri) {
         this.nodeUri = nodeUri;
     }
+
+    /**
+     * @param cfgUrl Url.
+     */
+    public void load(URL cfgUrl) throws IOException {
+        Properties props = new Properties();
+
+        try (Reader reader = new InputStreamReader(cfgUrl.openStream())) {
+            props.load(reader);
+        }
+
+        String val = (String)props.remove("login");
+
+        if (val != null)
+            setLogin(val);
+
+        val = (String)props.remove("password");
+
+        if (val != null)
+            setPassword(val);
+
+        val = (String)props.remove("serverURI");
+
+        if (val != null)
+            setServerUri(URI.create(val));
+
+        val = (String)props.remove("nodeURI");
+
+        if (val != null)
+            setNodeUri(URI.create(val));
+    }
+
+    /**
+     * @param cmd Command.
+     */
+    public void assign(AgentCommandLine cmd) {
+        if (cmd.getLogin() != null)
+            setLogin(cmd.getLogin());
+
+        if (cmd.getPassword() != null)
+            setPassword(cmd.getPassword());
+
+        if (cmd.getServerUri() != null)
+            setServerUri(URI.create(cmd.getServerUri()));
+
+        if (cmd.getNodeUri() != null)
+            setNodeUri(URI.create(cmd.getNodeUri()));
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a9580d2/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 7886ea3..a4c24e5 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
@@ -17,74 +17,54 @@
 
 package org.apache.ignite.agent;
 
-import org.apache.commons.cli.*;
+import com.beust.jcommander.*;
 import org.eclipse.jetty.util.ssl.*;
 import org.eclipse.jetty.websocket.client.*;
 
+import java.io.*;
 import java.net.*;
 
 /**
  *
  */
 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("s", "serverUrl", true, "web-control-center URL")
-        .addOption("n", "nodeUrl", true, "ignite REST server");
 
-    /**
-     *
-     */
-    private static void printHelp() {
-        HelpFormatter helpFormatter = new HelpFormatter();
-
-        helpFormatter.printHelp("\njava -jar control-center-agent.jar -l myemail@gmail.com -p qwerty", options);
-    }
-
-    /**
-     * @param args Args.
-     */
-    public static void main(String[] args) throws Exception {
-        CommandLineParser parser = new BasicParser();
+    protected static AgentConfiguration getConfiguration(String[] args) throws IOException {
+        AgentConfiguration cfg = new AgentConfiguration();
 
-        CommandLine cmd = parser.parse(options, args);
+        URL dftlCfgUrl = AgentLauncher.class.getResource("/config.properties");
 
-        String login = cmd.getOptionValue('l');
+        cfg.load(dftlCfgUrl);
 
-        if (login == null) {
-            System.out.println("Login is not specified.");
+        AgentCommandLine cmdCfg = new AgentCommandLine();
 
-            printHelp();
+        JCommander cmd = new JCommander(cmdCfg, args);
 
-            System.exit(1);
-        }
+        if (cmdCfg.getConfigFile() != null)
+            cfg.load(new File(cmdCfg.getConfigFile()).toURI().toURL());
 
-        String pwd = cmd.getOptionValue('p');
+        cfg.assign(cmdCfg);
 
-        if (pwd == null) {
-            System.out.println("Password is not specified.");
+        if (cfg.getLogin() == null) {
+            System.out.print("Login: ");
 
-            printHelp();
-
-            System.exit(1);
+            cfg.setLogin(System.console().readLine().trim());
         }
 
-        AgentConfiguration cfg = new AgentConfiguration();
-
-        cfg.setLogin(login);
-        cfg.setPassword(pwd);
+        if (cfg.getPassword() == null) {
+            System.out.print("Password: ");
 
-        String srvUri = cmd.getOptionValue('s');
-
-        if (srvUri != null)
-            cfg.setServerUri(URI.create(srvUri));
+            cfg.setPassword(new String(System.console().readPassword()));
+        }
 
-        String nodeUri = cmd.getOptionValue('n');
+        return cfg;
+    }
 
-        if (nodeUri != null)
-            cfg.setNodeUri(URI.create(nodeUri));
+    /**
+     * @param args Args.
+     */
+    public static void main(String[] args) throws Exception {
+        AgentConfiguration cfg = getConfiguration(args);
 
         Agent agent = new Agent(cfg);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3a9580d2/modules/control-center-agent/src/main/resources/config.properties
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/resources/config.properties b/modules/control-center-agent/src/main/resources/config.properties
new file mode 100644
index 0000000..f9b48b7
--- /dev/null
+++ b/modules/control-center-agent/src/main/resources/config.properties
@@ -0,0 +1,2 @@
+serverURI=wss://localhost:3001
+nodeURI=http://localhost:8080