Search in sources :

Example 11 with OServerParameterConfiguration

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;
        }
    }
}
Also used : OServerConfiguration(com.orientechnologies.orient.server.config.OServerConfiguration) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OConsoleReader(com.orientechnologies.common.console.OConsoleReader) ODefaultConsoleReader(com.orientechnologies.common.console.ODefaultConsoleReader) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) OServerHandlerConfiguration(com.orientechnologies.orient.server.config.OServerHandlerConfiguration) OIOException(com.orientechnologies.common.io.OIOException)

Example 12 with OServerParameterConfiguration

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);
}
Also used : OAutomaticBackup(com.orientechnologies.orient.server.handler.OAutomaticBackup) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) FileInputStream(java.io.FileInputStream) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with OServerParameterConfiguration

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);
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 14 with OServerParameterConfiguration

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);
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) OContextConfiguration(com.orientechnologies.orient.core.config.OContextConfiguration)

Example 15 with OServerParameterConfiguration

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);
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)18 File (java.io.File)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Date (java.util.Date)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 FileInputStream (java.io.FileInputStream)4 Test (org.junit.Test)4 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2 ODatabaseImport (com.orientechnologies.orient.core.db.tool.ODatabaseImport)2 OAutomaticBackup (com.orientechnologies.orient.server.handler.OAutomaticBackup)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 OConsoleReader (com.orientechnologies.common.console.OConsoleReader)1 ODefaultConsoleReader (com.orientechnologies.common.console.ODefaultConsoleReader)1 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)1 OContextConfiguration (com.orientechnologies.orient.core.config.OContextConfiguration)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OServerConfiguration (com.orientechnologies.orient.server.config.OServerConfiguration)1