Search in sources :

Example 1 with JobEvent

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

the class PlatformContextImpl method writeEvent.

/** {@inheritDoc} */
@Override
public void writeEvent(BinaryRawWriterEx writer, Event evt) {
    assert writer != null;
    if (evt == null) {
        writer.writeInt(-1);
        return;
    }
    EventAdapter evt0 = (EventAdapter) evt;
    if (evt0 instanceof CacheEvent) {
        writer.writeInt(2);
        writeCommonEventData(writer, evt0);
        CacheEvent event0 = (CacheEvent) evt0;
        writer.writeString(event0.cacheName());
        writer.writeInt(event0.partition());
        writer.writeBoolean(event0.isNear());
        writeNode(writer, event0.eventNode());
        writer.writeObject(event0.key());
        writer.writeObject(event0.xid());
        writer.writeObject(event0.newValue());
        writer.writeObject(event0.oldValue());
        writer.writeBoolean(event0.hasOldValue());
        writer.writeBoolean(event0.hasNewValue());
        writer.writeUuid(event0.subjectId());
        writer.writeString(event0.closureClassName());
        writer.writeString(event0.taskName());
    } else if (evt0 instanceof CacheQueryExecutedEvent) {
        writer.writeInt(3);
        writeCommonEventData(writer, evt0);
        CacheQueryExecutedEvent event0 = (CacheQueryExecutedEvent) evt0;
        writer.writeString(event0.queryType());
        writer.writeString(event0.cacheName());
        writer.writeString(event0.className());
        writer.writeString(event0.clause());
        writer.writeUuid(event0.subjectId());
        writer.writeString(event0.taskName());
    } else if (evt0 instanceof CacheQueryReadEvent) {
        writer.writeInt(4);
        writeCommonEventData(writer, evt0);
        CacheQueryReadEvent event0 = (CacheQueryReadEvent) evt0;
        writer.writeString(event0.queryType());
        writer.writeString(event0.cacheName());
        writer.writeString(event0.className());
        writer.writeString(event0.clause());
        writer.writeUuid(event0.subjectId());
        writer.writeString(event0.taskName());
        writer.writeObject(event0.key());
        writer.writeObject(event0.value());
        writer.writeObject(event0.oldValue());
        writer.writeObject(event0.row());
    } else if (evt0 instanceof CacheRebalancingEvent) {
        writer.writeInt(5);
        writeCommonEventData(writer, evt0);
        CacheRebalancingEvent event0 = (CacheRebalancingEvent) evt0;
        writer.writeString(event0.cacheName());
        writer.writeInt(event0.partition());
        writeNode(writer, event0.discoveryNode());
        writer.writeInt(event0.discoveryEventType());
        writer.writeString(event0.discoveryEventName());
        writer.writeLong(event0.discoveryTimestamp());
    } else if (evt0 instanceof CheckpointEvent) {
        writer.writeInt(6);
        writeCommonEventData(writer, evt0);
        CheckpointEvent event0 = (CheckpointEvent) evt0;
        writer.writeString(event0.key());
    } else if (evt0 instanceof DiscoveryEvent) {
        writer.writeInt(7);
        writeCommonEventData(writer, evt0);
        DiscoveryEvent event0 = (DiscoveryEvent) evt0;
        writeNode(writer, event0.eventNode());
        writer.writeLong(event0.topologyVersion());
        writeNodes(writer, event0.topologyNodes());
    } else if (evt0 instanceof JobEvent) {
        writer.writeInt(8);
        writeCommonEventData(writer, evt0);
        JobEvent event0 = (JobEvent) evt0;
        writer.writeString(event0.taskName());
        writer.writeString(event0.taskClassName());
        writer.writeObject(event0.taskSessionId());
        writer.writeObject(event0.jobId());
        writeNode(writer, event0.taskNode());
        writer.writeUuid(event0.taskSubjectId());
    } else if (evt0 instanceof TaskEvent) {
        writer.writeInt(10);
        writeCommonEventData(writer, evt0);
        TaskEvent event0 = (TaskEvent) evt0;
        writer.writeString(event0.taskName());
        writer.writeString(event0.taskClassName());
        writer.writeObject(event0.taskSessionId());
        writer.writeBoolean(event0.internal());
        writer.writeUuid(event0.subjectId());
    } else
        throw new IgniteException("Unsupported event: " + evt);
}
Also used : CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) JobEvent(org.apache.ignite.events.JobEvent) IgniteException(org.apache.ignite.IgniteException) CacheEvent(org.apache.ignite.events.CacheEvent) TaskEvent(org.apache.ignite.events.TaskEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CheckpointEvent(org.apache.ignite.events.CheckpointEvent) CacheRebalancingEvent(org.apache.ignite.events.CacheRebalancingEvent) EventAdapter(org.apache.ignite.events.EventAdapter) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent)

Example 2 with JobEvent

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

the class GridJobProcessor method handleException.

/**
     * Handles errors that happened prior to job creation.
     *
     * @param node Sender node.
     * @param req Job execution request.
     * @param ex Exception that happened.
     * @param endTime Job end time.
     */
private void handleException(ClusterNode node, GridJobExecuteRequest req, IgniteException ex, long endTime) {
    UUID locNodeId = ctx.localNodeId();
    ClusterNode sndNode = ctx.discovery().node(node.id());
    if (sndNode == null) {
        U.warn(log, "Failed to reply to sender node because it left grid [nodeId=" + node.id() + ", jobId=" + req.getJobId() + ']');
        if (ctx.event().isRecordable(EVT_JOB_FAILED)) {
            JobEvent evt = new JobEvent();
            evt.jobId(req.getJobId());
            evt.message("Job reply failed (original task node left grid): " + req.getJobId());
            evt.node(ctx.discovery().localNode());
            evt.taskName(req.getTaskName());
            evt.taskClassName(req.getTaskClassName());
            evt.taskSessionId(req.getSessionId());
            evt.type(EVT_JOB_FAILED);
            evt.taskNode(node);
            evt.taskSubjectId(req.getSubjectId());
            // Record job reply failure.
            ctx.event().record(evt);
        }
        return;
    }
    try {
        boolean loc = ctx.localNodeId().equals(sndNode.id()) && !ctx.config().isMarshalLocalJobs();
        GridJobExecuteResponse jobRes = new GridJobExecuteResponse(locNodeId, req.getSessionId(), req.getJobId(), loc ? null : U.marshal(marsh, ex), ex, loc ? null : U.marshal(marsh, null), null, loc ? null : U.marshal(marsh, null), null, false, null);
        if (req.isSessionFullSupport()) {
            // Send response to designated job topic.
            // Always go through communication to preserve order,
            // if attributes are enabled.
            // Job response topic.
            Object topic = TOPIC_TASK.topic(req.getJobId(), locNodeId);
            long timeout = endTime - U.currentTimeMillis();
            if (timeout <= 0)
                // Ignore the actual timeout and send response anyway.
                timeout = 1;
            // Send response to designated job topic.
            // Always go through communication to preserve order.
            ctx.io().sendOrderedMessage(sndNode, topic, jobRes, req.isInternal() ? MANAGEMENT_POOL : SYSTEM_POOL, timeout, false);
        } else if (ctx.localNodeId().equals(sndNode.id()))
            ctx.task().processJobExecuteResponse(ctx.localNodeId(), jobRes);
        else
            // Send response to common topic as unordered message.
            ctx.io().sendToGridTopic(sndNode, TOPIC_TASK, jobRes, req.isInternal() ? MANAGEMENT_POOL : SYSTEM_POOL);
    } catch (IgniteCheckedException e) {
        // The only option here is to log, as we must assume that resending will fail too.
        if (isDeadNode(node.id()))
            // Avoid stack trace for left nodes.
            U.error(log, "Failed to reply to sender node because it left grid [nodeId=" + node.id() + ", jobId=" + req.getJobId() + ']');
        else {
            assert sndNode != null;
            U.error(log, "Error sending reply for job [nodeId=" + sndNode.id() + ", jobId=" + req.getJobId() + ']', e);
        }
        if (ctx.event().isRecordable(EVT_JOB_FAILED)) {
            JobEvent evt = new JobEvent();
            evt.jobId(req.getJobId());
            evt.message("Failed to send reply for job: " + req.getJobId());
            evt.node(ctx.discovery().localNode());
            evt.taskName(req.getTaskName());
            evt.taskClassName(req.getTaskClassName());
            evt.taskSessionId(req.getSessionId());
            evt.type(EVT_JOB_FAILED);
            evt.taskNode(node);
            evt.taskSubjectId(req.getSubjectId());
            // Record job reply failure.
            ctx.event().record(evt);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) JobEvent(org.apache.ignite.events.JobEvent) GridJobExecuteResponse(org.apache.ignite.internal.GridJobExecuteResponse) UUID(java.util.UUID)

Example 3 with JobEvent

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

the class GridTaskWorker method recordJobEvent.

/**
     * @param evtType Event type.
     * @param jobId Job ID.
     * @param evtNode Event node.
     * @param msg Event message.
     */
private void recordJobEvent(int evtType, IgniteUuid jobId, ClusterNode evtNode, String msg) {
    if (!internal && ctx.event().isRecordable(evtType)) {
        JobEvent evt = new JobEvent();
        evt.message(msg);
        evt.node(ctx.discovery().localNode());
        evt.taskName(ses.getTaskName());
        evt.taskClassName(ses.getTaskClassName());
        evt.taskSessionId(ses.getId());
        evt.taskNode(evtNode);
        evt.jobId(jobId);
        evt.type(evtType);
        evt.taskSubjectId(ses.subjectId());
        ctx.event().record(evt);
    }
}
Also used : JobEvent(org.apache.ignite.events.JobEvent)

Example 4 with JobEvent

use of org.apache.ignite.events.JobEvent 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 5 with JobEvent

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

the class GridJobWorker method recordEvent.

/**
     * @param evtType Event type.
     * @param msg Message.
     */
private void recordEvent(int evtType, @Nullable String msg) {
    assert ctx.event().isRecordable(evtType);
    assert !internal;
    JobEvent evt = new JobEvent();
    evt.jobId(ses.getJobId());
    evt.message(msg);
    evt.node(ctx.discovery().localNode());
    evt.taskName(ses.getTaskName());
    evt.taskClassName(ses.getTaskClassName());
    evt.taskSessionId(ses.getId());
    evt.type(evtType);
    evt.taskNode(taskNode);
    evt.taskSubjectId(ses.subjectId());
    ctx.event().record(evt);
}
Also used : JobEvent(org.apache.ignite.events.JobEvent)

Aggregations

JobEvent (org.apache.ignite.events.JobEvent)7 TaskEvent (org.apache.ignite.events.TaskEvent)3 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 Event (org.apache.ignite.events.Event)2 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)2 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)2 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheEvent (org.apache.ignite.events.CacheEvent)1 CacheQueryExecutedEvent (org.apache.ignite.events.CacheQueryExecutedEvent)1 CacheQueryReadEvent (org.apache.ignite.events.CacheQueryReadEvent)1 CacheRebalancingEvent (org.apache.ignite.events.CacheRebalancingEvent)1 CheckpointEvent (org.apache.ignite.events.CheckpointEvent)1 EventAdapter (org.apache.ignite.events.EventAdapter)1 GridJobExecuteResponse (org.apache.ignite.internal.GridJobExecuteResponse)1