Search in sources :

Example 1 with ConsoleCommand

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

the class OConsoleApplication method help.

@ConsoleCommand(splitInWords = false, description = "Receives help on available commands or a specific one. Use 'help -online <cmd>' to fetch online documentation")
public void help(@ConsoleParameter(name = "command", description = "Command to receive help") String iCommand) {
    if (iCommand == null || iCommand.trim().isEmpty()) {
        // GENERIC HELP
        message("\nAVAILABLE COMMANDS:\n");
        for (Method m : getConsoleMethods().keySet()) {
            ConsoleCommand annotation = m.getAnnotation(ConsoleCommand.class);
            if (annotation == null)
                continue;
            message("* %-85s%s\n", getCorrectMethodName(m), annotation.description());
        }
        message("* %-85s%s\n", getClearName("exit"), "Close the console");
        return;
    }
    final String[] commandWords = OStringParser.getWords(iCommand, wordSeparator);
    boolean onlineMode = commandWords.length > 1 && commandWords[0].equalsIgnoreCase("-online");
    if (onlineMode)
        iCommand = iCommand.substring("-online".length() + 1);
    final Method m = getMethod(iCommand);
    if (m != null) {
        final ConsoleCommand ann = m.getAnnotation(ConsoleCommand.class);
        message("\nCOMMAND: " + iCommand + "\n\n");
        if (ann != null) {
            // FETCH ONLINE CONTENT
            if (onlineMode && !ann.onlineHelp().isEmpty()) {
                // try {
                final String text = getOnlineHelp(ONLINE_HELP_URL + ann.onlineHelp() + ONLINE_HELP_EXT);
                if (text != null && !text.isEmpty()) {
                    message(text);
                    // ONLINE FETCHING SUCCEED: RETURN
                    return;
                }
                // } catch (Exception e) {
                // }
                error("!CANNOT FETCH ONLINE DOCUMENTATION, CHECK IF COMPUTER IS CONNECTED TO THE INTERNET.");
                return;
            }
            message(ann.description() + "." + "\r\n\r\nSYNTAX: ");
            // IN ANY CASE DISPLAY INFORMATION BY READING ANNOTATIONS
            message(formatCommandSpecs(iCommand, m));
        } else
            message("No description available");
    }
}
Also used : Method(java.lang.reflect.Method) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 2 with ConsoleCommand

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

the class OGremlinConsole method exportDatabase.

@Override
@ConsoleCommand(description = "Export a database", splitInWords = false, onlineHelp = "Console-Command-Export")
public void exportDatabase(@ConsoleParameter(name = "options", description = "Export options") String iText) throws IOException {
    checkForDatabase();
    final List<String> items = OStringSerializerHelper.smartSplit(iText, ' ');
    final String fileName = items.size() <= 1 || items.get(1).charAt(0) == '-' ? null : items.get(1);
    if (fileName != null && (fileName.endsWith(".graphml") || fileName.endsWith(".xml"))) {
        message("\nExporting database in GRAPHML format to " + iText + "...");
        try {
            final OrientGraph g = (OrientGraph) OrientGraphFactory.getTxGraphImplFactory().getGraph(currentDatabase);
            g.setUseLog(false);
            g.setWarnOnForceClosingTx(false);
            // CREATE THE EXPORT FILE IF NOT EXIST YET
            final File f = new File(fileName);
            if (f.getParentFile() != null) {
                f.getParentFile().mkdirs();
            }
            f.createNewFile();
            new GraphMLWriter(g).outputGraph(fileName);
        } catch (ODatabaseImportException e) {
            printError(e);
        }
    } else
        // BASE EXPORT
        super.exportDatabase(iText);
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) GraphMLWriter(com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter) ODatabaseImportException(com.orientechnologies.orient.core.db.tool.ODatabaseImportException) File(java.io.File) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 3 with ConsoleCommand

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

the class OConsoleDatabaseApp method configGet.

@ConsoleCommand(description = "Return the value of a configuration value")
public void configGet(@ConsoleParameter(name = "config-name", description = "Name of the configuration") final String iConfigName) throws IOException {
    final OGlobalConfiguration config = OGlobalConfiguration.findByKey(iConfigName);
    if (config == null)
        throw new IllegalArgumentException("Configuration variable '" + iConfigName + "' wasn't found");
    final String value;
    if (serverAdmin != null) {
        value = serverAdmin.getGlobalConfiguration(config);
        message("\nRemote configuration: ");
    } else {
        value = config.getValueAsString();
        message("\nLocal configuration: ");
    }
    out.println(iConfigName + " = " + value);
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 4 with ConsoleCommand

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

the class OConsoleDatabaseApp method importDatabase.

@ConsoleCommand(description = "Import a database into the current one", splitInWords = false, onlineHelp = "Console-Command-Import")
public void importDatabase(@ConsoleParameter(name = "options", description = "Import options") final String text) throws IOException {
    checkForDatabase();
    message("\nImporting database " + text + "...");
    final List<String> items = OStringSerializerHelper.smartSplit(text, ' ');
    final String fileName = items.size() <= 0 || (items.get(1)).charAt(0) == '-' ? null : items.get(1);
    final String options = fileName != null ? text.substring((items.get(0)).length() + (items.get(1)).length() + 1).trim() : text;
    try {
        if (currentDatabase.getStorage().isRemote()) {
            ODatabaseImportRemote databaseImport = new ODatabaseImportRemote(currentDatabase, fileName, this);
            databaseImport.setOptions(options);
            databaseImport.importDatabase();
            databaseImport.close();
        } else {
            ODatabaseImport databaseImport = new ODatabaseImport(currentDatabase, fileName, this);
            databaseImport.setOptions(options);
            databaseImport.importDatabase();
            databaseImport.close();
        }
    } catch (ODatabaseImportException e) {
        printError(e);
    }
}
Also used : ODatabaseImportRemote(com.orientechnologies.orient.client.remote.ODatabaseImportRemote) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 5 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