How to create a compute tasks which uses Cache and transaction?

classic Classic list List threaded Threaded
7 messages Options
khurram khurram
Reply | Threaded
Open this post in threaded view
|

How to create a compute tasks which uses Cache and transaction?

Hi,

We have some persistence caches back with Cassandra and we can use the rest API to put and get and other small operations. Our client is written in Go.
Now we want to perform some transactions via task which we can call using Rest API. But we couldn't find any example in which task is accessing cache and performing the transaction. Also, all task examples start a new server. Is there any example where task classes are put into URL specified for deployment and these tasks use cache and transactions.

Thanks
dkarachentsev dkarachentsev
Reply | Threaded
Open this post in threaded view
|

Re: How to create a compute tasks which uses Cache and transaction?

Hi,

First of all, Java task class should be available on server, then you'll be able to run the task using it's class name [1].
In that task you may access cache with transaction using standard Ignite Java API [2].

You need start server only once, and then invoke task as many times as you want.

[1] https://apacheignite.readme.io/v1.8/docs/rest-api#execute
[2] https://apacheignite.readme.io/v1.8/docs/transactions

Thanks!
-Dmitry.
khurram khurram
Reply | Threaded
Open this post in threaded view
|

Re: How to create a compute tasks which uses Cache and transaction?

Hi,

Can you share some sample class for this? There's no such sample in examples.


Thanks and regards,
Khurram Baig
dmagda dmagda
Reply | Threaded
Open this post in threaded view
|

Re: How to create a compute tasks which uses Cache and transaction?

Hello Khurram,

I don’t have such a sample at hands but basically all you need to do is the following:
* mark you Java task implementation (IgniteCallable, IgniteRunnable or ComputeTask) using @ComputeTaskName annotation.
* create a JAR file that will contain the task class and add the jar to the server nodes classpath. Put it under {ignite_release}/libs folder if you use ignite.sh file to start a node.
* use the REST API shared by Dmtriy to trigger the task.


Denis

> On Jun 5, 2017, at 3:45 AM, khurram <[hidden email]> wrote:
>
> Hi,
>
> Can you share some sample class for this? There's no such sample in
> examples.
>
>
> Thanks and regards,
> Khurram Baig
>
>
>
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-create-a-compute-tasks-which-uses-Cache-and-transaction-tp13339p13365.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.

khurram khurram
Reply | Threaded
Open this post in threaded view
|

Re: How to create a compute tasks which uses Cache and transaction?

Hi,

I tried to run following class as tasks and it's saying no tasks found.

package load;
import org.apache.ignite.lang.IgniteRunnable;
import org.apache.ignite.compute.ComputeTaskName;


@ComputeTaskName("Transaction")
class Transaction implements IgniteRunnable {

    @Override
    public void run() {
        System.out.println("Hello World");
    }
}

What's the problem in above sample? Also how to pass arguments in class? Using constructor?

Thanks and regards,
Khurram Baig
Denis Magda Denis Magda
Reply | Threaded
Open this post in threaded view
|

Re: How to create a compute tasks which uses Cache and transaction?

Sure, use a constructor.
marble.zhong@coinflex.com marble.zhong@coinflex.com
Reply | Threaded
Open this post in threaded view
|

Re: How to create a compute tasks which uses Cache and transaction?

In reply to this post by dmagda
Hi Denis,

"use the REST API shared by Dmtriy to trigger the task."

How to do that? can you share more details, now I have the task deployed to
the ./libs, but don't know how to trigger, or ignite will help auto trigger,
as task already describe in the META-INF/ignite.xml?

And btw, does it must the task implement the computeTask, is it ok also
implement the ComputeTaskSplitAdapter or ComputeTaskAdapter?

thanks.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/