Search in sources :

Example 6 with ClientException

use of org.apache.ignite.client.ClientException in project ignite by apache.

the class ClientClusterImpl method state.

/**
 * {@inheritDoc}
 */
@Override
public void state(ClusterState newState) throws ClientException {
    try {
        ch.service(ClientOperation.CLUSTER_CHANGE_STATE, req -> {
            ProtocolContext protocolCtx = req.clientChannel().protocolCtx();
            checkClusterApiSupported(protocolCtx);
            if (newState.ordinal() > 1 && !protocolCtx.isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_STATES)) {
                throw new ClientFeatureNotSupportedByServerException("State " + newState.name() + " is not " + "supported by the server");
            }
            req.out().writeByte((byte) newState.ordinal());
        }, null);
    } catch (ClientError e) {
        throw new ClientException(e);
    }
}
Also used : ClientException(org.apache.ignite.client.ClientException) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException)

Example 7 with ClientException

use of org.apache.ignite.client.ClientException in project ignite by apache.

the class ClientClusterGroupImpl method requestNodeIds.

/**
 * Requests node IDs from the server.
 */
private synchronized Collection<UUID> requestNodeIds() {
    try {
        return ch.service(ClientOperation.CLUSTER_GROUP_GET_NODE_IDS, req -> {
            if (!req.clientChannel().protocolCtx().isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_GROUPS))
                throw new ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature.CLUSTER_GROUPS);
            try (BinaryRawWriterEx writer = utils.createBinaryWriter(req.out())) {
                writer.writeLong(cachedTopVer);
                projectionFilters.write(writer);
            }
        }, res -> {
            if (!res.in().readBoolean())
                // There were no changes since last request.
                return new ArrayList<>(cachedNodeIds);
            // Topology version.
            long topVer = res.in().readLong();
            int nodesCnt = res.in().readInt();
            Collection<UUID> nodeIds = new ArrayList<>(nodesCnt);
            for (int i = 0; i < nodesCnt; i++) nodeIds.add(new UUID(res.in().readLong(), res.in().readLong()));
            cachedNodes.keySet().retainAll(nodeIds);
            cachedTopVer = topVer;
            cachedNodeIds = nodeIds;
            return new ArrayList<>(nodeIds);
        });
    } catch (ClientError e) {
        throw new ClientException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) ClientException(org.apache.ignite.client.ClientException) UUID(java.util.UUID) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException)

Example 8 with ClientException

use of org.apache.ignite.client.ClientException in project ignite by apache.

the class ClientClusterGroupImpl method requestNodesByIds.

/**
 * Requests nodes from the server.
 *
 * @param nodeIds Node ids.
 */
private Collection<ClusterNode> requestNodesByIds(Collection<UUID> nodeIds) {
    try {
        return ch.service(ClientOperation.CLUSTER_GROUP_GET_NODE_INFO, req -> {
            if (!req.clientChannel().protocolCtx().isFeatureSupported(ProtocolBitmaskFeature.CLUSTER_GROUPS))
                throw new ClientFeatureNotSupportedByServerException(ProtocolBitmaskFeature.CLUSTER_GROUPS);
            req.out().writeInt(nodeIds.size());
            for (UUID nodeId : nodeIds) {
                req.out().writeLong(nodeId.getMostSignificantBits());
                req.out().writeLong(nodeId.getLeastSignificantBits());
            }
        }, res -> {
            try (BinaryReaderExImpl reader = utils.createBinaryReader(res.in())) {
                int nodesCnt = reader.readInt();
                Collection<ClusterNode> nodes = new ArrayList<>();
                for (int i = 0; i < nodesCnt; i++) {
                    ClusterNode node = readClusterNode(reader);
                    cachedNodes.put(node.id(), node);
                    if (projectionFilters.testClientSidePredicates(node))
                        nodes.add(node);
                }
                return nodes;
            } catch (IOException e) {
                throw new ClientError(e);
            }
        });
    } catch (ClientError e) {
        throw new ClientException(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientException(org.apache.ignite.client.ClientException) UUID(java.util.UUID) ClientFeatureNotSupportedByServerException(org.apache.ignite.client.ClientFeatureNotSupportedByServerException)

Example 9 with ClientException

use of org.apache.ignite.client.ClientException in project ignite by apache.

the class ReliableChannel method applyOnDefaultChannel.

/**
 * Apply specified {@code function} on any of available channel.
 */
private <T> T applyOnDefaultChannel(Function<ClientChannel, T> function, ClientOperation op, int attemptsLimit, Consumer<Integer> attemptsCallback) {
    ClientConnectionException failure = null;
    for (int attempt = 0; attempt < attemptsLimit; attempt++) {
        ClientChannelHolder hld = null;
        ClientChannel c = null;
        try {
            if (closed)
                throw new ClientException("Channel is closed");
            curChannelsGuard.readLock().lock();
            try {
                hld = channels.get(curChIdx);
            } finally {
                curChannelsGuard.readLock().unlock();
            }
            c = hld.getOrCreateChannel();
            if (c != null) {
                attemptsCallback.accept(attempt + 1);
                return function.apply(c);
            }
        } catch (ClientConnectionException e) {
            if (failure == null)
                failure = e;
            else
                failure.addSuppressed(e);
            onChannelFailure(hld, c);
            if (op != null && !shouldRetry(op, attempt, e))
                break;
        }
    }
    throw failure;
}
Also used : ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientException(org.apache.ignite.client.ClientException)

Example 10 with ClientException

use of org.apache.ignite.client.ClientException in project ignite by apache.

the class OptimizedMarshallerClassesCachedTest method testLocalDateTimeMetaCached.

/**
 * Test check that meta for classes serialized by {@link OptimizedMarshaller} are cached on client.
 */
@Test
public void testLocalDateTimeMetaCached() throws Exception {
    try (Ignite srv = startGrid(0)) {
        srv.getOrCreateCache(Config.DEFAULT_CACHE_NAME).put(1, LocalDateTime.now());
        IgniteClient cli = new TcpIgniteClient((cfg0, hnd) -> new TcpClientChannel(cfg0, hnd) {

            @Override
            public <T> T service(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) throws ClientException {
                if (op == ClientOperation.GET_BINARY_TYPE_NAME)
                    cnt.incrementAndGet();
                return super.service(op, payloadWriter, payloadReader);
            }

            @Override
            public <T> CompletableFuture<T> serviceAsync(ClientOperation op, Consumer<PayloadOutputChannel> payloadWriter, Function<PayloadInputChannel, T> payloadReader) {
                if (op == ClientOperation.GET_BINARY_TYPE_NAME)
                    cnt.incrementAndGet();
                return super.serviceAsync(op, payloadWriter, payloadReader);
            }
        }, new ClientConfiguration().setAddresses(Config.SERVER));
        try {
            cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
            cli.cache(Config.DEFAULT_CACHE_NAME).get(1);
        } finally {
            cli.close();
        }
        assertEquals(1, cnt.get());
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IgniteClient(org.apache.ignite.client.IgniteClient) Ignite(org.apache.ignite.Ignite) ClientException(org.apache.ignite.client.ClientException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClientException (org.apache.ignite.client.ClientException)20 ArrayList (java.util.ArrayList)9 UUID (java.util.UUID)6 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)6 ClientConnectionException (org.apache.ignite.client.ClientConnectionException)5 IgniteClient (org.apache.ignite.client.IgniteClient)5 HashMap (java.util.HashMap)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Consumer (java.util.function.Consumer)4 Function (java.util.function.Function)4 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)4 InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ClientAuthenticationException (org.apache.ignite.client.ClientAuthenticationException)3 ClientFeatureNotSupportedByServerException (org.apache.ignite.client.ClientFeatureNotSupportedByServerException)3