Search in sources :

Example 6 with ConsoleCommand

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

the class OConsoleDatabaseApp method disconnect.

@ConsoleCommand(aliases = { "close database" }, description = "Disconnect from the current database", onlineHelp = "Console-Command-Disconnect")
public void disconnect() {
    if (serverAdmin != null) {
        message("\nDisconnecting from remote server [" + serverAdmin.getURL() + "]...");
        serverAdmin.close(true);
        serverAdmin = null;
        message("\nOK");
    }
    if (currentDatabase != null) {
        message("\nDisconnecting from the database [" + currentDatabaseName + "]...");
        final OStorage stg = Orient.instance().getStorage(currentDatabase.getURL());
        currentDatabase.activateOnCurrentThread();
        if (!currentDatabase.isClosed())
            currentDatabase.close();
        // FORCE CLOSING OF STORAGE: THIS CLEAN UP REMOTE CONNECTIONS
        if (stg != null)
            stg.close(true, false);
        currentDatabase = null;
        currentDatabaseName = null;
        currentRecord = null;
        message("OK");
    }
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 7 with ConsoleCommand

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

the class OConsoleDatabaseApp method listServerUsers.

@SuppressWarnings("unchecked")
@ConsoleCommand(description = "Display all the server user names. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-List-Server-User")
public void listServerUsers() {
    final File serverCfgFile = new File("../config/orientdb-server-config.xml");
    if (!serverCfgFile.exists())
        throw new OConfigurationException("Cannot access to file " + serverCfgFile);
    try {
        final OServerConfigurationManager serverCfg = new OServerConfigurationManager(serverCfgFile);
        message("\nSERVER USERS\n");
        final Set<OServerUserConfiguration> users = serverCfg.getUsers();
        if (users.isEmpty())
            message("\nNo users found");
        else
            for (OServerUserConfiguration u : users) {
                message("\n- '%s', permissions: %s", u.name, u.resources);
            }
    } catch (Exception e) {
        error("\nError on loading %s file: %s", serverCfgFile, e.toString());
    }
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OServerUserConfiguration(com.orientechnologies.orient.server.config.OServerUserConfiguration) OServerConfigurationManager(com.orientechnologies.orient.server.config.OServerConfigurationManager) OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 8 with ConsoleCommand

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

the class OConsoleDatabaseApp method listClasses.

@ConsoleCommand(description = "Display all the configured classes", aliases = { "classes" }, onlineHelp = "Console-Command-List-Classes")
public void listClasses() {
    if (currentDatabaseName != null) {
        message("\n\nCLASSES");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        long totalElements = 0;
        long count;
        final List<OClass> classes = new ArrayList<OClass>(currentDatabase.getMetadata().getImmutableSchemaSnapshot().getClasses());
        Collections.sort(classes, new Comparator<OClass>() {

            public int compare(OClass o1, OClass o2) {
                return o1.getName().compareToIgnoreCase(o2.getName());
            }
        });
        for (OClass cls : classes) {
            try {
                final ODocument row = new ODocument();
                resultSet.add(row);
                final StringBuilder clusters = new StringBuilder(1024);
                if (cls.isAbstract())
                    clusters.append("-");
                else {
                    int[] clusterIds = cls.getClusterIds();
                    for (int i = 0; i < clusterIds.length; ++i) {
                        if (i > 0)
                            clusters.append(",");
                        clusters.append(currentDatabase.getClusterNameById(clusterIds[i]));
                        clusters.append("(");
                        clusters.append(clusterIds[i]);
                        clusters.append(")");
                    }
                }
                count = currentDatabase.countClass(cls.getName(), false);
                totalElements += count;
                final String superClasses = cls.hasSuperClasses() ? Arrays.toString(cls.getSuperClassesNames().toArray()) : "";
                row.field("NAME", cls.getName());
                row.field("SUPER-CLASSES", superClasses);
                row.field("CLUSTERS", clusters);
                row.field("COUNT", count);
            } catch (Exception ignored) {
            // IGNORED
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.setColumnAlignment("COUNT", OTableFormatter.ALIGNMENT.RIGHT);
        final ODocument footer = new ODocument();
        footer.field("NAME", "TOTAL");
        footer.field("COUNT", totalElements);
        formatter.setFooter(footer);
        formatter.writeRecords(resultSet, -1);
        message("\n");
    } else
        message("\nNo database selected yet.");
}
Also used : OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 9 with ConsoleCommand

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

the class OConsoleDatabaseApp method config.

@ConsoleCommand(description = "Return all the configuration values")
public void config() throws IOException {
    if (serverAdmin != null) {
        // REMOTE STORAGE
        final Map<String, String> values = serverAdmin.getGlobalConfigurations();
        message("\nREMOTE SERVER CONFIGURATION");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (Entry<String, String> p : values.entrySet()) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", p.getKey());
            row.field("VALUE", p.getValue());
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    } else {
        // LOCAL STORAGE
        message("\nLOCAL SERVER CONFIGURATION");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (OGlobalConfiguration cfg : OGlobalConfiguration.values()) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", cfg.getKey());
            row.field("VALUE", cfg.getValue());
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
    message("\n");
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 10 with ConsoleCommand

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

the class OConsoleDatabaseApp method repairDatabase.

@ConsoleCommand(description = "Repair database structure")
public void repairDatabase(@ConsoleParameter(name = "options", description = "Options: -v", optional = true) final String iOptions) throws IOException {
    checkForDatabase();
    message("\nRepairing database...");
    boolean verbose = iOptions != null && iOptions.contains("-v");
    new ODatabaseRepair().setDatabase(currentDatabase).setOutputListener(new OCommandOutputListener() {

        @Override
        public void onMessage(String iText) {
            message(iText);
        }
    }).setVerbose(verbose).run();
}
Also used : OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) 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