This is an automated email from the ASF dual-hosted git repository. namelchev 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 7ddf565b90c IGNITE-21139 Provide ability to extract a command argument and class from management task event (#11125) 7ddf565b90c is described below commit 7ddf565b90c4fb3115f7fb8946dfb4e953eebf02 Author: Nikita Amelchev <nsamelc...@gmail.com> AuthorDate: Wed Feb 7 13:17:42 2024 +0300 IGNITE-21139 Provide ability to extract a command argument and class from management task event (#11125) --- .../commandline/meta/subcommands/VoidDto.java | 42 --------------- .../internal/events/ManagementTaskEvent.java | 63 ++++++++++++++++++++++ .../processors/task/GridTaskProcessor.java | 10 ++-- .../internal/TestManagementVisorOneNodeTask.java | 11 ++-- .../internal/VisorManagementEventSelfTest.java | 49 ++++++++++++++--- 5 files changed, 117 insertions(+), 58 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/commandline/meta/subcommands/VoidDto.java b/modules/core/src/main/java/org/apache/ignite/internal/commandline/meta/subcommands/VoidDto.java deleted file mode 100644 index abe0b51ff27..00000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/commandline/meta/subcommands/VoidDto.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.commandline.meta.subcommands; - -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import org.apache.ignite.internal.dto.IgniteDataTransferObject; - -/** - * - */ -public class VoidDto extends IgniteDataTransferObject { - /** */ - private static final long serialVersionUID = 0L; - - /** {@inheritDoc} */ - @Override protected void writeExternalData(ObjectOutput out) throws IOException { - // No-op. - } - - /** {@inheritDoc} */ - @Override protected void readExternalData(byte protoVer, ObjectInput in) - throws IOException, ClassNotFoundException { - // No-op. - } -} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/events/ManagementTaskEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/events/ManagementTaskEvent.java new file mode 100644 index 00000000000..c18f0263b05 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/events/ManagementTaskEvent.java @@ -0,0 +1,63 @@ +/* + * 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.events; + +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.events.EventType; +import org.apache.ignite.events.TaskEvent; +import org.apache.ignite.internal.visor.VisorTaskArgument; +import org.apache.ignite.lang.IgniteUuid; +import org.jetbrains.annotations.Nullable; + +/** + * Management task started event. + * + * @see EventType#EVT_MANAGEMENT_TASK_STARTED + */ +public class ManagementTaskEvent extends TaskEvent { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final VisorTaskArgument<?> arg; + + /** + * Creates task event with given parameters. + * + * @param node Node. + * @param msg Optional message. + * @param type Event type. + * @param sesId Task session ID. + * @param taskName Task name. + * @param subjId Subject ID. + * @param internal Whether current task belongs to Ignite internal tasks. + * @param taskClsName Name ot the task class. + */ + public ManagementTaskEvent(ClusterNode node, String msg, int type, IgniteUuid sesId, String taskName, + String taskClsName, boolean internal, @Nullable UUID subjId, VisorTaskArgument<?> arg) { + super(node, msg, type, sesId, taskName, taskClsName, internal, subjId); + + this.arg = arg; + } + + /** @return Task argument. */ + public VisorTaskArgument<?> argument() { + return arg; + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java index 8764d9e3eb8..977263c1afc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java @@ -59,6 +59,7 @@ import org.apache.ignite.internal.IgniteInterruptedCheckedException; import org.apache.ignite.internal.NodeStoppingException; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException; +import org.apache.ignite.internal.events.ManagementTaskEvent; import org.apache.ignite.internal.managers.communication.GridIoManager; import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.managers.deployment.GridDeployment; @@ -716,16 +717,17 @@ public class GridTaskProcessor extends GridProcessorAdapter implements IgniteCha if (ctx.event().isRecordable(EVT_MANAGEMENT_TASK_STARTED) && dep.visorManagementTask(task, taskCls)) { VisorTaskArgument visorTaskArg = (VisorTaskArgument)arg; - Event evt = new TaskEvent( + Event evt = new ManagementTaskEvent( ctx.discovery().localNode(), visorTaskArg != null && visorTaskArg.getArgument() != null ? visorTaskArg.getArgument().toString() : "[]", EVT_MANAGEMENT_TASK_STARTED, ses.getId(), - taskCls == null ? null : taskCls.getSimpleName(), - "VisorManagementTask", + taskName, + taskCls == null ? null : taskCls.getName(), false, - securitySubjectId(ctx) + securitySubjectId(ctx), + visorTaskArg ); ctx.event().record(evt); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/TestManagementVisorOneNodeTask.java b/modules/core/src/test/java/org/apache/ignite/internal/TestManagementVisorOneNodeTask.java index a1861c9870b..1af21e3ecb2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/TestManagementVisorOneNodeTask.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/TestManagementVisorOneNodeTask.java @@ -21,18 +21,17 @@ import java.util.List; import org.apache.ignite.compute.ComputeJobResult; import org.apache.ignite.internal.visor.VisorJob; import org.apache.ignite.internal.visor.VisorOneNodeTask; -import org.apache.ignite.internal.visor.VisorTaskArgument; import org.jetbrains.annotations.Nullable; /** * */ -public class TestManagementVisorOneNodeTask extends VisorOneNodeTask<VisorTaskArgument, Object> { +public class TestManagementVisorOneNodeTask extends VisorOneNodeTask<String, Object> { /** */ private static final long serialVersionUID = 0L; /** {@inheritDoc} */ - @Override protected VisorValidOneNodeJob job(VisorTaskArgument arg) { + @Override protected VisorValidOneNodeJob job(String arg) { return new VisorValidOneNodeJob(arg, debug); } @@ -44,7 +43,7 @@ public class TestManagementVisorOneNodeTask extends VisorOneNodeTask<VisorTaskAr /** * Valid Management one node visor job. */ - private static class VisorValidOneNodeJob extends VisorJob<VisorTaskArgument, Object> { + private static class VisorValidOneNodeJob extends VisorJob<String, Object> { /** */ private static final long serialVersionUID = 0L; @@ -52,12 +51,12 @@ public class TestManagementVisorOneNodeTask extends VisorOneNodeTask<VisorTaskAr * @param arg Argument. * @param debug Debug flag. */ - protected VisorValidOneNodeJob(VisorTaskArgument arg, boolean debug) { + protected VisorValidOneNodeJob(String arg, boolean debug) { super(arg, debug); } /** {@inheritDoc} */ - @Override protected Object run(VisorTaskArgument arg) { + @Override protected Object run(String arg) { return null; } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/VisorManagementEventSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/VisorManagementEventSelfTest.java index 2da03f38ce7..a16e1e51113 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/VisorManagementEventSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/VisorManagementEventSelfTest.java @@ -17,18 +17,25 @@ package org.apache.ignite.internal; +import java.util.List; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobResult; import org.apache.ignite.compute.ComputeTask; +import org.apache.ignite.compute.ComputeTaskAdapter; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.events.EventType; import org.apache.ignite.events.TaskEvent; -import org.apache.ignite.internal.client.thin.TestTask; +import org.apache.ignite.internal.events.ManagementTaskEvent; import org.apache.ignite.internal.visor.VisorTaskArgument; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.jetbrains.annotations.Nullable; import org.junit.Test; import static org.apache.ignite.events.EventType.EVT_MANAGEMENT_TASK_STARTED; @@ -59,13 +66,13 @@ public class VisorManagementEventSelfTest extends GridCommonAbstractTest { /** @throws Exception If failed. */ @Test public void testManagementTask() throws Exception { - doTestVisorTask(TestManagementVisorOneNodeTask.class, true); + doTestTask(TestManagementVisorOneNodeTask.class, true); } /** @throws Exception If failed. */ @Test public void testNotManagementTask() throws Exception { - doTestVisorTask(TestTask.class, false); + doTestTask(NotManagementTask.class, false); } /** @@ -73,9 +80,11 @@ public class VisorManagementEventSelfTest extends GridCommonAbstractTest { * * @throws Exception If failed. */ - private void doTestVisorTask(Class<? extends ComputeTask<?, ?>> cls, boolean expEvt) throws Exception { + private void doTestTask(Class<? extends ComputeTask<?, ?>> cls, boolean expEvt) throws Exception { IgniteEx ignite = startGrid(0); + String arg = "test-arg"; + final AtomicReference<TaskEvent> evt = new AtomicReference<>(); final CountDownLatch evtLatch = new CountDownLatch(1); @@ -91,13 +100,41 @@ public class VisorManagementEventSelfTest extends GridCommonAbstractTest { }, EventType.EVT_MANAGEMENT_TASK_STARTED); for (ClusterNode node : ignite.cluster().forServers().nodes()) - ignite.compute().executeAsync(cls.getName(), new VisorTaskArgument<>(node.id(), new VisorTaskArgument(), true)); + ignite.compute().execute(cls.getName(), new VisorTaskArgument<>(node.id(), arg, true)); if (expEvt) { assertTrue(evtLatch.await(10000, TimeUnit.MILLISECONDS)); - assertTrue(evt.get() instanceof TaskEvent); + assertTrue(evt.get() instanceof ManagementTaskEvent); + assertEquals(arg, ((ManagementTaskEvent)evt.get()).argument().getArgument()); } else assertFalse(evtLatch.await(1000, TimeUnit.MILLISECONDS)); } + + /** */ + private static class NotManagementTask extends ComputeTaskAdapter<VisorTaskArgument<String>, Void> { + /** {@inheritDoc} */ + @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, + @Nullable VisorTaskArgument<String> arg) { + return subgrid.stream().collect(Collectors.toMap(node -> new TestJob(), node -> node)); + } + + /** {@inheritDoc} */ + @Override public @Nullable Void reduce(List<ComputeJobResult> results) { + return null; + } + + /** */ + public static class TestJob implements ComputeJob { + /** {@inheritDoc} */ + @Override public void cancel() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public Object execute() { + return null; + } + } + } }