Search in sources :

Example 11 with TaskEvent

use of org.apache.ignite.events.TaskEvent in project ignite by apache.

the class GridTaskTimeoutSelfTest method checkTimedOutEvents.

/**
     * @param execId Execution ID.
     */
private void checkTimedOutEvents(final IgniteUuid execId) {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    Collection<Event> evts = ignite.events().localQuery(new PE() {

        @Override
        public boolean apply(Event evt) {
            return ((TaskEvent) evt).taskSessionId().equals(execId);
        }
    }, EVT_TASK_TIMEDOUT);
    assert evts.size() == 1 : "Invalid number of timed out tasks: " + evts.size();
}
Also used : PE(org.apache.ignite.internal.util.typedef.PE) TaskEvent(org.apache.ignite.events.TaskEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 12 with TaskEvent

use of org.apache.ignite.events.TaskEvent in project ignite by apache.

the class WeightedRandomLoadBalancingSpi method onContextInitialized0.

/** {@inheritDoc} */
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
    getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof TaskEvent || evt instanceof JobEvent;
            if (evt.type() == EVT_TASK_FINISHED || evt.type() == EVT_TASK_FAILED) {
                IgniteUuid sesId = ((TaskEvent) evt).taskSessionId();
                taskTops.remove(sesId);
                if (log.isDebugEnabled())
                    log.debug("Removed task topology from topology cache for session: " + sesId);
            } else // Here we set mapped property and later cache will be ignored
            if (evt.type() == EVT_JOB_MAPPED) {
                IgniteUuid sesId = ((JobEvent) evt).taskSessionId();
                IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(sesId);
                if (weightedTop != null)
                    weightedTop.set1(true);
                if (log.isDebugEnabled())
                    log.debug("Job has been mapped. Ignore cache for session: " + sesId);
            }
        }
    }, EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
}
Also used : JobEvent(org.apache.ignite.events.JobEvent) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) IgniteUuid(org.apache.ignite.lang.IgniteUuid) TaskEvent(org.apache.ignite.events.TaskEvent) JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event)

Example 13 with TaskEvent

use of org.apache.ignite.events.TaskEvent in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiMultipleNodesSelfTest method testMultipleTasks.

/**
     * @throws Exception If test failed.
     */
@SuppressWarnings({ "ObjectEquality" })
public void testMultipleTasks() throws Exception {
    ComputeTaskSession ses1 = new GridTestTaskSession(IgniteUuid.randomUuid());
    ComputeTaskSession ses2 = new GridTestTaskSession(IgniteUuid.randomUuid());
    List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    // Initialize.
    getSpi().getBalancedNode(ses1, allNodes, new GridTestJob());
    getSpi().getBalancedNode(ses2, allNodes, new GridTestJob());
    List<UUID> orderedNodes1 = getSpi().getNodeIds(ses1);
    List<UUID> orderedNodes2 = getSpi().getNodeIds(ses2);
    assert orderedNodes1 != orderedNodes2;
    // Check the round-robin actually did circle.
    for (int i = 0; i < allNodes.size(); i++) {
        ClusterNode node1 = getSpi().getBalancedNode(ses1, allNodes, new GridTestJob());
        assert orderedNodes1.get(i) == node1.id();
        ClusterNode node2 = getSpi().getBalancedNode(ses2, allNodes, new GridTestJob());
        assert orderedNodes2.get(i) == node2.id();
        assert orderedNodes1.get(i) == orderedNodes2.get(i);
    }
    // Double-check.
    for (int i = 0; i < allNodes.size(); i++) {
        ClusterNode node1 = getSpi().getBalancedNode(ses1, allNodes, new GridTestJob());
        assert orderedNodes1.get(i) == node1.id();
        ClusterNode node2 = getSpi().getBalancedNode(ses2, allNodes, new GridTestJob());
        assert orderedNodes2.get(i) == node2.id();
        assert orderedNodes1.get(i) == orderedNodes2.get(i);
    }
    getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FINISHED, ses1.getId(), null, null, false, null));
    getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FAILED, ses2.getId(), null, null, false, null));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) TaskEvent(org.apache.ignite.events.TaskEvent) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) GridTestJob(org.apache.ignite.GridTestJob) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 14 with TaskEvent

use of org.apache.ignite.events.TaskEvent in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiNotPerTaskSelfTest method testMultipleTaskSessions.

/**
     * @throws Exception If test failed.
     */
public void testMultipleTaskSessions() throws Exception {
    ComputeTaskSession ses1 = new GridTestTaskSession(IgniteUuid.randomUuid());
    ComputeTaskSession ses2 = new GridTestTaskSession(IgniteUuid.randomUuid());
    List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    List<UUID> orderedNodes = getSpi().getNodeIds(ses1);
    assertEquals("Balancer doesn't use all available nodes", orderedNodes.size(), allNodes.size());
    checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses1, ses2);
    getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FINISHED, ses1.getId(), null, null, false, null));
    getSpiContext().triggerEvent(new TaskEvent(null, null, EVT_TASK_FAILED, ses2.getId(), null, null, false, null));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) TaskEvent(org.apache.ignite.events.TaskEvent) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 15 with TaskEvent

use of org.apache.ignite.events.TaskEvent in project ignite by apache.

the class TaskEventSubjectIdSelfTest method testClosure.

/**
     * @throws Exception If failed.
     */
public void testClosure() throws Exception {
    latch = new CountDownLatch(3);
    grid().compute().run(new IgniteRunnable() {

        @Override
        public void run() {
        // No-op.
        }
    });
    assert latch.await(1000, MILLISECONDS);
    assertEquals(3, evts.size());
    Iterator<TaskEvent> it = evts.iterator();
    assert it.hasNext();
    TaskEvent evt = it.next();
    assert evt != null;
    assertEquals(EVT_TASK_STARTED, evt.type());
    assertEquals(nodeId, evt.subjectId());
    assert it.hasNext();
    evt = it.next();
    assert evt != null;
    assertEquals(EVT_TASK_REDUCED, evt.type());
    assertEquals(nodeId, evt.subjectId());
    assert it.hasNext();
    evt = it.next();
    assert evt != null;
    assertEquals(EVT_TASK_FINISHED, evt.type());
    assertEquals(nodeId, evt.subjectId());
    assert !it.hasNext();
}
Also used : TaskEvent(org.apache.ignite.events.TaskEvent) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Aggregations

TaskEvent (org.apache.ignite.events.TaskEvent)19 Event (org.apache.ignite.events.Event)7 UUID (java.util.UUID)6 Ignite (org.apache.ignite.Ignite)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 IgniteException (org.apache.ignite.IgniteException)5 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)5 JobEvent (org.apache.ignite.events.JobEvent)5 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)4 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)4 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)3 TaskSessionResource (org.apache.ignite.resources.TaskSessionResource)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)2 Ignition (org.apache.ignite.Ignition)2 ComputeTaskTimeoutException (org.apache.ignite.compute.ComputeTaskTimeoutException)2