use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class ODistributedAbstractPlugin method config.
@SuppressWarnings("unchecked")
@Override
public void config(OServer oServer, OServerParameterConfiguration[] iParams) {
serverInstance = oServer;
oServer.setVariable("ODistributedAbstractPlugin", this);
for (OServerParameterConfiguration param : iParams) {
if (param.name.equalsIgnoreCase("enabled")) {
if (!Boolean.parseBoolean(OSystemVariableResolver.resolveSystemVariables(param.value))) {
// DISABLE IT
enabled = false;
return;
}
} else if (param.name.equalsIgnoreCase("nodeName")) {
nodeName = param.value;
if (nodeName.contains("."))
throw new OConfigurationException("Illegal node name '" + nodeName + "'. '.' is not allowed in node name");
} else if (param.name.startsWith(PAR_DEF_DISTRIB_DB_CONFIG)) {
setDefaultDatabaseConfigFile(param.value);
}
}
if (serverInstance.getUser("replicator") == null)
// DROP THE REPLICATOR USER. THIS USER WAS NEEDED BEFORE 2.2, BUT IT'S NOT REQUIRED ANYMORE
OLogManager.instance().config(this, "Found 'replicator' user. Starting from OrientDB v2.2 this internal user is no needed anymore. Removing it...");
try {
serverInstance.dropUser("replicator");
} catch (IOException e) {
throw OException.wrapException(new OConfigurationException("Error on deleting 'replicator' user"), e);
}
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class OServerSSLSocketFactory method config.
@Override
public void config(String name, final OServerParameterConfiguration[] iParameters) {
super.config(name, iParameters);
for (OServerParameterConfiguration param : iParameters) {
if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_CLIENT_AUTH)) {
clientAuth = Boolean.parseBoolean(param.value);
} else if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_KEYSTORE)) {
keyStorePath = param.value;
} else if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_KEYSTORE_PASSWORD)) {
keyStorePassword = param.value;
} else if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_KEYSTORE_TYPE)) {
keyStoreType = param.value;
} else if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_TRUSTSTORE)) {
trustStorePath = param.value;
} else if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_TRUSTSTORE_PASSWORD)) {
trustStorePassword = param.value;
} else if (param.name.equalsIgnoreCase(PARAM_NETWORK_SSL_TRUSTSTORE_TYPE)) {
trustStoreType = param.value;
}
}
if (keyStorePath == null) {
throw new OConfigurationException("Missing parameter " + PARAM_NETWORK_SSL_KEYSTORE);
} else if (keyStorePassword == null) {
throw new OConfigurationException("Missing parameter " + PARAM_NETWORK_SSL_KEYSTORE_PASSWORD);
}
keyStoreFile = new File(keyStorePath);
if (!keyStoreFile.isAbsolute()) {
keyStoreFile = new File(OSystemVariableResolver.resolveSystemVariables("${ORIENTDB_HOME}"), keyStorePath);
}
if (trustStorePath != null) {
trustStoreFile = new File(trustStorePath);
if (!trustStoreFile.isAbsolute()) {
trustStoreFile = new File(OSystemVariableResolver.resolveSystemVariables("${ORIENTDB_HOME}"), trustStorePath);
}
}
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration 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);
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class LuceneAutomaticBackupRestoreTest method shouldExportImport.
@Test
public void shouldExportImport() throws IOException, InterruptedException {
List<?> query = databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"));
Assert.assertEquals(query.size(), 1);
String jsonConfig = OIOUtils.readStreamAsString(getClass().getClassLoader().getResourceAsStream("automatic-backup.json"));
ODocument doc = new ODocument().fromJSON(jsonConfig);
doc.field("enabled", true);
doc.field("targetFileName", "${DBNAME}.json");
doc.field("targetDirectory", BACKUPDIR);
doc.field("mode", "EXPORT");
doc.field("dbInclude", new String[] { "LuceneAutomaticBackupRestoreTest" });
doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));
OIOUtils.writeFile(new File(tempFolder.getRoot().getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {};
aBackup.config(server, config);
final CountDownLatch latch = new CountDownLatch(1);
aBackup.registerListener(new OAutomaticBackup.OAutomaticBackupListener() {
@Override
public void onBackupCompleted(String database) {
latch.countDown();
}
});
latch.await();
aBackup.sendShutdown();
// RESTORE
databaseDocumentTx.drop();
databaseDocumentTx.create();
GZIPInputStream stream = new GZIPInputStream(new FileInputStream(BACKUFILE + ".json.gz"));
new ODatabaseImport(databaseDocumentTx, stream, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
}
}).importDatabase();
databaseDocumentTx.close();
// VERIFY
databaseDocumentTx.open("admin", "admin");
assertThat(databaseDocumentTx.countClass("City")).isEqualTo(1);
OIndex<?> index = databaseDocumentTx.getMetadata().getIndexManager().getIndex("City.name");
assertThat(index).isNotNull();
assertThat(index.getType()).isEqualTo(OClass.INDEX_TYPE.FULLTEXT.name());
assertThat(databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"))).hasSize(1);
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class ODistributedAbstractPlugin method assignNodeName.
protected void assignNodeName() {
// ORIENTDB_NODE_NAME ENV VARIABLE OR JVM SETTING
nodeName = OSystemVariableResolver.resolveVariable(NODE_NAME_ENV);
if (nodeName != null) {
nodeName = nodeName.trim();
if (nodeName.isEmpty())
nodeName = null;
}
if (nodeName == null) {
try {
// WAIT ANY LOG IS PRINTED
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println();
System.out.println();
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | WARNING: FIRST DISTRIBUTED RUN CONFIGURATION |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | This is the first time that the server is running as |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | distributed. Please type the name you want to assign to the |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | current server node. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | To avoid this message set the environment variable or JVM |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow | setting ORIENTDB_NODE_NAME to the server node name to use. |}"));
System.out.println(OAnsiCode.format("$ANSI{yellow +---------------------------------------------------------------+}"));
System.out.print(OAnsiCode.format("\n$ANSI{yellow Node name [BLANK=auto generate it]: }"));
OConsoleReader reader = new ODefaultConsoleReader();
try {
nodeName = reader.readLine();
} catch (IOException e) {
}
if (nodeName != null) {
nodeName = nodeName.trim();
if (nodeName.isEmpty())
nodeName = null;
}
}
if (nodeName == null)
// GENERATE NODE NAME
this.nodeName = "node" + System.currentTimeMillis();
OLogManager.instance().warn(this, "Assigning distributed node name: %s", this.nodeName);
// SALVE THE NODE NAME IN CONFIGURATION
boolean found = false;
final OServerConfiguration cfg = serverInstance.getConfiguration();
for (OServerHandlerConfiguration h : cfg.handlers) {
if (h.clazz.equals(getClass().getName())) {
for (OServerParameterConfiguration p : h.parameters) {
if (p.name.equals("nodeName")) {
found = true;
p.value = this.nodeName;
break;
}
}
if (!found) {
h.parameters = OArrays.copyOf(h.parameters, h.parameters.length + 1);
h.parameters[h.parameters.length - 1] = new OServerParameterConfiguration("nodeName", this.nodeName);
}
try {
serverInstance.saveConfiguration();
} catch (IOException e) {
throw OException.wrapException(new OConfigurationException("Cannot save server configuration"), e);
}
break;
}
}
}
Aggregations