public static void main(final String[] args) { int result = 0; try { boolean tty = false; try { if (setTerminalToCBreak()) tty = true; Runtime.getRuntime().addShutdownHook(new Thread(() -> restoreTerminal())); } catch (Exception ignored) { } new OSignalHandler().installDefaultSignals(signal -> restoreTerminal()); final OConsoleDatabaseApp console = new OConsoleDatabaseApp(args); if (tty) console.setReader(new TTYConsoleReader(console.historyEnabled())); result = console.run(); } finally { restoreTerminal(); } Orient.instance().shutdown(); System.exit(result); }
@Override public void error(final String message, final Object... args) { // clean up error messages to remove redundant/irrelevant content if (!message.contains("Unrecognized command")) { super.error(message.replaceFirst("(?s)!Wrong syntax.*Expected", "Syntax"), args); } } }
@ConsoleCommand(description = "Browse all records of a class", onlineHelp = "Console-Command-Browse-Class") public void browseClass(@ConsoleParameter(name = "class-name", description = "The name of the class") final String iClassName) { checkForDatabase(); resetResultSet(); final OIdentifiableIterator<?> it = currentDatabase.browseClass(iClassName); browseRecords(it); }
public static void main(final String[] args) { int result; try { boolean tty = false; try { if (setTerminalToCBreak()) tty = true; } catch (Exception e) { } final OConsoleDatabaseApp console = new OGremlinConsole(args); if (tty) console.setReader(new TTYConsoleReader(console.historyEnabled())); result = console.run(); } finally { try { stty("echo"); } catch (Exception e) { } } System.exit(result); }
@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(Locale.ENGLISH)); 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); } }
@ConsoleParameter(name = "options", description = "Options: [--fix-graph] [--force-embedded-ridbags] [--fix-links] [-v]] [--fix-ridbags] [--fix-bonsai]", optional = true) String iOptions) throws IOException { checkForDatabase(); final boolean force_embedded = iOptions == null || iOptions.contains("--force-embedded-ridbags"); final boolean fix_graph = iOptions == null || iOptions.contains("--fix-graph"); final Map<String, List<String>> options = parseOptions(iOptions); new OGraphRepair().repair(currentDatabase, this, options); if (fix_links) { repairDatabase(iOptions); message("\n fix-bonsai can be run only on plocal connection \n"); return;
@Override public Object executeBlock() { return console.run(); } }
@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()); } }
@ConsoleCommand(aliases = { "display" }, description = "Display current record attributes", onlineHelp = "Console-Command-Display-Record") public void displayRecord( @ConsoleParameter(name = "number", description = "The number of the record in the most recent result set") final String iRecordNumber) { checkForDatabase(); if (iRecordNumber == null || currentResultSet == null) checkCurrentObject(); else { int recNumber = Integer.parseInt(iRecordNumber); if (currentResultSet.size() == 0) throw new OSystemException("No result set where to find the requested record. Execute a query first."); if (currentResultSet.size() <= recNumber) throw new OSystemException("The record requested is not part of current result set (0" + (currentResultSet.size() > 0 ? "-" + (currentResultSet.size() - 1) : "") + ")"); setCurrentRecord(recNumber); } dumpRecordDetails(); }
@Override public void configure(final ODocument iConfiguration, OCommandContext iContext) { super.configure(iConfiguration, iContext); if (iConfiguration.containsField("file")) file = iConfiguration.field("file"); if (iConfiguration.containsField("commands.sh")) commands = iConfiguration.field("commands.sh"); if (file == null && commands == null) throw new OConfigurationException("file or commands.sh are mandatory"); if (file != null) console = new OConsoleDatabaseApp(new String[] { file }); else console = new OConsoleDatabaseApp(commands.toArray(new String[commands.size()])); }
if (fix_links) { super.repairDatabase(iOptions);
@Override @ConsoleCommand(description = "Check database integrity", splitInWords = false) public void checkDatabase( @ConsoleParameter(name = "options", description = "Options: -v --skip-graph", optional = true) final String iOptions) throws IOException { final boolean fix_graph = iOptions == null || !iOptions.contains("--skip-graph"); if (fix_graph) { // REPAIR GRAPH final Map<String, List<String>> options = parseOptions(iOptions); new OGraphRepair().check(OrientGraphFactory.getNoTxGraphImplFactory().getGraph(currentDatabase), this, options); } super.checkDatabase(iOptions); }
@Override public Object executeBlock() { return console.run(); } }
@SuppressWarnings("unchecked") @ConsoleCommand(description = "Drop a server user. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-Drop-Server-User") public void dropServerUser(@ConsoleParameter(name = "user-name", description = "User name") String iServerUserName) { if (iServerUserName == null || iServerUserName.length() == 0) throw new IllegalArgumentException("User name null or empty"); 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); if (!serverCfg.existsUser(iServerUserName)) { error("\nServer user '%s' not found in configuration", iServerUserName); return; } serverCfg.dropUser(iServerUserName); serverCfg.saveConfiguration(); message("\nServer user '%s' dropped correctly", iServerUserName); } catch (Exception e) { error("\nError on loading %s file: %s", serverCfgFile, e.toString()); } }
@Override public void configure(OETLProcessor iProcessor, final ODocument iConfiguration, OCommandContext iContext) { super.configure(iProcessor, iConfiguration, iContext); if (iConfiguration.containsField("file")) file = iConfiguration.field("file"); if (iConfiguration.containsField("commands")) commands = iConfiguration.field("commands"); if (file == null && commands == null) throw new OConfigurationException("file or commands are mandatory"); if (file != null) console = new OConsoleDatabaseApp(new String[] { file }); else console = new OConsoleDatabaseApp(commands.toArray(new String[commands.size()])); }
public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException { if (inputFile == null) throw new OSystemException("needed an input file as first argument"); if (dbURL == null) throw new OSystemException("needed an database location as second argument"); ODatabaseDocumentInternal db = new ODatabaseDocumentTx(dbURL); ODatabaseHelper.deleteDatabase(db, db.getType()); OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL); System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "..."); final long startTime = System.currentTimeMillis(); OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }) .setCurrentDatabase(g.getRawGraph()); console.run(); System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices()); g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute(); g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute(); g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute(); g.shutdown(); } }
@SuppressWarnings("unchecked") @ConsoleCommand(description = "Set a server user. If the user already exists, the password and permissions are updated. For more information look at http://orientdb.com/docs/last/Security.html#orientdb-server-security", onlineHelp = "Console-Command-Set-Server-User") public void setServerUser(@ConsoleParameter(name = "user-name", description = "User name") String iServerUserName, @ConsoleParameter(name = "user-password", description = "User password") String iServerUserPasswd, @ConsoleParameter(name = "user-permissions", description = "Permissions, look at http://orientdb.com/docs/last/Security.html#servers-resources") String iPermissions) { if (iServerUserName == null || iServerUserName.length() == 0) throw new IllegalArgumentException("User name null or empty"); if (iPermissions == null || iPermissions.length() == 0) throw new IllegalArgumentException("User permissions null or empty"); 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); final String defAlgo = OGlobalConfiguration.SECURITY_USER_PASSWORD_DEFAULT_ALGORITHM.getValueAsString(); final String hashedPassword = OSecurityManager.instance().createHash(iServerUserPasswd, defAlgo, true); serverCfg.setUser(iServerUserName, hashedPassword, iPermissions); serverCfg.saveConfiguration(); message("\nServer user '%s' set correctly", iServerUserName); } catch (Exception e) { error("\nError on loading %s file: %s", serverCfgFile, e.toString()); } }
@ConsoleCommand(description = "Browse all records of a cluster", onlineHelp = "Console-Command-Browse-Cluster") public void browseCluster( @ConsoleParameter(name = "cluster-name", description = "The name of the cluster") final String iClusterName) { checkForDatabase(); resetResultSet(); final ORecordIteratorCluster<?> it = currentDatabase.browseCluster(iClusterName); browseRecords(it); }