Search in sources :

Example 1 with OGlobalConfiguration

use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method create.

@Override
public <DB extends ODatabase> DB create(final Map<OGlobalConfiguration, Object> iInitialSettings) {
    setupThreadOwner();
    activateOnCurrentThread();
    try {
        if (status == STATUS.OPEN)
            throw new IllegalStateException("Database " + getName() + " is already open");
        if (storage == null)
            storage = Orient.instance().loadStorage(url);
        final OContextConfiguration ctxCfg = storage.getConfiguration().getContextConfiguration();
        if (iInitialSettings != null && !iInitialSettings.isEmpty()) {
            // SETUP INITIAL SETTINGS
            for (Map.Entry<OGlobalConfiguration, Object> e : iInitialSettings.entrySet()) {
                ctxCfg.setValue(e.getKey(), e.getValue());
            }
            storage.getConfiguration().update();
        }
        storage.create(properties);
        status = STATUS.OPEN;
        componentsFactory = getStorage().getComponentsFactory();
        localCache.startup();
        getStorage().getConfiguration().setRecordSerializer(getSerializer().toString());
        getStorage().getConfiguration().setRecordSerializerVersion(getSerializer().getCurrentVersion());
        // since 2.1 newly created databases use strict SQL validation by default
        getStorage().getConfiguration().setProperty(OStatement.CUSTOM_STRICT_SQL, "true");
        getStorage().getConfiguration().update();
        // THIS IF SHOULDN'T BE NEEDED, CREATE HAPPEN ONLY IN EMBEDDED
        if (!(getStorage() instanceof OStorageProxy))
            installHooksEmbedded();
        // CREATE THE DEFAULT SCHEMA WITH DEFAULT USER
        metadata = new OMetadataDefault(this);
        metadata.create();
        if (!(getStorage() instanceof OStorageProxy))
            registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR);
        registerHook(new OSecurityTrackerHook(metadata.getSecurity(), this), ORecordHook.HOOK_POSITION.LAST);
        final OUser usr = getMetadata().getSecurity().getUser(OUser.ADMIN);
        if (usr == null)
            user = null;
        else
            user = new OImmutableUser(getMetadata().getSecurity().getVersion(), usr);
        // WAKE UP DB LIFECYCLE LISTENER
        for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreate(getDatabaseOwner());
        // WAKE UP LISTENERS
        for (ODatabaseListener listener : browseListeners()) try {
            listener.onCreate(this);
        } catch (Throwable ignore) {
        }
    } catch (Exception e) {
        // REMOVE THE (PARTIAL) DATABASE
        try {
            drop();
        } catch (Exception ex) {
        // IGNORE IT
        }
        // DELETE THE STORAGE TOO
        try {
            if (storage == null)
                storage = Orient.instance().loadStorage(url);
            storage.delete();
        } catch (Exception ex) {
        // IGNORE IT
        }
        status = STATUS.CLOSED;
        owner.set(null);
        throw OException.wrapException(new ODatabaseException("Cannot create database '" + getName() + "'"), e);
    }
    return (DB) this;
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) OException(com.orientechnologies.common.exception.OException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) IOException(java.io.IOException) OCommandCacheHook(com.orientechnologies.orient.core.cache.OCommandCacheHook) OMetadataDefault(com.orientechnologies.orient.core.metadata.OMetadataDefault) OContextConfiguration(com.orientechnologies.orient.core.config.OContextConfiguration)

Example 2 with OGlobalConfiguration

use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.

the class OServerInfo method getGlobalProperties.

public static void getGlobalProperties(final OServer server, final OJSONWriter json) throws IOException {
    json.beginCollection(2, true, "globalProperties");
    for (OGlobalConfiguration c : OGlobalConfiguration.values()) {
        json.beginObject(3, true, null);
        json.writeAttribute(4, false, "key", c.getKey());
        json.writeAttribute(4, false, "description", c.getDescription());
        json.writeAttribute(4, false, "value", c.isHidden() ? "<hidden>" : c.getValue());
        json.writeAttribute(4, false, "defaultValue", c.getDefValue());
        json.writeAttribute(4, false, "canChange", c.isChangeableAtRuntime());
        json.endObject(3, true);
    }
    json.endCollection(2, true);
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration)

Example 3 with OGlobalConfiguration

use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.

the class OServerConfigurationLoaderXml method load.

public OServerConfiguration load() throws IOException {
    try {
        if (file != null) {
            fileLastModified = file.lastModified();
            String path = OFileUtils.getPath(file.getAbsolutePath());
            String current = OFileUtils.getPath(new File("").getAbsolutePath());
            if (path.startsWith(current))
                path = path.substring(current.length() + 1);
            OLogManager.instance().info(this, "Loading configuration from: %s...", path);
        } else {
            OLogManager.instance().info(this, "Loading configuration from input stream");
        }
        context = JAXBContext.newInstance(rootClass);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        unmarshaller.setSchema(null);
        final OServerConfiguration obj;
        if (file != null) {
            if (file.exists())
                obj = rootClass.cast(unmarshaller.unmarshal(file));
            else {
                OLogManager.instance().error(this, "Server configuration file not found: %s", file);
                return rootClass.getConstructor(OServerConfigurationLoaderXml.class).newInstance(this);
            }
            obj.location = file.getAbsolutePath();
        } else {
            obj = rootClass.cast(unmarshaller.unmarshal(inputStream));
            obj.location = "memory";
        }
        // AUTO CONFIGURE SYSTEM CONFIGURATION
        OGlobalConfiguration config;
        if (obj.properties != null)
            for (OServerEntryConfiguration prop : obj.properties) {
                try {
                    config = OGlobalConfiguration.findByKey(prop.name);
                    if (config != null) {
                        config.setValue(prop.value);
                    }
                } catch (Exception e) {
                }
            }
        return obj;
    } catch (Exception e) {
        // SYNTAX ERROR? PRINT AN EXAMPLE
        OLogManager.instance().error(this, "Invalid syntax. Below an example of how it should be:", e);
        try {
            context = JAXBContext.newInstance(rootClass);
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            Object example = rootClass.getConstructor(OServerConfigurationLoaderXml.class).newInstance(this);
            marshaller.marshal(example, System.out);
        } catch (Exception ex) {
        }
        throw new IOException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 4 with OGlobalConfiguration

use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method config.

@ConsoleCommand(description = "Return all the configuration values")
public void config() throws IOException {
    if (serverAdmin != null) {
        // REMOTE STORAGE
        final Map<String, String> values = serverAdmin.getGlobalConfigurations();
        message("\nREMOTE SERVER CONFIGURATION");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (Entry<String, String> p : values.entrySet()) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", p.getKey());
            row.field("VALUE", p.getValue());
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    } else {
        // LOCAL STORAGE
        message("\nLOCAL SERVER CONFIGURATION");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (OGlobalConfiguration cfg : OGlobalConfiguration.values()) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", cfg.getKey());
            row.field("VALUE", cfg.getValue());
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
    message("\n");
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 5 with OGlobalConfiguration

use of com.orientechnologies.orient.core.config.OGlobalConfiguration in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method configGet.

@ConsoleCommand(description = "Return the value of a configuration value")
public void configGet(@ConsoleParameter(name = "config-name", description = "Name of the configuration") final String iConfigName) throws IOException {
    final OGlobalConfiguration config = OGlobalConfiguration.findByKey(iConfigName);
    if (config == null)
        throw new IllegalArgumentException("Configuration variable '" + iConfigName + "' wasn't found");
    final String value;
    if (serverAdmin != null) {
        value = serverAdmin.getGlobalConfiguration(config);
        message("\nRemote configuration: ");
    } else {
        value = config.getValueAsString();
        message("\nLocal configuration: ");
    }
    out.println(iConfigName + " = " + value);
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Aggregations

OGlobalConfiguration (com.orientechnologies.orient.core.config.OGlobalConfiguration)13 ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)3 IOException (java.io.IOException)3 OException (com.orientechnologies.common.exception.OException)2 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OLockException (com.orientechnologies.common.concur.lock.OLockException)1 OIOException (com.orientechnologies.common.io.OIOException)1 OCommandCacheHook (com.orientechnologies.orient.core.cache.OCommandCacheHook)1 OContextConfiguration (com.orientechnologies.orient.core.config.OContextConfiguration)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 ODatabaseRecordThreadLocal (com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal)1 OMetadataDefault (com.orientechnologies.orient.core.metadata.OMetadataDefault)1 File (java.io.File)1 SocketException (java.net.SocketException)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1