use of org.apache.ignite.events.TaskEvent in project ignite by apache.
the class VisorManagementEventSelfTest method doTestNotManagementVisorTask.
/**
* @param cls class of the task.
* @param arg argument.
* @param ignite instance of Ignite.
*
* @throws Exception If failed.
*/
private <T, R> void doTestNotManagementVisorTask(Class<? extends ComputeTask<VisorTaskArgument<T>, R>> cls, T arg, IgniteEx ignite) throws Exception {
final AtomicReference<TaskEvent> evt = new AtomicReference<>();
final CountDownLatch evtLatch = new CountDownLatch(1);
ignite.events().localListen(new IgnitePredicate<TaskEvent>() {
@Override
public boolean apply(TaskEvent e) {
evt.set(e);
evtLatch.countDown();
return false;
}
}, EventType.EVT_MANAGEMENT_TASK_STARTED);
for (ClusterNode node : ignite.cluster().forServers().nodes()) ignite.compute().executeAsync(cls, new VisorTaskArgument<>(node.id(), arg, true));
assertFalse(evtLatch.await(10000, TimeUnit.MILLISECONDS));
}
use of org.apache.ignite.events.TaskEvent in project ignite by apache.
the class VisorManagementEventSelfTest method doTestVisorTask.
/**
* @param cls class of the task.
* @param arg argument.
* @param ignite instance of Ignite.
*
* @throws Exception If failed.
*/
private <T, R> void doTestVisorTask(Class<? extends ComputeTask<VisorTaskArgument<T>, R>> cls, T arg, IgniteEx ignite) throws Exception {
final AtomicReference<TaskEvent> evt = new AtomicReference<>();
final CountDownLatch evtLatch = new CountDownLatch(1);
ignite.events().localListen(new IgnitePredicate<TaskEvent>() {
@Override
public boolean apply(TaskEvent e) {
evt.set(e);
evtLatch.countDown();
return false;
}
}, EventType.EVT_MANAGEMENT_TASK_STARTED);
for (ClusterNode node : ignite.cluster().forServers().nodes()) ignite.compute().executeAsync(cls, new VisorTaskArgument<>(node.id(), arg, true));
assertTrue(evtLatch.await(10000, TimeUnit.MILLISECONDS));
assertNotNull(evt.get());
}
use of org.apache.ignite.events.TaskEvent in project ignite by apache.
the class AdaptiveLoadBalancingSpi method onContextInitialized0.
/**
* {@inheritDoc}
*/
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
getSpiContext().addLocalEventListener(evtLsnr = new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
switch(evt.type()) {
case EVT_TASK_FINISHED:
case EVT_TASK_FAILED:
{
TaskEvent taskEvt = (TaskEvent) evt;
taskTops.remove(taskEvt.taskSessionId());
if (log.isDebugEnabled())
log.debug("Removed task topology from topology cache for session: " + taskEvt.taskSessionId());
break;
}
case EVT_JOB_MAPPED:
{
// We should keep topology and use cache in ComputeTask#map() method to
// avoid O(n*n/2) complexity, after that we can drop caches.
// Here we set mapped property and later cache will be ignored
JobEvent jobEvt = (JobEvent) evt;
IgniteBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(jobEvt.taskSessionId());
if (weightedTop != null)
weightedTop.set1(true);
if (log.isDebugEnabled())
log.debug("Job has been mapped. Ignore cache for session: " + jobEvt.taskSessionId());
break;
}
case EVT_NODE_METRICS_UPDATED:
case EVT_NODE_FAILED:
case EVT_NODE_JOINED:
case EVT_NODE_LEFT:
{
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
rwLock.writeLock().lock();
try {
switch(evt.type()) {
case EVT_NODE_JOINED:
{
nodeJobs.put(discoEvt.eventNode().id(), new AtomicInteger(0));
break;
}
case EVT_NODE_LEFT:
case EVT_NODE_FAILED:
{
nodeJobs.remove(discoEvt.eventNode().id());
break;
}
case EVT_NODE_METRICS_UPDATED:
{
// Reset counter.
nodeJobs.put(discoEvt.eventNode().id(), new AtomicInteger(0));
break;
}
}
} finally {
rwLock.writeLock().unlock();
}
}
}
}
}, EVT_NODE_METRICS_UPDATED, EVT_NODE_FAILED, EVT_NODE_JOINED, EVT_NODE_LEFT, EVT_TASK_FINISHED, EVT_TASK_FAILED, EVT_JOB_MAPPED);
// Put all known nodes.
rwLock.writeLock().lock();
try {
for (ClusterNode node : getSpiContext().nodes()) nodeJobs.put(node.id(), new AtomicInteger(0));
} finally {
rwLock.writeLock().unlock();
}
}
Aggregations