This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 9d0e2dd IGNITE-12407 Java thin client: Cluster API support - Fixes
#7753.
9d0e2dd is described below
commit 9d0e2ddff2708a0f3eabcbf586832821f90600e9
Author: Aleksey Plekhanov <[email protected]>
AuthorDate: Thu May 7 16:00:15 2020 +0300
IGNITE-12407 Java thin client: Cluster API support - Fixes #7753.
Signed-off-by: Aleksey Plekhanov <[email protected]>
---
.../org/apache/ignite/client/ClientCluster.java | 67 ++++++++++-
...ClientFeatureNotSupportedByServerException.java | 9 ++
.../internal/client/thin/ClientClusterImpl.java | 119 ++++++++++++++++++-
.../internal/client/thin/ClientOperation.java | 10 ++
.../client/thin/ProtocolBitmaskFeature.java | 8 +-
.../client/thin/ProtocolVersionFeature.java | 3 +
.../internal/client/thin/TcpIgniteClient.java | 2 +-
.../platform/client/ClientBitmaskFeature.java | 5 +-
...eStateResponse.java => ClientByteResponse.java} | 23 ++--
.../platform/client/ClientMessageParser.java | 8 +-
.../cluster/ClientClusterChangeStateRequest.java | 11 +-
...uest.java => ClientClusterGetStateRequest.java} | 15 ++-
.../ClientClusterWalChangeStateRequest.java | 9 +-
.../internal/client/thin/ClusterApiTest.java | 129 +++++++++++++++++++++
.../org/apache/ignite/client/ClientTestSuite.java | 2 +
15 files changed, 382 insertions(+), 38 deletions(-)
diff --git
a/modules/core/src/main/java/org/apache/ignite/client/ClientCluster.java
b/modules/core/src/main/java/org/apache/ignite/client/ClientCluster.java
index 7ff0e51..fc34b41 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/ClientCluster.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/ClientCluster.java
@@ -17,9 +17,74 @@
package org.apache.ignite.client;
+import org.apache.ignite.cluster.ClusterState;
+
/**
* Thin client cluster facade. Represents whole cluster (all available nodes).
*/
public interface ClientCluster extends ClientClusterGroup {
- // No-op.
+ /**
+ * Gets current cluster state.
+ *
+ * @return Current cluster state.
+ */
+ public ClusterState state();
+
+ /**
+ * Changes current cluster state to given {@code newState} cluster state.
+ * <p>
+ * <b>NOTE:</b>
+ * Deactivation clears in-memory caches (without persistence) including
the system caches.
+ *
+ * @param newState New cluster state.
+ * @throws ClientException If change state operation failed.
+ */
+ public void state(ClusterState newState) throws ClientException;
+
+ /**
+ * Disables write-ahead logging for specified cache. When WAL is disabled,
changes are not logged to disk.
+ * This significantly improves cache update speed. The drawback is absence
of local crash-recovery guarantees.
+ * If node is crashed, local content of WAL-disabled cache will be cleared
on restart to avoid data corruption.
+ * <p>
+ * Internally this method will wait for all current cache operations to
finish and prevent new cache operations
+ * from being executed. Then checkpoint is initiated to flush all data to
disk. Control is returned to the callee
+ * when all dirty pages are prepared for checkpoint, but not necessarily
flushed to disk.
+ * <p>
+ * WAL state can be changed only for persistent caches.
+ *
+ * @param cacheName Cache name.
+ * @return Whether WAL disabled by this call.
+ * @throws ClientException If error occurs.
+ * @see #enableWal(String)
+ * @see #isWalEnabled(String)
+ */
+ public boolean disableWal(String cacheName) throws ClientException;
+
+ /**
+ * Enables write-ahead logging for specified cache. Restoring
crash-recovery guarantees of a previous call to
+ * {@link #disableWal(String)}.
+ * <p>
+ * Internally this method will wait for all current cache operations to
finish and prevent new cache operations
+ * from being executed. Then checkpoint is initiated to flush all data to
disk. Control is returned to the callee
+ * when all data is persisted to disk.
+ * <p>
+ * WAL state can be changed only for persistent caches.
+ *
+ * @param cacheName Cache name.
+ * @return Whether WAL enabled by this call.
+ * @throws ClientException If error occurs.
+ * @see #disableWal(String)
+ * @see #isWalEnabled(String)
+ */
+ public boolean enableWal(String cacheName) throws ClientException;
+
+ /**
+ * Checks if write-ahead logging is enabled for specified cache.
+ *
+ * @param cacheName Cache name.
+ * @return {@code True} if WAL is enabled for cache.
+ * @see #disableWal(String)
+ * @see #enableWal(String)
+ */
+ public boolean isWalEnabled(String cacheName);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/client/ClientFeatureNotSupportedByServerException.java
b/modules/core/src/main/java/org/apache/ignite/client/ClientFeatureNotSupportedByServerException.java
index e8c2110..2bde0b8 100644
---
a/modules/core/src/main/java/org/apache/ignite/client/ClientFeatureNotSupportedByServerException.java
+++
b/modules/core/src/main/java/org/apache/ignite/client/ClientFeatureNotSupportedByServerException.java
@@ -17,6 +17,8 @@
package org.apache.ignite.client;
+import org.apache.ignite.internal.client.thin.ProtocolBitmaskFeature;
+
/**
* Feature not supported by server exception.
*/
@@ -32,4 +34,11 @@ public class ClientFeatureNotSupportedByServerException
extends ClientException
public ClientFeatureNotSupportedByServerException(String msg) {
super(msg);
}
+
+ /**
+ * @param feature Feature.
+ */
+ public ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature
feature) {
+ super("Feature " + feature.name() + " is not supported by the server");
+ }
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientClusterImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientClusterImpl.java
index dd43a03..9d822cd 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientClusterImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientClusterImpl.java
@@ -18,15 +18,130 @@
package org.apache.ignite.internal.client.thin;
import org.apache.ignite.client.ClientCluster;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.ClientFeatureNotSupportedByServerException;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
/**
* Implementation of {@link ClientCluster}.
*/
class ClientClusterImpl extends ClientClusterGroupImpl implements
ClientCluster {
+ /** Channel. */
+ private final ReliableChannel ch;
+
+ /** Binary marshaller. */
+ private final ClientBinaryMarshaller marsh;
+
/**
- * Default constructor.
+ * Constructor.
*/
- ClientClusterImpl() {
+ ClientClusterImpl(ReliableChannel ch, ClientBinaryMarshaller marsh) {
super(null);
+
+ this.ch = ch;
+ this.marsh = marsh;
+ }
+
+ /** {@inheritDoc} */
+ @Override public ClusterState state() {
+ try {
+ return ch.service(ClientOperation.CLUSTER_GET_STATE,
+ req ->
checkClusterApiSupported(req.clientChannel().protocolCtx()),
+ res -> ClusterState.fromOrdinal(res.in().readByte())
+ );
+ }
+ catch (ClientError e) {
+ throw new ClientException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void state(ClusterState newState) throws ClientException {
+ try {
+ ch.service(ClientOperation.CLUSTER_CHANGE_STATE,
+ req -> {
+ ProtocolContext protocolCtx =
req.clientChannel().protocolCtx();
+
+ checkClusterApiSupported(protocolCtx);
+
+ if (newState.ordinal() > 1 &&
!protocolCtx.isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_API)) {
+ throw new
ClientFeatureNotSupportedByServerException("State " + newState.name() + " is
not " +
+ "supported by the server");
+ }
+
+ req.out().writeByte((byte)newState.ordinal());
+ },
+ null
+ );
+ }
+ catch (ClientError e) {
+ throw new ClientException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean disableWal(String cacheName) throws
ClientException {
+ return changeWalState(cacheName, false);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean enableWal(String cacheName) throws
ClientException {
+ return changeWalState(cacheName, true);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isWalEnabled(String cacheName) {
+ try {
+ return ch.service(ClientOperation.CLUSTER_GET_WAL_STATE,
+ req -> {
+
checkClusterApiSupported(req.clientChannel().protocolCtx());
+
+ try (BinaryRawWriterEx writer = new
BinaryWriterExImpl(marsh.context(), req.out(), null, null)) {
+ writer.writeString(cacheName);
+ }
+ },
+ res -> res.in().readBoolean()
+ );
+ }
+ catch (ClientError e) {
+ throw new ClientException(e);
+ }
+ }
+
+ /**
+ * @param cacheName Cache name.
+ * @param enable {@code True} if WAL should be enabled, {@code false} if
WAL should be disabled.
+ */
+ private boolean changeWalState(String cacheName, boolean enable) throws
ClientException {
+ try {
+ return ch.service(ClientOperation.CLUSTER_CHANGE_WAL_STATE,
+ req -> {
+
checkClusterApiSupported(req.clientChannel().protocolCtx());
+
+ try (BinaryRawWriterEx writer = new
BinaryWriterExImpl(marsh.context(), req.out(), null, null)) {
+ writer.writeString(cacheName);
+ writer.writeBoolean(enable);
+ }
+ },
+ res -> res.in().readBoolean()
+ );
+ }
+ catch (ClientError e) {
+ throw new ClientException(e);
+ }
+ }
+
+ /**
+ * Check that Cluster API is supported by server.
+ *
+ * @param protocolCtx Protocol context.
+ */
+ private void checkClusterApiSupported(ProtocolContext protocolCtx)
+ throws ClientFeatureNotSupportedByServerException {
+ if
(!protocolCtx.isFeatureSupported(ProtocolVersionFeature.CLUSTER_API) &&
+
!protocolCtx.isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_API))
+ throw new
ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature.CLUSTER_API);
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientOperation.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientOperation.java
index 8ad6b64..d6529fb 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientOperation.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ClientOperation.java
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
/** Operation codes. */
enum ClientOperation {
/** Resource close. */RESOURCE_CLOSE(0),
+
/** Cache get or create with name. */CACHE_GET_OR_CREATE_WITH_NAME(1052),
/** Cache put. */CACHE_PUT(1001),
/** Cache get. */CACHE_GET(1000),
@@ -49,18 +50,27 @@ enum ClientOperation {
/** Cache put if absent. */CACHE_PUT_IF_ABSENT(1002),
/** Cache clear. */CACHE_CLEAR(1013),
/** Cache partitions. */CACHE_PARTITIONS(1101),
+
/** Query scan. */QUERY_SCAN(2000),
/** Query scan cursor get page. */QUERY_SCAN_CURSOR_GET_PAGE(2001),
/** Query sql. */QUERY_SQL(2002),
/** Query sql cursor get page. */QUERY_SQL_CURSOR_GET_PAGE(2003),
/** Query sql fields. */QUERY_SQL_FIELDS(2004),
/** Query sql fields cursor get page.
*/QUERY_SQL_FIELDS_CURSOR_GET_PAGE(2005),
+
/** Get binary type. */GET_BINARY_TYPE(3002),
/** Register binary type name. */REGISTER_BINARY_TYPE_NAME(3001),
/** Put binary type. */PUT_BINARY_TYPE(3003),
/** Get binary type name. */GET_BINARY_TYPE_NAME(3000),
+
/** Start new transaction. */TX_START(4000),
/** End the transaction (commit or rollback). */TX_END(4001),
+
+ /** Get cluster state. */CLUSTER_GET_STATE(5000),
+ /** Change cluster state. */CLUSTER_CHANGE_STATE(5001),
+ /** Get WAL state. */CLUSTER_GET_WAL_STATE(5003),
+ /** Change WAL state. */CLUSTER_CHANGE_WAL_STATE(5002),
+
/** Execute compute task. */COMPUTE_TASK_EXECUTE(6000),
/** Finished compute task notification. */COMPUTE_TASK_FINISHED(6001,
true);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
index e57a9ce..5e6e395 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolBitmaskFeature.java
@@ -29,7 +29,13 @@ public enum ProtocolBitmaskFeature {
USER_ATTRIBUTES(0),
/** Compute tasks (execute by task name). */
- EXECUTE_TASK_BY_NAME(1);
+ EXECUTE_TASK_BY_NAME(1),
+
+ /**
+ * Cluster operations (state and WAL). In addition to {@link
ProtocolVersionFeature#CLUSTER_API} this feature
+ * also allows to use other cluster states beside ACTIVE and INACTIVE.
+ */
+ CLUSTER_API(2);
/** */
private static final EnumSet<ProtocolBitmaskFeature>
ALL_FEATURES_AS_ENUM_SET =
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolVersionFeature.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolVersionFeature.java
index bb04914..5586bfb 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolVersionFeature.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/ProtocolVersionFeature.java
@@ -45,6 +45,9 @@ public class ProtocolVersionFeature {
/** Expiry policy feature. */
public static final ProtocolVersionFeature EXPIRY_POLICY = new
ProtocolVersionFeature(V1_6_0);
+ /** Cluster API (activation and WAL enable/disable) feature. */
+ public static final ProtocolVersionFeature CLUSTER_API = new
ProtocolVersionFeature(V1_6_0);
+
/** Bitmap features introduced. */
public static final ProtocolVersionFeature BITMAP_FEATURES = new
ProtocolVersionFeature(V1_7_0);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java
index ee9003f..955f764 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpIgniteClient.java
@@ -112,7 +112,7 @@ public class TcpIgniteClient implements IgniteClient {
transactions = new TcpClientTransactions(ch, marsh,
new
ClientTransactionConfiguration(cfg.getTransactionConfiguration()));
- cluster = new ClientClusterImpl();
+ cluster = new ClientClusterImpl(ch, marsh);
compute = new ClientComputeImpl(ch, marsh, cluster);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
index 6610c0a..57e314f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientBitmaskFeature.java
@@ -28,7 +28,10 @@ public enum ClientBitmaskFeature implements
ThinProtocolFeature {
USER_ATTRIBUTES(0),
/** Compute tasks (execute by task name). */
- EXECUTE_TASK_BY_NAME(1);
+ EXECUTE_TASK_BY_NAME(1),
+
+ /** Cluster operations (state and WAL). */
+ CLUSTER_API(2);
/** */
private static final EnumSet<ClientBitmaskFeature>
ALL_FEATURES_AS_ENUM_SET =
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateResponse.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientByteResponse.java
similarity index 65%
rename from
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateResponse.java
rename to
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientByteResponse.java
index fe0d616..9b50dc3 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateResponse.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientByteResponse.java
@@ -15,37 +15,32 @@
* limitations under the License.
*/
-package org.apache.ignite.internal.processors.platform.client.cluster;
+package org.apache.ignite.internal.processors.platform.client;
import org.apache.ignite.internal.binary.BinaryRawWriterEx;
-import
org.apache.ignite.internal.processors.platform.client.ClientConnectionContext;
-import org.apache.ignite.internal.processors.platform.client.ClientResponse;
/**
- * Change cache WAL state response.
+ * Byte response.
*/
-public class ClientClusterWalChangeStateResponse extends ClientResponse {
- /**
- * Operation result.
- */
- private final boolean res;
+public class ClientByteResponse extends ClientResponse {
+ /** */
+ private final byte val;
/**
- * Ctor.
+ * Constructor.
*
* @param reqId Request id.
- * @param res Operation result.
*/
- ClientClusterWalChangeStateResponse(long reqId, boolean res) {
+ public ClientByteResponse(long reqId, byte val) {
super(reqId);
- this.res = res;
+ this.val = val;
}
/** {@inheritDoc} */
@Override public void encode(ClientConnectionContext ctx,
BinaryRawWriterEx writer) {
super.encode(ctx, writer);
- writer.writeBoolean(res);
+ writer.writeByte(val);
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
index 71a466b..69e1e5f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
@@ -71,7 +71,7 @@ import
org.apache.ignite.internal.processors.platform.client.compute.ClientExecu
import
org.apache.ignite.internal.processors.platform.client.tx.ClientTxEndRequest;
import
org.apache.ignite.internal.processors.platform.client.tx.ClientTxStartRequest;
import
org.apache.ignite.internal.processors.platform.client.cluster.ClientClusterChangeStateRequest;
-import
org.apache.ignite.internal.processors.platform.client.cluster.ClientClusterIsActiveRequest;
+import
org.apache.ignite.internal.processors.platform.client.cluster.ClientClusterGetStateRequest;
import
org.apache.ignite.internal.processors.platform.client.cluster.ClientClusterWalChangeStateRequest;
import
org.apache.ignite.internal.processors.platform.client.cluster.ClientClusterWalGetStateRequest;
import
org.apache.ignite.internal.processors.platform.client.cluster.ClientClusterGroupGetNodeIdsRequest;
@@ -222,7 +222,7 @@ public class ClientMessageParser implements
ClientListenerMessageParser {
/* Cluster operations. */
/** */
- private static final short OP_CLUSTER_IS_ACTIVE = 5000;
+ private static final short OP_CLUSTER_GET_STATE = 5000;
/** */
private static final short OP_CLUSTER_CHANGE_STATE = 5001;
@@ -423,8 +423,8 @@ public class ClientMessageParser implements
ClientListenerMessageParser {
case OP_TX_END:
return new ClientTxEndRequest(reader);
- case OP_CLUSTER_IS_ACTIVE:
- return new ClientClusterIsActiveRequest(reader);
+ case OP_CLUSTER_GET_STATE:
+ return new ClientClusterGetStateRequest(reader);
case OP_CLUSTER_CHANGE_STATE:
return new ClientClusterChangeStateRequest(reader);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterChangeStateRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterChangeStateRequest.java
index 929e878..e8b7379 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterChangeStateRequest.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterChangeStateRequest.java
@@ -17,8 +17,8 @@
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.ClientConnectionContext;
import org.apache.ignite.internal.processors.platform.client.ClientRequest;
import org.apache.ignite.internal.processors.platform.client.ClientResponse;
@@ -28,7 +28,7 @@ import
org.apache.ignite.internal.processors.platform.client.ClientResponse;
*/
public class ClientClusterChangeStateRequest extends ClientRequest {
/** Next state. */
- private final boolean isActive;
+ private final ClusterState state;
/**
* Constructor.
@@ -37,13 +37,14 @@ public class ClientClusterChangeStateRequest extends
ClientRequest {
*/
public ClientClusterChangeStateRequest(BinaryRawReader reader) {
super(reader);
- isActive = reader.readBoolean();
+
+ state = ClusterState.fromOrdinal(reader.readByte());
}
/** {@inheritDoc} */
@Override public ClientResponse process(ClientConnectionContext ctx) {
- IgniteCluster cluster = ctx.kernalContext().grid().cluster();
- cluster.active(isActive);
+ ctx.kernalContext().grid().cluster().state(state);
+
return new ClientResponse(requestId());
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterIsActiveRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterGetStateRequest.java
similarity index 69%
rename from
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterIsActiveRequest.java
rename to
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterGetStateRequest.java
index b48fa7f..6251257 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterIsActiveRequest.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterGetStateRequest.java
@@ -17,9 +17,11 @@
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;
@@ -27,19 +29,22 @@ 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(), ClusterState.active(state));
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateRequest.java
index 7c04e1b..13b0d74 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateRequest.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/cluster/ClientClusterWalChangeStateRequest.java
@@ -19,6 +19,7 @@ package
org.apache.ignite.internal.processors.platform.client.cluster;
import org.apache.ignite.IgniteCluster;
import org.apache.ignite.binary.BinaryRawReader;
+import
org.apache.ignite.internal.processors.platform.client.ClientBooleanResponse;
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;
@@ -47,9 +48,9 @@ public class ClientClusterWalChangeStateRequest extends
ClientRequest {
/** {@inheritDoc} */
@Override public ClientResponse process(ClientConnectionContext ctx) {
IgniteCluster cluster = ctx.kernalContext().grid().cluster();
- boolean res = shouldBeActive
- ? cluster.enableWal(cacheName)
- : cluster.disableWal(cacheName);
- return new ClientClusterWalChangeStateResponse(requestId(), res);
+
+ boolean res = shouldBeActive ? cluster.enableWal(cacheName) :
cluster.disableWal(cacheName);
+
+ return new ClientBooleanResponse(requestId(), res);
}
}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ClusterApiTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ClusterApiTest.java
new file mode 100644
index 0000000..9f78342
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/client/thin/ClusterApiTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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 change cluster state operation by thin client.
+ */
+ @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 change WAL state for cache operation by thin client.
+ */
+ @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));
+ }
+ }
+
+ /**
+ * Changes state by thin client and check by thin and thick clients that
state is changed.
+ */
+ private void changeAndCheckState(ClientCluster clientCluster,
IgniteCluster igniteCluster, ClusterState state) {
+ clientCluster.state(state);
+
+ assertEquals(state, clientCluster.state());
+ assertEquals(state, igniteCluster.state());
+ }
+}
diff --git
a/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
b/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
index 9059aa7..68bb391 100644
---
a/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
+++
b/modules/indexing/src/test/java/org/apache/ignite/client/ClientTestSuite.java
@@ -17,6 +17,7 @@
package org.apache.ignite.client;
+import org.apache.ignite.internal.client.thin.ClusterApiTest;
import org.apache.ignite.internal.client.thin.ComputeTaskTest;
import
org.apache.ignite.internal.client.thin.ThinClientPartitionAwarenessResourceReleaseTest;
import
org.apache.ignite.internal.client.thin.ThinClientPartitionAwarenessStableTopologyTest;
@@ -43,6 +44,7 @@ import org.junit.runners.Suite;
ConnectToStartingNodeTest.class,
AsyncChannelTest.class,
ComputeTaskTest.class,
+ ClusterApiTest.class,
ThinClientPartitionAwarenessStableTopologyTest.class,
ThinClientPartitionAwarenessUnstableTopologyTest.class,
ThinClientPartitionAwarenessResourceReleaseTest.class