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/04/28 09:17:16 UTC

[GitHub] [ignite] alex-plekhanov opened a new pull request #7753: IGNITE-12407 Java thin client: Cluster API support

alex-plekhanov opened a new pull request #7753:
URL: https://github.com/apache/ignite/pull/7753


   


----------------------------------------------------------------
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] NSAmelchev commented on a change in pull request #7753: IGNITE-12407 Java thin client: Cluster API support

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7753:
URL: https://github.com/apache/ignite/pull/7753#discussion_r421134766



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
##########
@@ -28,7 +28,10 @@
     USER_ATTRIBUTES(0),
 
     /** Compute tasks (execute by task name). */
-    EXECUTE_TASK_BY_NAME(1);
+    EXECUTE_TASK_BY_NAME(1),
+
+    /** Cluster operations (state and WAL) */

Review comment:
       Missed dot.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterGetStateRequest.java
##########
@@ -17,29 +17,34 @@
 
 package org.apache.ignite.internal.processors.platform.client.cluster;
 
-import org.apache.ignite.IgniteCluster;
 import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.processors.platform.client.ClientBitmaskFeature;
 import org.apache.ignite.internal.processors.platform.client.ClientBooleanResponse;
+import org.apache.ignite.internal.processors.platform.client.ClientByteResponse;
 import org.apache.ignite.internal.processors.platform.client.ClientConnectionContext;
 import org.apache.ignite.internal.processors.platform.client.ClientRequest;
 import org.apache.ignite.internal.processors.platform.client.ClientResponse;
 
 /**
  * Cluster status request.
  */
-public class ClientClusterIsActiveRequest extends ClientRequest {
+public class ClientClusterGetStateRequest extends ClientRequest {
     /**
      * Constructor.
      *
      * @param reader Reader.
      */
-    public ClientClusterIsActiveRequest(BinaryRawReader reader) {
+    public ClientClusterGetStateRequest(BinaryRawReader reader) {
         super(reader);
     }
 
     /** {@inheritDoc} */
     @Override public ClientResponse process(ClientConnectionContext ctx) {
-        IgniteCluster cluster = ctx.kernalContext().grid().cluster();
-        return new ClientBooleanResponse(requestId(), cluster.active());
+        ClusterState state = ctx.kernalContext().grid().cluster().state();
+
+        return ctx.currentProtocolContext().isFeatureSupported(ClientBitmaskFeature.CLUSTER_API) ?
+            new ClientByteResponse(requestId(), (byte)state.ordinal()) :
+            new ClientBooleanResponse(requestId(), state != ClusterState.INACTIVE);

Review comment:
       Let's use `ClusterState.active(state)`

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/client/thin/ClusterApiTest.java
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.client.thin;
+
+import org.apache.ignite.IgniteCluster;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.ClientCluster;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Checks cluster state/WAL state operations for thin client.
+ */
+public class ClusterApiTest extends GridCommonAbstractTest {
+    /** Client connector address. */
+    private static final String CLIENT_CONN_ADDR = "127.0.0.1:" + ClientConnectorConfiguration.DFLT_PORT;
+
+    /**
+     * {@inheritDoc}

Review comment:
       Use one-line javadoc, please

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/client/thin/ClusterApiTest.java
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.client.thin;
+
+import org.apache.ignite.IgniteCluster;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.ClientCluster;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Checks cluster state/WAL state operations for thin client.
+ */
+public class ClusterApiTest extends GridCommonAbstractTest {
+    /** Client connector address. */
+    private static final String CLIENT_CONN_ADDR = "127.0.0.1:" + ClientConnectorConfiguration.DFLT_PORT;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                    .setPersistenceEnabled(true)))
+            .setClusterStateOnStart(ClusterState.INACTIVE);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        cleanPersistenceDir();
+
+        startGrid(0);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        cleanPersistenceDir();
+
+        super.afterTestsStopped();
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testClusterState() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(CLIENT_CONN_ADDR))) {
+            ClientCluster clientCluster = client.cluster();
+            IgniteCluster igniteCluster = grid(0).cluster();
+
+            changeAndCheckState(clientCluster, igniteCluster, ClusterState.INACTIVE);
+            changeAndCheckState(clientCluster, igniteCluster, ClusterState.ACTIVE_READ_ONLY);
+            changeAndCheckState(clientCluster, igniteCluster, ClusterState.ACTIVE);
+            changeAndCheckState(clientCluster, igniteCluster, ClusterState.INACTIVE);
+        }
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void testWalState() throws Exception {
+        try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(CLIENT_CONN_ADDR))) {
+            ClientCluster clientCluster = client.cluster();
+            IgniteCluster igniteCluster = grid(0).cluster();
+
+            igniteCluster.state(ClusterState.ACTIVE);
+
+            grid(0).getOrCreateCache(DEFAULT_CACHE_NAME);
+
+            igniteCluster.disableWal(DEFAULT_CACHE_NAME);
+
+            // Check enable WAL operation.
+            assertTrue(clientCluster.enableWal(DEFAULT_CACHE_NAME));
+            assertTrue(clientCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+            assertTrue(igniteCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+
+            // Check enable WAL operation on already enabled WAL.
+            assertFalse(clientCluster.enableWal(DEFAULT_CACHE_NAME));
+            assertTrue(clientCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+            assertTrue(igniteCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+
+            // Check disable WAL operation.
+            assertTrue(clientCluster.disableWal(DEFAULT_CACHE_NAME));
+            assertFalse(clientCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+            assertFalse(igniteCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+
+            // Check disable WAL operation on already disabled WAL.
+            assertFalse(clientCluster.disableWal(DEFAULT_CACHE_NAME));
+            assertFalse(clientCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+            assertFalse(igniteCluster.isWalEnabled(DEFAULT_CACHE_NAME));
+        }
+    }
+
+    /**
+     *

Review comment:
       Add javadoc, please.




----------------------------------------------------------------
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