Search in sources :

Example 21 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestDeterminism method testDeterminismReadOnlyNoWarning.

/*
     * A test that runs some read-only non-deterministic DDLs, check that the output does not contain
     * any ND warnings
     */
public void testDeterminismReadOnlyNoWarning() throws Exception {
    // Should the members be reused here?
    HSQLInterface hsql = HSQLInterface.loadHsqldb();
    VoltCompiler compiler = new VoltCompiler(false);
    VoltCompiler.DdlProceduresToLoad all_procs = DdlProceduresToLoad.NO_DDL_PROCEDURES;
    URL path = TestDeterminism.class.getResource("testplans-determinism-read-only.sql");
    String pathStr = URLDecoder.decode(path.getPath(), "UTF-8");
    compiler.loadSchema(hsql, all_procs, pathStr);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    compiler.summarizeSuccess(new PrintStream(outputStream), null, "");
    System.out.println(outputStream.toString());
    // There is no warnings generated for read-only ND queries
    String msg = outputStream.toString();
    assertFalse(stringContains(msg, "ND"));
    assertFalse(stringContains(msg, "WARN"));
    assertTrue(stringContains(msg, "Successfully created"));
    assertTrue(stringContains(msg, "Catalog contains"));
    outputStream.close();
}
Also used : PrintStream(java.io.PrintStream) VoltCompiler(org.voltdb.compiler.VoltCompiler) HSQLInterface(org.hsqldb_voltpatches.HSQLInterface) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DdlProceduresToLoad(org.voltdb.compiler.VoltCompiler.DdlProceduresToLoad) URL(java.net.URL)

Example 22 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestInitStartLocalClusterAllOutOfProcess method loadAndAddProcs.

void loadAndAddProcs() throws IOException, NoConnectionsException {
    ClientResponse resp = null;
    long numberOfClasses = 0;
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    numberOfClasses = resp.getResults()[0].getRowCount();
    InMemoryJarfile jarfile = new InMemoryJarfile();
    VoltCompiler comp = new VoltCompiler(false);
    try {
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testCreateProcFromClassProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.InnerClassesTestProc.class);
    } catch (Exception e) {
        assert false : "Failed add class to jar: " + e.getMessage();
    }
    try {
        client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
    } catch (ProcCallException excp) {
        assert false : "Failed updating the class";
    }
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue((numberOfClasses + jarfile.getLoader().getClassNames().size()) == resp.getResults()[0].getRowCount());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 23 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestDRCatalogDiffs method createCatalog.

private Catalog createCatalog(String schema) throws Exception {
    File jarOut = new File(UUID.randomUUID() + ".jar");
    jarOut.deleteOnExit();
    File schemaFile = VoltProjectBuilder.writeStringToTempFile(schema);
    String schemaPath = schemaFile.getPath();
    VoltCompiler compiler = new VoltCompiler(false);
    boolean success = compiler.compileFromDDL(jarOut.getPath(), schemaPath);
    assertTrue("Compilation failed unexpectedly", success);
    Catalog catalog = new Catalog();
    catalog.execute(CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(MiscUtils.fileToBytes(new File(jarOut.getPath())), false).getFirst()));
    return catalog;
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) File(java.io.File)

Example 24 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class UpdateApplicationBase method modifyCatalogClasses.

/**
     * @return NUll if no classes changed, otherwise return the update jar file.
     * @throws ClassNotFoundException
     * @throws IOException
     */
private static InMemoryJarfile modifyCatalogClasses(Catalog catalog, InMemoryJarfile jarfile, String deletePatterns, InMemoryJarfile newJarfile, boolean isXDCR) throws ClassNotFoundException, IOException {
    // modify the old jar in place based on the @UpdateClasses inputs, and then
    // recompile it if necessary
    boolean deletedClasses = false;
    if (deletePatterns != null) {
        String[] patterns = deletePatterns.split(",");
        ClassMatcher matcher = new ClassMatcher();
        // Need to concatenate all the classnames together for ClassMatcher
        String currentClasses = "";
        for (String classname : jarfile.getLoader().getClassNames()) {
            currentClasses = currentClasses.concat(classname + "\n");
        }
        matcher.m_classList = currentClasses;
        for (String pattern : patterns) {
            ClassNameMatchStatus status = matcher.addPattern(pattern.trim());
            if (status == ClassNameMatchStatus.MATCH_FOUND) {
                deletedClasses = true;
            }
        }
        for (String classname : matcher.getMatchedClassList()) {
            jarfile.removeClassFromJar(classname);
        }
    }
    boolean foundClasses = false;
    if (newJarfile != null) {
        for (Entry<String, byte[]> e : newJarfile.entrySet()) {
            String filename = e.getKey();
            if (!filename.endsWith(".class")) {
                continue;
            }
            foundClasses = true;
            jarfile.put(e.getKey(), e.getValue());
        }
    }
    if (!deletedClasses && !foundClasses) {
        return null;
    }
    compilerLog.info("Updating java classes available to stored procedures");
    VoltCompiler compiler = new VoltCompiler(isXDCR);
    compiler.compileInMemoryJarfile(jarfile);
    return jarfile;
}
Also used : ClassMatcher(org.voltdb.compiler.ClassMatcher) VoltCompiler(org.voltdb.compiler.VoltCompiler) ClassNameMatchStatus(org.voltdb.compiler.ClassMatcher.ClassNameMatchStatus)

Example 25 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class UpdateApplicationBase method addDDLToCatalog.

/**
     * Append the supplied adhoc DDL to the current catalog's DDL and recompile the
     * jarfile
     * @throws VoltCompilerException
     */
protected static InMemoryJarfile addDDLToCatalog(Catalog oldCatalog, InMemoryJarfile jarfile, String[] adhocDDLStmts, boolean isXDCR) throws IOException, VoltCompilerException {
    StringBuilder sb = new StringBuilder();
    compilerLog.info("Applying the following DDL to cluster:");
    for (String stmt : adhocDDLStmts) {
        compilerLog.info("\t" + stmt);
        sb.append(stmt);
        sb.append(";\n");
    }
    String newDDL = sb.toString();
    compilerLog.trace("Adhoc-modified DDL:\n" + newDDL);
    VoltCompiler compiler = new VoltCompiler(isXDCR);
    compiler.compileInMemoryJarfileWithNewDDL(jarfile, newDDL, oldCatalog);
    return jarfile;
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler)

Aggregations

VoltCompiler (org.voltdb.compiler.VoltCompiler)43 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)26 File (java.io.File)16 ClientResponse (org.voltdb.client.ClientResponse)15 ProcCallException (org.voltdb.client.ProcCallException)15 Test (org.junit.Test)13 Configuration (org.voltdb.VoltDB.Configuration)12 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)11 VoltDB (org.voltdb.VoltDB)9 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 VoltTable (org.voltdb.VoltTable)4 Catalog (org.voltdb.catalog.Catalog)4 URL (java.net.URL)3 DeploymentType (org.voltdb.compiler.deploymentfile.DeploymentType)3 VoltFile (org.voltdb.utils.VoltFile)3 PrintWriter (java.io.PrintWriter)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2