Repository: ignite Updated Branches: refs/heads/master 5f84bf498 -> f337f142b
IGNITE-5474 Simplified usage of VisorComputeCancelSessionsTask, added compute load in agent demo. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f337f142 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f337f142 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f337f142 Branch: refs/heads/master Commit: f337f142b9dc3f2fcbc2c0b36bbfa718b3a5954d Parents: 5f84bf4 Author: Vasiliy Sisko <[email protected]> Authored: Tue Jun 13 17:51:18 2017 +0700 Committer: Andrey Novikov <[email protected]> Committed: Tue Jun 13 17:51:18 2017 +0700 ---------------------------------------------------------------------- .../compute/VisorComputeCancelSessionsTask.java | 6 +- .../VisorComputeCancelSessionsTaskArg.java | 10 +- .../frontend/app/helpers/jade/mixins.pug | 1 + .../frontend/app/primitives/index.js | 1 + .../frontend/app/primitives/switch/index.pug | 34 ++++++ .../frontend/app/primitives/switch/index.scss | 87 +++++++++++++++ .../ignite/console/demo/AgentClusterDemo.java | 3 + .../demo/service/DemoComputeLoadService.java | 79 ++++++++++++++ .../console/demo/task/DemoCancellableTask.java | 92 ++++++++++++++++ .../console/demo/task/DemoComputeTask.java | 105 +++++++++++++++++++ 10 files changed, 410 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTask.java index f28d988..6cd683c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTask.java @@ -26,7 +26,7 @@ import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.internal.processors.task.GridInternal; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.visor.VisorJob; -import org.apache.ignite.internal.visor.VisorMultiNodeTask; +import org.apache.ignite.internal.visor.VisorOneNodeTask; import org.apache.ignite.lang.IgniteUuid; import org.jetbrains.annotations.Nullable; @@ -34,7 +34,7 @@ import org.jetbrains.annotations.Nullable; * Cancels given tasks sessions. */ @GridInternal -public class VisorComputeCancelSessionsTask extends VisorMultiNodeTask<VisorComputeCancelSessionsTaskArg, Void, Void> { +public class VisorComputeCancelSessionsTask extends VisorOneNodeTask<VisorComputeCancelSessionsTaskArg, Void> { /** */ private static final long serialVersionUID = 0L; @@ -66,7 +66,7 @@ public class VisorComputeCancelSessionsTask extends VisorMultiNodeTask<VisorComp /** {@inheritDoc} */ @Override protected Void run(VisorComputeCancelSessionsTaskArg arg) { - Set<IgniteUuid> sesIds = arg.getSessionIds().get(ignite.localNode().id()); + Set<IgniteUuid> sesIds = arg.getSessionIds(); if (sesIds != null && !sesIds.isEmpty()) { IgniteCompute compute = ignite.compute(ignite.cluster().forLocal()); http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTaskArg.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTaskArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTaskArg.java index 28b7953..c014982 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTaskArg.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/compute/VisorComputeCancelSessionsTaskArg.java @@ -36,7 +36,7 @@ public class VisorComputeCancelSessionsTaskArg extends VisorDataTransferObject { private static final long serialVersionUID = 0L; /** Session IDs to cancel. */ - private Map<UUID, Set<IgniteUuid>> sesIds; + private Set<IgniteUuid> sesIds; /** * Default constructor. @@ -48,25 +48,25 @@ public class VisorComputeCancelSessionsTaskArg extends VisorDataTransferObject { /** * @param sesIds Session IDs to cancel. */ - public VisorComputeCancelSessionsTaskArg(Map<UUID, Set<IgniteUuid>> sesIds) { + public VisorComputeCancelSessionsTaskArg(Set<IgniteUuid> sesIds) { this.sesIds = sesIds; } /** * @return Session IDs to cancel. */ - public Map<UUID, Set<IgniteUuid>> getSessionIds() { + public Set<IgniteUuid> getSessionIds() { return sesIds; } /** {@inheritDoc} */ @Override protected void writeExternalData(ObjectOutput out) throws IOException { - U.writeMap(out, sesIds); + U.writeCollection(out, sesIds); } /** {@inheritDoc} */ @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException { - sesIds = U.readMap(in); + sesIds = U.readSet(in); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/frontend/app/helpers/jade/mixins.pug ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/helpers/jade/mixins.pug b/modules/web-console/frontend/app/helpers/jade/mixins.pug index a357966..7bf1362 100644 --- a/modules/web-console/frontend/app/helpers/jade/mixins.pug +++ b/modules/web-console/frontend/app/helpers/jade/mixins.pug @@ -20,6 +20,7 @@ include ../../primitives/datepicker/index include ../../primitives/dropdown/index include ../../primitives/tooltip/index include ../../primitives/ui-grid-settings/index +include ../../primitives/switch/index //- Mixin for advanced options toggle. mixin advanced-options-toggle(click, cond, showMessage, hideMessage) http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/frontend/app/primitives/index.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/primitives/index.js b/modules/web-console/frontend/app/primitives/index.js index 8382c19..35a7cde 100644 --- a/modules/web-console/frontend/app/primitives/index.js +++ b/modules/web-console/frontend/app/primitives/index.js @@ -27,3 +27,4 @@ import './ui-grid/index.scss'; import './ui-grid-header/index.scss'; import './ui-grid-settings/index.scss'; import './page/index.scss'; +import './switch/index.scss'; http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/frontend/app/primitives/switch/index.pug ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/primitives/switch/index.pug b/modules/web-console/frontend/app/primitives/switch/index.pug new file mode 100644 index 0000000..02b9852 --- /dev/null +++ b/modules/web-console/frontend/app/primitives/switch/index.pug @@ -0,0 +1,34 @@ +//- + 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. + +mixin form-field-switch(label, model, name, disabled, required) + .switch--ignite + label(id=`{{ ${name} }}Label`) + .input-tip + if block + block + else + input( + id=`{{ ${name} }}Input` + name=`{{ ${name} }}` + type='checkbox' + + data-ng-model=model + data-ng-required=required && `${required}` + data-ng-disabled=disabled && `${disabled}` + ) + div + span #{label} http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/frontend/app/primitives/switch/index.scss ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/primitives/switch/index.scss b/modules/web-console/frontend/app/primitives/switch/index.scss new file mode 100644 index 0000000..9f67af3 --- /dev/null +++ b/modules/web-console/frontend/app/primitives/switch/index.scss @@ -0,0 +1,87 @@ +/* + * 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. + */ + +@import '../../../public/stylesheets/variables'; + +.switch--ignite { + width: 34px; + height: 20px; + + label { + width: 34px; + max-width: 34px !important; + height: 100%; + padding-left: 20px; + + line-height: 20px; + vertical-align: middle; + + cursor: pointer; + + .input-tip { + float: left; + + height: 100%; + margin-left: -20px; + + input[type="checkbox"] { + position: absolute; + left: -20px; + + & + div { + position: relative; + + width: 34px; + height: 14px; + margin-top: 3px; + + border-radius: 8px; + background-color: #C5C5C5; + + &:before { + content: ''; + + position: absolute; + top: -3px; + left: 0; + + width: 20px; + height: 20px; + + border: solid 1px #C5C5C5; + border-radius: 50%; + background-color: #FFF; + } + } + + &:checked + div { + background-color: #FF8485; + + &:before { + content: ''; + + left: initial; + right: 0; + + border: 0; + background-color: #EE2B27; + } + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/AgentClusterDemo.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/AgentClusterDemo.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/AgentClusterDemo.java index 776e407..80c8c0c 100644 --- a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/AgentClusterDemo.java +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/AgentClusterDemo.java @@ -29,6 +29,7 @@ import org.apache.ignite.IgniteServices; import org.apache.ignite.Ignition; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.console.demo.service.DemoCachesLoadService; +import org.apache.ignite.console.demo.service.DemoComputeLoadService; import org.apache.ignite.console.demo.service.DemoRandomCacheLoadService; import org.apache.ignite.console.demo.service.DemoServiceClusterSingleton; import org.apache.ignite.console.demo.service.DemoServiceKeyAffinity; @@ -142,6 +143,8 @@ public class AgentClusterDemo { services.deployClusterSingleton("Demo caches load service", new DemoCachesLoadService(20)); services.deployNodeSingleton("RandomCache load service", new DemoRandomCacheLoadService(20)); + + services.deployMultiple("Demo service: Compute load", new DemoComputeLoadService(), 2, 1); } /** */ http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/service/DemoComputeLoadService.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/service/DemoComputeLoadService.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/service/DemoComputeLoadService.java new file mode 100644 index 0000000..e775a9a --- /dev/null +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/service/DemoComputeLoadService.java @@ -0,0 +1,79 @@ +/* + * 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.console.demo.service; + +import java.util.Random; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.console.demo.AgentDemoUtils; +import org.apache.ignite.console.demo.task.DemoCancellableTask; +import org.apache.ignite.console.demo.task.DemoComputeTask; +import org.apache.ignite.resources.IgniteInstanceResource; +import org.apache.ignite.services.Service; +import org.apache.ignite.services.ServiceContext; + +/** + * Demo service. Run tasks on nodes. Run demo load on caches. + */ +public class DemoComputeLoadService implements Service { + /** Ignite instance. */ + @IgniteInstanceResource + private Ignite ignite; + + /** Thread pool to execute cache load operations. */ + private ScheduledExecutorService computePool; + + /** {@inheritDoc} */ + @Override public void cancel(ServiceContext ctx) { + if (computePool != null) + computePool.shutdownNow(); + } + + /** {@inheritDoc} */ + @Override public void init(ServiceContext ctx) throws Exception { + computePool = AgentDemoUtils.newScheduledThreadPool(2, "demo-compute-load-tasks"); + } + + /** {@inheritDoc} */ + @Override public void execute(ServiceContext ctx) throws Exception { + computePool.scheduleWithFixedDelay(new Runnable() { + @Override public void run() { + try { + ignite.compute().withNoFailover() + .execute(DemoComputeTask.class, null); + } + catch (Throwable e) { + ignite.log().error("Task execution error", e); + } + } + }, 10, 3, TimeUnit.SECONDS); + + computePool.scheduleWithFixedDelay(new Runnable() { + @Override public void run() { + try { + ignite.compute().withNoFailover() + .execute(DemoCancellableTask.class, null); + } + catch (Throwable e) { + ignite.log().error("DemoCancellableTask execution error", e); + } + } + }, 10, 30, TimeUnit.SECONDS); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoCancellableTask.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoCancellableTask.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoCancellableTask.java new file mode 100644 index 0000000..2a22908 --- /dev/null +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoCancellableTask.java @@ -0,0 +1,92 @@ +/* + * 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.console.demo.task; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteInterruptedException; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobAdapter; +import org.apache.ignite.compute.ComputeJobResult; +import org.apache.ignite.compute.ComputeJobResultPolicy; +import org.apache.ignite.compute.ComputeTask; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.Nullable; + +/** + * Simple compute task to test task cancellation from Visor. + */ +public class DemoCancellableTask implements ComputeTask<Void, Void> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, + @Nullable Void arg) throws IgniteException { + HashMap<ComputeJob, ClusterNode> map = U.newHashMap(1); + + map.put(new DemoCancellableJob(), subgrid.get(0)); + + return map; + } + + /** {@inheritDoc} */ + @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException { + return ComputeJobResultPolicy.WAIT; + } + + /** {@inheritDoc} */ + @Nullable @Override public Void reduce(List<ComputeJobResult> results) throws IgniteException { + return null; + } + + /** + * Simple compute job to execute cancel action. + */ + private static class DemoCancellableJob extends ComputeJobAdapter { + /** */ + private static final long serialVersionUID = 0L; + + /** Random generator. */ + private static final Random rnd = new Random(); + + /** {@inheritDoc} */ + @Override public Object execute() throws IgniteException { + try { + Thread.sleep(1000 + rnd.nextInt(60000)); + } + catch (InterruptedException e) { + // Restore interrupt status + Thread.currentThread().interrupt(); + + throw new IgniteInterruptedException(e); + } + + return null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DemoCancellableJob.class, this); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f337f142/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoComputeTask.java ---------------------------------------------------------------------- diff --git a/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoComputeTask.java b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoComputeTask.java new file mode 100644 index 0000000..bc237cb --- /dev/null +++ b/modules/web-console/web-agent/src/main/java/org/apache/ignite/console/demo/task/DemoComputeTask.java @@ -0,0 +1,105 @@ +/* + * 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.console.demo.task; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteInterruptedException; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobAdapter; +import org.apache.ignite.compute.ComputeJobResult; +import org.apache.ignite.compute.ComputeJobResultPolicy; +import org.apache.ignite.compute.ComputeTask; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.Nullable; + +/** + * Simple compute task. + */ +public class DemoComputeTask implements ComputeTask<Void, Integer>{ + /** */ + private static final long serialVersionUID = 0L; + + /** Random generator. */ + private static final Random rnd = new Random(); + + /** {@inheritDoc} */ + @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, + @Nullable Void arg) throws IgniteException { + HashMap<ComputeJob, ClusterNode> map = new HashMap<>(subgrid.size()); + + for (ClusterNode node: subgrid) { + for (int i = 0; i < Math.max(1, rnd.nextInt(5)); i++) + map.put(new DemoComputeJob(), node); + } + + return map; + } + + /** {@inheritDoc} */ + @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteException { + return ComputeJobResultPolicy.REDUCE; + } + + /** {@inheritDoc} */ + @Nullable @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteException { + int sum = 0; + + for (ComputeJobResult r: results) { + if (!r.isCancelled() && r.getException() == null) { + int jobRes = r.getData(); + + sum += jobRes; + } + } + + return sum; + } + + /** + * Simple compute job. + */ + private static class DemoComputeJob extends ComputeJobAdapter { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public Object execute() throws IgniteException { + try { + Thread.sleep(rnd.nextInt(50)); + } + catch (InterruptedException e) { + // Restore interrupt status + Thread.currentThread().interrupt(); + + throw new IgniteInterruptedException(e); + } + + return rnd.nextInt(10000); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(DemoComputeJob.class, this); + } + } +}
