Search in sources :

Example 1 with IgniteDeploymentCheckedException

use of org.apache.ignite.internal.IgniteDeploymentCheckedException in project ignite by apache.

the class GridDeploymentLocalStore method explicitDeploy.

/** {@inheritDoc} */
@Nullable
@Override
public GridDeployment explicitDeploy(Class<?> cls, ClassLoader clsLdr) throws IgniteCheckedException {
    try {
        // if local one exists.
        if (clsLdr.getClass().equals(GridDeploymentClassLoader.class))
            clsLdr = clsLdr.getParent();
        spi.register(clsLdr, cls);
        GridDeployment dep = deployment(cls.getName());
        if (dep == null) {
            DeploymentResource rsrc = spi.findResource(cls.getName());
            if (rsrc != null && rsrc.getClassLoader() == clsLdr)
                dep = deploy(ctx.config().getDeploymentMode(), rsrc.getClassLoader(), rsrc.getResourceClass(), rsrc.getName(), true);
        }
        return dep;
    } catch (IgniteSpiException e) {
        recordDeployFailed(cls, clsLdr, true);
        // Avoid double wrapping.
        if (e.getCause() instanceof IgniteCheckedException)
            throw (IgniteCheckedException) e.getCause();
        throw new IgniteDeploymentCheckedException("Failed to deploy class: " + cls.getName(), e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) DeploymentResource(org.apache.ignite.spi.deployment.DeploymentResource) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IgniteDeploymentCheckedException

use of org.apache.ignite.internal.IgniteDeploymentCheckedException in project ignite by apache.

the class GridIoManager method sendUserMessage.

/**
     * Sends a peer deployable user message.
     *
     * @param nodes Destination nodes.
     * @param msg Message to send.
     * @param topic Message topic to use.
     * @param ordered Is message ordered?
     * @param timeout Message timeout in milliseconds for ordered messages.
     * @param async Async flag.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
@SuppressWarnings("ConstantConditions")
public void sendUserMessage(Collection<? extends ClusterNode> nodes, Object msg, @Nullable Object topic, boolean ordered, long timeout, boolean async) throws IgniteCheckedException {
    boolean loc = nodes.size() == 1 && F.first(nodes).id().equals(locNodeId);
    byte[] serMsg = null;
    byte[] serTopic = null;
    if (!loc) {
        serMsg = U.marshal(marsh, msg);
        if (topic != null)
            serTopic = U.marshal(marsh, topic);
    }
    GridDeployment dep = null;
    String depClsName = null;
    if (ctx.config().isPeerClassLoadingEnabled()) {
        Class<?> cls0 = U.detectClass(msg);
        if (U.isJdk(cls0) && topic != null)
            cls0 = U.detectClass(topic);
        dep = ctx.deploy().deploy(cls0, U.detectClassLoader(cls0));
        if (dep == null)
            throw new IgniteDeploymentCheckedException("Failed to deploy user message: " + msg);
        depClsName = cls0.getName();
    }
    Message ioMsg = new GridIoUserMessage(msg, serMsg, depClsName, topic, serTopic, dep != null ? dep.classLoaderId() : null, dep != null ? dep.deployMode() : null, dep != null ? dep.userVersion() : null, dep != null ? dep.participants() : null);
    if (ordered)
        sendOrderedMessageToGridTopic(nodes, TOPIC_COMM_USER, ioMsg, PUBLIC_POOL, timeout, true);
    else if (loc) {
        send(F.first(nodes), TOPIC_COMM_USER, TOPIC_COMM_USER.ordinal(), ioMsg, PUBLIC_POOL, false, 0, false, null, async);
    } else {
        ClusterNode locNode = F.find(nodes, null, F.localNode(locNodeId));
        Collection<? extends ClusterNode> rmtNodes = F.view(nodes, F.remoteNodes(locNodeId));
        if (!rmtNodes.isEmpty())
            sendToGridTopic(rmtNodes, TOPIC_COMM_USER, ioMsg, PUBLIC_POOL);
        // to allow remote nodes execute the requested operation in parallel.
        if (locNode != null) {
            send(locNode, TOPIC_COMM_USER, TOPIC_COMM_USER.ordinal(), ioMsg, PUBLIC_POOL, false, 0, false, null, async);
        }
    }
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) ClusterNode(org.apache.ignite.cluster.ClusterNode) Message(org.apache.ignite.plugin.extensions.communication.Message) GridNioBackPressureControl.threadProcessingMessage(org.apache.ignite.internal.util.nio.GridNioBackPressureControl.threadProcessingMessage) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException) Collection(java.util.Collection)

Example 3 with IgniteDeploymentCheckedException

use of org.apache.ignite.internal.IgniteDeploymentCheckedException in project ignite by apache.

the class GridAffinityUtils method unmarshall.

/**
     * Unmarshalls transfer object from remote node within a given context.
     *
     * @param ctx Grid kernal context that provides deployment and marshalling services.
     * @param sndNodeId {@link UUID} of the sender node.
     * @param msg Transfer object that contains original serialized object and deployment information.
     * @return Unmarshalled object.
     * @throws IgniteCheckedException If node cannot obtain deployment.
     */
static Object unmarshall(GridKernalContext ctx, UUID sndNodeId, GridAffinityMessage msg) throws IgniteCheckedException {
    GridDeployment dep = ctx.deploy().getGlobalDeployment(msg.deploymentMode(), msg.sourceClassName(), msg.sourceClassName(), msg.userVersion(), sndNodeId, msg.classLoaderId(), msg.loaderParticipants(), null);
    if (dep == null)
        throw new IgniteDeploymentCheckedException("Failed to obtain affinity object (is peer class loading turned on?): " + msg);
    Object src = U.unmarshal(ctx, msg.source(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
    // Resource injection.
    ctx.resource().inject(dep, dep.deployedClass(msg.sourceClassName()), src);
    return src;
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException)

Example 4 with IgniteDeploymentCheckedException

use of org.apache.ignite.internal.IgniteDeploymentCheckedException in project ignite by apache.

the class GridAffinityUtils method affinityMessage.

/**
     * @param ctx  {@code GridKernalContext} instance which provides deployment manager
     * @param o Object for which deployment should be obtained.
     * @return Deployment object for given instance,
     * @throws IgniteCheckedException If node cannot create deployment for given object.
     */
private static GridAffinityMessage affinityMessage(GridKernalContext ctx, Object o) throws IgniteCheckedException {
    Class cls = o.getClass();
    GridDeployment dep = ctx.deploy().deploy(cls, cls.getClassLoader());
    if (dep == null)
        throw new IgniteDeploymentCheckedException("Failed to deploy affinity object with class: " + cls.getName());
    return new GridAffinityMessage(U.marshal(ctx, o), cls.getName(), dep.classLoaderId(), dep.deployMode(), dep.userVersion(), dep.participants());
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteDeploymentCheckedException(org.apache.ignite.internal.IgniteDeploymentCheckedException)

Example 5 with IgniteDeploymentCheckedException

use of org.apache.ignite.internal.IgniteDeploymentCheckedException 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)

Aggregations

IgniteDeploymentCheckedException (org.apache.ignite.internal.IgniteDeploymentCheckedException)8 GridDeployment (org.apache.ignite.internal.managers.deployment.GridDeployment)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 UUID (java.util.UUID)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 Collection (java.util.Collection)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ComputeExecutionRejectedException (org.apache.ignite.compute.ComputeExecutionRejectedException)1 ComputeTask (org.apache.ignite.compute.ComputeTask)1 ComputeTaskMapAsync (org.apache.ignite.compute.ComputeTaskMapAsync)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 Event (org.apache.ignite.events.Event)1 EVT_NODE_LEFT (org.apache.ignite.events.EventType.EVT_NODE_LEFT)1 ComputeTaskInternalFuture (org.apache.ignite.internal.ComputeTaskInternalFuture)1 GridMessageListenHandler (org.apache.ignite.internal.GridMessageListenHandler)1 GridTaskSessionImpl (org.apache.ignite.internal.GridTaskSessionImpl)1