Search in sources :

Example 6 with GridDeployment

use of org.apache.ignite.internal.managers.deployment.GridDeployment 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 7 with GridDeployment

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

the class GridCacheDeploymentManager method registerClass.

/**
     * @param cls Class to register.
     * @param ldr Class loader.
     * @throws IgniteCheckedException If registration failed.
     */
public void registerClass(Class<?> cls, ClassLoader ldr) throws IgniteCheckedException {
    assert cctx.deploymentEnabled();
    if (cls == null || GridCacheInternal.class.isAssignableFrom(cls))
        return;
    if (ldr == null)
        ldr = U.detectClassLoader(cls);
    // Don't register remote class loaders.
    if (U.p2pLoader(ldr))
        return;
    GridDeployment dep = locDep.get();
    if (dep == null || (!ldr.equals(dep.classLoader()) && !U.hasParent(ldr, dep.classLoader()))) {
        while (true) {
            dep = locDep.get();
            // Don't register remote class loaders.
            if (dep != null && !dep.local())
                return;
            if (dep != null) {
                ClassLoader curLdr = dep.classLoader();
                if (curLdr.equals(ldr))
                    break;
                // then we don't check it, as new loader is most likely wider.
                if (!curLdr.equals(U.gridClassLoader()) && dep.deployedClass(cls.getName()) != null)
                    // to look for another class loader.
                    break;
            }
            GridDeployment newDep = cctx.gridDeploy().deploy(cls, ldr);
            if (newDep != null) {
                if (dep != null) {
                    // Check new deployment.
                    if (newDep.deployedClass(dep.sampleClassName()) != null) {
                        if (locDep.compareAndSet(dep, newDep))
                            // While loop.
                            break;
                    } else
                        throw new IgniteCheckedException("Encountered incompatible class loaders for cache " + "[class1=" + cls.getName() + ", class2=" + dep.sampleClassName() + ']');
                } else if (locDep.compareAndSet(null, newDep))
                    // While loop.
                    break;
            } else
                throw new IgniteCheckedException("Failed to deploy class for local deployment [clsName=" + cls.getName() + ", ldr=" + ldr + ']');
        }
    }
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 8 with GridDeployment

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

the class DataStreamProcessor method processRequest.

/**
     * @param nodeId Sender ID.
     * @param req Request.
     */
private void processRequest(final UUID nodeId, final DataStreamerRequest req) {
    if (!busyLock.enterBusy()) {
        if (log.isDebugEnabled())
            log.debug("Ignoring data load request (node is stopping): " + req);
        return;
    }
    try {
        if (log.isDebugEnabled())
            log.debug("Processing data load request: " + req);
        AffinityTopologyVersion locAffVer = ctx.cache().context().exchange().readyAffinityVersion();
        AffinityTopologyVersion rmtAffVer = req.topologyVersion();
        if (locAffVer.compareTo(rmtAffVer) < 0) {
            if (log.isDebugEnabled())
                log.debug("Received request has higher affinity topology version [request=" + req + ", locTopVer=" + locAffVer + ", rmtTopVer=" + rmtAffVer + ']');
            IgniteInternalFuture<?> fut = ctx.cache().context().exchange().affinityReadyFuture(rmtAffVer);
            if (fut != null && !fut.isDone()) {
                final byte plc = threadIoPolicy();
                fut.listen(new CI1<IgniteInternalFuture<?>>() {

                    @Override
                    public void apply(IgniteInternalFuture<?> t) {
                        ctx.closure().runLocalSafe(new Runnable() {

                            @Override
                            public void run() {
                                processRequest(nodeId, req);
                            }
                        }, plc);
                    }
                });
                return;
            }
        }
        Object topic;
        try {
            topic = U.unmarshal(marsh, req.responseTopicBytes(), U.resolveClassLoader(null, ctx.config()));
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to unmarshal topic from request: " + req, e);
            return;
        }
        ClassLoader clsLdr;
        if (req.forceLocalDeployment())
            clsLdr = U.gridClassLoader();
        else {
            GridDeployment dep = ctx.deploy().getGlobalDeployment(req.deploymentMode(), req.sampleClassName(), req.sampleClassName(), req.userVersion(), nodeId, req.classLoaderId(), req.participants(), null);
            if (dep == null) {
                sendResponse(nodeId, topic, req.requestId(), new IgniteCheckedException("Failed to get deployment for request [sndId=" + nodeId + ", req=" + req + ']'), false);
                return;
            }
            clsLdr = dep.classLoader();
        }
        StreamReceiver<K, V> updater;
        try {
            updater = U.unmarshal(marsh, req.updaterBytes(), U.resolveClassLoader(clsLdr, ctx.config()));
            if (updater != null)
                ctx.resource().injectGeneric(updater);
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to unmarshal message [nodeId=" + nodeId + ", req=" + req + ']', e);
            sendResponse(nodeId, topic, req.requestId(), e, false);
            return;
        }
        localUpdate(nodeId, req, updater, topic);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException)

Example 9 with GridDeployment

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

the class GridJobProcessor method processJobExecuteRequest.

/**
     * @param node Node.
     * @param req Request.
     */
@SuppressWarnings("TooBroadScope")
public void processJobExecuteRequest(ClusterNode node, final GridJobExecuteRequest req) {
    if (log.isDebugEnabled())
        log.debug("Received job request message [req=" + req + ", nodeId=" + node.id() + ']');
    PartitionsReservation partsReservation = null;
    if (req.getCacheIds() != null) {
        assert req.getPartition() >= 0 : req;
        assert !F.isEmpty(req.getCacheIds()) : req;
        partsReservation = new PartitionsReservation(req.getCacheIds(), req.getPartition(), req.getTopVer());
    }
    GridJobWorker job = null;
    if (!rwLock.tryReadLock()) {
        if (log.isDebugEnabled())
            log.debug("Received job execution request while stopping this node (will ignore): " + req);
        return;
    }
    try {
        long endTime = req.getCreateTime() + req.getTimeout();
        // Account for overflow.
        if (endTime < 0)
            endTime = Long.MAX_VALUE;
        GridDeployment tmpDep = req.isForceLocalDeployment() ? ctx.deploy().getLocalDeployment(req.getTaskClassName()) : ctx.deploy().getGlobalDeployment(req.getDeploymentMode(), req.getTaskName(), req.getTaskClassName(), req.getUserVersion(), node.id(), req.getClassLoaderId(), req.getLoaderParticipants(), null);
        if (tmpDep == null) {
            if (log.isDebugEnabled())
                log.debug("Checking local tasks...");
            // Check local tasks.
            for (Map.Entry<String, GridDeployment> d : ctx.task().getUsedDeploymentMap().entrySet()) {
                if (d.getValue().classLoaderId().equals(req.getClassLoaderId())) {
                    assert d.getValue().local();
                    tmpDep = d.getValue();
                    break;
                }
            }
        }
        final GridDeployment dep = tmpDep;
        if (log.isDebugEnabled())
            log.debug("Deployment: " + dep);
        boolean releaseDep = true;
        try {
            if (dep != null && dep.acquire()) {
                GridJobSessionImpl jobSes;
                GridJobContextImpl jobCtx;
                try {
                    List<ComputeJobSibling> siblings = null;
                    if (!req.isDynamicSiblings()) {
                        Collection<ComputeJobSibling> siblings0 = req.getSiblings();
                        if (siblings0 == null) {
                            assert req.getSiblingsBytes() != null;
                            siblings0 = U.unmarshal(marsh, req.getSiblingsBytes(), U.resolveClassLoader(ctx.config()));
                        }
                        siblings = new ArrayList<>(siblings0);
                    }
                    Map<Object, Object> sesAttrs = null;
                    if (req.isSessionFullSupport()) {
                        sesAttrs = req.getSessionAttributes();
                        if (sesAttrs == null)
                            sesAttrs = U.unmarshal(marsh, req.getSessionAttributesBytes(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
                    }
                    // Note that we unmarshal session/job attributes here with proper class loader.
                    GridTaskSessionImpl taskSes = ctx.session().createTaskSession(req.getSessionId(), node.id(), req.getTaskName(), dep, req.getTaskClassName(), req.topology(), req.getStartTaskTime(), endTime, siblings, sesAttrs, req.isSessionFullSupport(), req.isInternal(), req.getSubjectId(), req.executorName());
                    taskSes.setCheckpointSpi(req.getCheckpointSpi());
                    taskSes.setClassLoader(dep.classLoader());
                    jobSes = new GridJobSessionImpl(ctx, taskSes, req.getJobId());
                    Map<? extends Serializable, ? extends Serializable> jobAttrs = req.getJobAttributes();
                    if (jobAttrs == null)
                        jobAttrs = U.unmarshal(marsh, req.getJobAttributesBytes(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
                    jobCtx = new GridJobContextImpl(ctx, req.getJobId(), jobAttrs);
                } catch (IgniteCheckedException e) {
                    IgniteException ex = new IgniteException("Failed to deserialize task attributes " + "[taskName=" + req.getTaskName() + ", taskClsName=" + req.getTaskClassName() + ", codeVer=" + req.getUserVersion() + ", taskClsLdr=" + dep.classLoader() + ']', e);
                    U.error(log, ex.getMessage(), e);
                    handleException(node, req, ex, endTime);
                    return;
                }
                job = new GridJobWorker(ctx, dep, req.getCreateTime(), jobSes, jobCtx, req.getJobBytes(), req.getJob(), node, req.isInternal(), evtLsnr, holdLsnr, partsReservation, req.getTopVer(), req.executorName());
                jobCtx.job(job);
                // If exception occurs on job initialization, deployment is released in job listener.
                releaseDep = false;
                if (job.initialize(dep, dep.deployedClass(req.getTaskClassName()))) {
                    // Internal jobs will always be executed synchronously.
                    if (job.isInternal()) {
                        // This is an internal job and can be executed inside busy lock
                        // since job is expected to be short.
                        // This is essential for proper stop without races.
                        job.run();
                        // No execution outside lock.
                        job = null;
                    } else if (jobAlwaysActivate) {
                        if (onBeforeActivateJob(job)) {
                            if (ctx.localNodeId().equals(node.id())) {
                                // Always execute in another thread for local node.
                                executeAsync(job);
                                // No sync execution.
                                job = null;
                            } else if (metricsUpdateFreq > -1L)
                                // Job will be executed synchronously.
                                startedJobsCnt.increment();
                        } else
                            // Job has been cancelled.
                            // Set to null, to avoid sync execution.
                            job = null;
                    } else {
                        GridJobWorker old = passiveJobs.putIfAbsent(job.getJobId(), job);
                        if (old == null)
                            handleCollisions();
                        else
                            U.error(log, "Received computation request with duplicate job ID (could be " + "network malfunction, source node may hang if task timeout was not set) " + "[srcNode=" + node.id() + ", jobId=" + req.getJobId() + ", sesId=" + req.getSessionId() + ", locNodeId=" + ctx.localNodeId() + ']');
                        // No sync execution.
                        job = null;
                    }
                } else
                    // Job was not initialized, no execution.
                    job = null;
            } else {
                // Deployment is null.
                IgniteException ex = new IgniteDeploymentException("Task was not deployed or was redeployed since " + "task execution [taskName=" + req.getTaskName() + ", taskClsName=" + req.getTaskClassName() + ", codeVer=" + req.getUserVersion() + ", clsLdrId=" + req.getClassLoaderId() + ", seqNum=" + req.getClassLoaderId().localId() + ", depMode=" + req.getDeploymentMode() + ", dep=" + dep + ']');
                U.error(log, ex.getMessage(), ex);
                handleException(node, req, ex, endTime);
            }
        } finally {
            if (dep != null && releaseDep)
                release(dep);
        }
    } finally {
        rwLock.readUnlock();
    }
    if (job != null)
        job.run();
}
Also used : GridJobSessionImpl(org.apache.ignite.internal.GridJobSessionImpl) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) GridJobContextImpl(org.apache.ignite.internal.GridJobContextImpl) GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeJobSibling(org.apache.ignite.compute.ComputeJobSibling) GridTaskSessionImpl(org.apache.ignite.internal.GridTaskSessionImpl) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)

Example 10 with GridDeployment

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

the class GridTaskProcessor method getUsedDeploymentMap.

/**
     * Gets currently used deployments mapped by task name or aliases.
     *
     * @return Currently used deployments.
     */
public Map<String, GridDeployment> getUsedDeploymentMap() {
    Map<String, GridDeployment> deps = new HashMap<>();
    for (GridTaskWorker w : tasks.values()) {
        GridTaskSessionImpl ses = w.getSession();
        deps.put(ses.getTaskClassName(), w.getDeployment());
        if (ses.getTaskName() != null && ses.getTaskClassName().equals(ses.getTaskName()))
            deps.put(ses.getTaskName(), w.getDeployment());
    }
    return deps;
}
Also used : GridDeployment(org.apache.ignite.internal.managers.deployment.GridDeployment) HashMap(java.util.HashMap) GridTaskSessionImpl(org.apache.ignite.internal.GridTaskSessionImpl)

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