You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/10/25 22:06:03 UTC

[GitHub] [ignite-extensions] ololo3000 opened a new pull request #26: IGNITE-13519 Adds Spring Data thin client support.

ololo3000 opened a new pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] ololo3000 commented on a change in pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#discussion_r516110159



##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteCacheProxy.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.springdata22.repository.support;
+
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.cache.expiry.ExpiryPolicy;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.client.ClientCache;
+
+/** Reperesents Ignite cache operations required by Spring Data. */
+public interface IgniteCacheProxy<K, V> extends Iterable<Cache.Entry<K, V>> {

Review comment:
       Done. Proxy classes were moved to ignite-spring-data-connector module.

##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
##########
@@ -89,29 +96,37 @@ public IgniteRepositoryFactory(ApplicationContext ctx) {
     }
 
     /** */
-    private Ignite igniteForRepoConfig(RepositoryConfig config) {
+    private IgniteProxy igniteForRepoConfig(RepositoryConfig config) {
         try {
-            String igniteInstanceName = evaluateExpression(config.igniteInstance());
-            return (Ignite)ctx.getBean(igniteInstanceName);
+            Object igniteInstanceBean = ctx.getBean(evaluateExpression(config.igniteInstance()));
+
+            if (igniteInstanceBean instanceof Ignite)
+                return new IgniteProxyImpl((Ignite)igniteInstanceBean);
+            else if (igniteInstanceBean instanceof IgniteClient)
+                return new IgniteClientProxy((IgniteClient)igniteInstanceBean);
+
+            throw new IllegalStateException("Invalid repository configuration. The Spring Bean corresponding to the" +
+                " \"igniteInstance\" property of repository configuration must be one of the following types:" +
+                " \"org.apache.ignite.Ignite\", \"org.apache.ignite.client.IgniteClient\"");
         }
         catch (BeansException ex) {
             try {
                 String igniteConfigName = evaluateExpression(config.igniteCfg());
                 IgniteConfiguration cfg = (IgniteConfiguration)ctx.getBean(igniteConfigName);
                 try {
                     // first try to attach to existing ignite instance
-                    return Ignition.ignite(cfg.getIgniteInstanceName());
+                    return new IgniteProxyImpl(Ignition.ignite(cfg.getIgniteInstanceName()));
                 }
                 catch (Exception ignored) {
                     // nop
                 }
-                return Ignition.start(cfg);
+                return new IgniteProxyImpl(Ignition.start(cfg));

Review comment:
       Done.

##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteCacheProxy.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.springdata22.repository.support;
+
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.cache.expiry.ExpiryPolicy;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.client.ClientCache;
+
+/** Reperesents Ignite cache operations required by Spring Data. */
+public interface IgniteCacheProxy<K, V> extends Iterable<Cache.Entry<K, V>> {

Review comment:
       Done. Proxy classes were moved to ignite-spring-data-proxy module.

##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
##########
@@ -237,7 +260,14 @@ private IgniteCache getRepositoryCache(Class<?> repoIf) {
                     + ".config.Query annotation.");
             }
 
-            return new IgniteRepositoryQuery(ignite, metadata, IgniteQueryGenerator.generateSql(mtd, metadata), mtd,
+            IgniteQuery qry = IgniteQueryGenerator.generateSql(mtd, metadata);
+
+            if (qry.isTextQuery() && isThinClient) {

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] alex-plekhanov commented on pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#issuecomment-723021037


   Looks good to me, thanks. I will merge it a little bit later today.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] alex-plekhanov commented on a change in pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#discussion_r515782555



##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryFactory.java
##########
@@ -89,29 +96,37 @@ public IgniteRepositoryFactory(ApplicationContext ctx) {
     }
 
     /** */
-    private Ignite igniteForRepoConfig(RepositoryConfig config) {
+    private IgniteProxy igniteForRepoConfig(RepositoryConfig config) {
         try {
-            String igniteInstanceName = evaluateExpression(config.igniteInstance());
-            return (Ignite)ctx.getBean(igniteInstanceName);
+            Object igniteInstanceBean = ctx.getBean(evaluateExpression(config.igniteInstance()));
+
+            if (igniteInstanceBean instanceof Ignite)
+                return new IgniteProxyImpl((Ignite)igniteInstanceBean);
+            else if (igniteInstanceBean instanceof IgniteClient)
+                return new IgniteClientProxy((IgniteClient)igniteInstanceBean);
+
+            throw new IllegalStateException("Invalid repository configuration. The Spring Bean corresponding to the" +
+                " \"igniteInstance\" property of repository configuration must be one of the following types:" +
+                " \"org.apache.ignite.Ignite\", \"org.apache.ignite.client.IgniteClient\"");
         }
         catch (BeansException ex) {
             try {
                 String igniteConfigName = evaluateExpression(config.igniteCfg());
                 IgniteConfiguration cfg = (IgniteConfiguration)ctx.getBean(igniteConfigName);
                 try {
                     // first try to attach to existing ignite instance
-                    return Ignition.ignite(cfg.getIgniteInstanceName());
+                    return new IgniteProxyImpl(Ignition.ignite(cfg.getIgniteInstanceName()));
                 }
                 catch (Exception ignored) {
                     // nop
                 }
-                return Ignition.start(cfg);
+                return new IgniteProxyImpl(Ignition.start(cfg));

Review comment:
       We have the ability to start Ignite nodes now, starting thin client is much more lightweight and I think sometimes will be helpful. Those who use spring-data not always use spring-boot. 

##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteCacheProxy.java
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.springdata22.repository.support;
+
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.cache.expiry.ExpiryPolicy;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.query.Query;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.client.ClientCache;
+
+/** Reperesents Ignite cache operations required by Spring Data. */
+public interface IgniteCacheProxy<K, V> extends Iterable<Cache.Entry<K, V>> {

Review comment:
       I think it's reasonable to move the common part into a separate module even if there will be no usage outside of spring-data module. But perhaps this module will be also usable for transaction manager in ignite-spring module (we should also add support for thin clients in transaction manager)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] ololo3000 commented on a change in pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#discussion_r518674514



##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/query/IgniteRepositoryQuery.java
##########
@@ -351,7 +340,21 @@ public IgniteRepositoryQuery(Ignite ignite,
 
         Query iQry = prepareQuery(qry, config, returnStgy, parameters);
 
-        QueryCursor qryCursor = cache.query(iQry);
+        QueryCursor qryCursor;
+
+        try {
+            qryCursor = cache.query(iQry);
+        }
+        catch (IllegalArgumentException e) {
+            if (cache instanceof IgniteCacheClientProxy) {
+                throw new IllegalStateException(String.format("Query of type %s is not supported by thin client." +
+                    " Check %s#%s method configuration or use Ignite node instance to connect to the Ignite cluster.",
+                    iQry.getClass().getSimpleName(), mtd.getDeclaringClass().getName(), mtd.getName()), e);
+            }
+
+            throw e;
+        }
+

Review comment:
       Done.

##########
File path: modules/spring-data-ext/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactoryBean.java
##########
@@ -81,12 +84,30 @@ protected IgniteRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
                     return new IgniteRepositoryFactory(path);
                 }
                 catch (BeansException ex3) {
-                    throw new IgniteException("Failed to initialize Ignite repository factory. Ignite instance or" +
-                        " IgniteConfiguration or a path to Ignite's spring XML configuration must be defined in the" +
-                        " application configuration");
+                    throw new IgniteException("Failed to initialize Ignite repository factory. One of the following" +
+                        " beans must be defined in application configuration: \"igniteInstance\", \"igniteCfg\"," +
+                        " \"igniteSpringCfgPath\".");
                 }
             }
         }
     }
+
+    /**
+     * Creates instance of {@link IgniteRepositoryFactory} via reflection.
+     *
+     * @param args Arguments to be used when creating the {@link IgniteRepositoryFactory} instance.
+     * @return {@link IgniteRepositoryFactory} instance.
+     */
+    private IgniteRepositoryFactory createRepositoryFactory(Object... args) {
+        Constructor<?> ctor = ReflectionUtils.findConstructor(IgniteRepositoryFactory.class, args);

Review comment:
       Done.

##########
File path: modules/spring-data-2.0-ext/src/main/java/org/apache/ignite/springdata20/repository/query/IgniteRepositoryQuery.java
##########
@@ -351,7 +340,21 @@ public IgniteRepositoryQuery(Ignite ignite,
 
         Query iQry = prepareQuery(qry, config, returnStgy, parameters);
 
-        QueryCursor qryCursor = cache.query(iQry);
+        QueryCursor qryCursor;
+
+        try {
+            qryCursor = cache.query(iQry);
+        }
+        catch (IllegalArgumentException e) {
+            if (cache instanceof IgniteCacheClientProxy) {
+                throw new IllegalStateException(String.format("Query of type %s is not supported by thin client." +
+                    " Check %s#%s method configuration or use Ignite node instance to connect to the Ignite cluster.",
+                    iQry.getClass().getSimpleName(), mtd.getDeclaringClass().getName(), mtd.getName()), e);
+            }
+
+            throw e;
+        }
+

Review comment:
       Done.

##########
File path: modules/spring-data-2.0-ext/pom.xml
##########
@@ -149,6 +149,12 @@
             <version>${ignite.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-spring-data-proxy</artifactId>

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] asfgit closed pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] alex-plekhanov commented on a change in pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#discussion_r518571185



##########
File path: modules/spring-data-2.0-ext/pom.xml
##########
@@ -149,6 +149,12 @@
             <version>${ignite.version}</version>
             <scope>test</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-spring-data-proxy</artifactId>

Review comment:
       Let's name it "ignite-spring-data-commons", perhaps we can move here some more classes later.

##########
File path: modules/spring-data-2.0-ext/src/main/java/org/apache/ignite/springdata20/repository/query/IgniteRepositoryQuery.java
##########
@@ -351,7 +340,21 @@ public IgniteRepositoryQuery(Ignite ignite,
 
         Query iQry = prepareQuery(qry, config, returnStgy, parameters);
 
-        QueryCursor qryCursor = cache.query(iQry);
+        QueryCursor qryCursor;
+
+        try {
+            qryCursor = cache.query(iQry);
+        }
+        catch (IllegalArgumentException e) {
+            if (cache instanceof IgniteCacheClientProxy) {
+                throw new IllegalStateException(String.format("Query of type %s is not supported by thin client." +
+                    " Check %s#%s method configuration or use Ignite node instance to connect to the Ignite cluster.",
+                    iQry.getClass().getSimpleName(), mtd.getDeclaringClass().getName(), mtd.getName()), e);
+            }
+
+            throw e;
+        }
+

Review comment:
       Redundant NL

##########
File path: modules/spring-data-ext/src/main/java/org/apache/ignite/springdata/repository/support/IgniteRepositoryFactoryBean.java
##########
@@ -81,12 +84,30 @@ protected IgniteRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
                     return new IgniteRepositoryFactory(path);
                 }
                 catch (BeansException ex3) {
-                    throw new IgniteException("Failed to initialize Ignite repository factory. Ignite instance or" +
-                        " IgniteConfiguration or a path to Ignite's spring XML configuration must be defined in the" +
-                        " application configuration");
+                    throw new IgniteException("Failed to initialize Ignite repository factory. One of the following" +
+                        " beans must be defined in application configuration: \"igniteInstance\", \"igniteCfg\"," +
+                        " \"igniteSpringCfgPath\".");
                 }
             }
         }
     }
+
+    /**
+     * Creates instance of {@link IgniteRepositoryFactory} via reflection.
+     *
+     * @param args Arguments to be used when creating the {@link IgniteRepositoryFactory} instance.
+     * @return {@link IgniteRepositoryFactory} instance.
+     */
+    private IgniteRepositoryFactory createRepositoryFactory(Object... args) {
+        Constructor<?> ctor = ReflectionUtils.findConstructor(IgniteRepositoryFactory.class, args);

Review comment:
       Let's use if/else if instead of reflection. 
   Or better inline these if's to `createRepositoryFactory()` method (like in other modules).

##########
File path: modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/query/IgniteRepositoryQuery.java
##########
@@ -351,7 +340,21 @@ public IgniteRepositoryQuery(Ignite ignite,
 
         Query iQry = prepareQuery(qry, config, returnStgy, parameters);
 
-        QueryCursor qryCursor = cache.query(iQry);
+        QueryCursor qryCursor;
+
+        try {
+            qryCursor = cache.query(iQry);
+        }
+        catch (IllegalArgumentException e) {
+            if (cache instanceof IgniteCacheClientProxy) {
+                throw new IllegalStateException(String.format("Query of type %s is not supported by thin client." +
+                    " Check %s#%s method configuration or use Ignite node instance to connect to the Ignite cluster.",
+                    iQry.getClass().getSimpleName(), mtd.getDeclaringClass().getName(), mtd.getName()), e);
+            }
+
+            throw e;
+        }
+

Review comment:
       Redundant NL




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] ololo3000 commented on pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#issuecomment-723019574


   @alex-plekhanov All comments mentioned by you were fixed. Could you please take a look?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-extensions] ololo3000 commented on pull request #26: IGNITE-13519 Adds Spring Data thin client support.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on pull request #26:
URL: https://github.com/apache/ignite-extensions/pull/26#issuecomment-720793554


   @alex-plekhanov All comments mentioned by you were fixed. Could you please take a look?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org