You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/10/04 16:03:12 UTC
[04/50] [abbrv] ignite git commit: IGNITE-9253: Rename
activation/deactivation commands for REST API. - Fixes #4525.
IGNITE-9253: Rename activation/deactivation commands for REST API. - Fixes #4525.
Signed-off-by: shroman <rs...@yahoo.com>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c7227cf1
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c7227cf1
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c7227cf1
Branch: refs/heads/ignite-5797
Commit: c7227cf117b826fff013f757531c2737d6fc94de
Parents: 5aef881
Author: shroman <rs...@yahoo.com>
Authored: Fri Sep 28 17:56:06 2018 +0900
Committer: shroman <rs...@yahoo.com>
Committed: Fri Sep 28 17:56:06 2018 +0900
----------------------------------------------------------------------
.../JettyRestProcessorAbstractSelfTest.java | 21 ++++++++-------
.../processors/rest/GridRestCommand.java | 12 +++++++--
.../processors/rest/GridRestProcessor.java | 2 ++
.../cluster/GridChangeStateCommandHandler.java | 25 +++++++++++------
.../protocols/tcp/GridTcpRestNioListener.java | 6 ++---
.../http/jetty/GridJettyRestHandler.java | 28 +++++++++++---------
6 files changed, 60 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7227cf1/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 f39c280..a972bc3 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
@@ -850,8 +850,12 @@ public abstract class JettyRestProcessorAbstractSelfTest extends JettyRestProces
public void testDeactivateActivate() throws Exception {
assertClusterState(true);
- changeClusterState(false);
- changeClusterState(true);
+ changeClusterState(GridRestCommand.CLUSTER_DEACTIVATE);
+ changeClusterState(GridRestCommand.CLUSTER_ACTIVATE);
+
+ // same for deprecated.
+ changeClusterState(GridRestCommand.CLUSTER_INACTIVE);
+ changeClusterState(GridRestCommand.CLUSTER_ACTIVE);
initCache();
}
@@ -2797,7 +2801,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends JettyRestProces
* @return This helper for chaining method calls.
*/
public VisorGatewayArgument forNode(ClusterNode node) {
- put("p1", node != null ? node.id().toString() : null);
+ put("p1", node != null ? node.id().toString() : null);
return this;
}
@@ -2991,18 +2995,17 @@ public abstract class JettyRestProcessorAbstractSelfTest extends JettyRestProces
/**
* Change cluster state and test new state.
*
- * @param state Desired state.
+ * @param cmd Command.
* @throws Exception If failed.
*/
- private void changeClusterState(boolean state) throws Exception {
- GridRestCommand cmd = state ? GridRestCommand.CLUSTER_ACTIVE : GridRestCommand.CLUSTER_INACTIVE;
-
+ private void changeClusterState(GridRestCommand cmd) throws Exception {
String ret = content(null, cmd);
JsonNode res = jsonResponse(ret);
- assertTrue(res.isNull());
+ assertFalse(res.isNull());
+ assertTrue(res.asText().startsWith(cmd.key()));
- assertClusterState(state);
+ assertClusterState(cmd == GridRestCommand.CLUSTER_ACTIVATE || cmd == GridRestCommand.CLUSTER_ACTIVE);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7227cf1/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 265fe40..587ed2e 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
@@ -159,13 +159,21 @@ public enum GridRestCommand {
/** Close query. */
CLOSE_SQL_QUERY("qrycls"),
- /** */
+ /** @deprecated Use {@link #CLUSTER_ACTIVATE} instead. */
+ @Deprecated
CLUSTER_ACTIVE("active"),
- /** */
+ /** @deprecated Use {@link #CLUSTER_DEACTIVATE} instead. */
+ @Deprecated
CLUSTER_INACTIVE("inactive"),
/** */
+ CLUSTER_ACTIVATE("activate"),
+
+ /** */
+ CLUSTER_DEACTIVATE("deactivate"),
+
+ /** */
CLUSTER_CURRENT_STATE("currentstate"),
/** */
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7227cf1/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 b6c1310..30d2f0a 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
@@ -890,6 +890,8 @@ public class GridRestProcessor extends GridProcessorAdapter {
case CLUSTER_ACTIVE:
case CLUSTER_INACTIVE:
+ case CLUSTER_ACTIVATE:
+ case CLUSTER_DEACTIVATE:
perm = SecurityPermission.ADMIN_OPS;
break;
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7227cf1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
index 619be34..c9b5a12 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cluster/GridChangeStateCommandHandler.java
@@ -18,7 +18,6 @@
package org.apache.ignite.internal.processors.rest.handlers.cluster;
import java.util.Collection;
-
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.processors.rest.GridRestCommand;
@@ -31,8 +30,10 @@ import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_ACTIVATE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_ACTIVE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_CURRENT_STATE;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_DEACTIVATE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_INACTIVE;
/**
@@ -41,7 +42,7 @@ import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER
public class GridChangeStateCommandHandler extends GridRestCommandHandlerAdapter {
/** Commands. */
private static final Collection<GridRestCommand> commands =
- U.sealList(CLUSTER_ACTIVE, CLUSTER_INACTIVE, CLUSTER_CURRENT_STATE);
+ U.sealList(CLUSTER_ACTIVATE, CLUSTER_DEACTIVATE, CLUSTER_CURRENT_STATE, CLUSTER_ACTIVE, CLUSTER_INACTIVE);
/**
* @param ctx Context.
@@ -64,13 +65,21 @@ public class GridChangeStateCommandHandler extends GridRestCommandHandlerAdapter
final GridRestResponse res = new GridRestResponse();
try {
- if (req.command().equals(CLUSTER_CURRENT_STATE)) {
- Boolean currentState = ctx.state().publicApiActiveState(false);
-
- res.setResponse(currentState);
+ switch (req.command()) {
+ case CLUSTER_CURRENT_STATE:
+ Boolean currentState = ctx.state().publicApiActiveState(false);
+
+ res.setResponse(currentState);
+ break;
+ case CLUSTER_ACTIVE:
+ case CLUSTER_INACTIVE:
+ log.warning(req.command().key() + " is deprecated. Use newer commands.");
+ default:
+ ctx.grid().cluster().active(req.active());
+
+ res.setResponse(req.command().key() + " started");
+ break;
}
- else
- ctx.grid().active(req.active());
fut.onDone(res);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7227cf1/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java
index 23c25c7..d4d2b07 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestNioListener.java
@@ -72,8 +72,8 @@ import static org.apache.ignite.internal.processors.rest.GridRestCommand.EXE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.NODE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.NOOP;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.TOPOLOGY;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_ACTIVE;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_INACTIVE;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_ACTIVATE;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_DEACTIVATE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_CURRENT_STATE;
import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.APPEND;
import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.CAS;
@@ -366,7 +366,7 @@ public class GridTcpRestNioListener extends GridNioServerListenerAdapter<GridCli
}
else {
restChangeReq.active(req.active());
- restChangeReq.command(req.active() ? CLUSTER_ACTIVE : CLUSTER_INACTIVE);
+ restChangeReq.command(req.active() ? CLUSTER_ACTIVATE : CLUSTER_DEACTIVATE);
}
restReq = restChangeReq;
http://git-wip-us.apache.org/repos/asf/ignite/blob/c7227cf1/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 12dc0dd..03bed69 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
@@ -17,6 +17,8 @@
package org.apache.ignite.internal.processors.rest.protocols.http.jetty;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -40,7 +42,6 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
@@ -64,11 +65,8 @@ import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.plugin.security.SecurityCredentials;
-
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_REST_GETALL_AS_ARRAY;
@@ -77,9 +75,10 @@ import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_C
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_ALL;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_REMOVE_ALL;
-import static org.apache.ignite.internal.processors.rest.GridRestCommand.EXECUTE_SQL_QUERY;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_ACTIVATE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_ACTIVE;
import static org.apache.ignite.internal.processors.rest.GridRestCommand.CLUSTER_CURRENT_STATE;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.EXECUTE_SQL_QUERY;
import static org.apache.ignite.internal.processors.rest.GridRestResponse.STATUS_FAILED;
/**
@@ -110,10 +109,10 @@ public class GridJettyRestHandler extends AbstractHandler {
/** */
private static final String WRITE_SYNCHRONIZATION_MODE_PARAM = "writeSynchronizationMode";
- /**@deprecated Should be replaced with AUTHENTICATION + token in IGNITE 3.0 */
+ /** @deprecated Should be replaced with AUTHENTICATION + token in IGNITE 3.0 */
private static final String IGNITE_LOGIN = "ignite.login";
- /**@deprecated Should be replaced with AUTHENTICATION + token in IGNITE 3.0 */
+ /** @deprecated Should be replaced with AUTHENTICATION + token in IGNITE 3.0 */
private static final String IGNITE_PASSWORD = "ignite.password";
/** */
@@ -425,7 +424,7 @@ public class GridJettyRestHandler extends AbstractHandler {
cmdRes = new GridRestResponse(STATUS_FAILED, e.getMessage());
}
- try(ServletOutputStream os = res.getOutputStream()) {
+ try (ServletOutputStream os = res.getOutputStream()) {
try {
// Try serialize.
jsonMapper.writeValue(NULL_OUTPUT_STREAM, cmdRes);
@@ -740,13 +739,17 @@ public class GridJettyRestHandler extends AbstractHandler {
case CLUSTER_ACTIVE:
case CLUSTER_INACTIVE:
+ case CLUSTER_ACTIVATE:
+ case CLUSTER_DEACTIVATE:
case CLUSTER_CURRENT_STATE: {
GridRestChangeStateRequest restReq0 = new GridRestChangeStateRequest();
if (cmd == CLUSTER_CURRENT_STATE)
restReq0.reqCurrentState();
+ else if (cmd == CLUSTER_ACTIVE || cmd == CLUSTER_ACTIVATE)
+ restReq0.active(true);
else
- restReq0.active(cmd == CLUSTER_ACTIVE);
+ restReq0.active(false);
restReq = restReq0;
@@ -911,14 +914,14 @@ public class GridJettyRestHandler extends AbstractHandler {
}
/**
- *
* @param params Parameters.
* @param userParam Parameter name to take user name.
* @param pwdParam Parameter name to take password.
* @param restReq Request to add credentials if any.
* @return {@code true} If params contains credentials.
*/
- private boolean credentials(Map<String, Object> params, String userParam, String pwdParam, GridRestRequest restReq) {
+ private boolean credentials(Map<String, Object> params, String userParam, String pwdParam,
+ GridRestRequest restReq) {
boolean hasCreds = params.containsKey(userParam) || params.containsKey(pwdParam);
if (hasCreds) {
@@ -939,7 +942,8 @@ public class GridJettyRestHandler extends AbstractHandler {
* @param params Parameters map.
* @return Values.
*/
- protected List<Object> values(String type, String keyPrefix, Map<String, Object> params) throws IgniteCheckedException {
+ protected List<Object> values(String type, String keyPrefix,
+ Map<String, Object> params) throws IgniteCheckedException {
assert keyPrefix != null;
List<Object> vals = new LinkedList<>();