Search in sources :

Example 76 with IgniteSpiException

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

the class TcpCommunicationSpi method getNodeAttributes.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Object> getNodeAttributes() throws IgniteSpiException {
    initFailureDetectionTimeout();
    assertParameter(locPort > 1023, "locPort > 1023");
    assertParameter(locPort <= 0xffff, "locPort < 0xffff");
    assertParameter(locPortRange >= 0, "locPortRange >= 0");
    assertParameter(idleConnTimeout > 0, "idleConnTimeout > 0");
    assertParameter(sockRcvBuf >= 0, "sockRcvBuf >= 0");
    assertParameter(sockSndBuf >= 0, "sockSndBuf >= 0");
    assertParameter(msgQueueLimit >= 0, "msgQueueLimit >= 0");
    assertParameter(shmemPort > 0 || shmemPort == -1, "shmemPort > 0 || shmemPort == -1");
    assertParameter(selectorsCnt > 0, "selectorsCnt > 0");
    assertParameter(connectionsPerNode > 0, "connectionsPerNode > 0");
    assertParameter(connectionsPerNode <= 1024, "connectionsPerNode <= 1024");
    if (!failureDetectionTimeoutEnabled()) {
        assertParameter(reconCnt > 0, "reconnectCnt > 0");
        assertParameter(connTimeout >= 0, "connTimeout >= 0");
        assertParameter(maxConnTimeout >= connTimeout, "maxConnTimeout >= connTimeout");
    }
    assertParameter(sockWriteTimeout >= 0, "sockWriteTimeout >= 0");
    assertParameter(ackSndThreshold > 0, "ackSndThreshold > 0");
    assertParameter(unackedMsgsBufSize >= 0, "unackedMsgsBufSize >= 0");
    if (unackedMsgsBufSize > 0) {
        assertParameter(unackedMsgsBufSize >= msgQueueLimit * 5, "Specified 'unackedMsgsBufSize' is too low, it should be at least 'msgQueueLimit * 5'.");
        assertParameter(unackedMsgsBufSize >= ackSndThreshold * 5, "Specified 'unackedMsgsBufSize' is too low, it should be at least 'ackSndThreshold * 5'.");
    }
    if (connectionsPerNode > 1) {
        connPlc = new ConnectionPolicy() {

            @Override
            public int connectionIndex() {
                return (int) (U.safeAbs(Thread.currentThread().getId()) % connectionsPerNode);
            }
        };
    } else {
        connPlc = new ConnectionPolicy() {

            @Override
            public int connectionIndex() {
                return 0;
            }
        };
    }
    try {
        locHost = U.resolveLocalHost(locAddr);
    } catch (IOException e) {
        throw new IgniteSpiException("Failed to initialize local address: " + locAddr, e);
    }
    try {
        shmemSrv = resetShmemServer();
    } catch (IgniteCheckedException e) {
        U.warn(log, "Failed to start shared memory communication server.", e);
    }
    try {
        // This method potentially resets local port to the value
        // local node was bound to.
        nioSrvr = resetNioServer();
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to initialize TCP server: " + locHost, e);
    }
    // Set local node attributes.
    try {
        IgniteBiTuple<Collection<String>, Collection<String>> addrs = U.resolveLocalAddresses(locHost);
        Collection<InetSocketAddress> extAddrs = addrRslvr == null ? null : U.resolveAddresses(addrRslvr, F.flat(Arrays.asList(addrs.get1(), addrs.get2())), boundTcpPort);
        HashMap<String, Object> res = new HashMap<>(5);
        res.put(createSpiAttributeName(ATTR_ADDRS), addrs.get1());
        res.put(createSpiAttributeName(ATTR_HOST_NAMES), addrs.get2());
        res.put(createSpiAttributeName(ATTR_PORT), boundTcpPort);
        res.put(createSpiAttributeName(ATTR_SHMEM_PORT), boundTcpShmemPort >= 0 ? boundTcpShmemPort : null);
        res.put(createSpiAttributeName(ATTR_EXT_ADDRS), extAddrs);
        res.put(createSpiAttributeName(ATTR_PAIRED_CONN), usePairedConnections);
        return res;
    } catch (IOException | IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to resolve local host to addresses: " + locHost, e);
    }
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Collection(java.util.Collection) IgniteSpiTimeoutObject(org.apache.ignite.spi.IgniteSpiTimeoutObject) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 77 with IgniteSpiException

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

the class ServerImpl method localAuthentication.

/**
 * Authenticate local node.
 *
 * @param locCred Local security credentials for authentication.
 * @throws IgniteSpiException If any error occurs.
 */
private void localAuthentication(SecurityCredentials locCred) {
    assert spi.nodeAuth != null;
    assert locCred != null;
    try {
        SecurityContext subj = spi.nodeAuth.authenticateNode(locNode, locCred);
        if (subj == null)
            throw new IgniteSpiException("Authentication failed for local node: " + locNode.id());
        Map<String, Object> attrs = new HashMap<>(locNode.attributes());
        attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT_V2, U.marshal(spi.marshaller(), subj));
        attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT, marshalWithSecurityVersion(subj, 1));
        locNode.setAttributes(attrs);
    } catch (IgniteException | IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to authenticate local node (will shutdown local node).", e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.IgniteException) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 78 with IgniteSpiException

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

the class ServerImpl method sendJoinRequestMessage.

/**
 * Tries to send join request message to a random node presenting in topology.
 * Address is provided by {@link org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder} and message is
 * sent to first node connection succeeded to.
 *
 * @param discoveryData Discovery data.
 * @return {@code true} if send succeeded.
 * @throws IgniteSpiException If any error occurs.
 */
@SuppressWarnings({ "BusyWait" })
private boolean sendJoinRequestMessage(DiscoveryDataPacket discoveryData) throws IgniteSpiException {
    TcpDiscoveryAbstractMessage joinReq = new TcpDiscoveryJoinRequestMessage(locNode, discoveryData);
    // Time when it has been detected, that addresses from IP finder do not respond.
    long noResStart = 0;
    while (true) {
        Collection<InetSocketAddress> addrs = spi.resolvedAddresses();
        if (F.isEmpty(addrs))
            return false;
        boolean retry = false;
        Collection<Exception> errs = new ArrayList<>();
        for (InetSocketAddress addr : addrs) {
            try {
                IgniteSpiOperationTimeoutHelper timeoutHelper = new IgniteSpiOperationTimeoutHelper(spi, true);
                Integer res;
                try {
                    SecurityUtils.serializeVersion(1);
                    res = sendMessageDirectly(joinReq, addr, timeoutHelper);
                } finally {
                    SecurityUtils.restoreDefaultSerializeVersion();
                }
                assert res != null;
                noResAddrs.remove(addr);
                // Address is responsive, reset period start.
                noResStart = 0;
                switch(res) {
                    case RES_WAIT:
                        // Concurrent startup, try sending join request again or wait if no success.
                        retry = true;
                        break;
                    case RES_OK:
                        if (log.isDebugEnabled())
                            log.debug("Join request message has been sent to address [addr=" + addr + ", req=" + joinReq + ']');
                        // Join request sending succeeded, wait for response from topology.
                        return true;
                    default:
                        // Concurrent startup, try next node.
                        if (res == RES_CONTINUE_JOIN) {
                            if (!fromAddrs.contains(addr))
                                retry = true;
                        } else {
                            if (log.isDebugEnabled())
                                log.debug("Unexpected response to join request: " + res);
                            retry = true;
                        }
                        break;
                }
            } catch (IgniteSpiException e) {
                errs.add(e);
                if (log.isDebugEnabled()) {
                    IOException ioe = X.cause(e, IOException.class);
                    log.debug("Failed to send join request message [addr=" + addr + ", msg=" + (ioe != null ? ioe.getMessage() : e.getMessage()) + ']');
                    onException("Failed to send join request message [addr=" + addr + ", msg=" + (ioe != null ? ioe.getMessage() : e.getMessage()) + ']', ioe);
                }
                noResAddrs.add(addr);
            }
        }
        if (retry) {
            if (log.isDebugEnabled())
                log.debug("Concurrent discovery SPI start has been detected (local node should wait).");
            try {
                U.sleep(spi.getReconnectDelay());
            } catch (IgniteInterruptedCheckedException e) {
                throw new IgniteSpiException("Thread has been interrupted.", e);
            }
        } else if (!spi.ipFinder.isShared() && !ipFinderHasLocAddr) {
            IgniteCheckedException e = null;
            if (!errs.isEmpty()) {
                e = new IgniteCheckedException("Multiple connection attempts failed.");
                for (Exception err : errs) e.addSuppressed(err);
            }
            if (e != null && X.hasCause(e, ConnectException.class)) {
                LT.warn(log, "Failed to connect to any address from IP finder " + "(make sure IP finder addresses are correct and firewalls are disabled on all host machines): " + toOrderedList(addrs), true);
            }
            if (spi.joinTimeout > 0) {
                if (noResStart == 0)
                    noResStart = U.currentTimeMillis();
                else if (U.currentTimeMillis() - noResStart > spi.joinTimeout)
                    throw new IgniteSpiException("Failed to connect to any address from IP finder within join timeout " + "(make sure IP finder addresses are correct, and operating system firewalls are disabled " + "on all host machines, or consider increasing 'joinTimeout' configuration property): " + addrs, e);
            }
            try {
                U.sleep(spi.getReconnectDelay());
            } catch (IgniteInterruptedCheckedException ex) {
                throw new IgniteSpiException("Thread has been interrupted.", ex);
            }
        } else
            break;
    }
    return false;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StreamCorruptedException(java.io.StreamCorruptedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SSLException(javax.net.ssl.SSLException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SocketException(java.net.SocketException) SocketTimeoutException(java.net.SocketTimeoutException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ObjectStreamException(java.io.ObjectStreamException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) NoSuchElementException(java.util.NoSuchElementException) IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) IgniteSpiOperationTimeoutHelper(org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpDiscoveryJoinRequestMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryJoinRequestMessage)

Example 79 with IgniteSpiException

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

the class TcpDiscoveryGoogleStorageIpFinder method init.

/**
 * Google Cloud Storage initialization.
 *
 * @throws IgniteSpiException In case of error.
 */
private void init() throws IgniteSpiException {
    if (initGuard.compareAndSet(false, true)) {
        if (srvcAccountId == null || srvcAccountP12FilePath == null || projectName == null || bucketName == null) {
            throw new IgniteSpiException("One or more of the required parameters is not set [serviceAccountId=" + srvcAccountId + ", serviceAccountP12FilePath=" + srvcAccountP12FilePath + ", projectName=" + projectName + ", bucketName=" + bucketName + "]");
        }
        try {
            NetHttpTransport httpTransport;
            try {
                httpTransport = GoogleNetHttpTransport.newTrustedTransport();
            } catch (GeneralSecurityException | IOException e) {
                throw new IgniteSpiException(e);
            }
            GoogleCredential cred;
            try {
                cred = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(JacksonFactory.getDefaultInstance()).setServiceAccountId(srvcAccountId).setServiceAccountPrivateKeyFromP12File(new File(srvcAccountP12FilePath)).setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)).build();
            } catch (Exception e) {
                throw new IgniteSpiException("Failed to authenticate on Google Cloud Platform", e);
            }
            try {
                storage = new Storage.Builder(httpTransport, JacksonFactory.getDefaultInstance(), cred).setApplicationName(projectName).build();
            } catch (Exception e) {
                throw new IgniteSpiException("Failed to open a storage for given project name: " + projectName, e);
            }
            boolean createBucket = false;
            try {
                Storage.Buckets.Get getBucket = storage.buckets().get(bucketName);
                getBucket.setProjection("full");
                getBucket.execute();
            } catch (GoogleJsonResponseException e) {
                if (e.getStatusCode() == 404) {
                    U.warn(log, "Bucket doesn't exist, will create it [bucketName=" + bucketName + "]");
                    createBucket = true;
                } else
                    throw new IgniteSpiException("Failed to open the bucket: " + bucketName, e);
            } catch (Exception e) {
                throw new IgniteSpiException("Failed to open the bucket: " + bucketName, e);
            }
            if (createBucket) {
                Bucket newBucket = new Bucket();
                newBucket.setName(bucketName);
                try {
                    Storage.Buckets.Insert insertBucket = storage.buckets().insert(projectName, newBucket);
                    insertBucket.setProjection("full");
                    insertBucket.setPredefinedDefaultObjectAcl("projectPrivate");
                    insertBucket.execute();
                } catch (Exception e) {
                    throw new IgniteSpiException("Failed to create the bucket: " + bucketName, e);
                }
            }
        } finally {
            initLatch.countDown();
        }
    } else {
        try {
            U.await(initLatch);
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteSpiException("Thread has been interrupted.", e);
        }
        if (storage == null)
            throw new IgniteSpiException("IpFinder has not been initialized properly");
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) 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) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Storage(com.google.api.services.storage.Storage) Bucket(com.google.api.services.storage.model.Bucket) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File)

Example 80 with IgniteSpiException

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

the class TcpDiscoveryGoogleStorageIpFinder method unregisterAddresses.

/**
 * {@inheritDoc}
 */
@Override
public void unregisterAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
    assert !F.isEmpty(addrs);
    init();
    for (InetSocketAddress addr : addrs) {
        String key = keyFromAddr(addr);
        try {
            Storage.Objects.Delete deleteObject = storage.objects().delete(bucketName, key);
            deleteObject.execute();
        } catch (Exception e) {
            throw new IgniteSpiException("Failed to delete entry [bucketName=" + bucketName + ", entry=" + key + ']', e);
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) 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)

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