Search in sources :

Example 1 with IgniteDeploymentException

use of org.apache.ignite.IgniteDeploymentException 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()));
                    }
                    IgnitePredicate<ClusterNode> topologyPred = req.getTopologyPredicate();
                    if (topologyPred == null && req.getTopologyPredicateBytes() != null) {
                        topologyPred = U.unmarshal(marsh, req.getTopologyPredicateBytes(), 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(), topologyPred, req.getStartTaskTime(), endTime, siblings, sesAttrs, req.isSessionFullSupport(), req.isInternal(), req.executorName(), ctx.security().enabled() ? ctx.security().securityContext().subject().login() : null);
                    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()).get1())) {
                    // 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();
                                startedJobsMetric.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) {
                            waitingJobsMetric.increment();
                            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) ClusterNode(org.apache.ignite.cluster.ClusterNode) 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) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridBoundedConcurrentLinkedHashMap(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap)

Example 2 with IgniteDeploymentException

use of org.apache.ignite.IgniteDeploymentException 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 3 with IgniteDeploymentException

use of org.apache.ignite.IgniteDeploymentException in project ignite by apache.

the class IgniteUtils method exceptionConverters.

/**
 * Gets map with converters to convert internal checked exceptions to public API unchecked exceptions.
 *
 * @return Exception converters.
 */
private static Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> exceptionConverters() {
    Map<Class<? extends IgniteCheckedException>, C1<IgniteCheckedException, IgniteException>> m = new HashMap<>();
    m.put(IgniteInterruptedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteInterruptedException(e.getMessage(), (InterruptedException) e.getCause());
        }
    });
    m.put(IgniteFutureCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteFutureCancelledException(e.getMessage(), e);
        }
    });
    m.put(IgniteFutureTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteFutureTimeoutException(e.getMessage(), e);
        }
    });
    m.put(ClusterGroupEmptyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ClusterGroupEmptyException(e.getMessage(), e);
        }
    });
    m.put(ClusterTopologyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            ClusterTopologyException topEx = new ClusterTopologyException(e.getMessage(), e);
            ClusterTopologyCheckedException checked = (ClusterTopologyCheckedException) e;
            if (checked.retryReadyFuture() != null)
                topEx.retryReadyFuture(new IgniteFutureImpl<>(checked.retryReadyFuture()));
            return topEx;
        }
    });
    m.put(IgniteDeploymentCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteDeploymentException(e.getMessage(), e);
        }
    });
    m.put(ComputeTaskTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ComputeTaskTimeoutException(e.getMessage(), e);
        }
    });
    m.put(ComputeTaskCancelledCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new ComputeTaskCancelledException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxRollbackCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionRollbackException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxHeuristicCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionHeuristicException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxTimeoutCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            if (e.getCause() instanceof TransactionDeadlockException)
                return new TransactionTimeoutException(e.getMessage(), e.getCause());
            return new TransactionTimeoutException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxOptimisticCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionOptimisticException(e.getMessage(), e);
        }
    });
    m.put(IgniteClientDisconnectedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new IgniteClientDisconnectedException(((IgniteClientDisconnectedCheckedException) e).reconnectFuture(), e.getMessage(), e);
        }
    });
    m.put(IgniteTxSerializationCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionSerializationException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxDuplicateKeyCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionDuplicateKeyException(e.getMessage(), e);
        }
    });
    m.put(IgniteTxAlreadyCompletedCheckedException.class, new C1<IgniteCheckedException, IgniteException>() {

        @Override
        public IgniteException apply(IgniteCheckedException e) {
            return new TransactionAlreadyCompletedException(e.getMessage(), e);
        }
    });
    return m;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) TransactionDuplicateKeyException(org.apache.ignite.transactions.TransactionDuplicateKeyException) TransactionSerializationException(org.apache.ignite.transactions.TransactionSerializationException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TransactionHeuristicException(org.apache.ignite.transactions.TransactionHeuristicException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) C1(org.apache.ignite.internal.util.typedef.C1) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) TransactionAlreadyCompletedException(org.apache.ignite.transactions.TransactionAlreadyCompletedException) ComputeTaskCancelledException(org.apache.ignite.compute.ComputeTaskCancelledException) IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteFutureCancelledException(org.apache.ignite.lang.IgniteFutureCancelledException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 4 with IgniteDeploymentException

use of org.apache.ignite.IgniteDeploymentException in project ignite by apache.

the class GridP2PCountTiesLoadClassDirectlyFromClassLoaderTest method executeP2PTaskWithRestartMaster.

/**
 * @throws Exception if error occurs.
 */
public void executeP2PTaskWithRestartMaster(DeploymentMode depMode) throws Exception {
    try {
        CountTriesClassLoader testCntLdr = new CountTriesClassLoader(Thread.currentThread().getContextClassLoader());
        this.depMode = depMode;
        Thread.currentThread().setContextClassLoader(testCntLdr);
        String path = GridTestProperties.getProperty(CLS_PATH_PROPERTY);
        ClassLoader urlClsLdr = new URLClassLoader(new URL[] { new URL(path) }, testCntLdr);
        Ignite ignite = startGrids(2);
        Map<UUID, Integer> res = (Map<UUID, Integer>) ignite.compute(ignite.cluster().forRemotes()).execute((ComputeTask<Integer, Object>) urlClsLdr.loadClass(COMPUTE_STEALING_TASK_NAME).newInstance(), 1);
        info("Result: " + res);
        int cnt = testCntLdr.count;
        ignite.compute(ignite.cluster().forRemotes()).execute(COMPUTE_STEALING_TASK_NAME, 2);
        ignite.compute(ignite.cluster().forRemotes()).execute(COMPUTE_STEALING_TASK_NAME, 3);
        ignite.compute(ignite.cluster().forRemotes()).execute(COMPUTE_STEALING_TASK_NAME, 4);
        assertEquals(cnt, testCntLdr.count);
        ignite.close();
        ignite = startGrid(0);
        try {
            ignite.compute().execute(COMPUTE_STEALING_TASK_NAME, 5);
            if (depMode != DeploymentMode.CONTINUOUS)
                fail("Task should be undeployed.");
        } catch (IgniteDeploymentException e) {
            if (depMode != DeploymentMode.CONTINUOUS)
                assertTrue(e.getMessage(), e.getMessage().contains("Unknown task name or failed to auto-deploy task"));
            else
                fail(e.getMessage());
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) IgniteDeploymentException(org.apache.ignite.IgniteDeploymentException) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) Map(java.util.Map)

Aggregations

IgniteDeploymentException (org.apache.ignite.IgniteDeploymentException)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IgniteException (org.apache.ignite.IgniteException)2 GridDeployment (org.apache.ignite.internal.managers.deployment.GridDeployment)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 UUID (java.util.UUID)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Ignite (org.apache.ignite.Ignite)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 ClusterGroupEmptyException (org.apache.ignite.cluster.ClusterGroupEmptyException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)1 ComputeJobSibling (org.apache.ignite.compute.ComputeJobSibling)1