Search in sources :

Example 6 with OConfigurationException

use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.

the class OServer method getStoragePath.

public String getStoragePath(final String iName) {
    if (iName == null)
        throw new IllegalArgumentException("Storage path is null");
    final String name = iName.indexOf(':') > -1 ? iName.substring(iName.indexOf(':') + 1) : iName;
    final String dbName = Orient.isRegisterDatabaseByPath() ? getDatabaseDirectory() + name : name;
    final String dbPath = Orient.isRegisterDatabaseByPath() ? dbName : getDatabaseDirectory() + name;
    if (dbPath.contains(".."))
        throw new IllegalArgumentException("Storage path is invalid because it contains '..'");
    if (dbPath.contains("*"))
        throw new IllegalArgumentException("Storage path is invalid because of the wildcard '*'");
    if (dbPath.startsWith("/")) {
        if (!dbPath.startsWith(getDatabaseDirectory()))
            throw new IllegalArgumentException("Storage path is invalid because it points to an absolute directory");
    }
    final OStorage stg = Orient.instance().getStorage(dbName);
    if (stg != null)
        // ALREADY OPEN
        return stg.getURL();
    // SEARCH IN CONFIGURED PATHS
    final OServerConfiguration configuration = serverCfg.getConfiguration();
    String dbURL = configuration.getStoragePath(name);
    if (dbURL == null) {
        // SEARCH IN DEFAULT DATABASE DIRECTORY
        if (new File(OIOUtils.getPathFromDatabaseName(dbPath) + "/database.ocf").exists())
            dbURL = "plocal:" + dbPath;
        else
            throw new OConfigurationException("Database '" + name + "' is not configured on server (home=" + getDatabaseDirectory() + ")");
    }
    return dbURL;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OStorage(com.orientechnologies.orient.core.storage.OStorage) File(java.io.File)

Example 7 with OConfigurationException

use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.

the class OObjectSerializerHelper method invokeCallback.

public static void invokeCallback(final Object iPojo, final ODocument iDocument, final Class<?> iAnnotation) {
    final Method m = callbacks.get(iPojo.getClass().getSimpleName() + "." + iAnnotation.getSimpleName());
    if (m != null)
        try {
            if (m.getParameterTypes().length > 0)
                m.invoke(iPojo, iDocument);
            else
                m.invoke(iPojo);
        } catch (Exception e) {
            throw OException.wrapException(new OConfigurationException("Error on executing user callback '" + m.getName() + "' annotated with '" + iAnnotation.getSimpleName() + "'"), e);
        }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) Method(java.lang.reflect.Method) OException(com.orientechnologies.common.exception.OException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) OObjectNotDetachedException(com.orientechnologies.orient.object.db.OObjectNotDetachedException) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException)

Example 8 with OConfigurationException

use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.

the class OObjectSerializerHelper method getObjectID.

public static ORecordId getObjectID(final ODatabasePojoAbstract<?> iDb, final Object iPojo) {
    getClassFields(iPojo.getClass());
    final Field idField = fieldIds.get(iPojo.getClass());
    if (idField != null) {
        final Object id = getFieldValue(iPojo, idField.getName());
        if (id != null) {
            // FOUND
            if (id instanceof ORecordId) {
                return (ORecordId) id;
            } else if (id instanceof Number) {
                // TREATS AS CLUSTER POSITION
                final OClass cls = iDb.getMetadata().getSchema().getClass(iPojo.getClass());
                if (cls == null)
                    throw new OConfigurationException("Class " + iPojo.getClass() + " is not managed by current database");
                return new ORecordId(cls.getDefaultClusterId(), ((Number) id).longValue());
            } else if (id instanceof String)
                return new ORecordId((String) id);
        }
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseObject(com.orientechnologies.orient.core.db.object.ODatabaseObject) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 9 with OConfigurationException

use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.

the class OServer method activate.

@SuppressWarnings("unchecked")
public OServer activate() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    try {
        serverSecurity = new ODefaultServerSecurity(this, serverCfg);
        Orient.instance().setSecurity(serverSecurity);
        // Checks to see if the OrientDB System Database exists and creates it if not.
        // Make sure this happens after setSecurityFactory() is called.
        initSystemDatabase();
        for (OServerLifecycleListener l : lifecycleListeners) l.onBeforeActivate();
        final OServerConfiguration configuration = serverCfg.getConfiguration();
        tokenHandler = new OTokenHandlerImpl(this);
        if (configuration.network != null) {
            // REGISTER/CREATE SOCKET FACTORIES
            if (configuration.network.sockets != null) {
                for (OServerSocketFactoryConfiguration f : configuration.network.sockets) {
                    Class<? extends OServerSocketFactory> fClass = (Class<? extends OServerSocketFactory>) loadClass(f.implementation);
                    OServerSocketFactory factory = fClass.newInstance();
                    try {
                        factory.config(f.name, f.parameters);
                        networkSocketFactories.put(f.name, factory);
                    } catch (OConfigurationException e) {
                        OLogManager.instance().error(this, "Error creating socket factory", e);
                    }
                }
            }
            // REGISTER PROTOCOLS
            for (OServerNetworkProtocolConfiguration p : configuration.network.protocols) networkProtocols.put(p.name, (Class<? extends ONetworkProtocol>) loadClass(p.implementation));
            // STARTUP LISTENERS
            for (OServerNetworkListenerConfiguration l : configuration.network.listeners) networkListeners.add(new OServerNetworkListener(this, networkSocketFactories.get(l.socket), l.ipAddress, l.portRange, l.protocol, networkProtocols.get(l.protocol), l.parameters, l.commands));
        } else
            OLogManager.instance().warn(this, "Network configuration was not found");
        try {
            loadStorages();
            loadUsers();
            loadDatabases();
        } catch (IOException e) {
            final String message = "Error on reading server configuration";
            OLogManager.instance().error(this, message, e);
            throw OException.wrapException(new OConfigurationException(message), e);
        }
        registerPlugins();
        for (OServerLifecycleListener l : lifecycleListeners) l.onAfterActivate();
        running = true;
        String httpAddress = "localhost:2480";
        for (OServerNetworkListener listener : getNetworkListeners()) {
            if (listener.getProtocolType().getName().equals(ONetworkProtocolHttpDb.class.getName()))
                httpAddress = listener.getListeningAddress(true);
        }
        OLogManager.instance().info(this, "OrientDB Studio available at $ANSI{blue http://%s/studio/index.html}", httpAddress);
        OLogManager.instance().info(this, "$ANSI{green:italic OrientDB Server is active} v" + OConstants.getVersion() + ".");
    } catch (ClassNotFoundException e) {
        running = false;
        throw e;
    } catch (InstantiationException e) {
        running = false;
        throw e;
    } catch (IllegalAccessException e) {
        running = false;
        throw e;
    } catch (RuntimeException e) {
        running = false;
        throw e;
    } finally {
        startupLatch.countDown();
    }
    return this;
}
Also used : OServerSocketFactory(com.orientechnologies.orient.server.network.OServerSocketFactory) IOException(java.io.IOException) OTokenHandlerImpl(com.orientechnologies.orient.server.token.OTokenHandlerImpl) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ODefaultServerSecurity(com.orientechnologies.orient.server.security.ODefaultServerSecurity) ONetworkProtocol(com.orientechnologies.orient.server.network.protocol.ONetworkProtocol) OServerNetworkListener(com.orientechnologies.orient.server.network.OServerNetworkListener) ONetworkProtocolHttpDb(com.orientechnologies.orient.server.network.protocol.http.ONetworkProtocolHttpDb)

Example 10 with OConfigurationException

use of com.orientechnologies.orient.core.exception.OConfigurationException in project orientdb by orientechnologies.

the class ODistributedConfiguration method getDataCenterServers.

/**
   * Returns the list of servers in a data center.
   *
   * @param dataCenter
   *          Data center name
   * @throws OConfigurationException
   *           if the list of servers is not found in data center configuration
   */
public List<String> getDataCenterServers(final String dataCenter) {
    synchronized (configuration) {
        final ODocument dc = getDataCenterConfiguration(dataCenter);
        final List<String> servers = dc.field(SERVERS);
        if (servers == null || servers.isEmpty())
            throw new OConfigurationException("Data center '" + dataCenter + "' does not contain any server in distributed database configuration");
        return new ArrayList<String>(servers);
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)43 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)16 IOException (java.io.IOException)12 OException (com.orientechnologies.common.exception.OException)9 File (java.io.File)8 OIOException (com.orientechnologies.common.io.OIOException)5 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 OSystemException (com.orientechnologies.common.exception.OSystemException)3 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)3 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)3 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)3 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OStorage (com.orientechnologies.orient.core.storage.OStorage)2 OETLProcessHaltedException (com.orientechnologies.orient.etl.OETLProcessHaltedException)2 OServerConfigurationManager (com.orientechnologies.orient.server.config.OServerConfigurationManager)2 OServerNetworkListener (com.orientechnologies.orient.server.network.OServerNetworkListener)2 KeyStore (java.security.KeyStore)2