Search in sources :

Example 1 with OHazelcastPlugin

use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.

the class OCommandExecutorSQLHAStatus method execute.

/**
   * Execute the command.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.SERVER, "status", ORole.PERMISSION_READ);
    final String dbUrl = database.getURL();
    final String path = dbUrl.substring(dbUrl.indexOf(":") + 1);
    final OServer serverInstance = OServer.getInstanceByPath(path);
    final OHazelcastPlugin dManager = (OHazelcastPlugin) serverInstance.getDistributedManager();
    if (dManager == null || !dManager.isEnabled())
        throw new OCommandExecutionException("OrientDB is not started in distributed mode");
    final String databaseName = database.getName();
    final ODistributedConfiguration cfg = dManager.getDatabaseConfiguration(databaseName);
    if (parsedStatement.outputText) {
        final StringBuilder output = new StringBuilder();
        if (parsedStatement.servers)
            output.append(ODistributedOutput.formatServerStatus(dManager, dManager.getClusterConfiguration()));
        if (parsedStatement.db)
            output.append(ODistributedOutput.formatClusterTable(dManager, databaseName, cfg, dManager.getAvailableNodes(databaseName)));
        if (parsedStatement.latency)
            output.append(ODistributedOutput.formatLatency(dManager, dManager.getClusterConfiguration()));
        if (parsedStatement.messages)
            output.append(ODistributedOutput.formatMessages(dManager, dManager.getClusterConfiguration()));
        return output.toString();
    }
    final ODocument output = new ODocument();
    if (parsedStatement.servers)
        output.field("servers", dManager.getClusterConfiguration(), OType.EMBEDDED);
    if (parsedStatement.db)
        output.field("database", cfg.getDocument(), OType.EMBEDDED);
    return output;
}
Also used : OServer(com.orientechnologies.orient.server.OServer) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODistributedConfiguration(com.orientechnologies.orient.server.distributed.ODistributedConfiguration) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OHazelcastPlugin

use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.

the class OCommandExecutorSQLHASyncDatabase method execute.

/**
   * Execute the SYNC DATABASE.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.DATABASE, "sync", ORole.PERMISSION_UPDATE);
    final OStorage stg = database.getStorage();
    if (!(stg instanceof ODistributedStorage))
        throw new ODistributedException("SYNC DATABASE command cannot be executed against a non distributed server");
    final ODistributedStorage dStg = (ODistributedStorage) stg;
    final OHazelcastPlugin dManager = (OHazelcastPlugin) dStg.getDistributedManager();
    if (dManager == null || !dManager.isEnabled())
        throw new OCommandExecutionException("OrientDB is not started in distributed mode");
    final String databaseName = database.getName();
    return dManager.installDatabase(true, databaseName, false, OGlobalConfiguration.DISTRIBUTED_BACKUP_TRY_INCREMENTAL_FIRST.getValueAsBoolean());
}
Also used : ODistributedStorage(com.orientechnologies.orient.server.distributed.impl.ODistributedStorage) ODistributedException(com.orientechnologies.orient.server.distributed.ODistributedException) OStorage(com.orientechnologies.orient.core.storage.OStorage) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 3 with OHazelcastPlugin

use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.

the class ServerRun method terminateServer.

public void terminateServer() {
    if (server != null) {
        try {
            HazelcastInstance hz = ((OHazelcastPlugin) server.getDistributedManager()).getHazelcastInstance();
            final Node node = getHazelcastNode(hz);
            node.getConnectionManager().shutdown();
            node.shutdown(true);
            hz.getLifecycleService().terminate();
        } catch (Exception e) {
        // IGNORE IT
        }
        try {
            server.shutdown();
        } catch (Exception e) {
        // IGNORE IT
        }
    }
    closeStorages();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) IOException(java.io.IOException)

Example 4 with OHazelcastPlugin

use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.

the class OCommandExecutorSQLHARemoveServer method execute.

/**
   * Execute the command.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.SERVER, "remove", ORole.PERMISSION_EXECUTE);
    final String dbUrl = database.getURL();
    final String path = dbUrl.substring(dbUrl.indexOf(":") + 1);
    final OServer serverInstance = OServer.getInstanceByPath(path);
    final OHazelcastPlugin dManager = (OHazelcastPlugin) serverInstance.getDistributedManager();
    if (dManager == null || !dManager.isEnabled())
        throw new OCommandExecutionException("OrientDB is not started in distributed mode");
    final String databaseName = database.getName();
    return dManager.removeNodeFromConfiguration(parsedStatement.serverName.getStringValue(), databaseName, false, true);
}
Also used : OServer(com.orientechnologies.orient.server.OServer) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 5 with OHazelcastPlugin

use of com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin in project orientdb by orientechnologies.

the class OCommandExecutorSQLHASyncCluster method execute.

/**
   * Execute the SYNC CLUSTER.
   */
public Object execute(final Map<Object, Object> iArgs) {
    final ODatabaseDocumentInternal database = getDatabase();
    database.checkSecurity(ORule.ResourceGeneric.CLUSTER, "sync", ORole.PERMISSION_UPDATE);
    final String dbUrl = database.getURL();
    final String path = dbUrl.substring(dbUrl.indexOf(":") + 1);
    final OServer serverInstance = OServer.getInstanceByPath(path);
    final OHazelcastPlugin dManager = (OHazelcastPlugin) serverInstance.getDistributedManager();
    if (dManager == null || !dManager.isEnabled())
        throw new OCommandExecutionException("OrientDB is not started in distributed mode");
    final String databaseName = database.getName();
    try {
        if (this.parsedStatement.modeFull) {
            return replaceCluster(dManager, database, serverInstance, databaseName, this.parsedStatement.clusterName.getStringValue());
        }
    // else {
    // int merged = 0;
    // return String.format("Merged %d records", merged);
    // }
    } catch (Exception e) {
        throw OException.wrapException(new OCommandExecutionException("Cannot execute synchronization of cluster"), e);
    }
    return "Mode not supported";
}
Also used : OServer(com.orientechnologies.orient.server.OServer) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OHazelcastPlugin(com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OException(com.orientechnologies.common.exception.OException) OCommandSQLParsingException(com.orientechnologies.orient.core.sql.OCommandSQLParsingException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) IOException(java.io.IOException)

Aggregations

OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)11 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OModifiableDistributedConfiguration (com.orientechnologies.orient.server.distributed.OModifiableDistributedConfiguration)5 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)4 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4 ServerRun (com.orientechnologies.orient.server.distributed.ServerRun)4 OServer (com.orientechnologies.orient.server.OServer)3 IOException (java.io.IOException)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 ODistributedConfiguration (com.orientechnologies.orient.server.distributed.ODistributedConfiguration)2 LinkedList (java.util.LinkedList)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.Node)1 OException (com.orientechnologies.common.exception.OException)1 OCallable (com.orientechnologies.common.util.OCallable)1 ORecordId (com.orientechnologies.orient.core.id.ORecordId)1 OCommandSQLParsingException (com.orientechnologies.orient.core.sql.OCommandSQLParsingException)1 OStorage (com.orientechnologies.orient.core.storage.OStorage)1 ODistributedException (com.orientechnologies.orient.server.distributed.ODistributedException)1