You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Vadim Dedkov <de...@gmail.com> on 2017/05/29 10:02:28 UTC

How to return ID of Ignite task to stop this task in the future?

I want to broadcast some Apache Ignite task for some entity with ID stored
in DB of my app. At some moment I want to stop this task (may be even after
restart of my app). For this I think that I need to broadcast this task,
somehow return UUID of this task, save this task UUID near entity ID in DB
of my app. For example, if I know this task UUID (taskUuid), then I can
stop this task like this (scala code):

val clusterGroup = ignite$.cluster().forServers()
ignite$.compute(clusterGroup).broadcast(new IgniteRunnable {
  override def run(): Unit = {
    ignite$.compute().activeTaskFutures().asScala.filter(
      e => e._1.toString == taskUuid).foreach(e => e._2.cancel())
  }
})

So, my question is, how I can return this taskUuid, when I submit some task
with IgniteCompute.broadcast(...) method?

-- 
_______________             _______________
Best regards,                    С уважением
Vadim Dedkov.                  Вадим Дедков.

Re: How to return ID of Ignite task to stop this task in the future?

Posted by Vladimir Ozerov <vo...@gridgain.com>.
Yakov,

q.1 is answered in separate dev-list topic "IgniteCompute async methods do
not return ComputeTaskFuture".

On Tue, May 30, 2017 at 12:57 PM, Yakov Zhdanov <yz...@apache.org> wrote:

> Couple of questions to Igniters (cross-posting to dev list).
>
> 1. Why IgniteCompute does not return ComputeTaskFuture from all methods?
>
> 2. In GridGain 6.x and earlier there was a method
> GridComputeImpl#cancelTask(GridUuid sesId) - https://github.com/gridgain/
> gridgain/blob/cf56a35cbae442d11181f58004505d6b00fc2f59/modules/core/src/
> main/java/org/gridgain/grid/kernal/GridComputeImpl.java, but I cannot
> find it in Ignite. Who does know anything on this?
>
> Vadim, it seems that you have 2 options now:
> 1. You can get future from IgniteCompute#broadcastAsync() and call
> Future#cancel() - this works if you do not restart client and cancel your
> task from its master node.
> 2. If you want to restart client node and then somehow manage the spawned
> tasks (broadcast() is still a task deep inside Ignite) then first of all
> you need to implement org.apache.ignite.compute.ComputeJobMasterLeaveAware
> on your Runnables so they do not get automatically cancelled on master
> leave. Second, I think you will have to use distributed cache and put some
> job related data to it and periodically poll that cache for changes from
> your jobs and support job's automatic exit if its data changes accordingly.
> Then you can iterate over cache entry set and cancel jobs you want by
> changing their data.
>
> --Yakov
>

Re: How to return ID of Ignite task to stop this task in the future?

Posted by Vladimir Ozerov <vo...@gridgain.com>.
Yakov,

q.1 is answered in separate dev-list topic "IgniteCompute async methods do
not return ComputeTaskFuture".

On Tue, May 30, 2017 at 12:57 PM, Yakov Zhdanov <yz...@apache.org> wrote:

> Couple of questions to Igniters (cross-posting to dev list).
>
> 1. Why IgniteCompute does not return ComputeTaskFuture from all methods?
>
> 2. In GridGain 6.x and earlier there was a method
> GridComputeImpl#cancelTask(GridUuid sesId) - https://github.com/gridgain/
> gridgain/blob/cf56a35cbae442d11181f58004505d6b00fc2f59/modules/core/src/
> main/java/org/gridgain/grid/kernal/GridComputeImpl.java, but I cannot
> find it in Ignite. Who does know anything on this?
>
> Vadim, it seems that you have 2 options now:
> 1. You can get future from IgniteCompute#broadcastAsync() and call
> Future#cancel() - this works if you do not restart client and cancel your
> task from its master node.
> 2. If you want to restart client node and then somehow manage the spawned
> tasks (broadcast() is still a task deep inside Ignite) then first of all
> you need to implement org.apache.ignite.compute.ComputeJobMasterLeaveAware
> on your Runnables so they do not get automatically cancelled on master
> leave. Second, I think you will have to use distributed cache and put some
> job related data to it and periodically poll that cache for changes from
> your jobs and support job's automatic exit if its data changes accordingly.
> Then you can iterate over cache entry set and cancel jobs you want by
> changing their data.
>
> --Yakov
>

Re: How to return ID of Ignite task to stop this task in the future?

Posted by Yakov Zhdanov <yz...@apache.org>.
Couple of questions to Igniters (cross-posting to dev list).

1. Why IgniteCompute does not return ComputeTaskFuture from all methods?

2. In GridGain 6.x and earlier there was a method
GridComputeImpl#cancelTask(GridUuid sesId) -
https://github.com/gridgain/gridgain/blob/cf56a35cbae442d11181f58004505d6b00fc2f59/modules/core/src/main/java/org/gridgain/grid/kernal/GridComputeImpl.java,
but I cannot find it in Ignite. Who does know anything on this?

Vadim, it seems that you have 2 options now:
1. You can get future from IgniteCompute#broadcastAsync() and call
Future#cancel() - this works if you do not restart client and cancel your
task from its master node.
2. If you want to restart client node and then somehow manage the spawned
tasks (broadcast() is still a task deep inside Ignite) then first of all
you need to implement org.apache.ignite.compute.ComputeJobMasterLeaveAware
on your Runnables so they do not get automatically cancelled on master
leave. Second, I think you will have to use distributed cache and put some
job related data to it and periodically poll that cache for changes from
your jobs and support job's automatic exit if its data changes accordingly.
Then you can iterate over cache entry set and cancel jobs you want by
changing their data.

--Yakov

Re: How to return ID of Ignite task to stop this task in the future?

Posted by Yakov Zhdanov <yz...@apache.org>.
Couple of questions to Igniters (cross-posting to dev list).

1. Why IgniteCompute does not return ComputeTaskFuture from all methods?

2. In GridGain 6.x and earlier there was a method
GridComputeImpl#cancelTask(GridUuid sesId) -
https://github.com/gridgain/gridgain/blob/cf56a35cbae442d11181f58004505d6b00fc2f59/modules/core/src/main/java/org/gridgain/grid/kernal/GridComputeImpl.java,
but I cannot find it in Ignite. Who does know anything on this?

Vadim, it seems that you have 2 options now:
1. You can get future from IgniteCompute#broadcastAsync() and call
Future#cancel() - this works if you do not restart client and cancel your
task from its master node.
2. If you want to restart client node and then somehow manage the spawned
tasks (broadcast() is still a task deep inside Ignite) then first of all
you need to implement org.apache.ignite.compute.ComputeJobMasterLeaveAware
on your Runnables so they do not get automatically cancelled on master
leave. Second, I think you will have to use distributed cache and put some
job related data to it and periodically poll that cache for changes from
your jobs and support job's automatic exit if its data changes accordingly.
Then you can iterate over cache entry set and cancel jobs you want by
changing their data.

--Yakov

Re: How to return ID of Ignite task to stop this task in the future?

Posted by Vadim Dedkov <de...@gmail.com>.
I don't think that it is solution. I posted my comment there as well.

2017-05-29 15:20 GMT+03:00 Evgenii Zhuravlev <e....@gmail.com>:

> Hi,
>
> question was answered here: https://stackoverflow.com/
> questions/44239558/how-to-return-id-of-ignite-task-to-
> stop-this-task-in-the-future/44242152#44242152
>
> 2017-05-29 13:02 GMT+03:00 Vadim Dedkov <de...@gmail.com>:
>
>> I want to broadcast some Apache Ignite task for some entity with ID
>> stored in DB of my app. At some moment I want to stop this task (may be
>> even after restart of my app). For this I think that I need to broadcast this
>> task, somehow return UUID of this task, save this task UUID near entity
>> ID in DB of my app. For example, if I know this task UUID (taskUuid),
>> then I can stop this task like this (scala code):
>>
>> val clusterGroup = ignite$.cluster().forServers()
>> ignite$.compute(clusterGroup).broadcast(new IgniteRunnable {
>>   override def run(): Unit = {
>>     ignite$.compute().activeTaskFutures().asScala.filter(
>>       e => e._1.toString == taskUuid).foreach(e => e._2.cancel())
>>   }
>> })
>>
>> So, my question is, how I can return this taskUuid, when I submit some
>> task with IgniteCompute.broadcast(...) method?
>>
>> --
>> _______________             _______________
>> Best regards,                    С уважением
>> Vadim Dedkov.                  Вадим Дедков.
>>
>
>


-- 
_______________             _______________
Best regards,                    С уважением
Vadim Dedkov.                  Вадим Дедков.

Re: How to return ID of Ignite task to stop this task in the future?

Posted by Evgenii Zhuravlev <e....@gmail.com>.
Hi,

question was answered here:
https://stackoverflow.com/questions/44239558/how-to-return-id-of-ignite-task-to-stop-this-task-in-the-future/44242152#44242152

2017-05-29 13:02 GMT+03:00 Vadim Dedkov <de...@gmail.com>:

> I want to broadcast some Apache Ignite task for some entity with ID
> stored in DB of my app. At some moment I want to stop this task (may be
> even after restart of my app). For this I think that I need to broadcast this
> task, somehow return UUID of this task, save this task UUID near entity
> ID in DB of my app. For example, if I know this task UUID (taskUuid),
> then I can stop this task like this (scala code):
>
> val clusterGroup = ignite$.cluster().forServers()
> ignite$.compute(clusterGroup).broadcast(new IgniteRunnable {
>   override def run(): Unit = {
>     ignite$.compute().activeTaskFutures().asScala.filter(
>       e => e._1.toString == taskUuid).foreach(e => e._2.cancel())
>   }
> })
>
> So, my question is, how I can return this taskUuid, when I submit some
> task with IgniteCompute.broadcast(...) method?
>
> --
> _______________             _______________
> Best regards,                    С уважением
> Vadim Dedkov.                  Вадим Дедков.
>