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;
}
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);
}
}
}
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);
}
}
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;
}
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;
}
Aggregations