Search in sources :

Example 1 with OServerHandlerConfiguration

use of com.orientechnologies.orient.server.config.OServerHandlerConfiguration 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 2 with OServerHandlerConfiguration

use of com.orientechnologies.orient.server.config.OServerHandlerConfiguration in project orientdb by orientechnologies.

the class OServerTest method setUp.

@Before
public void setUp() throws Exception {
    OLogManager.instance().setConsoleLevel(Level.OFF.getName());
    prevPassword = System.setProperty("ORIENTDB_ROOT_PASSWORD", "rootPassword");
    prevOrientHome = System.setProperty("ORIENTDB_HOME", "./target/testhome");
    allowJvmShutdownPrev = OGlobalConfiguration.ENVIRONMENT_ALLOW_JVM_SHUTDOWN.getValueAsBoolean();
    OGlobalConfiguration.ENVIRONMENT_ALLOW_JVM_SHUTDOWN.setValue(false);
    conf = new OServerConfiguration();
    conf.handlers = new ArrayList<OServerHandlerConfiguration>();
    OServerHandlerConfiguration handlerConfiguration = new OServerHandlerConfiguration();
    handlerConfiguration.clazz = OServerFailingOnStarupPluginStub.class.getName();
    handlerConfiguration.parameters = new OServerParameterConfiguration[0];
    conf.handlers.add(0, handlerConfiguration);
}
Also used : OServerConfiguration(com.orientechnologies.orient.server.config.OServerConfiguration) OServerHandlerConfiguration(com.orientechnologies.orient.server.config.OServerHandlerConfiguration) Before(org.junit.Before)

Aggregations

OServerConfiguration (com.orientechnologies.orient.server.config.OServerConfiguration)2 OServerHandlerConfiguration (com.orientechnologies.orient.server.config.OServerHandlerConfiguration)2 OConsoleReader (com.orientechnologies.common.console.OConsoleReader)1 ODefaultConsoleReader (com.orientechnologies.common.console.ODefaultConsoleReader)1 OIOException (com.orientechnologies.common.io.OIOException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)1 Before (org.junit.Before)1