Search in sources :

Example 21 with OConfigurationException

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

the class OClassTrigger method executeFunction.

private RESULT executeFunction(final ODocument iDocument, final OFunction func) {
    if (func == null)
        return RESULT.RECORD_NOT_CHANGED;
    final OScriptManager scriptManager = Orient.instance().getScriptManager();
    final OPartitionedObjectPool.PoolEntry<ScriptEngine> entry = scriptManager.acquireDatabaseEngine(database.getName(), func.getLanguage());
    final ScriptEngine scriptEngine = entry.object;
    try {
        final Bindings binding = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
        scriptManager.bind(binding, (ODatabaseDocumentTx) database, null, null);
        binding.put("doc", iDocument);
        String result = null;
        try {
            if (func.getLanguage() == null)
                throw new OConfigurationException("Database function '" + func.getName() + "' has no language");
            final String funcStr = scriptManager.getFunctionDefinition(func);
            if (funcStr != null) {
                try {
                    scriptEngine.eval(funcStr);
                } catch (ScriptException e) {
                    scriptManager.throwErrorMessage(e, funcStr);
                }
            }
            if (scriptEngine instanceof Invocable) {
                final Invocable invocableEngine = (Invocable) scriptEngine;
                Object[] EMPTY = OCommonConst.EMPTY_OBJECT_ARRAY;
                result = (String) invocableEngine.invokeFunction(func.getName(), EMPTY);
            }
        } catch (ScriptException e) {
            throw OException.wrapException(new OCommandScriptException("Error on execution of the script", func.getName(), e.getColumnNumber()), e);
        } catch (NoSuchMethodException e) {
            throw OException.wrapException(new OCommandScriptException("Error on execution of the script", func.getName(), 0), e);
        } catch (OCommandScriptException e) {
            // PASS THROUGH
            throw e;
        } finally {
            scriptManager.unbind(binding, null, null);
        }
        if (result == null) {
            return RESULT.RECORD_NOT_CHANGED;
        }
        return RESULT.valueOf(result);
    } finally {
        scriptManager.releaseDatabaseEngine(func.getLanguage(), database.getName(), entry);
    }
}
Also used : OCommandScriptException(com.orientechnologies.orient.core.command.script.OCommandScriptException) OScriptManager(com.orientechnologies.orient.core.command.script.OScriptManager) OCommandScriptException(com.orientechnologies.orient.core.command.script.OCommandScriptException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OPartitionedObjectPool(com.orientechnologies.common.concur.resource.OPartitionedObjectPool)

Example 22 with OConfigurationException

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

the class OIndexAbstract method indexCluster.

protected long[] indexCluster(final String clusterName, final OProgressListener iProgressListener, long documentNum, long documentIndexed, long documentTotal) {
    try {
        for (final ORecord record : getDatabase().browseCluster(clusterName)) {
            if (Thread.interrupted())
                throw new OCommandExecutionException("The index rebuild has been interrupted");
            if (record instanceof ODocument) {
                final ODocument doc = (ODocument) record;
                if (indexDefinition == null)
                    throw new OConfigurationException("Index '" + name + "' cannot be rebuilt because has no a valid definition (" + indexDefinition + ")");
                final Object fieldValue = indexDefinition.getDocumentValueToIndex(doc);
                if (fieldValue != null || !indexDefinition.isNullValuesIgnored()) {
                    try {
                        populateIndex(doc, fieldValue);
                    } catch (OTooBigIndexKeyException e) {
                        OLogManager.instance().error(this, "Exception during index rebuild. Exception was caused by following key/ value pair - key %s, value %s." + " Rebuild will continue from this point", e, fieldValue, doc.getIdentity());
                    } catch (OIndexException e) {
                        OLogManager.instance().error(this, "Exception during index rebuild. Exception was caused by following key/ value pair - key %s, value %s." + " Rebuild will continue from this point", e, fieldValue, doc.getIdentity());
                    }
                    ++documentIndexed;
                }
            }
            documentNum++;
            if (iProgressListener != null)
                iProgressListener.onProgress(this, documentNum, (float) (documentNum * 100.0 / documentTotal));
        }
    } catch (NoSuchElementException e) {
    // END OF CLUSTER REACHED, IGNORE IT
    }
    return new long[] { documentNum, documentIndexed };
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORecord(com.orientechnologies.orient.core.record.ORecord) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 23 with OConfigurationException

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

the class ORuntimeKeyIndexDefinition method serializeFromStream.

@Override
protected void serializeFromStream() {
    super.serializeFromStream();
    final byte keySerializerId = ((Number) document.field("keySerializerId")).byteValue();
    serializer = (OBinarySerializer<T>) OBinarySerializerFactory.getInstance().getObjectSerializer(keySerializerId);
    if (serializer == null)
        throw new OConfigurationException("Runtime index definition cannot find binary serializer with id=" + keySerializerId + ". Assure to plug custom serializer into the server.");
    String collateField = document.field("collate");
    if (collateField == null)
        collateField = ODefaultCollate.NAME;
    setNullValuesIgnored(!Boolean.FALSE.equals(document.<Boolean>field("nullValuesIgnored")));
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException)

Example 24 with OConfigurationException

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

the class OSchemaShared method fromStream.

/**
   * Binds ODocument to POJO.
   */
@Override
public void fromStream() {
    rwSpinLock.acquireWriteLock();
    modificationCounter.get().increment();
    try {
        // READ CURRENT SCHEMA VERSION
        final Integer schemaVersion = (Integer) document.field("schemaVersion");
        if (schemaVersion == null) {
            OLogManager.instance().error(this, "Database's schema is empty! Recreating the system classes and allow the opening of the database but double check the integrity of the database");
            return;
        } else if (schemaVersion != CURRENT_VERSION_NUMBER && VERSION_NUMBER_V5 != schemaVersion) {
            // HANDLE SCHEMA UPGRADE
            throw new OConfigurationException("Database schema is different. Please export your old database with the previous version of OrientDB and reimport it using the current one.");
        }
        properties.clear();
        propertiesByNameType.clear();
        List<ODocument> globalProperties = document.field("globalProperties");
        boolean hasGlobalProperties = false;
        if (globalProperties != null) {
            hasGlobalProperties = true;
            for (ODocument oDocument : globalProperties) {
                OGlobalPropertyImpl prop = new OGlobalPropertyImpl();
                prop.fromDocument(oDocument);
                ensurePropertiesSize(prop.getId());
                properties.set(prop.getId(), prop);
                propertiesByNameType.put(prop.getName() + "|" + prop.getType().name(), prop);
            }
        }
        // REGISTER ALL THE CLASSES
        clustersToClasses.clear();
        final Map<String, OClass> newClasses = new HashMap<String, OClass>();
        OClassImpl cls;
        Collection<ODocument> storedClasses = document.field("classes");
        for (ODocument c : storedClasses) {
            cls = new OClassImpl(this, c, (String) c.field("name"));
            cls.fromStream();
            if (classes.containsKey(cls.getName().toLowerCase())) {
                cls = (OClassImpl) classes.get(cls.getName().toLowerCase());
                cls.fromStream(c);
            }
            newClasses.put(cls.getName().toLowerCase(), cls);
            if (cls.getShortName() != null)
                newClasses.put(cls.getShortName().toLowerCase(), cls);
            addClusterClassMap(cls);
        }
        classes.clear();
        classes.putAll(newClasses);
        // REBUILD THE INHERITANCE TREE
        Collection<String> superClassNames;
        String legacySuperClassName;
        List<OClass> superClasses;
        OClass superClass;
        for (ODocument c : storedClasses) {
            superClassNames = c.field("superClasses");
            legacySuperClassName = c.field("superClass");
            if (superClassNames == null)
                superClassNames = new ArrayList<String>();
            else
                superClassNames = new HashSet<String>(superClassNames);
            if (legacySuperClassName != null && !superClassNames.contains(legacySuperClassName))
                superClassNames.add(legacySuperClassName);
            if (!superClassNames.isEmpty()) {
                // HAS A SUPER CLASS or CLASSES
                cls = (OClassImpl) classes.get(((String) c.field("name")).toLowerCase());
                superClasses = new ArrayList<OClass>(superClassNames.size());
                for (String superClassName : superClassNames) {
                    superClass = classes.get(superClassName.toLowerCase());
                    if (superClass == null)
                        throw new OConfigurationException("Super class '" + superClassName + "' was declared in class '" + cls.getName() + "' but was not found in schema. Remove the dependency or create the class to continue.");
                    superClasses.add(superClass);
                }
                cls.setSuperClassesInternal(superClasses);
            }
        }
        if (document.containsField("blobClusters"))
            blobClusters = document.field("blobClusters");
        if (!hasGlobalProperties) {
            if (getDatabase().getStorage().getUnderlying() instanceof OAbstractPaginatedStorage)
                saveInternal();
        }
    } finally {
        version++;
        modificationCounter.get().decrement();
        rwSpinLock.releaseWriteLock();
    }
}
Also used : OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OAbstractPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 25 with OConfigurationException

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

the class OSocketFactory method createSSLContext.

protected SSLContext createSSLContext() {
    try {
        if (keyStorePath != null && trustStorePath != null) {
            if (keyStorePassword == null || keyStorePassword.equals("")) {
                throw new OConfigurationException("Please provide a keystore password");
            }
            if (trustStorePassword == null || trustStorePassword.equals("")) {
                throw new OConfigurationException("Please provide a truststore password");
            }
            SSLContext context = SSLContext.getInstance("TLS");
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            KeyStore keyStore = KeyStore.getInstance(keyStoreType);
            char[] keyStorePass = keyStorePassword.toCharArray();
            keyStore.load(getAsStream(keyStorePath), keyStorePass);
            kmf.init(keyStore, keyStorePass);
            TrustManagerFactory tmf = null;
            if (trustStorePath != null) {
                tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                KeyStore trustStore = KeyStore.getInstance(trustStoreType);
                char[] trustStorePass = trustStorePassword.toCharArray();
                trustStore.load(getAsStream(trustStorePath), trustStorePass);
                tmf.init(trustStore);
            }
            context.init(kmf.getKeyManagers(), (tmf == null ? null : tmf.getTrustManagers()), null);
            return context;
        } else {
            return SSLContext.getDefault();
        }
    } catch (Exception e) {
        throw OException.wrapException(new OConfigurationException("Failed to create ssl context"), e);
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

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