Search in sources :

Example 1 with Cluster

use of org.voltdb.catalog.Cluster 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;
}
Also used : DatabaseSizes(org.voltdb.utils.CatalogSizing.DatabaseSizes) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Database(org.voltdb.catalog.Database) Cluster(org.voltdb.catalog.Cluster) SimpleDateFormat(java.text.SimpleDateFormat) URL(java.net.URL)

Example 2 with Cluster

use of org.voltdb.catalog.Cluster 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();
}
Also used : Database(org.voltdb.catalog.Database) Cluster(org.voltdb.catalog.Cluster)

Example 3 with Cluster

use of org.voltdb.catalog.Cluster 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();
}
Also used : Group(org.voltdb.catalog.Group) Table(org.voltdb.catalog.Table) TableAnnotation(org.voltdb.compilereport.TableAnnotation) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Cluster(org.voltdb.catalog.Cluster) IOException(java.io.IOException) Date(java.util.Date) Function(org.voltdb.catalog.Function) Database(org.voltdb.catalog.Database) Procedure(org.voltdb.catalog.Procedure) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 4 with Cluster

use of org.voltdb.catalog.Cluster in project voltdb by VoltDB.

the class TestCatalogUtil method testSecurityEnabledFlag.

public void testSecurityEnabledFlag() throws Exception {
    final String secOff = "<?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>" + "   <security enabled=\"false\"/>" + "</deployment>";
    final String secOnWithNoAdmin = "<?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>" + "   <security enabled=\"true\"/>" + "   <users>" + "      <user name=\"joe\" password=\"aaa\"/>" + "   </users>" + "</deployment>";
    final String secOn = "<?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>" + "   <security enabled=\"true\"/>" + "   <users>" + "      <user name=\"joe\" password=\"aaa\" roles=\"administrator\"/>" + "   </users>" + "</deployment>";
    final File tmpSecOff = VoltProjectBuilder.writeStringToTempFile(secOff);
    CatalogUtil.compileDeployment(catalog, tmpSecOff.getPath(), false);
    Cluster cluster = catalog.getClusters().get("cluster");
    assertFalse(cluster.getSecurityenabled());
    setUp();
    final File tmpSecOnWithNoAdmin = VoltProjectBuilder.writeStringToTempFile(secOnWithNoAdmin);
    String result = CatalogUtil.compileDeployment(catalog, tmpSecOnWithNoAdmin.getPath(), false);
    assertTrue(result != null);
    assertTrue(result.contains("Cannot enable security without defining"));
    setUp();
    final File tmpSecOn = VoltProjectBuilder.writeStringToTempFile(secOn);
    CatalogUtil.compileDeployment(catalog, tmpSecOn.getPath(), false);
    cluster = catalog.getClusters().get("cluster");
    assertTrue(cluster.getSecurityenabled());
}
Also used : Cluster(org.voltdb.catalog.Cluster) File(java.io.File)

Example 5 with Cluster

use of org.voltdb.catalog.Cluster in project voltdb by VoltDB.

the class TestCatalogUtil method testCompileDeploymentAgainstEmptyCatalog.

public void testCompileDeploymentAgainstEmptyCatalog() {
    Catalog catalog = new Catalog();
    Cluster cluster = catalog.getClusters().add("cluster");
    cluster.getDatabases().add("database");
    String deploymentContent = "<?xml version=\"1.0\"?>\n" + "<deployment>\n" + "    <cluster hostcount='1' sitesperhost='1' kfactor='0' />\n" + "    <httpd enabled='true'>\n" + "        <jsonapi enabled='true' />\n" + "    </httpd>\n" + "    <export enabled='false'/>\n" + "</deployment>\n";
    final File schemaFile = VoltProjectBuilder.writeStringToTempFile(deploymentContent);
    final String depPath = schemaFile.getPath();
    CatalogUtil.compileDeployment(catalog, depPath, false);
    String commands = catalog.serialize();
    System.out.println(commands);
}
Also used : Cluster(org.voltdb.catalog.Cluster) File(java.io.File) Catalog(org.voltdb.catalog.Catalog)

Aggregations

Cluster (org.voltdb.catalog.Cluster)21 Database (org.voltdb.catalog.Database)10 File (java.io.File)9 IOException (java.io.IOException)4 Catalog (org.voltdb.catalog.Catalog)4 Constraint (org.voltdb.catalog.Constraint)4 VoltTable (org.voltdb.VoltTable)3 Table (org.voltdb.catalog.Table)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 Connector (org.voltdb.catalog.Connector)2 Procedure (org.voltdb.catalog.Procedure)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileWriter (java.io.FileWriter)1 SocketException (java.net.SocketException)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1 Date (java.util.Date)1 Properties (java.util.Properties)1