Search in sources :

Example 26 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method listProperties.

@ConsoleCommand(description = "Display the database properties")
public void listProperties() {
    if (currentDatabase == null)
        return;
    final OStorage stg = currentDatabase.getStorage();
    final OStorageConfiguration dbCfg = stg.getConfiguration();
    message("\n\nDATABASE PROPERTIES");
    if (dbCfg.getProperties() != null) {
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        if (dbCfg.name != null)
            resultSet.add(new ODocument().field("NAME", "Name").field("VALUE", dbCfg.name));
        resultSet.add(new ODocument().field("NAME", "Version").field("VALUE", dbCfg.version));
        resultSet.add(new ODocument().field("NAME", "Conflict-Strategy").field("VALUE", dbCfg.getConflictStrategy()));
        resultSet.add(new ODocument().field("NAME", "Date-Format").field("VALUE", dbCfg.dateFormat));
        resultSet.add(new ODocument().field("NAME", "Datetime-Format").field("VALUE", dbCfg.dateTimeFormat));
        resultSet.add(new ODocument().field("NAME", "Timezone").field("VALUE", dbCfg.getTimeZone().getID()));
        resultSet.add(new ODocument().field("NAME", "Locale-Country").field("VALUE", dbCfg.getLocaleCountry()));
        resultSet.add(new ODocument().field("NAME", "Locale-Language").field("VALUE", dbCfg.getLocaleLanguage()));
        resultSet.add(new ODocument().field("NAME", "Charset").field("VALUE", dbCfg.getCharset()));
        resultSet.add(new ODocument().field("NAME", "Schema-RID").field("VALUE", dbCfg.schemaRecordId, OType.LINK));
        resultSet.add(new ODocument().field("NAME", "Index-Manager-RID").field("VALUE", dbCfg.indexMgrRecordId, OType.LINK));
        resultSet.add(new ODocument().field("NAME", "Dictionary-RID").field("VALUE", dbCfg.dictionaryRecordId, OType.LINK));
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
        message("\n");
        if (!dbCfg.getProperties().isEmpty()) {
            message("\n\nDATABASE CUSTOM PROPERTIES:");
            final List<ODocument> dbResultSet = new ArrayList<ODocument>();
            for (OStorageEntryConfiguration cfg : dbCfg.getProperties()) dbResultSet.add(new ODocument().field("NAME", cfg.name).field("VALUE", cfg.value));
            final OTableFormatter dbFormatter = new OTableFormatter(this);
            dbFormatter.writeRecords(dbResultSet, -1);
        }
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OStorageEntryConfiguration(com.orientechnologies.orient.core.config.OStorageEntryConfiguration) OStorageConfiguration(com.orientechnologies.orient.core.config.OStorageConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 27 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method connect.

@ConsoleCommand(aliases = { "use database" }, description = "Connect to a database or a remote Server instance", onlineHelp = "Console-Command-Connect")
public void connect(@ConsoleParameter(name = "url", description = "The url of the remote server or the database to connect to in the format '<mode>:<path>'") String iURL, @ConsoleParameter(name = "user", description = "User name") String iUserName, @ConsoleParameter(name = "password", description = "User password", optional = true) String iUserPassword) throws IOException {
    disconnect();
    if (iUserPassword == null) {
        message("Enter password: ");
        final BufferedReader br = new BufferedReader(new InputStreamReader(this.in));
        iUserPassword = br.readLine();
        message("\n");
    }
    currentDatabaseUserName = iUserName;
    currentDatabaseUserPassword = iUserPassword;
    if (iURL.contains("/")) {
        // OPEN DB
        message("\nConnecting to database [" + iURL + "] with user '" + iUserName + "'...");
        currentDatabase = new ODatabaseDocumentTx(iURL);
        currentDatabase.registerListener(new OConsoleDatabaseListener(this));
        currentDatabase.open(iUserName, iUserPassword);
        currentDatabaseName = currentDatabase.getName();
    } else {
        // CONNECT TO REMOTE SERVER
        message("\nConnecting to remote Server instance [" + iURL + "] with user '" + iUserName + "'...");
        serverAdmin = new OServerAdmin(iURL).connect(iUserName, iUserPassword);
        currentDatabase = null;
        currentDatabaseName = null;
    }
    message("OK");
    final ODocument distribCfg = getDistributedConfiguration();
    if (distribCfg != null)
        listServers();
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OServerAdmin(com.orientechnologies.orient.client.remote.OServerAdmin) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 28 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method declareIntent.

@ConsoleCommand(description = "Declare an intent", onlineHelp = "")
public void declareIntent(@ConsoleParameter(name = "Intent name", description = "name of the intent to execute") final String iIntentName) {
    checkForDatabase();
    message("\nDeclaring intent '" + iIntentName + "'...");
    if (iIntentName.equalsIgnoreCase("massiveinsert"))
        currentDatabase.declareIntent(new OIntentMassiveInsert());
    else if (iIntentName.equalsIgnoreCase("massiveread"))
        currentDatabase.declareIntent(new OIntentMassiveRead());
    else if (iIntentName.equalsIgnoreCase("null"))
        currentDatabase.declareIntent(null);
    else
        throw new IllegalArgumentException("Intent '" + iIntentName + "' not supported. Available ones are: massiveinsert, massiveread, null");
    message("\nIntent '" + iIntentName + "' set successfully");
}
Also used : OIntentMassiveRead(com.orientechnologies.orient.core.intent.OIntentMassiveRead) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 29 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method listServers.

@ConsoleCommand(description = "Display all the connected servers that manage current database", onlineHelp = "Console-Command-List-Servers")
public void listServers() {
    final ODocument distribCfg = getDistributedConfiguration();
    if (distribCfg == null) {
        message("\n\nDistributed configuration is not active, cannot retrieve server list");
        return;
    }
    final List<OIdentifiable> servers = new ArrayList<OIdentifiable>();
    final Collection<ODocument> members = distribCfg.field("members");
    if (members != null) {
        message("\n\nCONFIGURED SERVERS");
        for (ODocument m : members) {
            final ODocument server = new ODocument();
            server.field("Name", m.field("name"));
            server.field("Status", m.field("status"));
            server.field("Connections", m.field("connections"));
            server.field("StartedOn", m.field("startedOn"));
            final Collection<Map> listeners = m.field("listeners");
            if (listeners != null) {
                for (Map l : listeners) {
                    final String protocol = (String) l.get("protocol");
                    if (protocol.equals("ONetworkProtocolBinary")) {
                        server.field("Binary", l.get("listen"));
                    } else if (protocol.equals("ONetworkProtocolHttpDb")) {
                        server.field("HTTP", l.get("listen"));
                    }
                }
            }
            final long usedMem = m.field("usedMemory");
            final long freeMem = m.field("freeMemory");
            final long maxMem = m.field("maxMemory");
            server.field("UsedMemory", String.format("%s (%.2f%%)", OFileUtils.getSizeAsString(usedMem), ((float) usedMem / (float) maxMem) * 100));
            server.field("FreeMemory", String.format("%s (%.2f%%)", OFileUtils.getSizeAsString(freeMem), ((float) freeMem / (float) maxMem) * 100));
            server.field("MaxMemory", OFileUtils.getSizeAsString(maxMem));
            servers.add(server);
        }
    }
    currentResultSet = servers;
    new OTableFormatter(this).setMaxWidthSize(getConsoleWidth()).writeRecords(servers, -1);
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 30 with ConsoleCommand

use of com.orientechnologies.common.console.annotation.ConsoleCommand in project orientdb by orientechnologies.

the class OConsoleDatabaseApp method exportRecord.

@ConsoleCommand(description = "Export the current record in the requested format", onlineHelp = "Console-Command-Export-Record")
public void exportRecord(@ConsoleParameter(name = "format", description = "Format, such as 'json'") final String iFormat, @ConsoleParameter(name = "options", description = "Options", optional = true) String iOptions) throws IOException {
    checkForDatabase();
    checkCurrentObject();
    final ORecordSerializer serializer = ORecordSerializerFactory.instance().getFormat(iFormat.toLowerCase());
    if (serializer == null) {
        message("\nERROR: Format '" + iFormat + "' was not found.");
        printSupportedSerializerFormat();
        return;
    } else if (!(serializer instanceof ORecordSerializerStringAbstract)) {
        message("\nERROR: Format '" + iFormat + "' does not export as text.");
        printSupportedSerializerFormat();
        return;
    }
    if (iOptions == null || iOptions.length() <= 0) {
        iOptions = "rid,version,class,type,keepTypes,alwaysFetchEmbedded,fetchPlan:*:0,prettyPrint";
    }
    try {
        out.println(currentRecord.toJSON(iOptions));
    } catch (ODatabaseExportException e) {
        printError(e);
    }
}
Also used : ORecordSerializerStringAbstract(com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerStringAbstract) ORecordSerializer(com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Aggregations

ConsoleCommand (com.orientechnologies.common.console.annotation.ConsoleCommand)36 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)12 OSystemException (com.orientechnologies.common.exception.OSystemException)10 ORetryQueryException (com.orientechnologies.orient.core.exception.ORetryQueryException)9 OIOException (com.orientechnologies.common.io.OIOException)8 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)8 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)8 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)4 Method (java.lang.reflect.Method)4 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)3 OGlobalConfiguration (com.orientechnologies.orient.core.config.OGlobalConfiguration)3 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)3 OIndex (com.orientechnologies.orient.core.index.OIndex)3 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OServerConfigurationManager (com.orientechnologies.orient.server.config.OServerConfigurationManager)3 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)2 ODatabaseImportException (com.orientechnologies.orient.core.db.tool.ODatabaseImportException)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2