Search in sources :

Example 1 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpCommunicationSpi method reserveClient.

/**
 * Returns existing or just created client to node.
 *
 * @param node Node to which client should be open.
 * @param connIdx Connection index.
 * @return The existing or just created client.
 * @throws IgniteCheckedException Thrown if any exception occurs.
 */
private GridCommunicationClient reserveClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
    assert node != null;
    assert (connIdx >= 0 && connIdx < connectionsPerNode) || !usePairedConnections(node) : connIdx;
    UUID nodeId = node.id();
    while (true) {
        GridCommunicationClient[] curClients = clients.get(nodeId);
        GridCommunicationClient client = curClients != null && connIdx < curClients.length ? curClients[connIdx] : null;
        if (client == null) {
            if (stopping)
                throw new IgniteSpiException("Node is stopping.");
            // Do not allow concurrent connects.
            GridFutureAdapter<GridCommunicationClient> fut = new ConnectFuture();
            ConnectionKey connKey = new ConnectionKey(nodeId, connIdx, -1);
            GridFutureAdapter<GridCommunicationClient> oldFut = clientFuts.putIfAbsent(connKey, fut);
            if (oldFut == null) {
                try {
                    GridCommunicationClient[] curClients0 = clients.get(nodeId);
                    GridCommunicationClient client0 = curClients0 != null && connIdx < curClients0.length ? curClients0[connIdx] : null;
                    if (client0 == null) {
                        client0 = createNioClient(node, connIdx);
                        if (client0 != null) {
                            addNodeClient(node, connIdx, client0);
                            if (client0 instanceof GridTcpNioCommunicationClient) {
                                GridTcpNioCommunicationClient tcpClient = ((GridTcpNioCommunicationClient) client0);
                                if (tcpClient.session().closeTime() > 0 && removeNodeClient(nodeId, client0)) {
                                    if (log.isDebugEnabled())
                                        log.debug("Session was closed after client creation, will retry " + "[node=" + node + ", client=" + client0 + ']');
                                    client0 = null;
                                }
                            }
                        } else {
                            U.sleep(200);
                            if (getSpiContext().node(node.id()) == null)
                                throw new ClusterTopologyCheckedException("Failed to send message " + "(node left topology): " + node);
                        }
                    }
                    fut.onDone(client0);
                } catch (Throwable e) {
                    fut.onDone(e);
                    if (e instanceof Error)
                        throw (Error) e;
                } finally {
                    clientFuts.remove(connKey, fut);
                }
            } else
                fut = oldFut;
            client = fut.get();
            if (client == null)
                continue;
            if (getSpiContext().node(nodeId) == null) {
                if (removeNodeClient(nodeId, client))
                    client.forceClose();
                throw new IgniteSpiException("Destination node is not in topology: " + node.id());
            }
        }
        assert connIdx == client.connectionIndex() : client;
        if (client.reserve())
            return client;
        else
            // Client has just been closed by idle worker. Help it and try again.
            removeNodeClient(nodeId, client);
    }
}
Also used : IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) UUID(java.util.UUID) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 2 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoveryGoogleStorageIpFinder method addrFromString.

/**
 * Constructs a node address from bucket's key.
 *
 * @param key Bucket key.
 * @return Node address.
 * @throws IgniteSpiException In case of error.
 */
private InetSocketAddress addrFromString(String key) throws IgniteSpiException {
    String[] res = key.split("#");
    if (res.length != 2)
        throw new IgniteSpiException("Invalid address string: " + key);
    int port;
    try {
        port = Integer.parseInt(res[1]);
    } catch (NumberFormatException ignored) {
        throw new IgniteSpiException("Invalid port number: " + res[1]);
    }
    return new InetSocketAddress(res[0], port);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 3 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoveryGoogleStorageIpFinder method removeBucket.

/**
 * Used by TEST SUITES only. Called through reflection.
 *
 * @param bucketName Bucket to delete.
 */
private void removeBucket(String bucketName) {
    init();
    try {
        Storage.Buckets.Delete deleteBucket = storage.buckets().delete(bucketName);
        deleteBucket.execute();
    } catch (Exception e) {
        throw new IgniteSpiException("Failed to remove the bucket: " + bucketName, e);
    }
}
Also used : IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GeneralSecurityException(java.security.GeneralSecurityException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 4 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoveryGoogleStorageIpFinder method registerAddresses.

/**
 * {@inheritDoc}
 */
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
    assert !F.isEmpty(addrs);
    init();
    for (InetSocketAddress addr : addrs) {
        String key = keyFromAddr(addr);
        StorageObject object = new StorageObject();
        object.setBucket(bucketName);
        object.setName(key);
        InputStreamContent content = new InputStreamContent("application/octet-stream", OBJECT_CONTENT);
        content.setLength(OBJECT_CONTENT.available());
        try {
            Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, object, content);
            insertObject.execute();
        } catch (Exception e) {
            throw new IgniteSpiException("Failed to put entry [bucketName=" + bucketName + ", entry=" + key + ']', e);
        }
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) InetSocketAddress(java.net.InetSocketAddress) InputStreamContent(com.google.api.client.http.InputStreamContent) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GeneralSecurityException(java.security.GeneralSecurityException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 5 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class S3CheckpointSpi method saveCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public boolean saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite) throws IgniteSpiException {
    assert !F.isEmpty(key);
    long expireTime = 0;
    if (timeout > 0) {
        expireTime = U.currentTimeMillis() + timeout;
        if (expireTime < 0)
            expireTime = Long.MAX_VALUE;
    }
    try {
        if (hasKey(key)) {
            if (!overwrite)
                return false;
            if (log.isDebugEnabled())
                log.debug("Overriding existing key: " + key);
        }
        S3CheckpointData data = new S3CheckpointData(state, expireTime, key);
        write(data);
    } catch (AmazonClientException e) {
        throw new IgniteSpiException("Failed to write checkpoint data [key=" + key + ", state=" + Arrays.toString(state) + ']', e);
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal checkpoint data [key=" + key + ", state=" + Arrays.toString(state) + ']', e);
    }
    if (timeout > 0)
        timeoutWrk.add(new S3TimeData(expireTime, key));
    return true;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AmazonClientException(com.amazonaws.AmazonClientException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)131 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IOException (java.io.IOException)32 InetSocketAddress (java.net.InetSocketAddress)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)21 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)21 IgniteException (org.apache.ignite.IgniteException)20 ArrayList (java.util.ArrayList)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)14 HashMap (java.util.HashMap)13 UUID (java.util.UUID)13 Nullable (org.jetbrains.annotations.Nullable)12 Test (org.junit.Test)12 File (java.io.File)10 Message (org.apache.ignite.plugin.extensions.communication.Message)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 SSLException (javax.net.ssl.SSLException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 SocketTimeoutException (java.net.SocketTimeoutException)7 Ignite (org.apache.ignite.Ignite)7