Search in sources :

Example 1 with OException

use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.

the class OStorageRemote method openRemoteDatabase.

protected String openRemoteDatabase(String currentURL) {
    do {
        do {
            OChannelBinaryAsynchClient network = null;
            try {
                network = getNetwork(currentURL);
                openRemoteDatabase(network);
                connectionManager.release(network);
                return currentURL;
            } catch (OIOException e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    connectionManager.remove(network);
                }
                OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
            } catch (OException e) {
                connectionManager.release(network);
                // PROPAGATE ANY OTHER ORIENTDB EXCEPTION
                throw e;
            } catch (Exception e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    try {
                        connectionManager.remove(network);
                    } catch (Exception ex) {
                        // IGNORE ANY EXCEPTION
                        OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
                    }
                }
                OLogManager.instance().error(this, "Cannot open database url=" + currentURL, e);
            }
        } while (connectionManager.getReusableConnections(currentURL) > 0);
        currentURL = useNewServerURL(currentURL);
    } while (currentURL != null);
    // REFILL ORIGINAL SERVER LIST
    parseServerURLs();
    synchronized (serverURLs) {
        throw new OStorageException("Cannot create a connection to remote server address(es): " + serverURLs);
    }
}
Also used : OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 2 with OException

use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.

the class OStorageRemote method reopenRemoteDatabase.

protected String reopenRemoteDatabase() throws IOException {
    String currentURL = getCurrentServerURL();
    do {
        do {
            final OChannelBinaryAsynchClient network = getNetwork(currentURL);
            try {
                OStorageRemoteSession session = getCurrentSession();
                OStorageRemoteNodeSession nodeSession = session.getOrCreateServerSession(network.getServerURL());
                if (nodeSession == null || !nodeSession.isValid()) {
                    openRemoteDatabase(network);
                    connectionManager.release(network);
                    return network.getServerURL();
                } else {
                    try {
                        network.writeByte(OChannelBinaryProtocol.REQUEST_DB_REOPEN);
                        network.writeInt(nodeSession.getSessionId());
                        network.writeBytes(nodeSession.getToken());
                    } finally {
                        endRequest(network);
                    }
                    final int sessionId;
                    try {
                        byte[] newToken = network.beginResponse(nodeSession.getSessionId(), true);
                        sessionId = network.readInt();
                        if (newToken != null && newToken.length > 0) {
                            nodeSession.setSession(sessionId, newToken);
                        } else {
                            nodeSession.setSession(sessionId, nodeSession.getToken());
                        }
                        OLogManager.instance().debug(this, "Client connected to %s with session id=%d", network.getServerURL(), sessionId);
                        return currentURL;
                    } finally {
                        endResponse(network);
                        connectionManager.release(network);
                    }
                }
            } catch (OIOException e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    connectionManager.remove(network);
                }
                OLogManager.instance().error(this, "Cannot open database with url " + currentURL, e);
            } catch (OOfflineNodeException e) {
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    connectionManager.remove(network);
                }
                OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
            } catch (OSecurityException ex) {
                OLogManager.instance().debug(this, "Invalidate token for url=%s", ex, currentURL);
                OStorageRemoteSession session = getCurrentSession();
                session.removeServerSession(currentURL);
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    try {
                        connectionManager.remove(network);
                    } catch (Exception e) {
                        // IGNORE ANY EXCEPTION
                        OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
                    }
                }
            } catch (OException e) {
                connectionManager.release(network);
                // PROPAGATE ANY OTHER ORIENTDB EXCEPTION
                throw e;
            } catch (Exception e) {
                OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
                if (network != null) {
                    // REMOVE THE NETWORK CONNECTION IF ANY
                    try {
                        connectionManager.remove(network);
                    } catch (Exception ex) {
                        // IGNORE ANY EXCEPTION
                        OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
                    }
                }
            }
        } while (connectionManager.getAvailableConnections(currentURL) > 0);
        currentURL = useNewServerURL(currentURL);
    } while (currentURL != null);
    // REFILL ORIGINAL SERVER LIST
    parseServerURLs();
    synchronized (serverURLs) {
        throw new OStorageException("Cannot create a connection to remote server address(es): " + serverURLs);
    }
}
Also used : OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OIOException(com.orientechnologies.common.io.OIOException) OException(com.orientechnologies.common.exception.OException) NamingException(javax.naming.NamingException) OTokenException(com.orientechnologies.orient.core.metadata.security.OTokenException) ODistributedRedirectException(com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException) OInterruptedException(com.orientechnologies.common.concur.lock.OInterruptedException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OOfflineNodeException(com.orientechnologies.common.concur.OOfflineNodeException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Example 3 with OException

use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.

the class OChannelBinaryAsynchClient method throwSerializedException.

private void throwSerializedException(final byte[] serializedException) throws IOException {
    final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException);
    final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
    Object throwable = null;
    try {
        throwable = objectInputStream.readObject();
    } catch (ClassNotFoundException e) {
        OLogManager.instance().error(this, "Error during exception deserialization", e);
        throw new IOException("Error during exception deserialization: " + e.toString());
    }
    objectInputStream.close();
    if (throwable instanceof OException) {
        try {
            final Class<? extends OException> cls = (Class<? extends OException>) throwable.getClass();
            final Constructor<? extends OException> constructor;
            constructor = cls.getConstructor(cls);
            final OException proxyInstance = constructor.newInstance(throwable);
            throw proxyInstance;
        } catch (NoSuchMethodException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InvocationTargetException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InstantiationException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (IllegalAccessException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        }
    }
    if (throwable instanceof Throwable) {
        throw new OResponseProcessingException("Exception during response processing", (Throwable) throwable);
    } else
        // WRAP IT
        OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null"));
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) OException(com.orientechnologies.common.exception.OException) OIOException(com.orientechnologies.common.io.OIOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OResponseProcessingException(com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with OException

use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.

the class OChannelBinaryClientAbstract method throwSerializedException.

protected void throwSerializedException(final byte[] serializedException) throws IOException {
    final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException);
    final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
    Object throwable = null;
    try {
        throwable = objectInputStream.readObject();
    } catch (ClassNotFoundException e) {
        OLogManager.instance().error(this, "Error during exception deserialization", e);
        throw new IOException("Error during exception deserialization: " + e.toString());
    }
    objectInputStream.close();
    if (throwable instanceof OException) {
        try {
            final Class<? extends OException> cls = (Class<? extends OException>) throwable.getClass();
            final Constructor<? extends OException> constructor;
            constructor = cls.getConstructor(cls);
            final OException proxyInstance = constructor.newInstance(throwable);
            throw proxyInstance;
        } catch (NoSuchMethodException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InvocationTargetException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (InstantiationException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        } catch (IllegalAccessException e) {
            OLogManager.instance().error(this, "Error during exception deserialization", e);
        }
    }
    if (throwable instanceof Throwable) {
        throw new OResponseProcessingException("Exception during response processing", (Throwable) throwable);
    } else
        // WRAP IT
        OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null"));
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OException(com.orientechnologies.common.exception.OException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OResponseProcessingException(com.orientechnologies.orient.enterprise.channel.binary.OResponseProcessingException)

Example 5 with OException

use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.

the class OServerAdmin method networkAdminOperation.

protected <T> T networkAdminOperation(final OStorageRemoteOperation<T> operation, final String errorMessage) {
    OChannelBinaryAsynchClient network = null;
    try {
        //TODO:replace this api with one that get connection for only the specified url.
        String serverUrl = storage.getNextAvailableServerURL(false, session);
        do {
            try {
                network = storage.getNetwork(serverUrl);
            } catch (OException e) {
                serverUrl = storage.useNewServerURL(serverUrl);
                if (serverUrl == null)
                    throw e;
            }
        } while (network == null);
        T res = operation.execute(network, storage.getCurrentSession());
        storage.connectionManager.release(network);
        return res;
    } catch (Exception e) {
        if (network != null)
            storage.connectionManager.release(network);
        storage.close(true, false);
        throw OException.wrapException(new OStorageException(errorMessage), e);
    }
}
Also used : OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OChannelBinaryAsynchClient(com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OModificationOperationProhibitedException(com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)

Aggregations

OException (com.orientechnologies.common.exception.OException)21 IOException (java.io.IOException)12 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)11 OModificationOperationProhibitedException (com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException)5 OIOException (com.orientechnologies.common.io.OIOException)5 OChannelBinaryAsynchClient (com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient)4 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)3 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 OTokenException (com.orientechnologies.orient.core.metadata.security.OTokenException)3 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)3 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)3 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)3 OTokenSecurityException (com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException)3 NamingException (javax.naming.NamingException)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2