Search in sources :

Example 16 with OConfigurationException

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

the class OAutomaticBackup method config.

@Override
public void config(final OServer iServer, final OServerParameterConfiguration[] iParams) {
    serverInstance = iServer;
    configuration = new ODocument();
    for (OServerParameterConfiguration param : iParams) {
        if (param.name.equalsIgnoreCase("config") && param.value.trim().length() > 0) {
            configFile = param.value.trim();
            final File f = new File(OSystemVariableResolver.resolveSystemVariables(configFile));
            if (!f.exists())
                throw new OConfigurationException("Automatic Backup configuration file '" + configFile + "' not found. Automatic Backup will be disabled");
            break;
        // LEGACY <v2.2: CONVERT ALL SETTINGS IN JSON
        } else if (param.name.equalsIgnoreCase("enabled")) {
            configuration.field("enabled", Boolean.parseBoolean(param.value));
        } else if (param.name.equalsIgnoreCase("delay"))
            configuration.field("delay", param.value);
        else if (param.name.equalsIgnoreCase("firstTime")) {
            configuration.field("firstTime", param.value);
        } else if (param.name.equalsIgnoreCase("target.directory"))
            configuration.field("targetDirectory", param.value);
        else if (param.name.equalsIgnoreCase("db.include") && param.value.trim().length() > 0)
            configuration.field("dbInclude", param.value);
        else if (param.name.equalsIgnoreCase("db.exclude") && param.value.trim().length() > 0)
            configuration.field("dbExclude", param.value);
        else if (param.name.equalsIgnoreCase("target.fileName"))
            configuration.field("targetFileName", param.value);
        else if (param.name.equalsIgnoreCase("bufferSize"))
            configuration.field("bufferSize", Integer.parseInt(param.value));
        else if (param.name.equalsIgnoreCase("compressionLevel"))
            configuration.field("compressionLevel", Integer.parseInt(param.value));
        else if (param.name.equalsIgnoreCase("mode"))
            configuration.field("mode", param.value);
        else if (param.name.equalsIgnoreCase("exportOptions"))
            configuration.field("exportOptions", param.value);
    }
    // LOAD CFG FROM JSON FILE. THIS FILE, IF SPECIFIED, OVERWRITE DEFAULT AND XML SETTINGS
    configure();
    if (delay <= 0)
        throw new OConfigurationException("Cannot find mandatory parameter 'delay'");
    if (!targetDirectory.endsWith("/"))
        targetDirectory += "/";
    final File filePath = new File(targetDirectory);
    if (filePath.exists()) {
        if (!filePath.isDirectory())
            throw new OConfigurationException("Parameter 'path' points to a file, not a directory");
    } else
        // CREATE BACKUP FOLDER(S) IF ANY
        filePath.mkdirs();
    OLogManager.instance().info(this, "Automatic Backup plugin installed and active: delay=%dms, firstTime=%s, targetDirectory=%s", delay, firstTime, targetDirectory);
    final TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            OLogManager.instance().info(this, "Scanning databases to backup...");
            int ok = 0, errors = 0;
            final Map<String, String> databases = serverInstance.getAvailableStorageNames();
            for (final Entry<String, String> database : databases.entrySet()) {
                final String dbName = database.getKey();
                final String dbURL = database.getValue();
                boolean include;
                if (includeDatabases.size() > 0)
                    include = includeDatabases.contains(dbName);
                else
                    include = true;
                if (excludeDatabases.contains(dbName))
                    include = false;
                if (include) {
                    ODatabaseDocumentInternal db = null;
                    try {
                        db = new ODatabaseDocumentTx(dbURL);
                        db.setProperty(ODatabase.OPTIONS.SECURITY.toString(), OSecurityNull.class);
                        db.open("admin", "aaa");
                        final long begin = System.currentTimeMillis();
                        switch(mode) {
                            case FULL_BACKUP:
                                fullBackupDatabase(dbURL, targetDirectory + getFileName(database), db);
                                OLogManager.instance().info(this, "Full Backup of database '" + dbURL + "' completed in " + (System.currentTimeMillis() - begin) + "ms");
                                break;
                            case INCREMENTAL_BACKUP:
                                incrementalBackupDatabase(dbURL, targetDirectory, db);
                                OLogManager.instance().info(this, "Incremental Backup of database '" + dbURL + "' completed in " + (System.currentTimeMillis() - begin) + "ms");
                                break;
                            case EXPORT:
                                exportDatabase(dbURL, targetDirectory + getFileName(database), db);
                                OLogManager.instance().info(this, "Export of database '" + dbURL + "' completed in " + (System.currentTimeMillis() - begin) + "ms");
                                break;
                        }
                        try {
                            for (OAutomaticBackupListener listener : listeners) {
                                listener.onBackupCompleted(dbName);
                            }
                        } catch (Exception e) {
                            OLogManager.instance().error(this, "Error on listener for database '" + dbURL, e);
                        }
                        ok++;
                    } catch (Exception e) {
                        OLogManager.instance().error(this, "Error on backup of database '" + dbURL + "' to directory: " + targetDirectory, e);
                        errors++;
                    } finally {
                        if (db != null)
                            db.close();
                    }
                }
            }
            OLogManager.instance().info(this, "Automatic Backup finished: %d ok, %d errors", ok, errors);
        }
    };
    if (firstTime == null)
        Orient.instance().scheduleTask(timerTask, delay, delay);
    else
        Orient.instance().scheduleTask(timerTask, firstTime, delay);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) ParseException(java.text.ParseException) IOException(java.io.IOException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OConfigurationException

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

the class OLinkTransformer method executeTransform.

@Override
public Object executeTransform(final Object input) {
    if (!(input instanceof OIdentifiable)) {
        log(OETLProcessor.LOG_LEVELS.DEBUG, "skip because input value is not a record, but rather an instance of class: %s", input.getClass());
        return null;
    }
    final ODocument doc = ((OIdentifiable) input).getRecord();
    final Object joinRuntimeValue;
    if (joinFieldName != null)
        joinRuntimeValue = doc.field(joinFieldName);
    else if (joinValue != null)
        joinRuntimeValue = resolve(joinValue);
    else
        joinRuntimeValue = null;
    Object result;
    if (OMultiValue.isMultiValue(joinRuntimeValue)) {
        // RESOLVE SINGLE JOINS
        final Collection<Object> singleJoinsResult = new ArrayList<Object>();
        for (Object o : OMultiValue.getMultiValueIterable(joinRuntimeValue)) {
            singleJoinsResult.add(lookup(o, true));
        }
        result = singleJoinsResult;
    } else
        result = lookup(joinRuntimeValue, true);
    log(OETLProcessor.LOG_LEVELS.DEBUG, "joinRuntimeValue=%s, lookupResult=%s", joinRuntimeValue, result);
    if (result != null) {
        if (linkFieldType != null) {
            // CONVERT IT
            if (linkFieldType == OType.LINK) {
                if (result instanceof Collection<?>) {
                    if (!((Collection) result).isEmpty())
                        result = ((Collection) result).iterator().next();
                    else
                        result = null;
                }
            } else if (linkFieldType == OType.LINKSET) {
                if (!(result instanceof Collection)) {
                    final Set<OIdentifiable> res = new HashSet<OIdentifiable>();
                    res.add((OIdentifiable) result);
                    result = res;
                }
            } else if (linkFieldType == OType.LINKLIST) {
                if (!(result instanceof Collection)) {
                    final List<OIdentifiable> res = new ArrayList<OIdentifiable>();
                    res.add((OIdentifiable) result);
                    result = res;
                }
            }
        }
        if (result == null) {
            // APPLY THE STRATEGY DEFINED IN unresolvedLinkAction
            switch(unresolvedLinkAction) {
                case CREATE:
                    if (lookup != null) {
                        final String[] lookupParts = lookup.split("\\.");
                        final ODocument linkedDoc = new ODocument(lookupParts[0]);
                        linkedDoc.field(lookupParts[1], joinRuntimeValue);
                        linkedDoc.save();
                        log(OETLProcessor.LOG_LEVELS.DEBUG, "created new document=%s", linkedDoc.getRecord());
                        result = linkedDoc;
                    } else
                        throw new OConfigurationException("Cannot create linked document because target class is unknown. Use 'lookup' field");
                    break;
                case ERROR:
                    processor.getStats().incrementErrors();
                    log(OETLProcessor.LOG_LEVELS.ERROR, "%s: ERROR Cannot resolve join for value '%s'", getName(), joinRuntimeValue);
                    break;
                case WARNING:
                    processor.getStats().incrementWarnings();
                    log(OETLProcessor.LOG_LEVELS.INFO, "%s: WARN Cannot resolve join for value '%s'", getName(), joinRuntimeValue);
                    break;
                case SKIP:
                    return null;
                case HALT:
                    throw new OETLProcessHaltedException("[Link transformer] Cannot resolve join for value '" + joinRuntimeValue + "'");
            }
        }
    }
    // SET THE TRANSFORMED FIELD BACK
    doc.field(linkFieldName, result);
    log(OETLProcessor.LOG_LEVELS.DEBUG, "set %s=%s in document=%s", linkFieldName, result, input);
    return input;
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OETLProcessHaltedException(com.orientechnologies.orient.etl.OETLProcessHaltedException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 18 with OConfigurationException

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

the class ODatabaseHelper method getConfigurationFile.

protected static File getConfigurationFile(final String iDirectory) {
    // LOAD SERVER CONFIG FILE TO EXTRACT THE ROOT'S PASSWORD
    String sysProperty = System.getProperty("orientdb.config.file");
    File file = new File(sysProperty != null ? sysProperty : "");
    if (!file.exists()) {
        sysProperty = System.getenv("CONFIG_FILE");
        file = new File(sysProperty != null ? sysProperty : "");
    }
    if (!file.exists())
        file = new File("../releases/orientdb-" + OConstants.ORIENT_VERSION + "/config/orientdb-server-config.xml");
    if (!file.exists())
        file = new File("../releases/orientdb-community-" + OConstants.ORIENT_VERSION + "/config/orientdb-server-config.xml");
    if (!file.exists())
        file = new File("../../releases/orientdb-" + OConstants.ORIENT_VERSION + "/config/orientdb-server-config.xml");
    if (!file.exists())
        file = new File("../../releases/orientdb-community-" + OConstants.ORIENT_VERSION + "/config/orientdb-server-config.xml");
    if (!file.exists() && iDirectory != null) {
        file = new File(iDirectory + "/config/orientdb-server-config.xml");
        if (!file.exists())
            file = new File("../" + iDirectory + "/config/orientdb-server-config.xml");
    }
    if (!file.exists())
        file = new File(OSystemVariableResolver.resolveSystemVariables("${" + Orient.ORIENTDB_HOME + "}/config/orientdb-server-config.xml"));
    if (!file.exists())
        throw new OConfigurationException("Cannot load file orientdb-server-config.xml to execute remote tests. Current directory is " + new File(".").getAbsolutePath());
    return file;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) File(java.io.File)

Example 19 with OConfigurationException

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

the class OScriptManager method getLibrary.

/**
   * Formats the library of functions for a language.
   * 
   * @param db
   *          Current database instance
   * @param iLanguage
   *          Language as filter
   * @return String containing all the functions
   */
public String getLibrary(final ODatabase<?> db, final String iLanguage) {
    if (db == null)
        // NO DB = NO LIBRARY
        return null;
    final StringBuilder code = new StringBuilder();
    final Set<String> functions = db.getMetadata().getFunctionLibrary().getFunctionNames();
    for (String fName : functions) {
        final OFunction f = db.getMetadata().getFunctionLibrary().getFunction(fName);
        if (f.getLanguage() == null)
            throw new OConfigurationException("Database function '" + fName + "' has no language");
        if (f.getLanguage().equalsIgnoreCase(iLanguage)) {
            final String def = getFunctionDefinition(f);
            if (def != null) {
                code.append(def);
                code.append("\n");
            }
        }
    }
    return code.length() == 0 ? null : code.toString();
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OFunction(com.orientechnologies.orient.core.metadata.function.OFunction)

Example 20 with OConfigurationException

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

the class Orient method loadStorage.

public OStorage loadStorage(String iURL) {
    if (iURL == null || iURL.length() == 0)
        throw new IllegalArgumentException("URL missed");
    if (iURL.endsWith("/"))
        iURL = iURL.substring(0, iURL.length() - 1);
    // SEARCH FOR ENGINE
    int pos = iURL.indexOf(':');
    if (pos <= 0)
        throw new OConfigurationException("Error in database URL: the engine was not specified. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL);
    final String engineName = iURL.substring(0, pos);
    engineLock.readLock().lock();
    try {
        final OEngine engine = engines.get(engineName.toLowerCase());
        if (engine == null)
            throw new OConfigurationException("Error on opening database: the engine '" + engineName + "' was not found. URL was: " + iURL + ". Registered engines are: " + engines.keySet());
        if (!engine.isRunning()) {
            final List<String> knownEngines = new ArrayList<String>(engines.keySet());
            if (!startEngine(engine))
                throw new OConfigurationException("Error on opening database: the engine '" + engineName + "' was unable to start. URL was: " + iURL + ". Registered engines was: " + knownEngines);
        }
        // SEARCH FOR DB-NAME
        iURL = iURL.substring(pos + 1);
        if (isWindowsOS()) {
            // WINDOWS ONLY: REMOVE DOUBLE SLASHES NOT AS PREFIX (WINDOWS PATH COULD NEED STARTING FOR "\\". EXAMPLE: "\\mydrive\db").
            // AT
            // THIS LEVEL BACKSLASHES ARRIVES AS SLASHES
            iURL = iURL.charAt(0) + iURL.substring(1).replace("//", "/");
        } else
            // REMOVE ANY //
            iURL = iURL.replace("//", "/");
        pos = iURL.indexOf('?');
        Map<String, String> parameters = null;
        String dbPath;
        if (pos > 0) {
            dbPath = iURL.substring(0, pos);
            iURL = iURL.substring(pos + 1);
            // PARSE PARAMETERS
            parameters = new HashMap<String, String>();
            String[] pairs = iURL.split("&");
            String[] kv;
            for (String pair : pairs) {
                kv = pair.split("=");
                if (kv.length < 2)
                    throw new OConfigurationException("Error on opening database: parameter has no value. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL);
                parameters.put(kv[0], kv[1]);
            }
        } else
            dbPath = iURL;
        if (registerDatabaseByPath) {
            try {
                dbPath = new File(dbPath).getCanonicalPath();
            } catch (IOException e) {
            // IGNORE IT
            }
        }
        final String dbName = registerDatabaseByPath ? dbPath : engine.getNameFromPath(dbPath);
        OStorage storage;
        // SEARCH IF ALREADY USED
        storage = storages.get(dbName);
        if (storage == null) {
            do {
                storage = engine.createStorage(dbPath, parameters);
            } while ((storage instanceof OIdentifiableStorage) && storageIds.putIfAbsent(((OIdentifiableStorage) storage).getId(), Boolean.TRUE) != null);
            final OStorage oldStorage = storages.putIfAbsent(dbName, storage);
            if (oldStorage != null)
                storage = oldStorage;
            for (OOrientListener l : browseListeners()) l.onStorageRegistered(storage);
        }
        return storage;
    } finally {
        engineLock.readLock().unlock();
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) IOException(java.io.IOException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OEngine(com.orientechnologies.orient.core.engine.OEngine) OIdentifiableStorage(com.orientechnologies.orient.core.storage.OIdentifiableStorage) File(java.io.File)

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