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-1155 Creating API on agent to request metadata.
Date Tue, 28 Jul 2015 16:40:20 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-1155_1 1e3c77f65 -> 3762de370


IGNITE-1155 Creating API on agent to request metadata.


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

Branch: refs/heads/ignite-1155_1
Commit: 3762de370e710ca792e300ba075ebdfe5d1d44c7
Parents: 1e3c77f
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Tue Jul 28 19:39:48 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Tue Jul 28 19:39:48 2015 +0300

----------------------------------------------------------------------
 modules/control-center-agent/pom.xml            |   8 +-
 .../java/org/apache/ignite/agent/Agent.java     |  23 ++++
 .../org/apache/ignite/agent/AgentSocket.java    |  40 ++++++-
 .../agent/messages/DbMetadataRequest.java       | 110 +++++++++++++++++++
 .../agent/messages/DbMetadataResponse.java      |  61 ++++++++++
 modules/schema-import-db/pom.xml                |   7 --
 .../apache/ignite/schema/parser/DBReader.java   |  61 +++++++++-
 .../schema/parser/DatabaseMetadataParser.java   |   2 +-
 .../ignite/schema/ui/SchemaImportApp.java       |  53 +--------
 pom.xml                                         |   1 +
 10 files changed, 298 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/control-center-agent/pom.xml
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/pom.xml b/modules/control-center-agent/pom.xml
index 59bc595..c40b4756 100644
--- a/modules/control-center-agent/pom.xml
+++ b/modules/control-center-agent/pom.xml
@@ -31,7 +31,7 @@
     </parent>
 
     <artifactId>control-center-agent</artifactId>
-    <version>1.2.1-SNAPSHOT</version>
+    <version>1.4.1-SNAPSHOT</version>
 
     <properties>
         <jetty.version>9.2.12.v20150709</jetty.version>
@@ -61,6 +61,12 @@
             <artifactId>httpclient</artifactId>
             <version>4.5</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-schema-import-db</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
     <build>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/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 ba3a9fd..306e21a 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
@@ -25,10 +25,12 @@ import org.apache.http.client.utils.*;
 import org.apache.http.entity.*;
 import org.apache.http.impl.client.*;
 import org.apache.ignite.agent.messages.*;
+import org.apache.ignite.schema.parser.*;
 
 import java.io.*;
 import java.net.*;
 import java.nio.charset.*;
+import java.sql.*;
 import java.util.*;
 
 /**
@@ -138,4 +140,25 @@ public class Agent {
             return res;
         }
     }
+
+    /**
+     * @param req Request.
+     */
+    public DbMetadataResponse dbMetadataRequest(DbMetadataRequest req) {
+        DbMetadataResponse res = new DbMetadataResponse();
+
+        try {
+            Connection conn = DBReader.getInstance().connect(req.getJdbcDriverJarPath(),
req.getJdbcDriverClass(),
+                req.getJdbcUrl(), req.getJdbcInfo());
+
+            Collection<DbTable> tbls = DBReader.getInstance().extractMetadata(conn,
req.isTablesOnly());
+
+            res.setTables(tbls);
+        }
+        catch (SQLException e) {
+            res.setError(e.getMessage());
+        }
+
+        return res;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/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 ec363b4..3c1c59a 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
@@ -44,6 +44,9 @@ public class AgentSocket {
     /** */
     private final Agent agent;
 
+    /** */
+    private Session ses;
+
     /**
      * @param cfg Config.
      */
@@ -70,6 +73,8 @@ public class AgentSocket {
     public void onConnect(Session ses) {
         log.log(Level.INFO, "Authentication...");
 
+        this.ses = ses;
+
         AuthMessage authMsg = new AuthMessage(cfg.getLogin(), cfg.getPassword());
 
         try {
@@ -80,6 +85,29 @@ public class AgentSocket {
     }
 
     /**
+     * @param msg Message.
+     */
+    public boolean send(AbstractMessage msg) {
+        return send(MessageFactory.toString(msg));
+    }
+
+    /**
+     * @param msg Message.
+     */
+    public boolean send(String msg) {
+        try {
+            ses.getRemote().sendString(msg);
+
+            return true;
+        }
+        catch (IOException e) {
+            log.log(Level.SEVERE, "Failed to send message to Control Center");
+
+            return false;
+        }
+    }
+
+    /**
      * @param ses Session.
      * @param error Error.
      */
@@ -126,12 +154,12 @@ public class AgentSocket {
 
             restRes.setRequestId(((RestRequest)m).getId());
 
-            try {
-                ses.getRemote().sendString(MessageFactory.toString(restRes));
-            }
-            catch (IOException e) {
-                e.printStackTrace();
-            }
+            send(MessageFactory.toString(restRes));
+        }
+        else if (m instanceof DbMetadataRequest) {
+            DbMetadataResponse resp = agent.dbMetadataRequest((DbMetadataRequest)m);
+
+            send(resp);
         }
         else
             log.log(Level.SEVERE, "Unknown message: " + msg);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataRequest.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataRequest.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataRequest.java
new file mode 100644
index 0000000..82e83e4
--- /dev/null
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataRequest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.ignite.agent.messages;
+
+import java.util.*;
+
+/**
+ *
+ */
+public class DbMetadataRequest extends AbstractMessage {
+    /** */
+    private String jdbcDriverJarPath;
+
+    /** */
+    private String jdbcDriverClass;
+
+    /** */
+    private String jdbcUrl;
+
+    /** */
+    private Properties jdbcInfo;
+
+    /** */
+    private boolean tablesOnly;
+
+    /**
+     * @return JDBC driver class name.
+     */
+    public String getJdbcDriverClass() {
+        return jdbcDriverClass;
+    }
+
+    /**
+     * @param jdbcDriverCls Jdbc driver class.
+     */
+    public void setJdbcDriverClass(String jdbcDriverCls) {
+        this.jdbcDriverClass = jdbcDriverCls;
+    }
+
+    /**
+     *
+     */
+    public String getJdbcUrl() {
+        return jdbcUrl;
+    }
+
+    /**
+     * @param jdbcUrl Jdbc url.
+     */
+    public void setJdbcUrl(String jdbcUrl) {
+        this.jdbcUrl = jdbcUrl;
+    }
+
+    /**
+     *
+     */
+    public Properties getJdbcInfo() {
+        return jdbcInfo;
+    }
+
+    /**
+     * @param jdbcInfo Jdbc info.
+     */
+    public void setJdbcInfo(Properties jdbcInfo) {
+        this.jdbcInfo = jdbcInfo;
+    }
+
+    /**
+     *
+     */
+    public String getJdbcDriverJarPath() {
+        return jdbcDriverJarPath;
+    }
+
+    /**
+     * @param jdbcDriverJarPath Jdbc drv jar path.
+     */
+    public void setJdbcDriverJarPath(String jdbcDriverJarPath) {
+        this.jdbcDriverJarPath = jdbcDriverJarPath;
+    }
+
+    /**
+     * @return Tables only flag.
+     */
+    public boolean isTablesOnly() {
+        return tablesOnly;
+    }
+
+    /**
+     * @param tblsOnly Tables only.
+     */
+    public void setTablesOnly(boolean tblsOnly) {
+        this.tablesOnly = tblsOnly;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataResponse.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataResponse.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataResponse.java
new file mode 100644
index 0000000..d6eec9d
--- /dev/null
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/messages/DbMetadataResponse.java
@@ -0,0 +1,61 @@
+/*
+ * 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.ignite.agent.messages;
+
+import org.apache.ignite.schema.parser.*;
+
+import java.util.*;
+
+/**
+ *
+ */
+public class DbMetadataResponse extends AbstractMessage {
+    /** */
+    private String error;
+
+    /** */
+    private Collection<DbTable> tables;
+
+    /**
+     *
+     */
+    public String getError() {
+        return error;
+    }
+
+    /**
+     * @param error Error.
+     */
+    public void setError(String error) {
+        this.error = error;
+    }
+
+    /**
+     *
+     */
+    public Collection<DbTable> getTables() {
+        return tables;
+    }
+
+    /**
+     * @param tbls Tables.
+     */
+    public void setTables(Collection<DbTable> tbls) {
+        this.tables = tbls;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/schema-import-db/pom.xml
----------------------------------------------------------------------
diff --git a/modules/schema-import-db/pom.xml b/modules/schema-import-db/pom.xml
index c0bfc8d..81b0a65 100644
--- a/modules/schema-import-db/pom.xml
+++ b/modules/schema-import-db/pom.xml
@@ -34,11 +34,4 @@
     <artifactId>ignite-schema-import-db</artifactId>
     <version>1.4.1-SNAPSHOT</version>
 
-    <dependencies>
-        <dependency>
-            <groupId>org.apache.ignite</groupId>
-            <artifactId>ignite-core</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-    </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java
----------------------------------------------------------------------
diff --git a/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java
b/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java
index 5c4466e..d220b14 100644
--- a/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java
+++ b/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java
@@ -19,6 +19,8 @@ package org.apache.ignite.schema.parser;
 
 import org.apache.ignite.schema.parser.dialect.*;
 
+import java.io.*;
+import java.net.*;
 import java.sql.*;
 import java.util.*;
 import java.util.logging.*;
@@ -30,6 +32,12 @@ public class DBReader {
     /** Logger. */
     private static final Logger log = Logger.getLogger(DBReader.class.getName());
 
+    /** */
+    private static final DBReader INSTANCE = new DBReader();
+
+    /** */
+    private final Map<String, Driver> drivers = new HashMap<>();
+
     /**
      * Default constructor.
      */
@@ -43,7 +51,7 @@ public class DBReader {
      * @param conn Connection.
      * @param tblsOnly Tables only flag.
      */
-    public static Collection<DbTable> extractMetadata(Connection conn, boolean tblsOnly)
throws SQLException {
+    public Collection<DbTable> extractMetadata(Connection conn, boolean tblsOnly) throws
SQLException {
         DatabaseMetadataDialect dialect;
 
         try {
@@ -65,4 +73,55 @@ public class DBReader {
         return dialect.tables(conn, tblsOnly);
     }
 
+    /**
+     * Connect to database.
+     *
+     * @param jdbcDrvJarPath Path to JDBC driver.
+     * @param jdbcDrvCls JDBC class name.
+     * @param jdbcUrl JDBC connection URL.
+     * @param jdbcInfo Connection properties.
+     * @return Connection to database.
+     * @throws SQLException if connection failed.
+     */
+    public Connection connect(String jdbcDrvJarPath, String jdbcDrvCls, String jdbcUrl, Properties
jdbcInfo)
+        throws SQLException {
+        Driver drv = drivers.get(jdbcDrvCls);
+
+        if (drv == null) {
+            if (jdbcDrvJarPath.isEmpty())
+                throw new IllegalStateException("Driver jar file name is not specified.");
+
+            File drvJar = new File(jdbcDrvJarPath);
+
+            if (!drvJar.exists())
+                throw new IllegalStateException("Driver jar file is not found.");
+
+            try {
+                URL u = new URL("jar:" + drvJar.toURI() + "!/");
+
+                URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {u});
+
+                drv = (Driver)Class.forName(jdbcDrvCls, true, ucl).newInstance();
+
+                drivers.put(jdbcDrvCls, drv);
+            }
+            catch (Exception e) {
+                throw new IllegalStateException(e);
+            }
+        }
+
+        Connection conn = drv.connect(jdbcUrl, jdbcInfo);
+
+        if (conn == null)
+            throw new IllegalStateException("Connection was not established (JDBC driver
returned null value).");
+
+        return conn;
+    }
+
+    /**
+     * @return Instance.
+     */
+    public static DBReader getInstance() {
+        return INSTANCE;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
index 54dc3ee..22cb5ba 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/parser/DatabaseMetadataParser.java
@@ -44,7 +44,7 @@ public class DatabaseMetadataParser {
 
         Map<String, Collection<PojoDescriptor>> childrens = new HashMap<>();
 
-        for (DbTable tbl : DBReader.extractMetadata(conn, tblsOnly)) {
+        for (DbTable tbl : DBReader.getInstance().extractMetadata(conn, tblsOnly)) {
             String schema = tbl.schema();
 
             PojoDescriptor parent = parents.get(schema);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
----------------------------------------------------------------------
diff --git a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
index 7b9c220..d85922a 100644
--- a/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
+++ b/modules/schema-import/src/main/java/org/apache/ignite/schema/ui/SchemaImportApp.java
@@ -23,7 +23,6 @@ import javafx.collections.*;
 import javafx.concurrent.*;
 import javafx.event.*;
 import javafx.geometry.*;
-import javafx.geometry.Insets;
 import javafx.scene.*;
 import javafx.scene.control.*;
 import javafx.scene.layout.*;
@@ -35,10 +34,8 @@ import org.apache.ignite.schema.model.*;
 import org.apache.ignite.schema.parser.*;
 
 import java.io.*;
-import java.net.*;
 import java.sql.*;
 import java.util.*;
-import java.util.List;
 import java.util.concurrent.*;
 import java.util.logging.*;
 
@@ -251,9 +248,6 @@ public class SchemaImportApp extends Application {
     /** Currently selected POJO. */
     private PojoDescriptor curPojo;
 
-    /** */
-    private final Map<String, Driver> drivers = new HashMap<>();
-
     /** Application preferences. */
     private final Properties prefs = new Properties();
 
@@ -348,7 +342,7 @@ public class SchemaImportApp extends Application {
             @Override protected Void call() throws Exception {
                 long started = System.currentTimeMillis();
 
-                try (Connection conn = connect(jdbcDrvJarPath, jdbcDrvCls, jdbcUrl, jdbcInfo))
{
+                try (Connection conn = DBReader.getInstance().connect(jdbcDrvJarPath, jdbcDrvCls,
jdbcUrl, jdbcInfo)) {
                     pojos = DatabaseMetadataParser.parse(conn, tblsOnly);
                 }
 
@@ -653,51 +647,6 @@ public class SchemaImportApp extends Application {
     }
 
     /**
-     * Connect to database.
-     *
-     * @param jdbcDrvJarPath Path to JDBC driver.
-     * @param jdbcDrvCls JDBC class name.
-     * @param jdbcUrl JDBC connection URL.
-     * @param jdbcInfo Connection properties.
-     * @return Connection to database.
-     * @throws SQLException if connection failed.
-     */
-    private Connection connect(String jdbcDrvJarPath, String jdbcDrvCls, String jdbcUrl,
Properties jdbcInfo)
-        throws SQLException {
-        Driver drv = drivers.get(jdbcDrvCls);
-
-        if (drv == null) {
-            if (jdbcDrvJarPath.isEmpty())
-                throw new IllegalStateException("Driver jar file name is not specified.");
-
-            File drvJar = new File(jdbcDrvJarPath);
-
-            if (!drvJar.exists())
-                throw new IllegalStateException("Driver jar file is not found.");
-
-            try {
-                URL u = new URL("jar:" + drvJar.toURI() + "!/");
-
-                URLClassLoader ucl = URLClassLoader.newInstance(new URL[] {u});
-
-                drv = (Driver)Class.forName(jdbcDrvCls, true, ucl).newInstance();
-
-                drivers.put(jdbcDrvCls, drv);
-            }
-            catch (Exception e) {
-                throw new IllegalStateException(e);
-            }
-        }
-
-        Connection conn = drv.connect(jdbcUrl, jdbcInfo);
-
-        if (conn == null)
-            throw new IllegalStateException("Connection was not established (JDBC driver
returned null value).");
-
-        return conn;
-    }
-
-    /**
      * Create connection pane with controls.
      *
      * @return Pane with connection controls.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3762de37/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0b9ac0a..4a19938 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,7 @@
         <module>modules/kafka</module>
         <module>modules/yarn</module>
         <module>modules/json</module>
+        <module>modules/schema-import-db</module>
     </modules>
 
     <profiles>


Mime
View raw message