Search in sources :

Example 11 with GridDeployment

use of org.apache.ignite.internal.managers.deployment.GridDeployment in project ignite by apache.

the class GridEventStorageManager method query.

/**
     * @param p Grid event predicate.
     * @param nodes Collection of nodes.
     * @param timeout Maximum time to wait for result, if {@code 0}, then wait until result is received.
     * @return Collection of events.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter", "deprecation" })
private <T extends Event> List<T> query(IgnitePredicate<T> p, Collection<? extends ClusterNode> nodes, long timeout) throws IgniteCheckedException {
    assert p != null;
    assert nodes != null;
    if (nodes.isEmpty()) {
        U.warn(log, "Failed to query events for empty nodes collection.");
        return Collections.emptyList();
    }
    GridIoManager ioMgr = ctx.io();
    final List<T> evts = new ArrayList<>();
    final AtomicReference<Throwable> err = new AtomicReference<>();
    final Set<UUID> uids = new HashSet<>();
    final Object qryMux = new Object();
    for (ClusterNode node : nodes) uids.add(node.id());
    GridLocalEventListener evtLsnr = new GridLocalEventListener() {

        @Override
        public void onEvent(Event evt) {
            assert evt instanceof DiscoveryEvent;
            synchronized (qryMux) {
                uids.remove(((DiscoveryEvent) evt).eventNode().id());
                if (uids.isEmpty())
                    qryMux.notifyAll();
            }
        }
    };
    GridMessageListener resLsnr = new GridMessageListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onMessage(UUID nodeId, Object msg) {
            assert nodeId != null;
            assert msg != null;
            if (!(msg instanceof GridEventStorageMessage)) {
                U.error(log, "Received unknown message: " + msg);
                return;
            }
            GridEventStorageMessage res = (GridEventStorageMessage) msg;
            try {
                if (res.eventsBytes() != null)
                    res.events(U.<Collection<Event>>unmarshal(marsh, res.eventsBytes(), U.resolveClassLoader(ctx.config())));
                if (res.exceptionBytes() != null)
                    res.exception(U.<Throwable>unmarshal(marsh, res.exceptionBytes(), U.resolveClassLoader(ctx.config())));
            } catch (IgniteCheckedException e) {
                U.error(log, "Failed to unmarshal events query response: " + msg, e);
                return;
            }
            synchronized (qryMux) {
                if (uids.remove(nodeId)) {
                    if (res.events() != null)
                        evts.addAll((Collection<T>) res.events());
                } else
                    U.warn(log, "Received duplicate response (ignoring) [nodeId=" + nodeId + ", msg=" + res + ']');
                if (res.exception() != null)
                    err.set(res.exception());
                if (uids.isEmpty() || err.get() != null)
                    qryMux.notifyAll();
            }
        }
    };
    Object resTopic = TOPIC_EVENT.topic(IgniteUuid.fromUuid(ctx.localNodeId()));
    try {
        addLocalEventListener(evtLsnr, new int[] { EVT_NODE_LEFT, EVT_NODE_FAILED });
        ioMgr.addMessageListener(resTopic, resLsnr);
        byte[] serFilter = U.marshal(marsh, p);
        GridDeployment dep = ctx.deploy().deploy(p.getClass(), U.detectClassLoader(p.getClass()));
        if (dep == null)
            throw new IgniteDeploymentCheckedException("Failed to deploy event filter: " + p);
        GridEventStorageMessage msg = new GridEventStorageMessage(resTopic, serFilter, p.getClass().getName(), dep.classLoaderId(), dep.deployMode(), dep.userVersion(), dep.participants());
        sendMessage(nodes, TOPIC_EVENT, msg, PUBLIC_POOL);
        if (timeout == 0)
            timeout = Long.MAX_VALUE;
        long now = U.currentTimeMillis();
        // Account for overflow of long value.
        long endTime = now + timeout <= 0 ? Long.MAX_VALUE : now + timeout;
        long delta = timeout;
        Collection<UUID> uidsCp = null;
        synchronized (qryMux) {
            try {
                while (!uids.isEmpty() && err.get() == null && delta > 0) {
                    qryMux.wait(delta);
                    delta = endTime - U.currentTimeMillis();
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IgniteCheckedException("Got interrupted while waiting for event query responses.", e);
            }
            if (err.get() != null)
                throw new IgniteCheckedException("Failed to query events due to exception on remote node.", err.get());
            if (!uids.isEmpty())
                uidsCp = new LinkedList<>(uids);
        }
        // Outside of synchronization.
        if (uidsCp != null) {
            for (Iterator<UUID> iter = uidsCp.iterator(); iter.hasNext(); ) // Ignore nodes that have left the grid.
            if (ctx.discovery().node(iter.next()) == null)
                iter.remove();
            if (!uidsCp.isEmpty())
                throw new IgniteCheckedException("Failed to receive event query response from following nodes: " + uidsCp);
        }
    } finally {
        ioMgr.removeMessageListener(resTopic, resLsnr);
        removeLocalEventListener(evtLsnr);
    }
    return evts;
}
Also used : GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) EVT_DISCOVERY_CUSTOM_EVT(org.apache.ignite.internal.events.DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) LT(org.apache.ignite.internal.util.typedef.internal.LT) TOPIC_EVENT(org.apache.ignite.internal.GridTopic.TOPIC_EVENT) UUID(java.util.UUID) GridConcurrentLinkedHashSet(org.apache.ignite.internal.util.GridConcurrentLinkedHashSet) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) LinkedList(java.util.LinkedList) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Collection(java.util.Collection)

Example 12 with GridDeployment

use of org.apache.ignite.internal.managers.deployment.GridDeployment in project ignite by apache.

the class IgniteComputeImpl method localDeployTask.

/** {@inheritDoc} */
@Override
public void localDeployTask(Class<? extends ComputeTask> taskCls, ClassLoader clsLdr) {
    A.notNull(taskCls, "taskCls", clsLdr, "clsLdr");
    guard();
    try {
        GridDeployment dep = ctx.deploy().deploy(taskCls, clsLdr);
        if (dep == null)
            throw new IgniteDeploymentException("Failed to deploy task (was task (re|un)deployed?): " + taskCls);
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    } finally {
        unguard();
    }
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException)

Example 13 with GridDeployment

use of org.apache.ignite.internal.managers.deployment.GridDeployment in project ignite by apache.

the class GridMessageListenHandler method p2pMarshal.

/** {@inheritDoc} */
@Override
public void p2pMarshal(GridKernalContext ctx) throws IgniteCheckedException {
    assert ctx != null;
    assert ctx.config().isPeerClassLoadingEnabled();
    if (topic != null)
        topicBytes = U.marshal(ctx.config().getMarshaller(), topic);
    predBytes = U.marshal(ctx.config().getMarshaller(), pred);
    // Deploy only listener, as it is very likely to be of some user class.
    GridPeerDeployAware pda = U.peerDeployAware(pred);
    clsName = pda.deployClass().getName();
    GridDeployment dep = ctx.deploy().deploy(pda.deployClass(), pda.classLoader());
    if (dep == null)
        throw new IgniteDeploymentCheckedException("Failed to deploy message listener.");
    depInfo = new GridDeploymentInfoBean(dep);
    depEnabled = true;
}
Also used : GridPeerDeployAware(org.apache.ignite.internal.util.lang.GridPeerDeployAware) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) GridDeploymentInfoBean(org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean)

Example 14 with GridDeployment

use of org.apache.ignite.internal.managers.deployment.GridDeployment in project ignite by apache.

the class GridEventConsumeHandler method p2pMarshal.

/** {@inheritDoc} */
@Override
public void p2pMarshal(GridKernalContext ctx) throws IgniteCheckedException {
    assert ctx != null;
    assert ctx.config().isPeerClassLoadingEnabled();
    if (filter != null) {
        Class cls = U.detectClass(filter);
        clsName = cls.getName();
        GridDeployment dep = ctx.deploy().deploy(cls, U.detectClassLoader(cls));
        if (dep == null)
            throw new IgniteDeploymentCheckedException("Failed to deploy event filter: " + filter);
        depInfo = new GridDeploymentInfoBean(dep);
        filterBytes = U.marshal(ctx.config().getMarshaller(), filter);
    }
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) GridDeploymentInfoBean(org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean)

Example 15 with GridDeployment

use of org.apache.ignite.internal.managers.deployment.GridDeployment in project ignite by apache.

the class GridCacheDeploymentManager method prepare.

/**
     * Prepares deployable object.
     *
     * @param deployable Deployable object.
     */
public void prepare(GridCacheDeployable deployable) {
    assert depEnabled;
    // Only set deployment info if it was not set automatically.
    if (deployable.deployInfo() == null) {
        GridDeploymentInfoBean dep = globalDeploymentInfo();
        if (dep == null) {
            GridDeployment locDep0 = locDep.get();
            if (locDep0 != null) {
                // Will copy sequence number to bean.
                dep = new GridDeploymentInfoBean(locDep0);
                dep.localDeploymentOwner(locDepOwner);
            }
        }
        if (dep != null)
            deployable.prepare(dep);
        if (log.isDebugEnabled())
            log.debug("Prepared grid cache deployable [dep=" + dep + ", deployable=" + deployable + ']');
    }
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) GridDeploymentInfoBean(org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean)

Aggregations

GridDeployment (org.apache.ignite.internal.managers.deployment.GridDeployment)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteDeploymentCheckedException (org.apache.ignite.internal.IgniteDeploymentCheckedException)7 UUID (java.util.UUID)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 GridDeploymentInfoBean (org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean)4 Collection (java.util.Collection)3 GridTaskSessionImpl (org.apache.ignite.internal.GridTaskSessionImpl)3 IgniteDeploymentException (org.apache.ignite.IgniteDeploymentException)2 GridPeerDeployAware (org.apache.ignite.internal.util.lang.GridPeerDeployAware)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteException (org.apache.ignite.IgniteException)1