Search in sources :

Example 16 with IgniteClientDisconnectedCheckedException

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

the class GridServiceProcessor method deploy.

/**
     * @param cfg Service configuration.
     * @return Future for deployment.
     */
public IgniteInternalFuture<?> deploy(ServiceConfiguration cfg) {
    A.notNull(cfg, "cfg");
    ServicesCompatibilityState state = markCompatibilityStateAsUsed();
    validate(cfg);
    ctx.security().authorize(cfg.getName(), SecurityPermission.SERVICE_DEPLOY, null);
    if (!state.srvcCompatibility) {
        Marshaller marsh = ctx.config().getMarshaller();
        LazyServiceConfiguration cfg0;
        try {
            byte[] srvcBytes = U.marshal(marsh, cfg.getService());
            cfg0 = new LazyServiceConfiguration(cfg, srvcBytes);
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to marshal service with configured marshaller [srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
            return new GridFinishedFuture<>(e);
        }
        cfg = cfg0;
    }
    GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(cfg);
    GridServiceDeploymentFuture old = depFuts.putIfAbsent(cfg.getName(), fut);
    if (old != null) {
        if (!old.configuration().equalsIgnoreNodeFilter(cfg)) {
            fut.onDone(new IgniteCheckedException("Failed to deploy service (service already exists with " + "different configuration) [deployed=" + old.configuration() + ", new=" + cfg + ']'));
            return fut;
        }
        return old;
    }
    if (ctx.clientDisconnected()) {
        fut.onDone(new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy service, client node disconnected."));
        depFuts.remove(cfg.getName(), fut);
    }
    while (true) {
        try {
            GridServiceDeploymentKey key = new GridServiceDeploymentKey(cfg.getName());
            if (ctx.deploy().enabled())
                ctx.cache().context().deploy().ignoreOwnership(true);
            try {
                GridServiceDeployment dep = (GridServiceDeployment) cache.getAndPutIfAbsent(key, new GridServiceDeployment(ctx.localNodeId(), cfg));
                if (dep != null) {
                    if (!dep.configuration().equalsIgnoreNodeFilter(cfg)) {
                        // Remove future from local map.
                        depFuts.remove(cfg.getName(), fut);
                        fut.onDone(new IgniteCheckedException("Failed to deploy service (service already exists with " + "different configuration) [deployed=" + dep.configuration() + ", new=" + cfg + ']'));
                    } else {
                        Iterator<Cache.Entry<Object, Object>> it = serviceEntries(ServiceAssignmentsPredicate.INSTANCE);
                        while (it.hasNext()) {
                            Cache.Entry<Object, Object> e = it.next();
                            GridServiceAssignments assigns = (GridServiceAssignments) e.getValue();
                            if (assigns.name().equals(cfg.getName())) {
                                // Remove future from local map.
                                depFuts.remove(cfg.getName(), fut);
                                fut.onDone();
                                break;
                            }
                        }
                        if (!dep.configuration().equalsIgnoreNodeFilter(cfg))
                            U.warn(log, "Service already deployed with different configuration (will ignore) " + "[deployed=" + dep.configuration() + ", new=" + cfg + ']');
                    }
                }
            } finally {
                if (ctx.deploy().enabled())
                    ctx.cache().context().deploy().ignoreOwnership(false);
            }
            return fut;
        } catch (ClusterTopologyCheckedException e) {
            if (log.isDebugEnabled())
                log.debug("Topology changed while deploying service (will retry): " + e.getMessage());
        } catch (IgniteCheckedException e) {
            if (e.hasCause(ClusterTopologyCheckedException.class)) {
                if (log.isDebugEnabled())
                    log.debug("Topology changed while deploying service (will retry): " + e.getMessage());
                continue;
            }
            U.error(log, "Failed to deploy service: " + cfg.getName(), e);
            return new GridFinishedFuture<>(e);
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) Cache(javax.cache.Cache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 17 with IgniteClientDisconnectedCheckedException

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

the class DataStreamerImpl method doFlush.

/**
     * Performs flush.
     *
     * @throws IgniteCheckedException If failed.
     */
private void doFlush() throws IgniteCheckedException {
    lastFlushTime = U.currentTimeMillis();
    List<IgniteInternalFuture> activeFuts0 = null;
    int doneCnt = 0;
    for (IgniteInternalFuture<?> f : activeFuts) {
        if (!f.isDone()) {
            if (activeFuts0 == null)
                activeFuts0 = new ArrayList<>((int) (activeFuts.size() * 1.2));
            activeFuts0.add(f);
        } else {
            f.get();
            doneCnt++;
        }
    }
    if (activeFuts0 == null || activeFuts0.isEmpty())
        return;
    while (true) {
        Queue<IgniteInternalFuture<?>> q = null;
        for (Buffer buf : bufMappings.values()) {
            IgniteInternalFuture<?> flushFut = buf.flush();
            if (flushFut != null) {
                if (q == null)
                    q = new ArrayDeque<>(bufMappings.size() * 2);
                q.add(flushFut);
            }
        }
        if (q != null) {
            assert !q.isEmpty();
            boolean err = false;
            long startTimeMillis = U.currentTimeMillis();
            for (IgniteInternalFuture fut = q.poll(); fut != null; fut = q.poll()) {
                try {
                    if (timeout == DFLT_UNLIMIT_TIMEOUT)
                        fut.get();
                    else {
                        long timeRemain = timeout - U.currentTimeMillis() + startTimeMillis;
                        if (timeRemain <= 0)
                            throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.");
                        fut.get(timeRemain);
                    }
                } catch (IgniteClientDisconnectedCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    throw CU.convertToCacheException(e);
                } catch (IgniteFutureTimeoutCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    throw new IgniteDataStreamerTimeoutException("Data streamer exceeded timeout on flush.", e);
                } catch (IgniteCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to flush buffer: " + e);
                    err = true;
                }
            }
            if (err)
                // Remaps needed - flush buffers.
                continue;
        }
        doneCnt = 0;
        for (int i = 0; i < activeFuts0.size(); i++) {
            IgniteInternalFuture f = activeFuts0.get(i);
            if (f == null)
                doneCnt++;
            else if (f.isDone()) {
                f.get();
                doneCnt++;
                activeFuts0.set(i, null);
            } else
                break;
        }
        if (doneCnt == activeFuts0.size())
            return;
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ArrayDeque(java.util.ArrayDeque) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteDataStreamerTimeoutException(org.apache.ignite.IgniteDataStreamerTimeoutException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Example 18 with IgniteClientDisconnectedCheckedException

use of org.apache.ignite.internal.IgniteClientDisconnectedCheckedException 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);
        }
    });
    return m;
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) 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 19 with IgniteClientDisconnectedCheckedException

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

the class ClientImpl method pingNode.

/** {@inheritDoc} */
@Override
public boolean pingNode(@NotNull final UUID nodeId) {
    if (nodeId.equals(getLocalNodeId()))
        return true;
    TcpDiscoveryNode node = rmtNodes.get(nodeId);
    if (node == null || !node.visible())
        return false;
    GridFutureAdapter<Boolean> fut = pingFuts.get(nodeId);
    if (fut == null) {
        fut = new GridFutureAdapter<>();
        GridFutureAdapter<Boolean> oldFut = pingFuts.putIfAbsent(nodeId, fut);
        if (oldFut != null)
            fut = oldFut;
        else {
            State state = this.state;
            if (spi.getSpiContext().isStopping() || state == STOPPED || state == SEGMENTED) {
                if (pingFuts.remove(nodeId, fut))
                    fut.onDone(false);
                return false;
            } else if (state == DISCONNECTED) {
                if (pingFuts.remove(nodeId, fut))
                    fut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
            } else {
                final GridFutureAdapter<Boolean> finalFut = fut;
                timer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        if (pingFuts.remove(nodeId, finalFut)) {
                            if (ClientImpl.this.state == DISCONNECTED)
                                finalFut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
                            else
                                finalFut.onDone(false);
                        }
                    }
                }, spi.netTimeout);
                sockWriter.sendMessage(new TcpDiscoveryClientPingRequest(getLocalNodeId(), nodeId));
            }
        }
    }
    try {
        return fut.get();
    } catch (IgniteInterruptedCheckedException ignored) {
        return false;
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException(e);
    }
}
Also used : TcpDiscoveryClientPingRequest(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryClientPingRequest) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TimerTask(java.util.TimerTask) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Aggregations

IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)19 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteException (org.apache.ignite.IgniteException)7 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 CacheException (javax.cache.CacheException)2 JMException (javax.management.JMException)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 IgniteDataStreamerTimeoutException (org.apache.ignite.IgniteDataStreamerTimeoutException)2 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)2 CacheExistsException (org.apache.ignite.cache.CacheExistsException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)2