ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [40/41] ignite git commit: ignite-1168 Fixed after review.
Date Wed, 30 Sep 2015 03:02:04 GMT
ignite-1168 Fixed after review.


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

Branch: refs/heads/ignite-1168
Commit: 6acba08e07b581eb5066f0a03c31ef29e4723773
Parents: 66b91b9
Author: Andrey <anovikov@gridgain.com>
Authored: Wed Sep 30 10:01:15 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Wed Sep 30 10:01:15 2015 +0700

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 160 ++++++++++++++++++-
 .../discovery/GridDiscoveryManager.java         |  29 ++--
 .../processors/cache/GridCacheProcessor.java    |   8 +-
 .../handlers/cache/GridCacheCommandHandler.java |  40 ++++-
 .../top/GridTopologyCommandHandler.java         |  22 ++-
 5 files changed, 223 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6acba08e/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 cc28536..9aa10b7 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
@@ -24,6 +24,7 @@ import java.io.Serializable;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLEncoder;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -31,15 +32,24 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 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.CachePeekMode;
 import org.apache.ignite.cache.query.SqlQuery;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetadata;
+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.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.testframework.GridTestUtils;
 
 import static org.apache.ignite.IgniteSystemProperties.IGNITE_JETTY_PORT;
@@ -901,10 +911,16 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
     }
 
     /**
+     * @param meta Metadata for Ignite cache.
      * @throws Exception If failed.
      */
-    public void testMetadata() throws Exception {
-        String ret = content(F.asMap("cmd", GridRestCommand.CACHE_METADATA.key()));
+    private void testMetadata(GridCacheSqlMetadata meta) throws Exception {
+        Map<String, String> params = F.asMap("cmd", GridRestCommand.CACHE_METADATA.key());
+
+        if (meta.cacheName() != null)
+            params.put("cacheName", meta.cacheName());
+
+        String ret = content(params);
 
         assertNotNull(ret);
         assertTrue(!ret.isEmpty());
@@ -912,6 +928,86 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         info("Cache metadata result: " + ret);
 
         jsonEquals(ret, pattern("\\{.+\\}", true));
+
+        Map res = (Map)JSONObject.fromObject(ret).get("response");
+
+        Collection types = (Collection)res.get("types");
+
+        assertNotNull(types);
+        assertEqualsCollections(meta.types(), types);
+
+        Map keyClasses = (Map)res.get("keyClasses");
+
+        assertNotNull(keyClasses);
+        assertTrue(meta.keyClasses().equals(keyClasses));
+
+        Map valClasses = (Map)res.get("valClasses");
+
+        assertNotNull(valClasses);
+        assertTrue(meta.valClasses().equals(valClasses));
+
+        Map fields = (Map)res.get("fields");
+
+        assertNotNull(fields);
+        assertTrue(meta.fields().equals(fields));
+
+        Map indexesByType = (Map)res.get("indexes");
+
+        assertNotNull(indexesByType);
+        assertEquals(meta.indexes().size(), indexesByType.size());
+
+        for (Map.Entry<String, Collection<GridCacheSqlIndexMetadata>> metaIndexes
: meta.indexes().entrySet()) {
+            Collection<Map> indexes = (Collection<Map>)indexesByType.get(metaIndexes.getKey());
+
+            assertNotNull(indexes);
+            assertEquals(metaIndexes.getValue().size(), indexes.size());
+
+            for (final GridCacheSqlIndexMetadata metaIdx : metaIndexes.getValue()) {
+                Map idx = F.find(indexes, null, new IgnitePredicate<Map>() {
+                    @Override public boolean apply(Map map) {
+                        return metaIdx.name().equals(map.get("name"));
+                    }
+                });
+
+                assertNotNull(idx);
+
+                assertEqualsCollections(metaIdx.fields(), (Collection)idx.get("fields"));
+                assertEqualsCollections(metaIdx.descendings(), (Collection)idx.get("descendings"));
+                assertEquals(metaIdx.unique(), idx.get("unique"));
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetadataLocal() throws Exception {
+        GridCacheProcessor cacheProc = grid(0).context().cache();
+
+        for (IgniteInternalCache<?, ?> cache : cacheProc.caches()) {
+            if (CU.isSystemCache(cache.name()))
+                continue;
+
+            GridCacheSqlMetadata meta = F.first(cache.context().queries().sqlMetadata());
+
+            testMetadata(meta);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetadataRemote() throws Exception {
+        CacheConfiguration<Integer, String> partialCacheCfg = new CacheConfiguration<>("partial");
+
+        partialCacheCfg.setIndexedTypes(Integer.class, String.class);
+        partialCacheCfg.setNodeFilter(new NodeIdFilter(grid(1).localNode().id()));
+
+        IgniteCacheProxy<Integer, String> c = (IgniteCacheProxy<Integer, String>)grid(1).createCache(partialCacheCfg);
+
+        GridCacheSqlMetadata meta = F.first(c.context().queries().sqlMetadata());
+
+        testMetadata(meta);
     }
 
     /**
@@ -926,6 +1022,23 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         info("Topology command result: " + ret);
 
         jsonEquals(ret, pattern("\\[\\{.+\\}\\]", true));
+
+        JSONObject json = JSONObject.fromObject(ret);
+
+        Collection<Map> nodes = (Collection)json.get("response");
+
+        assertEquals(GRID_CNT, nodes.size());
+
+        for (Map node : nodes) {
+            assertEquals(JSONNull.getInstance(), node.get("attributes"));
+            assertEquals(JSONNull.getInstance(), node.get("metrics"));
+
+            assertEquals("PARTITIONED", node.get("defaultCacheMode"));
+
+            Map caches = (Map)node.get("caches");
+
+            assertEquals(F.asMap("person", "PARTITIONED"), caches);
+        }
     }
 
     /**
@@ -1069,6 +1182,29 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         params.put("cmd", GridRestCommand.EXECUTE_SCAN_QUERY.key());
         params.put("pageSize", "10");
         params.put("cacheName", "person");
+
+        String ret = content(params);
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        JSONObject json = JSONObject.fromObject(ret);
+
+        List items = (List)((Map)json.get("response")).get("items");
+
+        assertEquals(4, items.size());
+
+        assertFalse(queryCursorFound());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFilterQueryScan() throws Exception {
+        Map<String, String> params = new HashMap<>();
+        params.put("cmd", GridRestCommand.EXECUTE_SCAN_QUERY.key());
+        params.put("pageSize", "10");
+        params.put("cacheName", "person");
         params.put("classname", ScanFilter.class.getName());
 
         String ret = content(params);
@@ -1088,7 +1224,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
     /**
      * @throws Exception If failed.
      */
-    public void testIncorrectQueryScan() throws Exception {
+    public void testIncorrectFilterQueryScan() throws Exception {
         Map<String, String> params = new HashMap<>();
         params.put("cmd", GridRestCommand.EXECUTE_SCAN_QUERY.key());
         params.put("pageSize", "10");
@@ -1387,4 +1523,22 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
             return person.salary > 1000;
         }
     }
+
+    /** Filter by node ID. */
+    private static class NodeIdFilter implements IgnitePredicate<ClusterNode> {
+        /** */
+        private final UUID nid;
+
+        /**
+         * @param nid Node ID where cache should be started.
+         */
+        NodeIdFilter(UUID nid) {
+            this.nid = nid;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(ClusterNode n) {
+            return n.id().equals(nid);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6acba08e/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index a64e14c..8add472 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -56,6 +56,7 @@ import org.apache.ignite.IgniteClientDisconnectedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteInterruptedException;
 import org.apache.ignite.cache.CacheMetrics;
+import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.events.DiscoveryEvent;
@@ -299,16 +300,16 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
      * @param cacheName Cache name.
      * @param filter Cache filter.
      * @param nearEnabled Near enabled flag.
-     * @param loc {@code True} if cache is local.
+     * @param cacheMode Cache mode.
      */
     public void setCacheFilter(
         String cacheName,
         IgnitePredicate<ClusterNode> filter,
         boolean nearEnabled,
-        boolean loc
+        CacheMode cacheMode
     ) {
         if (!registeredCaches.containsKey(cacheName))
-            registeredCaches.put(cacheName, new CachePredicate(filter, nearEnabled, loc));
+            registeredCaches.put(cacheName, new CachePredicate(filter, nearEnabled, cacheMode));
     }
 
     /**
@@ -1590,19 +1591,19 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
      * @param node Node to check.
      * @return Cache names accessible on the given node.
      */
-    public Collection<String> nodeCaches(ClusterNode node) {
-        Collection<String> cacheNames = new ArrayList<>(registeredCaches.size());
+    public Map<String, CacheMode> nodeCaches(ClusterNode node) {
+        Map<String, CacheMode> caches = U.newHashMap(registeredCaches.size());
 
         for (Map.Entry<String, CachePredicate> entry : registeredCaches.entrySet())
{
             String cacheName = entry.getKey();
 
-            CachePredicate filter = entry.getValue();
+            CachePredicate pred = entry.getValue();
 
-            if (filter != null && filter.cacheNode(node))
-                cacheNames.add(cacheName);
+            if (pred != null && pred.cacheNode(node))
+                caches.put(cacheName, pred.cacheMode);
         }
 
-        return cacheNames;
+        return caches;
     }
 
     /**
@@ -2846,8 +2847,8 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
         /** If near cache is enabled on data nodes. */
         private final boolean nearEnabled;
 
-        /** Flag indicating if cache is local. */
-        private final boolean loc;
+        /** Cache mode. */
+        private final CacheMode cacheMode;
 
         /** Collection of client near nodes. */
         private final ConcurrentHashMap<UUID, Boolean> clientNodes;
@@ -2855,14 +2856,14 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
         /**
          * @param cacheFilter Cache filter.
          * @param nearEnabled Near enabled flag.
-         * @param loc {@code True} if cache is local.
+         * @param cacheMode Cache mode.
          */
-        private CachePredicate(IgnitePredicate<ClusterNode> cacheFilter, boolean nearEnabled,
boolean loc) {
+        private CachePredicate(IgnitePredicate<ClusterNode> cacheFilter, boolean nearEnabled,
CacheMode cacheMode) {
             assert cacheFilter != null;
 
             this.cacheFilter = cacheFilter;
             this.nearEnabled = nearEnabled;
-            this.loc = loc;
+            this.cacheMode = cacheMode;
 
             clientNodes = new ConcurrentHashMap<>();
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/6acba08e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index c86dfd9..c185c54 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -685,7 +685,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                     cfg.getName(),
                     cfg.getNodeFilter(),
                     cfg.getNearConfiguration() != null && cfg.getCacheMode() == PARTITIONED,
-                    cfg.getCacheMode() == LOCAL);
+                    cfg.getCacheMode());
 
                 ctx.discovery().addClientNode(cfg.getName(),
                     ctx.localNodeId(),
@@ -1942,7 +1942,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                                     req.cacheName(),
                                     ccfg.getNodeFilter(),
                                     ccfg.getNearConfiguration() != null,
-                                    ccfg.getCacheMode() == LOCAL);
+                                    ccfg.getCacheMode());
                             }
                         }
                         else {
@@ -1965,7 +1965,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                                 req.cacheName(),
                                 ccfg.getNodeFilter(),
                                 ccfg.getNearConfiguration() != null,
-                                ccfg.getCacheMode() == LOCAL);
+                                ccfg.getCacheMode());
                         }
                     }
                 }
@@ -2434,7 +2434,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                             ccfg.getName(),
                             ccfg.getNodeFilter(),
                             ccfg.getNearConfiguration() != null,
-                            ccfg.getCacheMode() == LOCAL);
+                            ccfg.getCacheMode());
 
                         ctx.discovery().addClientNode(req.cacheName(),
                             req.initiatingNodeId(),

http://git-wip-us.apache.org/repos/asf/ignite/blob/6acba08e/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index 726f6ce..1c6d18d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -228,11 +228,20 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                 }
 
                 case CACHE_METADATA: {
-                    IgniteInternalCache<Object, Object> cache = localCache(cacheName);
+                    IgniteInternalCache<?, ?> cache = ctx.cache().cache(cacheName);
 
-                    GridCacheSqlMetadata res = F.first(cache.context().queries().sqlMetadata());
+                    if (cache != null) {
+                        GridCacheSqlMetadata res = F.first(cache.context().queries().sqlMetadata());
 
-                    fut = new GridFinishedFuture<>(new GridRestResponse(res));
+                        fut = new GridFinishedFuture<>(new GridRestResponse(res));
+                    }
+                    else {
+                        ClusterGroup prj = ctx.grid().cluster().forDataNodes(cacheName);
+
+                        ctx.task().setThreadContext(TC_NO_FAILOVER, true);
+
+                        fut = ctx.closure().callAsync(BALANCE, new MetadataCommand(cacheName),
prj.nodes());
+                    }
 
                     break;
                 }
@@ -905,6 +914,31 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
     }
 
     /** */
+    private static class MetadataCommand implements Callable<GridRestResponse>, Serializable
{
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private final String cacheName;
+
+        /** */
+        @IgniteInstanceResource
+        private Ignite g;
+
+        /**
+         * @param cacheName Cache name.
+         */
+        private MetadataCommand(String cacheName) {
+            this.cacheName = cacheName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            return  new GridRestResponse(F.first(cache(g, cacheName).context().queries().sqlMetadata()));
+        }
+    }
+
+    /** */
     private static class ContainsKeysCommand extends CacheProjectionCommand {
         /** */
         private static final long serialVersionUID = 0L;

http://git-wip-us.apache.org/repos/asf/ignite/blob/6acba08e/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 d217995..b68c7d4 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
@@ -27,12 +27,11 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.UUID;
 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.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
-import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.port.GridPortRecord;
 import org.apache.ignite.internal.processors.rest.GridRestCommand;
 import org.apache.ignite.internal.processors.rest.GridRestProtocol;
@@ -45,6 +44,7 @@ import org.apache.ignite.internal.processors.rest.request.GridRestTopologyReques
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.P1;
+import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.IgnitePortProtocol;
@@ -195,22 +195,20 @@ 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)));
 
-        Collection<String> cacheNames = ctx.discovery().nodeCaches(node);
+        Map<String, CacheMode> nodeCaches = ctx.discovery().nodeCaches(node);
 
-        Map<String, String> cacheMap = U.newHashMap(cacheNames.size());
+        Map<String, String> cacheMap = U.newHashMap(nodeCaches.size());
 
-        GridCacheProcessor cacheProc = ctx.cache();
+        for (Map.Entry<String, CacheMode> cache : nodeCaches.entrySet()) {
+            String cacheName = cache.getKey();
 
-        for (String cacheName : cacheNames) {
-            IgniteInternalCache<?, ?> cache = cacheProc.cache(cacheName);
-
-            if (cacheProc.systemCache(cache.name()))
+            if (CU.isSystemCache(cacheName))
                 continue;
 
-            String mode = cache.configuration().getCacheMode().toString();
+            String mode = cache.getValue().toString();
 
-            if (cache.name() != null)
-                cacheMap.put(cache.name(), mode);
+            if (cacheName != null)
+                cacheMap.put(cacheName, mode);
             else
                 nodeBean.setDefaultCacheMode(mode);
         }


Mime
View raw message