use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class ReportMaker method report.
/**
* Generate the HTML catalog report from a newly compiled VoltDB catalog
*/
public static String report(Catalog catalog, long minHeap, boolean isPro, int hostCount, int sitesPerHost, int kfactor, ArrayList<Feedback> warnings, String autoGenDDL) throws IOException {
// asynchronously get platform properties
new Thread() {
@Override
public void run() {
PlatformProperties.getPlatformProperties();
}
}.start();
URL url = Resources.getResource(ReportMaker.class, "template.html");
String contents = Resources.toString(url, Charsets.UTF_8);
Cluster cluster = catalog.getClusters().get("cluster");
assert (cluster != null);
Database db = cluster.getDatabases().get("database");
assert (db != null);
String statsData = getStatsHTML(db, minHeap, warnings);
contents = contents.replace("##STATS##", statsData);
// generateProceduresTable needs to happen before generateSchemaTable
// because some metadata used in the later is generated in the former
String procData = generateProceduresTable(db.getTables(), db.getProcedures());
contents = contents.replace("##PROCS##", procData);
String schemaData = generateSchemaTable(db);
contents = contents.replace("##SCHEMA##", schemaData);
DatabaseSizes sizes = CatalogSizing.getCatalogSizes(db, DrRoleType.XDCR.value().equals(cluster.getDrrole()));
String sizeData = generateSizeTable(sizes);
contents = contents.replace("##SIZES##", sizeData);
String clusterConfig = generateClusterConfiguration(isPro, hostCount, sitesPerHost, kfactor);
contents = contents.replace("##CLUSTERCONFIG##", clusterConfig);
String sizeSummary = generateSizeSummary(sizes);
contents = contents.replace("##SIZESUMMARY##", sizeSummary);
String heapSummary = generateRecommendedServerSettings(sizes);
contents = contents.replace("##RECOMMENDEDSERVERSETTINGS##", heapSummary);
String platformData = PlatformProperties.getPlatformProperties().toHTML();
contents = contents.replace("##PLATFORM##", platformData);
contents = contents.replace("##VERSION##", VoltDB.instance().getVersionString());
contents = contents.replace("##DDL##", escapeHtml4(autoGenDDL));
DateFormat df = new SimpleDateFormat("d MMM yyyy HH:mm:ss z");
contents = contents.replace("##TIMESTAMP##", df.format(m_timestamp));
String msg = Encoder.hexEncode(VoltDB.instance().getVersionString() + "," + System.currentTimeMillis());
contents = contents.replace("get.py?a=KEY&", String.format("get.py?a=%s&", msg));
return contents;
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class ExportManager method getConnectors.
private static CatalogMap<Connector> getConnectors(CatalogContext catalogContext) {
final Cluster cluster = catalogContext.catalog.getClusters().get("cluster");
final Database db = cluster.getDatabases().get("database");
return db.getConnectors();
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class CatalogSchemaTools method toSchema.
/**
* Convert a catalog into a string containing all DDL statements.
* @param catalog
* @param importLines A set of importLines, should not be mutated.
* @return String of DDL statements.
*/
public static String toSchema(Catalog catalog, Set<String> importLines) {
StringBuilder sb = new StringBuilder();
sb.append("-- This file was generated by VoltDB version ");
sb.append(VoltDB.instance().getVersionString());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
String time = sdf.format(System.currentTimeMillis());
sb.append(" on: " + time + ".\n");
sb.append("-- This file represents the current database schema.\n");
sb.append("-- Use this file as input to reproduce the current database structure in another database instance.\n");
sb.append("--\n");
sb.append(batchSpecificComments);
sb.append("-- If the schema declares Java stored procedures, be sure to load the .jar file\n");
sb.append("-- with the classes before loading the schema. For example:\n");
sb.append("--\n");
sb.append("-- LOAD CLASSES voltdb-procs.jar;\n");
sb.append("-- FILE ddl.sql;\n");
for (Cluster cluster : catalog.getClusters()) {
for (Database db : cluster.getDatabases()) {
toSchema(sb, importLines);
for (Group grp : db.getGroups()) {
toSchema(sb, grp);
}
sb.append("\n");
List<Table> viewList = new ArrayList<>();
CatalogMap<Table> tables = db.getTables();
if (!tables.isEmpty()) {
sb.append(startBatch);
for (Table table : tables) {
Object annotation = table.getAnnotation();
if (annotation != null && ((TableAnnotation) annotation).ddl != null && table.getMaterializer() != null) {
viewList.add(table);
continue;
}
toSchema(sb, table, null, CatalogUtil.isTableExportOnly(db, table), (table.getPartitioncolumn() != null ? table.getPartitioncolumn().getName() : null), CatalogUtil.getExportTargetIfExportTableOrNullOtherwise(db, table));
}
// A View cannot precede a table that it depends on in the DDL
for (Table table : viewList) {
String viewQuery = ((TableAnnotation) table.getAnnotation()).ddl;
toSchema(sb, table, viewQuery, false, null, null);
}
}
CatalogMap<Procedure> procedures = db.getProcedures();
if (!procedures.isEmpty()) {
for (Procedure proc : procedures) {
toSchema(sb, proc);
}
}
CatalogMap<Function> functions = db.getFunctions();
if (!functions.isEmpty()) {
for (Function func : functions) {
toSchema(sb, func);
}
}
if (!tables.isEmpty()) {
sb.append(endBatch);
}
}
}
if (dumpSchema) {
String ts = new SimpleDateFormat("MMddHHmmssSSS").format(new Date());
File f = new File(String.format("/tmp/canonical-%s.sql", ts));
try {
FileWriter fw = new FileWriter(f);
fw.write(sb.toString());
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class TestCatalogUtil method testUserRoles.
public void testUserRoles() throws Exception {
final String depRole = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<security enabled=\"true\"/>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + "<paths><voltdbroot path=\"/tmp/" + System.getProperty("user.name") + "\" /></paths>" + "<httpd port='0'>" + "<jsonapi enabled='true'/>" + "</httpd>" + "<users> " + "<user name=\"admin\" password=\"admin\" roles=\"administrator\"/>" + "<user name=\"joe\" password=\"aaa\" roles=\"lotre,lodue,louno,dontexist\"/>" + "<user name=\"jane\" password=\"bbb\" roles=\"launo,ladue,latre,dontexist\"/>" + "</users>" + "</deployment>";
catalog_db.getGroups().add("louno");
catalog_db.getGroups().add("lodue");
catalog_db.getGroups().add("lotre");
catalog_db.getGroups().add("launo");
catalog_db.getGroups().add("ladue");
catalog_db.getGroups().add("latre");
final File tmpRole = VoltProjectBuilder.writeStringToTempFile(depRole);
CatalogUtil.compileDeployment(catalog, tmpRole.getPath(), false);
Database db = catalog.getClusters().get("cluster").getDatabases().get("database");
User joe = db.getUsers().get("joe");
assertNotNull(joe);
assertNotNull(joe.getGroups().get("louno"));
assertNotNull(joe.getGroups().get("lodue"));
assertNotNull(joe.getGroups().get("lotre"));
assertNull(joe.getGroups().get("latre"));
assertNull(joe.getGroups().get("dontexist"));
User jane = db.getUsers().get("jane");
assertNotNull(jane);
assertNotNull(jane.getGroups().get("launo"));
assertNotNull(jane.getGroups().get("ladue"));
assertNotNull(jane.getGroups().get("latre"));
assertNull(jane.getGroups().get("lotre"));
assertNull(joe.getGroups().get("dontexist"));
}
use of org.voltdb.catalog.Database in project voltdb by VoltDB.
the class TestCatalogUtil method testAutoSnapshotEnabledFlag.
public void testAutoSnapshotEnabledFlag() throws Exception {
final String depOff = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + " <cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <paths><voltdbroot path=\"/tmp/" + System.getProperty("user.name") + "\" /></paths>" + " <snapshot frequency=\"5s\" retain=\"10\" prefix=\"pref2\" enabled=\"false\"/>" + "</deployment>";
final String depOn = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + " <cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <paths><voltdbroot path=\"/tmp/" + System.getProperty("user.name") + "\" /></paths>" + " <snapshot frequency=\"5s\" retain=\"10\" prefix=\"pref2\" enabled=\"true\"/>" + "</deployment>";
final File tmpDepOff = VoltProjectBuilder.writeStringToTempFile(depOff);
CatalogUtil.compileDeployment(catalog, tmpDepOff.getPath(), false);
Database db = catalog.getClusters().get("cluster").getDatabases().get("database");
assertFalse(db.getSnapshotschedule().get("default").getEnabled());
setUp();
final File tmpDepOn = VoltProjectBuilder.writeStringToTempFile(depOn);
CatalogUtil.compileDeployment(catalog, tmpDepOn.getPath(), false);
db = catalog.getClusters().get("cluster").getDatabases().get("database");
assertFalse(db.getSnapshotschedule().isEmpty());
assertTrue(db.getSnapshotschedule().get("default").getEnabled());
assertEquals(10, db.getSnapshotschedule().get("default").getRetain());
}
Aggregations