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);
}
}
}
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();
}
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");
}
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);
}
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);
}
}
Aggregations