ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [40/50] incubator-ignite git commit: IGNITE-1168 REST API: type metadata for cache.
Date Wed, 05 Aug 2015 01:15:31 GMT
IGNITE-1168 REST API: type metadata for cache.


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

Branch: refs/heads/ignite-843
Commit: d0871610fb9224f02c2cd8b392a2276559797e9f
Parents: e85b2b4
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Tue Aug 4 18:51:28 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Tue Aug 4 18:51:45 2015 +0300

----------------------------------------------------------------------
 .../ignite/examples/ExampleNodeStartup.java     |  4 ++-
 .../JettyRestProcessorAbstractSelfTest.java     | 14 ++++++++
 .../cache/query/GridCacheQueryManager.java      | 37 ++++++++++++++++----
 .../cache/query/GridCacheSqlIndexMetadata.java  | 11 ++++--
 .../cache/query/GridCacheSqlMetadata.java       | 28 ++++++++++++---
 .../jdbc/GridCacheQueryJdbcMetadataTask.java    | 10 +++---
 .../processors/rest/GridRestCommand.java        |  3 ++
 .../processors/rest/GridRestProcessor.java      |  5 +--
 .../handlers/cache/GridCacheCommandHandler.java | 14 +++++++-
 .../IgniteCacheAbstractFieldsQuerySelfTest.java | 14 ++++----
 modules/nodejs/src/main/js/cache.js             |  9 +++++
 .../http/jetty/GridJettyRestHandler.java        |  1 +
 12 files changed, 121 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/examples/src/main/java/org/apache/ignite/examples/ExampleNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/ExampleNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/ExampleNodeStartup.java
index f972b53..7bcd4f7 100644
--- a/examples/src/main/java/org/apache/ignite/examples/ExampleNodeStartup.java
+++ b/examples/src/main/java/org/apache/ignite/examples/ExampleNodeStartup.java
@@ -30,6 +30,8 @@ public class ExampleNodeStartup {
      * @throws IgniteException If failed.
      */
     public static void main(String[] args) throws IgniteException {
-        Ignition.start("examples/config/example-ignite.xml");
+        Ignite start = Ignition.start("examples/config/example-ignite.xml");
+
+        start.createCache("ccc");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/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 5f3d15e..661ed85 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
@@ -1172,6 +1172,20 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
     /**
      * @throws Exception If failed.
      */
+    public void testMetadata() throws Exception {
+        String ret = content(F.asMap("cmd", GridRestCommand.CACHE_METADATA.key()));
+
+        assertNotNull(ret);
+        assertTrue(!ret.isEmpty());
+
+        info("Cache metadata result: " + ret);
+
+        jsonEquals(ret, pattern("\\{.+\\}", true));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testTopology() throws Exception {
         String ret = content(F.asMap("cmd", GridRestCommand.TOPOLOGY.key(), "attr", "false",
"mtr", "false"));
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index 5d3f6a3..006e0d6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -1839,7 +1839,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
 
             for (Collection<CacheSqlMetadata> col : res) {
                 for (CacheSqlMetadata meta : col) {
-                    String name = meta.cacheName();
+                    String name = meta.getCacheName();
 
                     Collection<CacheSqlMetadata> cacheMetas = map.get(name);
 
@@ -2093,12 +2093,12 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         }
 
         /** {@inheritDoc} */
-        @Override public String cacheName() {
+        @Override public String getCacheName() {
             return cacheName;
         }
 
         /** {@inheritDoc} */
-        @Override public Collection<String> types() {
+        @Override public Collection<String> getTypes() {
             return types;
         }
 
@@ -2118,6 +2118,26 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         }
 
         /** {@inheritDoc} */
+        @Override public Map<String, String> getKeyClasses() {
+            return keyClasses;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map<String, String> getValClasses() {
+            return valClasses;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map<String, Map<String, String>> getFields() {
+            return fields;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Map<String, Collection<GridCacheSqlIndexMetadata>> getIndexes()
{
+            return indexes;
+        }
+
+        /** {@inheritDoc} */
         @Override public Collection<GridCacheSqlIndexMetadata> indexes(String type)
{
             return indexes.get(type);
         }
@@ -2193,12 +2213,12 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         }
 
         /** {@inheritDoc} */
-        @Override public String name() {
+        @Override public String getName() {
             return name;
         }
 
         /** {@inheritDoc} */
-        @Override public Collection<String> fields() {
+        @Override public Collection<String> getFields() {
             return fields;
         }
 
@@ -2208,7 +2228,12 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
         }
 
         /** {@inheritDoc} */
-        @Override public boolean unique() {
+        @Override public Collection<String> getDescendings() {
+            return descendings;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isUnique() {
             return unique;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java
index c9ab0e4..996e4b6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java
@@ -33,14 +33,14 @@ public interface GridCacheSqlIndexMetadata extends Externalizable {
      *
      * @return Index name.
      */
-    public String name();
+    public String getName();
 
     /**
      * Gets names of fields indexed by this index.
      *
      * @return Indexed fields names.
      */
-    public Collection<String> fields();
+    public Collection<String> getFields();
 
     /**
      * Gets order of the index for each indexed field.
@@ -51,9 +51,14 @@ public interface GridCacheSqlIndexMetadata extends Externalizable {
     public boolean descending(String field);
 
     /**
+     * @return Descendings.
+     */
+    public Collection<String> getDescendings();
+
+    /**
      * Gets whether this is a unique index.
      *
      * @return {@code True} if index is unique, {@code false} otherwise.
      */
-    public boolean unique();
+    public boolean isUnique();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java
index 7f25490..3a55ccf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java
@@ -36,7 +36,7 @@ public interface GridCacheSqlMetadata extends Externalizable {
      *
      * @return Cache name.
      */
-    public String cacheName();
+    public String getCacheName();
 
     /**
      * Gets the collection of types stored in cache.
@@ -47,12 +47,12 @@ public interface GridCacheSqlMetadata extends Externalizable {
      *
      * @return Collection of available types.
      */
-    public Collection<String> types();
+    public Collection<String> getTypes();
 
     /**
      * Gets key class name for provided type.
      * <p>
-     * Use {@link #types()} method to get available types.
+     * Use {@link #getTypes()} method to get available types.
      *
      * @param type Type name.
      * @return Key class name or {@code null} if type name is unknown.
@@ -62,7 +62,7 @@ public interface GridCacheSqlMetadata extends Externalizable {
     /**
      * Gets value class name for provided type.
      * <p>
-     * Use {@link #types()} method to get available types.
+     * Use {@link #getTypes()} method to get available types.
      *
      * @param type Type name.
      * @return Value class name or {@code null} if type name is unknown.
@@ -78,6 +78,26 @@ public interface GridCacheSqlMetadata extends Externalizable {
     @Nullable public Map<String, String> fields(String type);
 
     /**
+     * @return Key classes.
+     */
+    public Map<String, String> getKeyClasses();
+
+    /**
+     * @return Value classes.
+     */
+    public Map<String, String> getValClasses();
+
+    /**
+     * @return Fields.
+     */
+    public Map<String, Map<String, String>> getFields();
+
+    /**
+     * @return Indexes.
+     */
+    public Map<String, Collection<GridCacheSqlIndexMetadata>> getIndexes();
+
+    /**
      * Gets descriptors of indexes created for provided type.
      * See {@link GridCacheSqlIndexMetadata} javadoc for more information.
      *

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcMetadataTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcMetadataTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcMetadataTask.java
index 6111acd..90cd8c0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcMetadataTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/jdbc/GridCacheQueryJdbcMetadataTask.java
@@ -114,12 +114,12 @@ public class GridCacheQueryJdbcMetadataTask extends ComputeTaskAdapter<String,
b
                 Collection<List<Object>> indexesInfo = new LinkedList<>();
 
                 for (GridCacheSqlMetadata meta : metas) {
-                    String name = meta.cacheName();
+                    String name = meta.getCacheName();
 
                     if (name == null)
                         name = "PUBLIC";
 
-                    Collection<String> types = meta.types();
+                    Collection<String> types = meta.getTypes();
 
                     Map<String, Map<String, String>> typesMap = U.newHashMap(types.size());
 
@@ -129,9 +129,9 @@ public class GridCacheQueryJdbcMetadataTask extends ComputeTaskAdapter<String,
b
                         for (GridCacheSqlIndexMetadata idx : meta.indexes(type)) {
                             int cnt = 0;
 
-                            for (String field : idx.fields()) {
-                                indexesInfo.add(F.<Object>asList(name, type.toUpperCase(),
!idx.unique(),
-                                    idx.name().toUpperCase(), ++cnt, field, idx.descending(field)));
+                            for (String field : idx.getFields()) {
+                                indexesInfo.add(F.<Object>asList(name, type.toUpperCase(),
!idx.isUnique(),
+                                    idx.getName().toUpperCase(), ++cnt, field, idx.descending(field)));
                             }
                         }
                     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
index 44dec65..d28119a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
@@ -96,6 +96,9 @@ public enum GridRestCommand {
     /** Cache size. */
     CACHE_SIZE("size"),
 
+    /** Cache metadata. */
+    CACHE_METADATA("metadata"),
+
     /** Increment. */
     ATOMIC_INCREMENT("incr"),
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index f8ccf8b..5937c14 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -24,9 +24,9 @@ import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.rest.client.message.*;
 import org.apache.ignite.internal.processors.rest.handlers.*;
 import org.apache.ignite.internal.processors.rest.handlers.cache.*;
-import org.apache.ignite.internal.processors.rest.handlers.query.*;
 import org.apache.ignite.internal.processors.rest.handlers.datastructures.*;
-import org.apache.ignite.internal.processors.rest.handlers.scripting.IgniteScriptingCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.query.*;
+import org.apache.ignite.internal.processors.rest.handlers.scripting.*;
 import org.apache.ignite.internal.processors.rest.handlers.task.*;
 import org.apache.ignite.internal.processors.rest.handlers.top.*;
 import org.apache.ignite.internal.processors.rest.handlers.version.*;
@@ -597,6 +597,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
 
             case CACHE_METRICS:
             case CACHE_SIZE:
+            case CACHE_METADATA:
             case TOPOLOGY:
             case NODE:
             case VERSION:

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/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 64f595d..21ed401 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
@@ -22,6 +22,7 @@ import org.apache.ignite.cache.*;
 import org.apache.ignite.cluster.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.processors.cache.transactions.*;
 import org.apache.ignite.internal.processors.rest.*;
 import org.apache.ignite.internal.processors.rest.handlers.*;
@@ -76,7 +77,8 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
         CACHE_APPEND,
         CACHE_PREPEND,
         CACHE_METRICS,
-        CACHE_SIZE
+        CACHE_SIZE,
+        CACHE_METADATA
     );
 
     /** Requests with required parameter {@code key}. */
@@ -181,6 +183,16 @@ public class GridCacheCommandHandler extends GridRestCommandHandlerAdapter
{
                     break;
                 }
 
+                case CACHE_METADATA: {
+                    IgniteInternalCache<Object, Object> cache = localCache(cacheName);
+
+                    GridCacheSqlMetadata res = F.first(cache.context().queries().sqlMetadata());
+
+                    fut = new GridFinishedFuture<>(new GridRestResponse(res));
+
+                    break;
+                }
+
                 case CACHE_CONTAINS_KEYS: {
                     fut = executeCommand(req.destinationId(), req.clientId(), cacheName,
skipStore, key,
                         new ContainsKeysCommand(getKeys(req0)));

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
index ccb3115..ee607a6 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
@@ -221,8 +221,8 @@ public abstract class IgniteCacheAbstractFieldsQuerySelfTest extends GridCommonA
             boolean wasComplexKeys = false;
 
             for (GridCacheSqlMetadata meta : metas) {
-                if (meta.cacheName() == null) {
-                    Collection<String> types = meta.types();
+                if (meta.getCacheName() == null) {
+                    Collection<String> types = meta.getTypes();
 
                     assert types != null;
                     assert types.size() == 4;
@@ -278,16 +278,16 @@ public abstract class IgniteCacheAbstractFieldsQuerySelfTest extends
GridCommonA
 
                     wasNull = true;
                 }
-                else if (CACHE.equals(meta.cacheName()))
+                else if (CACHE.equals(meta.getCacheName()))
                     wasNamed = true;
-                else if (EMPTY_CACHE.equals(meta.cacheName())) {
-                    assert meta.types().isEmpty();
+                else if (EMPTY_CACHE.equals(meta.getCacheName())) {
+                    assert meta.getTypes().isEmpty();
 
                     wasEmpty = true;
                 }
-                else if (CACHE_NO_PRIMITIVES.equals(meta.cacheName()))
+                else if (CACHE_NO_PRIMITIVES.equals(meta.getCacheName()))
                     wasNoPrimitives = true;
-                else if (CACHE_COMPLEX_KEYS.equals(meta.cacheName()))
+                else if (CACHE_COMPLEX_KEYS.equals(meta.getCacheName()))
                     wasComplexKeys = true;
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index e9db1b3..7c04843 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -263,6 +263,15 @@ Cache.prototype.size = function(callback) {
 }
 
 /**
+ * Returns cache metadata.
+ *
+ * @this {Cache}
+ */
+Cache.prototype.metadata = function(callback) {
+    return this.__createPromise(this._createCommand("metadata"));
+}
+
+/**
  * Execute sql query
  *
  * @param {SqlQuery|SqlFieldsQuery} qry Query

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d0871610/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 2cf9988..4d5e14a 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -410,6 +410,7 @@ public class GridJettyRestHandler extends AbstractHandler {
             case CACHE_CAS:
             case CACHE_METRICS:
             case CACHE_SIZE:
+            case CACHE_METADATA:
             case CACHE_REPLACE:
             case CACHE_APPEND:
             case CACHE_PREPEND: {


Mime
View raw message