This is an automated email from the ASF dual-hosted git repository.

ptupitsyn 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 c00757c  IGNITE-13435 Fix uncovered issues for command "warm-up" of 
control.sh
c00757c is described below

commit c00757c793aeeb9649ae0117f00cc346cc5cbf0a
Author: Kirill Tkalenko <[email protected]>
AuthorDate: Thu Sep 17 13:07:35 2020 +0300

    IGNITE-13435 Fix uncovered issues for command "warm-up" of control.sh
---
 .../client/suite/IgniteClientTestSuite.java        |   2 +
 .../JettyRestProcessorBeforeNodeStartSelfTest.java | 143 +++++++++++++++++++++
 .../ignite/internal/commandline/WarmUpCommand.java |  12 +-
 .../commandline/CommandHandlerParsingTest.java     |   2 +
 .../apache/ignite/util/GridCommandHandlerTest.java |   9 +-
 .../processors/rest/GridRestProcessor.java         |   3 +-
 .../rest/protocols/tcp/GridTcpRestNioListener.java |   3 +-
 .../request/GridRestAuthenticationRequest.java     |  30 +++++
 .../protocols/http/jetty/GridJettyRestHandler.java |  18 +++
 9 files changed, 213 insertions(+), 9 deletions(-)

diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
index c48c541..8a3936b 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
@@ -55,6 +55,7 @@ import 
org.apache.ignite.internal.processors.rest.ClientMemcachedProtocolSelfTes
 import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationWithCredsSelfTest;
 import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationWithTokenSelfTest;
 import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorBaselineSelfTest;
+import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorBeforeNodeStartSelfTest;
 import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorGetAllAsArrayTest;
 import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorSignedSelfTest;
 import 
org.apache.ignite.internal.processors.rest.JettyRestProcessorUnsignedSelfTest;
@@ -97,6 +98,7 @@ import org.junit.runners.Suite;
     JettyRestProcessorAuthenticationWithTokenSelfTest.class,
     JettyRestProcessorGetAllAsArrayTest.class,
     JettyRestProcessorBaselineSelfTest.class,
+    JettyRestProcessorBeforeNodeStartSelfTest.class,
 
     // Test TCP rest processor with original memcache client.
     ClientMemcachedProtocolSelfTest.class,
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorBeforeNodeStartSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorBeforeNodeStartSelfTest.java
new file mode 100644
index 0000000..df0a2d6
--- /dev/null
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorBeforeNodeStartSelfTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.processors.rest;
+
+import java.util.HashMap;
+import java.util.Map;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import 
org.apache.ignite.internal.processors.cache.warmup.BlockedWarmUpConfiguration;
+import 
org.apache.ignite.internal.processors.cache.warmup.BlockedWarmUpStrategy;
+import 
org.apache.ignite.internal.processors.cache.warmup.WarmUpTestPluginProvider;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.Objects.nonNull;
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static 
org.apache.ignite.internal.processors.rest.GridRestCommand.NODE_STATE_BEFORE_START;
+import static 
org.apache.ignite.internal.processors.rest.GridRestCommand.WARM_UP;
+import static 
org.apache.ignite.internal.processors.rest.GridRestResponse.STATUS_SUCCESS;
+
+/**
+ * A class for testing query execution before the node starts.
+ */
+public class JettyRestProcessorBeforeNodeStartSelfTest extends 
JettyRestProcessorCommonSelfTest {
+    /** Flag for use next port for jetty. */
+    boolean nextPort;
+
+    /** {@inheritDoc} */
+    @Override protected String signature() throws Exception {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int restPort() {
+        return super.restPort() + (nextPort ? 1 : 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setPluginProviders(new WarmUpTestPluginProvider())
+            .setDataStorageConfiguration(
+                new 
DataStorageConfiguration().setDefaultDataRegionConfiguration(
+                    new DataRegionConfiguration().setPersistenceEnabled(true)
+                )
+            );
+    }
+
+    /**
+     * Test verifies that the requests will not be completed successfully 
because the node has already started.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testErrorExecuteCommandAfterNodeStart() throws Exception {
+        for (GridRestCommand cmd : new GridRestCommand[] 
{NODE_STATE_BEFORE_START, WARM_UP})
+            assertEquals("Node has already started.", content(cmd, 
null).get("error").asText());
+    }
+
+    /**
+     * Test checks that the warm-up will be stopped via an http request.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testStopWarmUp() throws Exception {
+        IgniteConfiguration cfg = 
getConfiguration(getTestIgniteInstanceName(gridCount()));
+
+        cfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration()
+            .setWarmUpConfiguration(new BlockedWarmUpConfiguration());
+
+        WarmUpTestPluginProvider warmUpProvider = 
(WarmUpTestPluginProvider)cfg.getPluginProviders()[0];
+        BlockedWarmUpStrategy warmUpStrat = 
(BlockedWarmUpStrategy)warmUpProvider.strats.get(1);
+
+        nextPort = true;
+
+        IgniteInternalFuture<IgniteEx> startNodeFut = 
GridTestUtils.runAsync(() -> startGrid(cfg));
+
+        try {
+            U.await(warmUpStrat.startLatch, 1, MINUTES);
+
+            JsonNode res = content(NODE_STATE_BEFORE_START, null);
+
+            assertEquals(STATUS_SUCCESS, res.get("successStatus").intValue());
+
+            res = content(WARM_UP, F.asMap("stopWarmUp", "true"));
+
+            assertEquals(STATUS_SUCCESS, res.get("successStatus").intValue());
+            assertEquals(0, warmUpStrat.stopLatch.getCount());
+        }
+        finally {
+            warmUpStrat.stopLatch.countDown();
+
+            startNodeFut.get(1, MINUTES).close();
+        }
+    }
+
+    /**
+     * Execute REST command and return result.
+     *
+     * @param cmd Command.
+     * @param params Command parameters.
+     * @return Returned content.
+     * @throws Exception If failed.
+     */
+    private JsonNode content(GridRestCommand cmd, @Nullable Map<String, 
String> params) throws Exception {
+        Map<String, String> p = new HashMap<>();
+
+        p.put("cmd", cmd.key());
+
+        if (nonNull(params))
+            p.putAll(params);
+
+        return JSON_MAPPER.readTree(content(p));
+    }
+}
diff --git 
a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/WarmUpCommand.java
 
b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/WarmUpCommand.java
index 1d69f09..2219c5a 100644
--- 
a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/WarmUpCommand.java
+++ 
b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/WarmUpCommand.java
@@ -26,7 +26,6 @@ import 
org.apache.ignite.internal.commandline.argument.CommandArg;
 import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
 
 import static java.util.Objects.isNull;
-import static java.util.Objects.nonNull;
 import static org.apache.ignite.internal.commandline.CommandList.WARM_UP;
 
 /**
@@ -52,14 +51,21 @@ public class WarmUpCommand implements Command<Void> {
     @Override public void parseArguments(CommandArgIterator argIter) {
         boolean stop = false;
 
-        while (nonNull(argIter.peekNextArg())) {
-            WarmUpCommandArg arg = CommandArgUtils.of(argIter.nextArg(""), 
WarmUpCommandArg.class);
+        while (true) {
+            String nextArg = argIter.peekNextArg();
+
+            if (nextArg == null)
+                break;
+
+            WarmUpCommandArg arg = CommandArgUtils.of(nextArg, 
WarmUpCommandArg.class);
 
             if (isNull(arg))
                 break;
 
             switch (arg) {
                 case STOP:
+                    argIter.nextArg("");
+
                     stop = true;
                     break;
 
diff --git 
a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
 
b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
index a9ae762..1066ca7 100644
--- 
a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
+++ 
b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
@@ -462,6 +462,8 @@ public class CommandHandlerParsingTest {
                 case WARM_UP: {
                     args = parseArgs(asList(cmdL.text(), "--stop", "--yes"));
 
+                    checkCommonParametersCorrectlyParsed(cmdL, args, true);
+
                     break;
                 }
 
diff --git 
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
 
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
index fcacd9b..e45d9a1 100644
--- 
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
+++ 
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
@@ -2359,14 +2359,15 @@ public class GridCommandHandlerTest extends 
GridCommandHandlerClusterPerMethodAb
         try {
             U.await(blockedWarmUpStgy.startLatch, 60, TimeUnit.SECONDS);
 
-            assertEquals(EXIT_CODE_OK, execute("--warm-up", "--stop", 
"--yes"));
+            // Arguments --user and --password are needed for additional 
sending of the GridClientAuthenticationRequest.
+            assertEquals(EXIT_CODE_OK, execute("--warm-up", "--stop", "--yes", 
"--user", "user", "--password", "123"));
 
-            fut.get(60_000);
+            assertEquals(0, blockedWarmUpStgy.stopLatch.getCount());
         }
-        catch (Throwable t) {
+        finally {
             blockedWarmUpStgy.stopLatch.countDown();
 
-            throw t;
+            fut.get(60_000);
         }
     }
 
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 5f1ea66..358f75b 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
@@ -62,6 +62,7 @@ import 
org.apache.ignite.internal.processors.rest.handlers.top.GridTopologyComma
 import 
org.apache.ignite.internal.processors.rest.handlers.user.UserActionCommandHandler;
 import 
org.apache.ignite.internal.processors.rest.handlers.version.GridVersionCommandHandler;
 import 
org.apache.ignite.internal.processors.rest.protocols.tcp.GridTcpRestProtocol;
+import 
org.apache.ignite.internal.processors.rest.request.GridRestAuthenticationRequest;
 import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
 import 
org.apache.ignite.internal.processors.rest.request.GridRestNodeStateBeforeStartRequest;
 import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
@@ -235,7 +236,7 @@ public class GridRestProcessor extends GridProcessorAdapter 
implements IgniteRes
             if (startLatch.getCount() == 0)
                 return new GridFinishedFuture<>(new 
IgniteCheckedException("Node has already started."));
         }
-        else if (startLatch.getCount() > 0) {
+        else if (!(req instanceof GridRestAuthenticationRequest) && 
startLatch.getCount() > 0) {
             try {
                 startLatch.await();
             }
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 29f89a4..6195460 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
@@ -51,6 +51,7 @@ import 
org.apache.ignite.internal.processors.rest.client.message.GridClientWarmU
 import 
org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheRestMetrics;
 import 
org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
 import 
org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisNioListener;
+import 
org.apache.ignite.internal.processors.rest.request.GridRestAuthenticationRequest;
 import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
 import 
org.apache.ignite.internal.processors.rest.request.GridRestChangeStateRequest;
 import 
org.apache.ignite.internal.processors.rest.request.GridRestClusterNameRequest;
@@ -321,7 +322,7 @@ public class GridTcpRestNioListener extends 
GridNioServerListenerAdapter<GridCli
         if (msg instanceof GridClientAuthenticationRequest) {
             GridClientAuthenticationRequest req = 
(GridClientAuthenticationRequest)msg;
 
-            restReq = new GridRestTaskRequest();
+            restReq = new GridRestAuthenticationRequest();
 
             restReq.command(NOOP);
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestAuthenticationRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestAuthenticationRequest.java
new file mode 100644
index 0000000..22724fc
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/GridRestAuthenticationRequest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.processors.rest.request;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Grid authentication request.
+ */
+public class GridRestAuthenticationRequest extends GridRestTaskRequest {
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridRestAuthenticationRequest.class, this, 
super.toString());
+    }
+}
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 586bb6d..42b8a30 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
@@ -62,9 +62,11 @@ import 
org.apache.ignite.internal.processors.rest.request.GridRestChangeStateReq
 import 
org.apache.ignite.internal.processors.rest.request.GridRestClusterNameRequest;
 import 
org.apache.ignite.internal.processors.rest.request.GridRestClusterStateRequest;
 import org.apache.ignite.internal.processors.rest.request.GridRestLogRequest;
+import 
org.apache.ignite.internal.processors.rest.request.GridRestNodeStateBeforeStartRequest;
 import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
 import org.apache.ignite.internal.processors.rest.request.GridRestTaskRequest;
 import 
org.apache.ignite.internal.processors.rest.request.GridRestTopologyRequest;
+import 
org.apache.ignite.internal.processors.rest.request.GridRestWarmUpRequest;
 import org.apache.ignite.internal.processors.rest.request.RestQueryRequest;
 import 
org.apache.ignite.internal.processors.rest.request.RestUserActionRequest;
 import org.apache.ignite.internal.util.typedef.C1;
@@ -898,6 +900,22 @@ public class GridJettyRestHandler extends AbstractHandler {
                 break;
             }
 
+            case NODE_STATE_BEFORE_START: {
+                restReq = new GridRestNodeStateBeforeStartRequest();
+
+                break;
+            }
+
+            case WARM_UP: {
+                GridRestWarmUpRequest restReq0 = new GridRestWarmUpRequest();
+
+                
restReq0.stopWarmUp(Boolean.parseBoolean(String.valueOf(params.get("stopWarmUp"))));
+
+                restReq = restReq0;
+
+                break;
+            }
+
             default:
                 throw new IgniteCheckedException("Invalid command: " + cmd);
         }

Reply via email to