Search in sources :

Example 1 with OConfigurationException

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

the class ORestrictedAccessHook method onRecordBeforeCreate.

@Override
public RESULT onRecordBeforeCreate(final ODocument iDocument) {
    final OImmutableClass cls = ODocumentInternal.getImmutableSchemaClass(iDocument);
    if (cls != null && cls.isRestricted()) {
        String fieldNames = cls.getCustom(OSecurityShared.ONCREATE_FIELD);
        if (fieldNames == null)
            fieldNames = ORestrictedOperation.ALLOW_ALL.getFieldName();
        final String[] fields = fieldNames.split(",");
        String identityType = cls.getCustom(OSecurityShared.ONCREATE_IDENTITY_TYPE);
        if (identityType == null)
            identityType = "user";
        OIdentifiable identity = null;
        if (identityType.equals("user")) {
            final OSecurityUser user = database.getUser();
            if (user != null)
                identity = user.getIdentity();
        } else if (identityType.equals("role")) {
            final Set<? extends OSecurityRole> roles = database.getUser().getRoles();
            if (!roles.isEmpty())
                identity = roles.iterator().next().getIdentity();
        } else
            throw new OConfigurationException("Wrong custom field '" + OSecurityShared.ONCREATE_IDENTITY_TYPE + "' in class '" + cls.getName() + "' with value '" + identityType + "'. Supported ones are: 'user', 'role'");
        if (identity != null) {
            for (String f : fields) database.getMetadata().getSecurity().allowIdentity(iDocument, f, identity);
            return RESULT.RECORD_CHANGED;
        }
    }
    return RESULT.RECORD_NOT_CHANGED;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) Set(java.util.Set) OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 2 with OConfigurationException

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

the class OCommandCacheSoftRefs method changeConfig.

public void changeConfig(ODocument cfg) {
    synchronized (configuration) {
        ODocument oldConfig = configuration;
        configuration = cfg;
        configure();
        try {
            updateCfgOnDisk();
        } catch (IOException e) {
            configuration = oldConfig;
            configure();
            throw OException.wrapException(new OConfigurationException("Cannot change Command Cache Cache configuration file '" + CONFIG_FILE + "'. Command Cache will use default settings"), e);
        }
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OConfigurationException

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

the class OCommandCacheSoftRefs method initCache.

private void initCache() {
    configuration = new ODocument();
    configuration.field("enabled", enable);
    configuration.field("evictStrategy", evictStrategy.toString());
    configuration.field("minExecutionTime", minExecutionTime);
    configuration.field("maxResultsetSize", maxResultsetSize);
    try {
        ODocument diskConfig = loadConfiguration();
        if (diskConfig != null) {
            configuration = diskConfig;
            configure();
        } else {
            updateCfgOnDisk();
        }
    } catch (Exception e) {
        throw OException.wrapException(new OConfigurationException("Cannot change Command Cache Cache configuration file '" + CONFIG_FILE + "'. Command Cache will use default settings"), e);
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OConfigurationException

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

the class ODatabaseImport method importClusters.

private long importClusters() throws ParseException, IOException {
    listener.onMessage("\nImporting clusters...");
    long total = 0;
    jsonReader.readNext(OJSONReader.BEGIN_COLLECTION);
    boolean recreateManualIndex = false;
    if (exporterVersion <= 4) {
        removeDefaultClusters();
        recreateManualIndex = true;
    }
    final Set<String> indexesToRebuild = new HashSet<String>();
    @SuppressWarnings("unused") ORecordId rid = null;
    while (jsonReader.lastChar() != ']') {
        jsonReader.readNext(OJSONReader.BEGIN_OBJECT);
        String name = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"name\"").readString(OJSONReader.COMMA_SEPARATOR);
        if (name.length() == 0)
            name = null;
        name = OClassImpl.decodeClassName(name);
        if (name != null)
            // CHECK IF THE CLUSTER IS INCLUDED
            if (includeClusters != null) {
                if (!includeClusters.contains(name)) {
                    jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
                    continue;
                }
            } else if (excludeClusters != null) {
                if (excludeClusters.contains(name)) {
                    jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
                    continue;
                }
            }
        int id;
        if (exporterVersion < 9) {
            id = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"id\"").readInteger(OJSONReader.COMMA_SEPARATOR);
            String type = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"type\"").readString(OJSONReader.NEXT_IN_OBJECT);
        } else
            id = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"id\"").readInteger(OJSONReader.NEXT_IN_OBJECT);
        String type;
        if (jsonReader.lastChar() == ',')
            type = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"type\"").readString(OJSONReader.NEXT_IN_OBJECT);
        else
            type = "PHYSICAL";
        if (jsonReader.lastChar() == ',') {
            rid = new ORecordId(jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"rid\"").readString(OJSONReader.NEXT_IN_OBJECT));
        } else
            rid = null;
        listener.onMessage("\n- Creating cluster " + (name != null ? "'" + name + "'" : "NULL") + "...");
        int clusterId = name != null ? database.getClusterIdByName(name) : -1;
        if (clusterId == -1) {
            // CREATE IT
            if (!preserveClusterIDs)
                clusterId = database.addCluster(name);
            else {
                clusterId = database.addCluster(name, id, null);
                assert clusterId == id;
            }
        }
        if (clusterId != id) {
            if (!preserveClusterIDs) {
                if (database.countClusterElements(clusterId - 1) == 0) {
                    listener.onMessage("Found previous version: migrating old clusters...");
                    database.dropCluster(name, true);
                    database.addCluster("temp_" + clusterId, null);
                    clusterId = database.addCluster(name);
                } else
                    throw new OConfigurationException("Imported cluster '" + name + "' has id=" + clusterId + " different from the original: " + id + ". To continue the import drop the cluster '" + database.getClusterNameById(clusterId - 1) + "' that has " + database.countClusterElements(clusterId - 1) + " records");
            } else {
                database.dropCluster(clusterId, false);
                database.addCluster(name, id, null);
            }
        }
        if (name != null && !(name.equalsIgnoreCase(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME) || name.equalsIgnoreCase(OMetadataDefault.CLUSTER_INTERNAL_NAME) || name.equalsIgnoreCase(OMetadataDefault.CLUSTER_INDEX_NAME))) {
            if (!merge)
                database.command(new OCommandSQL("truncate cluster `" + name + "`")).execute();
            for (OIndex existingIndex : database.getMetadata().getIndexManager().getIndexes()) {
                if (existingIndex.getClusters().contains(name)) {
                    indexesToRebuild.add(existingIndex.getName());
                }
            }
        }
        listener.onMessage("OK, assigned id=" + clusterId);
        total++;
        jsonReader.readNext(OJSONReader.NEXT_IN_ARRAY);
    }
    jsonReader.readNext(OJSONReader.COMMA_SEPARATOR);
    listener.onMessage("\nRebuilding indexes of truncated clusters ...");
    for (final String indexName : indexesToRebuild) database.getMetadata().getIndexManager().getIndex(indexName).rebuild(new OProgressListener() {

        private long last = 0;

        @Override
        public void onBegin(Object iTask, long iTotal, Object metadata) {
            listener.onMessage("\n- Cluster content was updated: rebuilding index '" + indexName + "'...");
        }

        @Override
        public boolean onProgress(Object iTask, long iCounter, float iPercent) {
            final long now = System.currentTimeMillis();
            if (last == 0)
                last = now;
            else if (now - last > 1000) {
                listener.onMessage(String.format("\nIndex '%s' is rebuilding (%.2f/100)", indexName, iPercent));
                last = now;
            }
            return true;
        }

        @Override
        public void onCompletition(Object iTask, boolean iSucceed) {
            listener.onMessage(" Index " + indexName + " was successfully rebuilt.");
        }
    });
    listener.onMessage("\nDone " + indexesToRebuild.size() + " indexes were rebuilt.");
    if (recreateManualIndex) {
        database.addCluster(OMetadataDefault.CLUSTER_MANUAL_INDEX_NAME);
        database.getMetadata().getIndexManager().create();
        listener.onMessage("\nManual index cluster was recreated.");
    }
    listener.onMessage("\nDone. Imported " + total + " clusters");
    if (database.load(new ORecordId(database.getStorage().getConfiguration().indexMgrRecordId)) == null) {
        ODocument indexDocument = new ODocument();
        indexDocument.save(OMetadataDefault.CLUSTER_INTERNAL_NAME);
        database.getStorage().getConfiguration().indexMgrRecordId = indexDocument.getIdentity().toString();
        database.getStorage().getConfiguration().update();
    }
    return total;
}
Also used : ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OProgressListener(com.orientechnologies.common.listener.OProgressListener) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OConfigurationException

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

the class OETLProcessor method parse.

/**
   * Creates an ETL processor by setting the configuration of each component.
   *
   * @param iBeginBlocks  List of Block configurations to execute at the beginning of processing
   * @param iSource       Source component configuration
   * @param iExtractor    Extractor component configuration
   * @param iTransformers List of Transformer configurations
   * @param iLoader       Loader component configuration
   * @param iEndBlocks    List of Block configurations to execute at the end of processing
   * @param iContext      Execution Context
   *
   * @return Current OETProcessor instance
   **/
public OETLProcessor parse(final Collection<ODocument> iBeginBlocks, final ODocument iSource, final ODocument iExtractor, final Collection<ODocument> iTransformers, final ODocument iLoader, final Collection<ODocument> iEndBlocks, final OCommandContext iContext) {
    if (iExtractor == null)
        throw new IllegalArgumentException("No Extractor configured");
    context = iContext != null ? iContext : createDefaultContext();
    init();
    try {
        configureBeginBlocks(iBeginBlocks, iContext);
        configureSource(iSource, iContext);
        configureExtractors(iExtractor, iContext);
        copySkipDuplicatestoLoaderConf(iTransformers, iLoader);
        configureLoader(iLoader, iContext);
        //projecting cluster info to transformers
        if (iLoader.containsField("cluster")) {
            for (ODocument aTransformer : iTransformers) {
                aTransformer.field("cluster", iLoader.field("cluster"));
            }
        }
        configureTransformers(iTransformers, iContext);
        configureEndBlocks(iEndBlocks, iContext);
    // isn't working right now
    // analyzeFlow();
    } catch (Exception e) {
        throw OException.wrapException(new OConfigurationException("Error on creating ETL processor"), e);
    }
    return this;
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) 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