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;
}
}
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class LuceneAutomaticBackupRestoreTest method shouldBackupAndRestore.
@Test
public void shouldBackupAndRestore() 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}.zip");
doc.field("targetDirectory", BACKUPDIR);
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();
FileInputStream stream = new FileInputStream(new File(BACKUFILE + ".zip"));
databaseDocumentTx.restore(stream, null, null, null);
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 OJMXPlugin method config.
@Override
public void config(final OServer oServer, final OServerParameterConfiguration[] iParams) {
for (OServerParameterConfiguration param : iParams) {
if (param.name.equalsIgnoreCase("enabled")) {
if (!Boolean.parseBoolean(param.value))
// DISABLE IT
return;
} else if (param.name.equalsIgnoreCase("profilerManaged"))
profilerManaged = Boolean.parseBoolean(param.value);
}
OLogManager.instance().info(this, "JMX plugin installed and active: profilerManaged=%s", profilerManaged);
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
if (profilerManaged) {
// REGISTER THE PROFILER
onProfiler = new ObjectName("com.orientechnologies.common.profiler:type=OProfilerMXBean");
if (mBeanServer.isRegistered(onProfiler))
mBeanServer.unregisterMBean(onProfiler);
mBeanServer.registerMBean(Orient.instance().getProfiler(), onProfiler);
}
} catch (Exception e) {
throw OException.wrapException(new OConfigurationException("Cannot initialize JMX server"), e);
}
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class OServerNetworkListener method readParameters.
/**
* Initializes connection parameters by the reading XML configuration. If not specified, get the parameters defined as global
* configuration.
*
* @param iServerConfig
*/
private void readParameters(final OContextConfiguration iServerConfig, final OServerParameterConfiguration[] iParameters) {
configuration = new OContextConfiguration(iServerConfig);
// SET PARAMETERS
if (iParameters != null && iParameters.length > 0) {
// CONVERT PARAMETERS IN MAP TO INTIALIZE THE CONTEXT-CONFIGURATION
for (OServerParameterConfiguration param : iParameters) configuration.setValue(param.name, param.value);
}
socketBufferSize = configuration.getValueAsInteger(OGlobalConfiguration.NETWORK_SOCKET_BUFFER_SIZE);
}
use of com.orientechnologies.orient.server.config.OServerParameterConfiguration in project orientdb by orientechnologies.
the class OrientTokenHandler method config.
@Override
public void config(final OServer iServer, final OServerParameterConfiguration[] iParams) {
String key = null;
Long baseSession = null;
String algorithm = null;
for (OServerParameterConfiguration param : iParams) {
if (param.name.equalsIgnoreCase("enabled")) {
if (!Boolean.parseBoolean(param.value))
return;
} else if (param.name.equalsIgnoreCase(SIGN_KEY_PAR)) {
key = param.value;
} else if (param.name.equalsIgnoreCase(SESSION_LENGHT_PAR)) {
baseSession = Long.parseLong(param.value);
} else if (param.name.equalsIgnoreCase(ENCRYPTION_ALGORITHM_PAR)) {
algorithm = param.value;
try {
Mac.getInstance(algorithm);
} catch (NoSuchAlgorithmException nsa) {
throw new IllegalArgumentException("Cannot find encryption algorithm '" + algorithm + "'", nsa);
}
}
}
if (key != null)
OGlobalConfiguration.NETWORK_TOKEN_SECRETKEY.setValue(key);
if (baseSession != null)
OGlobalConfiguration.NETWORK_TOKEN_EXPIRE_TIMEOUT.setValue(baseSession);
if (algorithm != null)
OGlobalConfiguration.NETWORK_TOKEN_ENCRYPTION_ALGORITHM.setValue(algorithm);
}
Aggregations