IGNITE-2252 Added support for cache sql schema in REST topology command - Fixes 
#374.

Signed-off-by: Andrey <anovi...@gridgain.com>


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

Branch: refs/heads/master
Commit: debe34de1881f5a1268993ae584db70f16a761cf
Parents: 383f317
Author: Andrey <anovi...@gridgain.com>
Authored: Thu Dec 24 17:49:02 2015 +0700
Committer: Andrey <anovi...@gridgain.com>
Committed: Thu Dec 24 17:49:02 2015 +0700

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     |  25 +++-
 .../connection/GridClientNioTcpConnection.java  |  17 +--
 .../client/message/GridClientCacheBean.java     | 139 +++++++++++++++++++
 .../rest/client/message/GridClientNodeBean.java |  70 ++++++----
 .../top/GridTopologyCommandHandler.java         |  38 +++--
 5 files changed, 230 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/debe34de/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index 4c73f78..4b1d47c 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@ -35,6 +35,7 @@ import java.util.regex.Pattern;
 import net.sf.json.JSONNull;
 import net.sf.json.JSONObject;
 import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.query.SqlQuery;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
@@ -45,7 +46,6 @@ import 
org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetada
 import org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata;
 import 
org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler;
 import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.util.typedef.P1;
 import org.apache.ignite.lang.IgniteBiPredicate;
@@ -1054,11 +1054,28 @@ public abstract class 
JettyRestProcessorAbstractSelfTest extends AbstractRestPro
             assertEquals(JSONNull.getInstance(), node.get("attributes"));
             assertEquals(JSONNull.getInstance(), node.get("metrics"));
 
-            assertEquals("PARTITIONED", node.get("defaultCacheMode"));
+            Collection<Map> caches = (Collection)node.get("caches");
 
-            Map caches = (Map)node.get("caches");
+            Collection<IgniteCacheProxy<?, ?>> publicCaches = 
grid(0).context().cache().publicCaches();
 
-            assertEquals(F.asMap("person", "PARTITIONED"), caches);
+            assertNotNull(caches);
+            assertEquals(publicCaches.size(), caches.size());
+
+            for (Map cache : caches) {
+                final String cacheName = cache.get("name").equals("") ? null : 
(String)cache.get("name");
+
+                IgniteCacheProxy<?, ?> publicCache = F.find(publicCaches, 
null, new P1<IgniteCacheProxy<?, ?>>() {
+                    @Override public boolean apply(IgniteCacheProxy<?, ?> c) {
+                        return F.eq(c.getName(), cacheName);
+                    }
+                });
+
+                assertNotNull(publicCache);
+
+                CacheMode cacheMode = 
CacheMode.valueOf((String)cache.get("mode"));
+
+                
assertEquals(publicCache.getConfiguration(CacheConfiguration.class).getCacheMode(),cacheMode);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/debe34de/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
index 576df3a..cfcb07f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
@@ -60,6 +60,7 @@ import 
org.apache.ignite.internal.processors.rest.client.message.GridClientCache
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientMessage;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean;
+import 
org.apache.ignite.internal.processors.rest.client.message.GridClientCacheBean;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientNodeMetricsBean;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientResponse;
@@ -926,27 +927,17 @@ public class GridClientNioTcpConnection extends 
GridClientConnection {
         Map<String, GridClientCacheMode> caches = new HashMap<>();
 
         if (nodeBean.getCaches() != null) {
-            for (Map.Entry<String, String> e : 
nodeBean.getCaches().entrySet()) {
+            for (GridClientCacheBean cacheBean : nodeBean.getCaches()) {
                 try {
-                    caches.put(e.getKey(), 
GridClientCacheMode.valueOf(e.getValue()));
+                    caches.put(cacheBean.getName(), cacheBean.getMode());
                 }
                 catch (IllegalArgumentException ignored) {
                     log.warning("Invalid cache mode received from remote node 
(will ignore) [srv=" + serverAddress() +
-                        ", cacheName=" + e.getKey() + ", cacheMode=" + 
e.getValue() + ']');
+                        ", cacheName=" + cacheBean.getName() + ", cacheMode=" 
+ cacheBean.getMode() + ']');
                 }
             }
         }
 
-        if (nodeBean.getDefaultCacheMode() != null) {
-            try {
-                caches.put(null, 
GridClientCacheMode.valueOf(nodeBean.getDefaultCacheMode()));
-            }
-            catch (IllegalArgumentException ignored) {
-                log.warning("Invalid cache mode received for default cache 
from remote node (will ignore) [srv="
-                    + serverAddress() + ", cacheMode=" + 
nodeBean.getDefaultCacheMode() + ']');
-            }
-        }
-
         if (!caches.isEmpty())
             nodeBuilder.caches(caches);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/debe34de/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheBean.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheBean.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheBean.java
new file mode 100644
index 0000000..e055ec3
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientCacheBean.java
@@ -0,0 +1,139 @@
+/*
+ * 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.internal.processors.rest.client.message;
+
+import java.io.Serializable;
+import org.apache.ignite.internal.client.GridClientCacheMode;
+
+/**
+ * Cache bean.
+ */
+public class GridClientCacheBean implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Cache name
+     */
+    private String name;
+
+    /**
+     * Cache mode
+     */
+    private GridClientCacheMode mode;
+
+    /**
+     * Custom name of the sql schema.
+     */
+    private String sqlSchema;
+
+    public GridClientCacheBean() {
+    }
+
+    public GridClientCacheBean(String name, GridClientCacheMode mode, String 
sqlSchema) {
+        this.name = name;
+        this.mode = mode;
+        this.sqlSchema = sqlSchema;
+    }
+
+    /**
+     * Gets cache name.
+     *
+     * @return Cache name.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Sets cache name.
+     *
+     * @param name Cache name.
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Gets cache mode.
+     *
+     * @return Cache mode.
+     */
+    public GridClientCacheMode getMode() {
+        return mode;
+    }
+
+    /**
+     * Sets cache mode.
+     *
+     * @param mode Cache mode.
+     */
+    public void setMode(GridClientCacheMode mode) {
+        this.mode = mode;
+    }
+
+    /**
+     * Gets custom name of the sql schema.
+     *
+     * @return Custom name of the sql schema.
+     */
+    public String getSqlSchema() {
+        return sqlSchema;
+    }
+
+    /**
+     * Sets custom name of the sql schema.
+     *
+     * @param sqlSchema Custom name of the sql schema.
+     */
+    public void setSqlSchema(String sqlSchema) {
+        this.sqlSchema = sqlSchema;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int hashCode() {
+        return name != null ? name.hashCode() : 0;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+
+        if (obj == null || getClass() != obj.getClass())
+            return false;
+
+        GridClientCacheBean other = (GridClientCacheBean) obj;
+
+        return name == null ? other.name == null : name.equals(other.name);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String toString() {
+        return "GridClientCacheBean [name=" + name + ", mode=" + mode + ']';
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/debe34de/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java
index 2a34c80..8ba6eb5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientNodeBean.java
@@ -21,10 +21,12 @@ import java.io.Externalizable;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
 import java.util.UUID;
+import org.apache.ignite.internal.client.GridClientCacheMode;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
@@ -55,11 +57,8 @@ public class GridClientNodeBean implements Externalizable {
     /** Node attributes. */
     private Map<String, Object> attrs;
 
-    /** Mode for cache with {@code null} name. */
-    private String dfltCacheMode;
-
     /** Node caches. */
-    private Map<String, String> caches;
+    private Collection<GridClientCacheBean> caches;
 
     /**
      * Gets node ID.
@@ -177,40 +176,22 @@ public class GridClientNodeBean implements Externalizable 
{
     /**
      * Gets configured node caches.
      *
-     * @return Map where key is cache name and value is cache mode ("LOCAL", 
"REPLICATED", "PARTITIONED").
+     * @return Configured node caches.
      */
-    public Map<String, String> getCaches() {
+    public Collection<GridClientCacheBean> getCaches() {
         return caches;
     }
 
     /**
      * Sets configured node caches.
      *
-     * @param caches Map where key is cache name and value is cache mode 
("LOCAL", "REPLICATED", "PARTITIONED").
+     * @param caches Configured node caches.
      */
-    public void setCaches(Map<String, String> caches) {
+    public void setCaches(Collection<GridClientCacheBean> caches) {
         this.caches = caches;
     }
 
     /**
-     * Gets mode for cache with null name.
-     *
-     * @return Default cache mode.
-     */
-    public String getDefaultCacheMode() {
-        return dfltCacheMode;
-    }
-
-    /**
-     * Sets mode for default cache.
-     *
-     * @param dfltCacheMode Default cache mode.
-     */
-    public void setDefaultCacheMode(String dfltCacheMode) {
-        this.dfltCacheMode = dfltCacheMode;
-    }
-
-    /**
      * Sets REST binary protocol port.
      *
      * @param tcpPort Port on which REST binary protocol is bound.
@@ -242,10 +223,25 @@ public class GridClientNodeBean implements Externalizable 
{
         out.writeInt(tcpPort);
         out.writeInt(0); // Jetty port.
 
+        String dfltCacheMode = null;
+
+        Map<String, String> cacheMap = null;
+
+        if (caches != null) {
+            cacheMap = U.newHashMap(caches.size());
+
+            for (GridClientCacheBean cacheBean : caches) {
+                if (cacheBean.getName() == null)
+                    dfltCacheMode = cacheBean.getMode().toString();
+                else
+                    cacheMap.put(cacheBean.getName(), 
cacheBean.getMode().toString());
+            }
+        }
+
         U.writeString(out, dfltCacheMode);
 
         U.writeMap(out, attrs);
-        U.writeMap(out, caches);
+        U.writeMap(out, cacheMap);
 
         U.writeCollection(out, tcpAddrs);
         U.writeCollection(out, tcpHostNames);
@@ -263,10 +259,24 @@ public class GridClientNodeBean implements Externalizable 
{
         tcpPort = in.readInt();
         in.readInt(); // Jetty port.
 
-        dfltCacheMode = U.readString(in);
+        String dfltCacheMode = U.readString(in);
 
         attrs = U.readMap(in);
-        caches = U.readMap(in);
+
+        Map<String, String> cacheMap = U.readMap(in);
+
+        if (cacheMap == null && dfltCacheMode != null) {
+            cacheMap = U.newHashMap(1);
+
+            cacheMap.put(null, dfltCacheMode);
+        }
+
+        if (cacheMap != null) {
+            caches = new ArrayList<>(cacheMap.size());
+
+            for (Map.Entry<String, String> e : cacheMap.entrySet())
+                caches.add(new GridClientCacheBean(e.getKey(), 
GridClientCacheMode.valueOf(e.getValue()), null));
+        }
 
         tcpAddrs = U.readCollection(in);
         tcpHostNames = U.readCollection(in);
@@ -283,4 +293,4 @@ public class GridClientNodeBean implements Externalizable {
     @Override public String toString() {
         return "GridClientNodeBean [id=" + nodeId + ']';
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/debe34de/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
index f950ac2..297785e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
@@ -30,13 +30,17 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.client.GridClientCacheMode;
+import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
 import org.apache.ignite.internal.processors.port.GridPortRecord;
 import org.apache.ignite.internal.processors.rest.GridRestCommand;
 import org.apache.ignite.internal.processors.rest.GridRestProtocol;
 import org.apache.ignite.internal.processors.rest.GridRestResponse;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientNodeBean;
+import 
org.apache.ignite.internal.processors.rest.client.message.GridClientCacheBean;
 import 
org.apache.ignite.internal.processors.rest.client.message.GridClientNodeMetricsBean;
 import 
org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandlerAdapter;
 import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
@@ -175,6 +179,22 @@ public class GridTopologyCommandHandler extends 
GridRestCommandHandlerAdapter {
     }
 
     /**
+     * Creates cache bean.
+     *
+     * @param ccfg Cache configuration.
+     * @return Cache bean.
+     */
+    public GridClientCacheBean createCacheBean(CacheConfiguration ccfg) {
+        GridClientCacheBean cacheBean = new GridClientCacheBean();
+
+        cacheBean.setName(ccfg.getName());
+        
cacheBean.setMode(GridClientCacheMode.valueOf(ccfg.getCacheMode().toString()));
+        cacheBean.setSqlSchema(ccfg.getSqlSchema());
+
+        return cacheBean;
+    }
+
+    /**
      * Creates node bean out of grid node. Notice that cache attribute is 
handled separately.
      *
      * @param node Grid node.
@@ -194,22 +214,16 @@ public class GridTopologyCommandHandler extends 
GridRestCommandHandlerAdapter {
         
nodeBean.setTcpAddresses(nonEmptyList(node.<Collection<String>>attribute(ATTR_REST_TCP_ADDRS)));
         
nodeBean.setTcpHostNames(nonEmptyList(node.<Collection<String>>attribute(ATTR_REST_TCP_HOST_NAMES)));
 
-        Map<String, CacheMode> nodeCaches = ctx.discovery().nodeCaches(node);
-
-        Map<String, String> cacheMap = U.newHashMap(nodeCaches.size());
+        GridCacheProcessor cacheProc = ctx.cache();
 
-        for (Map.Entry<String, CacheMode> cache : nodeCaches.entrySet()) {
-            String cacheName = cache.getKey();
+        Map<String, CacheMode> nodeCaches = ctx.discovery().nodeCaches(node);
 
-            String mode = cache.getValue().toString();
+        Collection<GridClientCacheBean> caches = new 
ArrayList<>(nodeCaches.size());
 
-            if (cacheName != null)
-                cacheMap.put(cacheName, mode);
-            else
-                nodeBean.setDefaultCacheMode(mode);
-        }
+        for (String cacheName : nodeCaches.keySet())
+            
caches.add(createCacheBean(cacheProc.cacheConfiguration(cacheName)));
 
-        nodeBean.setCaches(cacheMap);
+        nodeBean.setCaches(caches);
 
         if (mtr) {
             ClusterMetrics metrics = node.metrics();

Reply via email to