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/03/03 17:43:19 UTC

[GitHub] [ignite] nizhikov opened a new pull request #7495: IGNITE-12745: Compute job view implemented.

nizhikov opened a new pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495
 
 
   

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387834148
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
 
 Review comment:
   Lets check each job view:
   ```
   for (ComputeJobView job : jobs)
        checkJob(job);
   ```

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387581402
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
 
 Review comment:
   typo `finishTime`

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387849364
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,196 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.managers.collision.GridCollisionManager;
+import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.spi.collision.CollisionSpi;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Compute job state. */
+    public enum ComputeJobState {
+        /**
+         * Job scheduled for the execution.
+         * If collision not configured all jobs in this state by default.
+         *
+         * @see GridCollisionManager
+         * @see CollisionSpi
+         */
+        ACTIVE,
+
+        /**
+         * If collision configured jobs may be passivated before execution.
+         *
+         * @see GridCollisionManager
+         * @see CollisionSpi
+         */
+        PASSIVE,
+
+        /**
+         * Job execution canceled.
+         *
+         * @see GridJobProcessor#cancelJob(IgniteUuid, IgniteUuid, boolean)
+         */
+        CANCELED
+    }
+
+    /** Job. */
+    public final GridJobWorker job;
+
+    /** Job id. */
+    public final IgniteUuid id;
+
+    /** Job state. */
+    public final ComputeJobState state;
+
+    /**
+     * @param id Job id.
+     * @param job Job.
+     * @param state Job state.
+     */
+    public ComputeJobView(IgniteUuid id, GridJobWorker job, ComputeJobState state) {
+        this.id = id;
+        this.job = job;
+        this.state = state;
+    }
+
+    /** @return Job id. */
+    @Order
+    public IgniteUuid id() {
+        return id;
+    }
+
+    /**
+     * {@link ComputeJobView#sessionId()} value equal to the value of {@link ComputeTaskView#sessionId()}
+     * if both records represents parts of the same computation.
+     *
+     * @return Session id.
+     * @see ComputeTaskView#sessionId()
+     */
+    @Order(1)
+    public IgniteUuid sessionId() {
+        return job.getSession().getId();
+    }
+
+    /** @return Origin node id. */
+    @Order(2)
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return Task name. */
+    @Order(3)
+    public String taskName() {
+        return job.getSession().getTaskName();
+    }
+
+    /** @return Task class name. */
+    @Order(4)
+    public String taskClassName() {
+        return job.getSession().getTaskClassName();
+    }
+
+    /** @return Comma separated list of cache identifiers or {@code null} for non affinity call. */
+    @Order(5)
+    public String affinityCacheIds() {
+        GridReservable res = job.getPartsReservation();
+
+        if (!(res instanceof GridJobProcessor.PartitionsReservation))
+            return null;
+
+        int[] ids = ((GridJobProcessor.PartitionsReservation)res).getCacheIds();
+
+        if (ids == null || ids.length == 0)
+            return null;
+
+        StringJoiner joiner = new StringJoiner(",");
+
+        for (int id : ids)
+            joiner.add(Integer.toString(id));
+
+        return joiner.toString();
+    }
+
+    /** @return Affinity partition id or {@code -1} for non affinity call. */
+    @Order(6)
+    public int affinityPartitionId() {
+        GridReservable res = job.getPartsReservation();
+
+        if (!(res instanceof GridJobProcessor.PartitionsReservation))
+            return -1;
+
+        return ((GridJobProcessor.PartitionsReservation)res).getPartId();
+    }
+
+    /** @return Create time in milliseconds. */
+    @Order(7)
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time in milliseconds. */
+    @Order(8)
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time in milliseconds. */
+    @Order(9)
+    public long finishTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
+    /** @return {@code True} if job started. */
+    public boolean isStarted() {
+        return job.isStarted();
+    }
+
+    /** @return Executor name. */
+    public String executorName() {
 
 Review comment:
   It can be null. Let's mark as nullable and update javadoc.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387833290
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnable() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().runAsync(() -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call. */
+    @Test
+    public void testComputeApply() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        GridTestUtils.runAsync(() -> {
+            client.compute().apply(x -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return 0;
+            }, 1);
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Tests work of {@link SystemView} for compute grid
+     * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
+     */
+    @Test
+    public void testComputeAffinityCall() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        assertFalse(t.isInternal());
+        assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
+        assertEquals(1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** */
+    @Test
+    public void testComputeTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().executeAsync(new ComputeTask<Object, Object>() {
+            @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Object arg) throws IgniteException {
+                return Collections.singletonMap(new ComputeJob() {
+                    @Override public void cancel() {
+                        // No-op.
+                    }
+
+                    @Override public Object execute() throws IgniteException {
+                        try {
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                        }
+                        catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                            throw new RuntimeException(e);
+                        }
+
+                        return 1;
+                    }
+                }, subgrid.get(0));
+            }
+
+            @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+                List<ComputeJobResult> rcvd) throws IgniteException {
+
+                return null;
+            }
+
+            @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+                return 1;
+            }
+        }, 1);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnableJobAndTask() throws Exception {
+        try (IgniteEx server2 = startGrid(2)) {
+            barrier = new CyclicBarrier(3);
+
+            SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+
+            assertEquals(1, tasks.size());
+            assertEquals(1, jobs1.size());
+            assertEquals(1, jobs2.size());
+
+            ComputeTaskView task = tasks.iterator().next();
+
+            checkJobAndTask(task, jobs1.iterator().next());
+            checkJobAndTask(task, jobs2.iterator().next());
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+        }
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeAffinityCallJobAndTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, tasks.size());
+        assertEquals(1, jobs.size());
+
+        checkJobAndTask(tasks.iterator().next(), jobs.iterator().next());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Check fields for local {@link ComputeTaskView} and remote {@link ComputeJobView} info of the same computation.
+     */
+    private void checkJobAndTask(ComputeTaskView task, ComputeJobView job) {
+        assertNotSame(task.id(), job.id());
+        assertEquals(task.sessionId(), job.sessionId());
+        assertEquals(task.taskNodeId(), job.originNodeId());
+        assertEquals(task.taskName(), job.taskName());
+        assertEquals(task.taskClassName(), job.taskClassName());
+
+        if (task.affinityCacheName() != null)
+            assertEquals((Integer)CU.cacheId(task.affinityCacheName()), Integer.valueOf(job.affinityCacheIds()));
+        else
+            assertNull(job.affinityCacheIds());
+
+        assertEquals(task.affinityPartitionId(), job.affinityPartitionId());
+    }
+
+    /** Check tasks fields. */
+    private void checkTask(ComputeJobView t) {
 
 Review comment:
   check job?

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


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387947503
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
 
 Review comment:
   tests added.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387842471
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnable() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().runAsync(() -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call. */
+    @Test
+    public void testComputeApply() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        GridTestUtils.runAsync(() -> {
+            client.compute().apply(x -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return 0;
+            }, 1);
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Tests work of {@link SystemView} for compute grid
+     * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
+     */
+    @Test
+    public void testComputeAffinityCall() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        assertFalse(t.isInternal());
+        assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
+        assertEquals(1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** */
+    @Test
+    public void testComputeTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().executeAsync(new ComputeTask<Object, Object>() {
+            @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Object arg) throws IgniteException {
+                return Collections.singletonMap(new ComputeJob() {
+                    @Override public void cancel() {
+                        // No-op.
+                    }
+
+                    @Override public Object execute() throws IgniteException {
+                        try {
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                        }
+                        catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                            throw new RuntimeException(e);
+                        }
+
+                        return 1;
+                    }
+                }, subgrid.get(0));
+            }
+
+            @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+                List<ComputeJobResult> rcvd) throws IgniteException {
+
+                return null;
+            }
+
+            @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+                return 1;
+            }
+        }, 1);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnableJobAndTask() throws Exception {
+        try (IgniteEx server2 = startGrid(2)) {
+            barrier = new CyclicBarrier(3);
+
+            SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+
+            assertEquals(1, tasks.size());
+            assertEquals(1, jobs1.size());
+            assertEquals(1, jobs2.size());
+
+            ComputeTaskView task = tasks.iterator().next();
+
+            checkJobAndTask(task, jobs1.iterator().next());
+            checkJobAndTask(task, jobs2.iterator().next());
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+        }
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeAffinityCallJobAndTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, tasks.size());
+        assertEquals(1, jobs.size());
+
+        checkJobAndTask(tasks.iterator().next(), jobs.iterator().next());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Check fields for local {@link ComputeTaskView} and remote {@link ComputeJobView} info of the same computation.
+     */
+    private void checkJobAndTask(ComputeTaskView task, ComputeJobView job) {
+        assertNotSame(task.id(), job.id());
+        assertEquals(task.sessionId(), job.sessionId());
+        assertEquals(task.taskNodeId(), job.originNodeId());
+        assertEquals(task.taskName(), job.taskName());
+        assertEquals(task.taskClassName(), job.taskClassName());
+
+        if (task.affinityCacheName() != null)
+            assertEquals((Integer)CU.cacheId(task.affinityCacheName()), Integer.valueOf(job.affinityCacheIds()));
+        else
+            assertNull(job.affinityCacheIds());
+
+        assertEquals(task.affinityPartitionId(), job.affinityPartitionId());
+    }
+
+    /** Check tasks fields. */
+    private void checkTask(ComputeJobView t) {
+        assertFalse(t.isInternal());
+        assertNull(t.affinityCacheIds());
+        assertEquals(-1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+        assertEquals(ACTIVE, t.state);
 
 Review comment:
   Getter state() can be used here.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387571618
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return Origin node id. */
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysCancelled() {
+        return job.isSystemCanceled();
+    }
+
+    /** @return {@code True} if ???. */
 
 Review comment:
   Please, add meaningful description instead ???.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387569998
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return Origin node id. */
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysCancelled() {
+        return job.isSystemCanceled();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysStopping() {
+        return job.isSysStopping();
+    }
+
+    /** @return {@code True} if job started. */
+    public boolean isStarted() {
+        return job.isStarted();
+    }
+
+    /** @return Executor name. */
+    public String executorName() {
+        return job.executorName();
+    }
+
+    /** @return Job class name. */
+    public String taskClassName() {
+        return job.getSession().getTaskClassName();
+    }
+
+    /** @return Task name. */
+    public String taskName() {
+        return job.getSession().getTaskName();
+    }
+
+    /** @return Affinity cache ids. */
 
 Review comment:
   I suggest to mark `nullable` and update javadoc.

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


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387729841
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,157 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    public final GridJobWorker job;
+
+    /** Job id. */
+    public final IgniteUuid id;
+
+    /**
+     * @param id Job id.
+     * @param job Job.
+     */
+    public ComputeJobView(IgniteUuid id, GridJobWorker job) {
+        this.id = id;
+        this.job = job;
+    }
+
+    /** @return Job id. */
+    @Order
+    public IgniteUuid id() {
+        return id;
+    }
+
+    /**
+     * {@link ComputeJobView#sessionId()} value equal to the value of {@link ComputeTaskView#sessionId()}
+     * if both records represents parts of the same computation.
+     *
+     * @see ComputeTaskView#sessionId()
+     * @return Session id.
+     */
+    @Order(1)
+    public IgniteUuid sessionId() {
+        return job.getSession().getId();
+    }
+
+    /** @return Origin node id. */
+    @Order(2)
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return Task name. */
+    @Order(3)
+    public String taskName() {
+        return job.getSession().getTaskName();
+    }
+
+    /** @return Task class name. */
+    @Order(4)
+    public String taskClassName() {
+        return job.getSession().getTaskClassName();
+    }
+
+    /** @return Affinity cache name or {@code null} for non affinity call. */
 
 Review comment:
   Yes. Thank you. Fixed.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387837734
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
 
 Review comment:
   I suggest adding a check that jobs.size will be 0 after all jobs finish. 

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387854228
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnable() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().runAsync(() -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call. */
+    @Test
+    public void testComputeApply() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        GridTestUtils.runAsync(() -> {
+            client.compute().apply(x -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return 0;
+            }, 1);
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Tests work of {@link SystemView} for compute grid
+     * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
+     */
+    @Test
+    public void testComputeAffinityCall() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        assertFalse(t.isInternal());
+        assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
+        assertEquals(1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** */
+    @Test
+    public void testComputeTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().executeAsync(new ComputeTask<Object, Object>() {
+            @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Object arg) throws IgniteException {
+                return Collections.singletonMap(new ComputeJob() {
+                    @Override public void cancel() {
+                        // No-op.
+                    }
+
+                    @Override public Object execute() throws IgniteException {
+                        try {
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                        }
+                        catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                            throw new RuntimeException(e);
+                        }
+
+                        return 1;
+                    }
+                }, subgrid.get(0));
+            }
+
+            @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+                List<ComputeJobResult> rcvd) throws IgniteException {
+
+                return null;
+            }
+
+            @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+                return 1;
+            }
+        }, 1);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnableJobAndTask() throws Exception {
+        try (IgniteEx server2 = startGrid(2)) {
+            barrier = new CyclicBarrier(3);
+
+            SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+
+            assertEquals(1, tasks.size());
+            assertEquals(1, jobs1.size());
+            assertEquals(1, jobs2.size());
+
+            ComputeTaskView task = tasks.iterator().next();
+
+            checkJobAndTask(task, jobs1.iterator().next());
+            checkJobAndTask(task, jobs2.iterator().next());
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+        }
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeAffinityCallJobAndTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, tasks.size());
+        assertEquals(1, jobs.size());
+
+        checkJobAndTask(tasks.iterator().next(), jobs.iterator().next());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Check fields for local {@link ComputeTaskView} and remote {@link ComputeJobView} info of the same computation.
+     */
+    private void checkJobAndTask(ComputeTaskView task, ComputeJobView job) {
+        assertNotSame(task.id(), job.id());
+        assertEquals(task.sessionId(), job.sessionId());
+        assertEquals(task.taskNodeId(), job.originNodeId());
+        assertEquals(task.taskName(), job.taskName());
+        assertEquals(task.taskClassName(), job.taskClassName());
+
+        if (task.affinityCacheName() != null)
+            assertEquals((Integer)CU.cacheId(task.affinityCacheName()), Integer.valueOf(job.affinityCacheIds()));
+        else
+            assertNull(job.affinityCacheIds());
+
+        assertEquals(task.affinityPartitionId(), job.affinityPartitionId());
+    }
+
+    /** Check tasks fields. */
+    private void checkTask(ComputeJobView t) {
+        assertFalse(t.isInternal());
+        assertNull(t.affinityCacheIds());
+        assertEquals(-1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+        assertEquals(ACTIVE, t.state);
+    }
 
 Review comment:
   \+ `assertTrue(t.isStarted());`

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387727821
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,157 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    public final GridJobWorker job;
+
+    /** Job id. */
+    public final IgniteUuid id;
+
+    /**
+     * @param id Job id.
+     * @param job Job.
+     */
+    public ComputeJobView(IgniteUuid id, GridJobWorker job) {
+        this.id = id;
+        this.job = job;
+    }
+
+    /** @return Job id. */
+    @Order
+    public IgniteUuid id() {
+        return id;
+    }
+
+    /**
+     * {@link ComputeJobView#sessionId()} value equal to the value of {@link ComputeTaskView#sessionId()}
+     * if both records represents parts of the same computation.
+     *
+     * @see ComputeTaskView#sessionId()
+     * @return Session id.
+     */
+    @Order(1)
+    public IgniteUuid sessionId() {
+        return job.getSession().getId();
+    }
+
+    /** @return Origin node id. */
+    @Order(2)
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return Task name. */
+    @Order(3)
+    public String taskName() {
+        return job.getSession().getTaskName();
+    }
+
+    /** @return Task class name. */
+    @Order(4)
+    public String taskClassName() {
+        return job.getSession().getTaskClassName();
+    }
+
+    /** @return Affinity cache name or {@code null} for non affinity call. */
 
 Review comment:
   Comma separated list of affinity cache identifiers?

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387844593
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
 
 Review comment:
   Can you cover job states(PASSIVE, CANCELED), 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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387580811
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
 
 Review comment:
   in milliseconds?

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387570874
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return Origin node id. */
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysCancelled() {
+        return job.isSystemCanceled();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysStopping() {
+        return job.isSysStopping();
+    }
+
+    /** @return {@code True} if job started. */
+    public boolean isStarted() {
+        return job.isStarted();
+    }
+
+    /** @return Executor name. */
+    public String executorName() {
+        return job.executorName();
+    }
+
+    /** @return Job class name. */
 
 Review comment:
   Job or Task class name is correct?

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387850173
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnable() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().runAsync(() -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call. */
+    @Test
+    public void testComputeApply() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        GridTestUtils.runAsync(() -> {
+            client.compute().apply(x -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return 0;
+            }, 1);
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Tests work of {@link SystemView} for compute grid
+     * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
+     */
+    @Test
+    public void testComputeAffinityCall() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        assertFalse(t.isInternal());
+        assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
+        assertEquals(1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** */
+    @Test
+    public void testComputeTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().executeAsync(new ComputeTask<Object, Object>() {
+            @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Object arg) throws IgniteException {
+                return Collections.singletonMap(new ComputeJob() {
+                    @Override public void cancel() {
+                        // No-op.
+                    }
+
+                    @Override public Object execute() throws IgniteException {
+                        try {
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                        }
+                        catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                            throw new RuntimeException(e);
+                        }
+
+                        return 1;
+                    }
+                }, subgrid.get(0));
+            }
+
+            @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+                List<ComputeJobResult> rcvd) throws IgniteException {
+
+                return null;
+            }
+
+            @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+                return 1;
+            }
+        }, 1);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnableJobAndTask() throws Exception {
+        try (IgniteEx server2 = startGrid(2)) {
+            barrier = new CyclicBarrier(3);
+
+            SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+
+            assertEquals(1, tasks.size());
+            assertEquals(1, jobs1.size());
+            assertEquals(1, jobs2.size());
+
+            ComputeTaskView task = tasks.iterator().next();
+
+            checkJobAndTask(task, jobs1.iterator().next());
+            checkJobAndTask(task, jobs2.iterator().next());
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+        }
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeAffinityCallJobAndTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, tasks.size());
+        assertEquals(1, jobs.size());
+
+        checkJobAndTask(tasks.iterator().next(), jobs.iterator().next());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Check fields for local {@link ComputeTaskView} and remote {@link ComputeJobView} info of the same computation.
+     */
+    private void checkJobAndTask(ComputeTaskView task, ComputeJobView job) {
+        assertNotSame(task.id(), job.id());
+        assertEquals(task.sessionId(), job.sessionId());
+        assertEquals(task.taskNodeId(), job.originNodeId());
+        assertEquals(task.taskName(), job.taskName());
+        assertEquals(task.taskClassName(), job.taskClassName());
+
+        if (task.affinityCacheName() != null)
+            assertEquals((Integer)CU.cacheId(task.affinityCacheName()), Integer.valueOf(job.affinityCacheIds()));
+        else
+            assertNull(job.affinityCacheIds());
+
+        assertEquals(task.affinityPartitionId(), job.affinityPartitionId());
+    }
+
+    /** Check tasks fields. */
+    private void checkTask(ComputeJobView t) {
+        assertFalse(t.isInternal());
+        assertNull(t.affinityCacheIds());
+        assertEquals(-1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+        assertEquals(ACTIVE, t.state);
+    }
 
 Review comment:
   Let's add additional checks:
   ```
           assertEquals(0, j.finishTime());
           assertTrue(j.startTime() > 0);
   ```

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387846530
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnable() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().runAsync(() -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call. */
+    @Test
+    public void testComputeApply() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        GridTestUtils.runAsync(() -> {
+            client.compute().apply(x -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return 0;
+            }, 1);
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Tests work of {@link SystemView} for compute grid
+     * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
+     */
+    @Test
+    public void testComputeAffinityCall() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        assertFalse(t.isInternal());
+        assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
+        assertEquals(1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** */
+    @Test
+    public void testComputeTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().executeAsync(new ComputeTask<Object, Object>() {
+            @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Object arg) throws IgniteException {
+                return Collections.singletonMap(new ComputeJob() {
+                    @Override public void cancel() {
+                        // No-op.
+                    }
+
+                    @Override public Object execute() throws IgniteException {
+                        try {
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                        }
+                        catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                            throw new RuntimeException(e);
+                        }
+
+                        return 1;
+                    }
+                }, subgrid.get(0));
+            }
+
+            @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+                List<ComputeJobResult> rcvd) throws IgniteException {
+
+                return null;
+            }
+
+            @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+                return 1;
+            }
+        }, 1);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnableJobAndTask() throws Exception {
+        try (IgniteEx server2 = startGrid(2)) {
+            barrier = new CyclicBarrier(3);
+
+            SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+
+            assertEquals(1, tasks.size());
+            assertEquals(1, jobs1.size());
+            assertEquals(1, jobs2.size());
+
+            ComputeTaskView task = tasks.iterator().next();
+
+            checkJobAndTask(task, jobs1.iterator().next());
+            checkJobAndTask(task, jobs2.iterator().next());
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+        }
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeAffinityCallJobAndTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, tasks.size());
+        assertEquals(1, jobs.size());
+
+        checkJobAndTask(tasks.iterator().next(), jobs.iterator().next());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Check fields for local {@link ComputeTaskView} and remote {@link ComputeJobView} info of the same computation.
+     */
+    private void checkJobAndTask(ComputeTaskView task, ComputeJobView job) {
 
 Review comment:
   Let's name it `checkTaskAndJob` like parameters ordered  :)

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


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov merged pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
nizhikov merged pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495
 
 
   

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387575334
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
 
 Review comment:
   Job id

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387589019
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobWorker.java
 ##########
 @@ -271,17 +271,42 @@ public GridDeployment getDeployment() {
      *
      * @return {@code True} if job was cancelled by the system.
      */
-    boolean isSystemCanceled() {
+    public boolean isSystemCanceled() {
         return sysCancelled;
     }
 
     /**
      * @return Create time.
      */
-    long getCreateTime() {
+    public long getCreateTime() {
         return createTime;
     }
 
+    /** @return Start time. */
+    public long getStartTime() {
+        return startTime;
+    }
+
+    /** @return Finish time. */
+    public long getFinishTime() {
+        return finishTime;
+    }
+
+    /** @return Sys stopping. */
 
 Review comment:
   What `sys` is means?

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387568854
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return Origin node id. */
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysCancelled() {
+        return job.isSystemCanceled();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysStopping() {
+        return job.isSysStopping();
+    }
+
+    /** @return {@code True} if job started. */
+    public boolean isStarted() {
+        return job.isStarted();
+    }
+
+    /** @return Executor name. */
+    public String executorName() {
+        return job.executorName();
+    }
+
+    /** @return Job class name. */
+    public String taskClassName() {
+        return job.getSession().getTaskClassName();
+    }
+
+    /** @return Task name. */
+    public String taskName() {
+        return job.getSession().getTaskName();
+    }
+
+    /** @return Affinity cache ids. */
+    public String affinityCacheIds() {
+        GridReservable res = job.getPartsReservation();
+
+        if (!(res instanceof GridJobProcessor.PartitionsReservation))
+            return null;
+
+        int[] ids = ((GridJobProcessor.PartitionsReservation)res).getCacheIds();
+
+        if (ids == null || ids.length == 0)
+            return null;
+
+        StringJoiner joiner = new StringJoiner(",");
+
+        for (int id : ids)
+            joiner.add(Integer.toString(id));
+
+        return joiner.toString();
+    }
+
+    /** @return Affinity partition id. */
 
 Review comment:
   I think it should be described what -1 is means.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387588599
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/internal/processors/job/GridJobProcessor.java
 ##########
 @@ -1702,6 +1726,16 @@ public PartitionsReservation(int[] cacheIds, int partId,
             partititons = new GridDhtLocalPartition[cacheIds.length];
         }
 
+        /** @return Caches. */
 
 Review comment:
   Caches' identifiers ?

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387731070
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,157 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    public final GridJobWorker job;
+
+    /** Job id. */
+    public final IgniteUuid id;
+
+    /**
+     * @param id Job id.
+     * @param job Job.
+     */
+    public ComputeJobView(IgniteUuid id, GridJobWorker job) {
+        this.id = id;
+        this.job = job;
+    }
+
+    /** @return Job id. */
+    @Order
+    public IgniteUuid id() {
+        return id;
+    }
+
+    /**
+     * {@link ComputeJobView#sessionId()} value equal to the value of {@link ComputeTaskView#sessionId()}
+     * if both records represents parts of the same computation.
+     *
+     * @see ComputeTaskView#sessionId()
 
 Review comment:
   `@see` should be placed after `@return`

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387875432
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
 
 Review comment:
   Let's increase timeout to avoid infrastructures affect. 

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387731382
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeTaskView.java
 ##########
 @@ -18,73 +18,100 @@
 package org.apache.ignite.spi.systemview.view;
 
 import java.util.UUID;
+import org.apache.ignite.internal.managers.systemview.walker.Order;
 import org.apache.ignite.internal.processors.task.GridTaskWorker;
 import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Compute task representation for a {@link SystemView}.
  */
 public class ComputeTaskView {
     /** Worker for task. */
-    private final GridTaskWorker worker;
+    public final GridTaskWorker worker;
+
+    /** Task id. */
+    public final IgniteUuid id;
 
     /**
+     * @param id Task id.
      * @param worker Worker for task.
      */
-    public ComputeTaskView(GridTaskWorker worker) {
+    public ComputeTaskView(IgniteUuid id, GridTaskWorker worker) {
+        this.id = id;
         this.worker = worker;
     }
 
+    /** @return Task id. */
+    @Order
+    public IgniteUuid id() {
+        return id;
+    }
+
+    /**
+     * {@link ComputeTaskView#sessionId()} value equal to the value of {@link ComputeJobView#sessionId()}
+     * if both records represents parts of the same computation.
+     *
+     * @see ComputeJobView#sessionId()
 
 Review comment:
   @see should be placed after @return

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


With regards,
Apache Git Services

[GitHub] [ignite] nizhikov commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387697966
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return Origin node id. */
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysCancelled() {
+        return job.isSystemCanceled();
+    }
+
+    /** @return {@code True} if ???. */
+    public boolean isSysStopping() {
+        return job.isSysStopping();
+    }
+
+    /** @return {@code True} if job started. */
+    public boolean isStarted() {
+        return job.isStarted();
+    }
+
+    /** @return Executor name. */
+    public String executorName() {
+        return job.executorName();
+    }
+
+    /** @return Job class name. */
 
 Review comment:
   They both are correct. I think we should use `taskName` and `taskClassName` to highlight to the user that these columns are the same as in `TASKS` view.

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387854228
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewComputeJobTest.java
 ##########
 @@ -0,0 +1,352 @@
+/*
+ * 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.metric;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCompute;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeJobResultPolicy;
+import org.apache.ignite.compute.ComputeTask;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.spi.systemview.view.ComputeJobView;
+import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
+import static org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
+import static org.apache.ignite.spi.systemview.view.ComputeJobView.ComputeJobState.ACTIVE;
+
+/** Tests for compute task {@link SystemView}. */
+public class SystemViewComputeJobTest extends GridCommonAbstractTest {
+    /** */
+    public static final long TIMEOUT = 5_000L;
+
+    /** */
+    private static CyclicBarrier barrier;
+
+    /** */
+    private static IgniteEx server;
+
+    /** */
+    private static IgniteEx client;
+
+    /** */
+    private static IgniteCache<Integer, Integer> cache;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        server = startGrid(0);
+        client = startClientGrid(1);
+
+        cache = server.createCache("test-cache");
+
+        cache.put(1, 1);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#broadcastAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeBroadcast() throws Exception {
+        barrier = new CyclicBarrier(6);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        for (int i = 0; i < 5; i++) {
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(5, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnable() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().runAsync(() -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#apply(IgniteClosure, Object)} call. */
+    @Test
+    public void testComputeApply() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        GridTestUtils.runAsync(() -> {
+            client.compute().apply(x -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return 0;
+            }, 1);
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Tests work of {@link SystemView} for compute grid
+     * {@link IgniteCompute#affinityCallAsync(String, Object, IgniteCallable)} call.
+     */
+    @Test
+    public void testComputeAffinityCall() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        assertFalse(t.isInternal());
+        assertEquals(String.valueOf(CU.cacheId("test-cache")), t.affinityCacheIds());
+        assertEquals(1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** */
+    @Test
+    public void testComputeTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+
+        client.compute().executeAsync(new ComputeTask<Object, Object>() {
+            @Override public @NotNull Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid,
+                @Nullable Object arg) throws IgniteException {
+                return Collections.singletonMap(new ComputeJob() {
+                    @Override public void cancel() {
+                        // No-op.
+                    }
+
+                    @Override public Object execute() throws IgniteException {
+                        try {
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                            barrier.await(TIMEOUT, MILLISECONDS);
+                        }
+                        catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                            throw new RuntimeException(e);
+                        }
+
+                        return 1;
+                    }
+                }, subgrid.get(0));
+            }
+
+            @Override public ComputeJobResultPolicy result(ComputeJobResult res,
+                List<ComputeJobResult> rcvd) throws IgniteException {
+
+                return null;
+            }
+
+            @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteException {
+                return 1;
+            }
+        }, 1);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, jobs.size());
+
+        ComputeJobView t = jobs.iterator().next();
+
+        checkTask(t);
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeRunnableJobAndTask() throws Exception {
+        try (IgniteEx server2 = startGrid(2)) {
+            barrier = new CyclicBarrier(3);
+
+            SystemView<ComputeJobView> jobs1 = server.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeJobView> jobs2 = server2.context().systemView().view(JOBS_VIEW);
+            SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+            client.compute().broadcastAsync(() -> {
+                try {
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                    barrier.await(TIMEOUT, MILLISECONDS);
+                }
+                catch (InterruptedException | BrokenBarrierException | TimeoutException e) {
+                    throw new RuntimeException(e);
+                }
+            });
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+
+            assertEquals(1, tasks.size());
+            assertEquals(1, jobs1.size());
+            assertEquals(1, jobs2.size());
+
+            ComputeTaskView task = tasks.iterator().next();
+
+            checkJobAndTask(task, jobs1.iterator().next());
+            checkJobAndTask(task, jobs2.iterator().next());
+
+            barrier.await(TIMEOUT, MILLISECONDS);
+        }
+    }
+
+    /** Tests work of {@link SystemView} for compute grid {@link IgniteCompute#runAsync(IgniteRunnable)} call. */
+    @Test
+    public void testComputeAffinityCallJobAndTask() throws Exception {
+        barrier = new CyclicBarrier(2);
+
+        SystemView<ComputeJobView> jobs = server.context().systemView().view(JOBS_VIEW);
+        SystemView<ComputeTaskView> tasks = client.context().systemView().view(TASKS_VIEW);
+
+        client.compute().affinityCallAsync("test-cache", 1, () -> {
+            try {
+                barrier.await(TIMEOUT, MILLISECONDS);
+                barrier.await(TIMEOUT, MILLISECONDS);
+            }
+            catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+
+            return 0;
+        });
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+
+        assertEquals(1, tasks.size());
+        assertEquals(1, jobs.size());
+
+        checkJobAndTask(tasks.iterator().next(), jobs.iterator().next());
+
+        barrier.await(TIMEOUT, MILLISECONDS);
+    }
+
+    /**
+     * Check fields for local {@link ComputeTaskView} and remote {@link ComputeJobView} info of the same computation.
+     */
+    private void checkJobAndTask(ComputeTaskView task, ComputeJobView job) {
+        assertNotSame(task.id(), job.id());
+        assertEquals(task.sessionId(), job.sessionId());
+        assertEquals(task.taskNodeId(), job.originNodeId());
+        assertEquals(task.taskName(), job.taskName());
+        assertEquals(task.taskClassName(), job.taskClassName());
+
+        if (task.affinityCacheName() != null)
+            assertEquals((Integer)CU.cacheId(task.affinityCacheName()), Integer.valueOf(job.affinityCacheIds()));
+        else
+            assertNull(job.affinityCacheIds());
+
+        assertEquals(task.affinityPartitionId(), job.affinityPartitionId());
+    }
+
+    /** Check tasks fields. */
+    private void checkTask(ComputeJobView t) {
+        assertFalse(t.isInternal());
+        assertNull(t.affinityCacheIds());
+        assertEquals(-1, t.affinityPartitionId());
+        assertTrue(t.taskClassName().startsWith(getClass().getName()));
+        assertTrue(t.taskName().startsWith(getClass().getName()));
+        assertEquals(client.localNode().id(), t.originNodeId());
+        assertEquals(ACTIVE, t.state);
+    }
 
 Review comment:
   + `assertTrue(t.isStarted());`

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


With regards,
Apache Git Services

[GitHub] [ignite] NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #7495: IGNITE-12745: Compute job view implemented.
URL: https://github.com/apache/ignite/pull/7495#discussion_r387571568
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/systemview/view/ComputeJobView.java
 ##########
 @@ -0,0 +1,140 @@
+/*
+ * 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.spi.systemview.view;
+
+import java.util.StringJoiner;
+import java.util.UUID;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridReservable;
+import org.apache.ignite.internal.processors.job.GridJobProcessor;
+import org.apache.ignite.internal.processors.job.GridJobWorker;
+import org.apache.ignite.lang.IgniteUuid;
+
+/**
+ * Compute job representation for a {@link SystemView}.
+ */
+public class ComputeJobView {
+    /** Job. */
+    private final GridJobWorker job;
+
+    /**
+     * @param job Job.
+     */
+    public ComputeJobView(GridJobWorker job) {
+        this.job = job;
+    }
+
+    /** @return Task id. */
+    public IgniteUuid id() {
+        return job.getJobId();
+    }
+
+    /** @return Create time. */
+    public long createTime() {
+        return job.getCreateTime();
+    }
+
+    /** @return Start time. */
+    public long startTime() {
+        return job.getStartTime();
+    }
+
+    /** @return Finish time. */
+    public long fininshTime() {
+        return job.getFinishTime();
+    }
+
+    /** @return Origin node id. */
+    public UUID originNodeId() {
+        return job.getTaskNode().id();
+    }
+
+    /** @return {@code True} if job is internal. */
+    public boolean isInternal() {
+        return job.isInternal();
+    }
+
+    /** @return {@code True} if job is finishing. */
+    public boolean isFinishing() {
+        return job.isFinishing();
+    }
+
+    /** @return {@code True} if job is timed out. */
+    public boolean isTimedOut() {
+        return job.isTimedOut();
+    }
+
 
 Review comment:
   Please, add meaningful description instead ???.

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


With regards,
Apache Git Services