Search in sources :

Example 11 with VoltProjectBuilder

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

the class HTTPAdminListenerStarter method main.

/**
     * Added a main here for manual test purposes. It just starts up
     * a brain-dead VoltDB server so you can look at the admin page.
     */
public static void main(String[] args) throws Exception {
    String simpleSchema = "create table blah (" + "ival bigint default 0 not null, " + "PRIMARY KEY(ival));";
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema(simpleSchema);
    builder.addPartitionInfo("blah", "ival");
    builder.addStmtProcedure("Insert", "insert into blah values (?);", null);
    builder.setHTTPDPort(8080);
    builder.setJSONAPIEnabled(true);
    boolean success = builder.compile(Configuration.getPathToCatalogForTest("rejoin.jar"), 1, 1, 0);
    assert (success);
    MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml"));
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = Configuration.getPathToCatalogForTest("rejoin.jar");
    config.m_pathToDeployment = Configuration.getPathToCatalogForTest("rejoin.xml");
    ServerThread localServer = new ServerThread(config);
    localServer.start();
    localServer.waitForInitialization();
    Thread.sleep(240000);
}
Also used : VoltDB(org.voltdb.VoltDB) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ServerThread(org.voltdb.ServerThread)

Example 12 with VoltProjectBuilder

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

the class TestCatalogUtil method verifyDrTableSignature.

private void verifyDrTableSignature(boolean shouldEqual, String schemaA, String schemaB) throws IOException {
    String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
    final File fileA = VoltFile.createTempFile("catA", ".jar", new File(testDir));
    final File fileB = VoltFile.createTempFile("catB", ".jar", new File(testDir));
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema(schemaA);
    builder.compile(fileA.getPath());
    Catalog catA = TestCatalogDiffs.catalogForJar(fileA.getPath());
    builder = new VoltProjectBuilder();
    builder.addLiteralSchema(schemaB);
    builder.compile(fileB.getPath());
    Catalog catB = TestCatalogDiffs.catalogForJar(fileB.getPath());
    fileA.delete();
    fileB.delete();
    final Pair<Long, String> sigA = CatalogUtil.calculateDrTableSignatureAndCrc(catA.getClusters().get("cluster").getDatabases().get("database"));
    final Pair<Long, String> sigB = CatalogUtil.calculateDrTableSignatureAndCrc(catB.getClusters().get("cluster").getDatabases().get("database"));
    assertFalse(sigA.getFirst() == 0);
    assertFalse(sigA.getSecond().isEmpty());
    assertEquals(shouldEqual, sigA.equals(sigB));
}
Also used : VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) File(java.io.File) Catalog(org.voltdb.catalog.Catalog)

Example 13 with VoltProjectBuilder

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

the class TestAdhocCreateDropJavaProc method testBasic.

@Test
public void testBasic() throws Exception {
    System.out.println("\n\n-----\n testBasic \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    try {
        LocalCluster cluster = new LocalCluster("updateclasses.jar", 2, 1, 0, BackendTarget.NATIVE_EE_JNI);
        cluster.compile(builder);
        cluster.setHasLocalServer(false);
        cluster.startUp();
        m_client = ClientFactory.createClient();
        m_client.createConnection(cluster.getListenerAddress(0));
        ClientResponse resp;
        // Can't create a procedure without a class
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println("CLASSES: " + resp.getResults()[0]);
        try {
            resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
            fail("Shouldn't be able to create a procedure backed by no class");
        } catch (ProcCallException pce) {
        }
        assertFalse(findProcedureInSystemCatalog("testImportProc"));
        InMemoryJarfile jarfile = new InMemoryJarfile();
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        // call the procedure.  Maybe this gets better in the future
        try {
            resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
        } catch (ProcCallException pce) {
            fail("We allow procedures to be created with unsatisfied dependencies");
        }
        assertTrue(findProcedureInSystemCatalog("testImportProc"));
        // Make sure we don't crash when we call it though
        try {
            resp = m_client.callProcedure("testImportProc");
            fail("Should return an error and not crash calling procedure w/ bad dependencies");
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("ClassNotFoundException"));
        }
        // Okay, add the missing dependency
        jarfile = new InMemoryJarfile();
        comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.NoMeaningClass.class);
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        // now we should be able to call it
        try {
            resp = m_client.callProcedure("testImportProc");
        } catch (ProcCallException pce) {
            fail("Should be able to call fully consistent procedure");
        }
        assertEquals(10L, resp.getResults()[0].asScalarLong());
        // Now try to remove the procedure class
        try {
            resp = m_client.callProcedure("@UpdateClasses", null, "org.voltdb_testprocs.updateclasses.*");
            fail("Shouldn't be able to rip a class out from under an active proc");
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage(), pce.getMessage().contains("Cannot load class for procedure: org.voltdb_testprocs.updateclasses.testImportProc"));
        }
        // Make sure we didn't purge anything (even the extra dependency)
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        assertEquals(2, resp.getResults()[0].getRowCount());
        // Okay, drop the procedure first
        try {
            resp = m_client.callProcedure("@AdHoc", "drop procedure testImportProc");
        } catch (ProcCallException pce) {
            fail("Should be able to drop a stored procedure");
        }
        assertFalse(findProcedureInSystemCatalog("testImportProc"));
        // Now try to remove the procedure class again
        try {
            resp = m_client.callProcedure("@UpdateClasses", null, "org.voltdb_testprocs.updateclasses.*");
        } catch (ProcCallException pce) {
            fail("Should be able to remove the classes for an inactive procedure");
        }
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        // no classes in catalog
        assertEquals(0, resp.getResults()[0].getRowCount());
        m_client.close();
        cluster.shutDown();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) LocalCluster(org.voltdb.regressionsuites.LocalCluster) VoltCompiler(org.voltdb.compiler.VoltCompiler) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ProcCallException(org.voltdb.client.ProcCallException) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 14 with VoltProjectBuilder

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

the class TestAdhocCreateDropJavaProc method testCreateUsingExistingImport.

// This test should trigger the same failure seen in ENG-6611
@Test
public void testCreateUsingExistingImport() throws Exception {
    System.out.println("\n\n-----\n testCreateUsingExistingImport \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    // Start off with the dependency imported
    builder.addLiteralSchema("import class org.voltdb_testprocs.updateclasses.NoMeaningClass;");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    try {
        LocalCluster cluster = new LocalCluster("updateclasses.jar", 2, 1, 0, BackendTarget.NATIVE_EE_JNI);
        cluster.compile(builder);
        cluster.setHasLocalServer(false);
        cluster.startUp();
        m_client = ClientFactory.createClient();
        m_client.createConnection(cluster.getListenerAddress(0));
        ClientResponse resp;
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // Now load the procedure requiring the already-resident dependency
        InMemoryJarfile jarfile = new InMemoryJarfile();
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Triggered ENG-6611!");
        }
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        assertEquals(2, resp.getResults()[0].getRowCount());
        // create the proc and make sure it runs
        try {
            resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
        } catch (ProcCallException pce) {
            fail("Should be able to create testImportProc procedure");
        }
        assertTrue(findProcedureInSystemCatalog("testImportProc"));
        try {
            resp = m_client.callProcedure("testImportProc");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to call fully consistent procedure");
        }
        assertEquals(10L, resp.getResults()[0].asScalarLong());
        m_client.close();
        cluster.shutDown();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) LocalCluster(org.voltdb.regressionsuites.LocalCluster) VoltCompiler(org.voltdb.compiler.VoltCompiler) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ProcCallException(org.voltdb.client.ProcCallException) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 15 with VoltProjectBuilder

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

the class TestAdhocDropCreateTable method testDropCreateTableError.

@Test
public void testDropCreateTableError() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table FOO (ID integer);");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;
    try {
        startSystem(config);
        // separate commands (succeed)
        assertTrue(findTableInSystemCatalogResults("FOO"));
        try {
            m_client.callProcedure("@AdHoc", "drop table FOO;");
            m_client.callProcedure("@AdHoc", "create table FOO (ID integer);");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Separate DROP/CREATE commands should have worked.");
        }
        // batch with conflicting DROP/CREATE for same table (fail)
        assertTrue(findTableInSystemCatalogResults("FOO"));
        boolean threw = false;
        try {
            m_client.callProcedure("@AdHoc", "drop table FOO; create table FOO (ID integer);");
        } catch (ProcCallException pce) {
            threw = true;
            boolean correct = pce.getMessage().contains("contains both DROP and CREATE");
            assertTrue("Wrong error received for DROP/CREATE batch.", correct);
        }
        assertTrue("DROP/CREATE batch didn't fail.", threw);
        // batch with non-conflicting DROP/CREATE for different tables (succeed)
        assertTrue(findTableInSystemCatalogResults("FOO"));
        assertFalse(findTableInSystemCatalogResults("FO"));
        try {
            m_client.callProcedure("@AdHoc", "drop table FOO; create table FO (NAME varchar(20));");
        } catch (ProcCallException pce) {
            fail("Non-conflicting DROP/CREATE commands should have worked.");
        }
        assertFalse(findTableInSystemCatalogResults("FOO"));
        assertTrue(findTableInSystemCatalogResults("FO"));
    } finally {
        teardownSystem();
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Aggregations

VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)269 Configuration (org.voltdb.VoltDB.Configuration)89 IOException (java.io.IOException)49 Test (org.junit.Test)45 File (java.io.File)40 ProcCallException (org.voltdb.client.ProcCallException)38 ClientResponse (org.voltdb.client.ClientResponse)37 VoltDB (org.voltdb.VoltDB)22 LocalCluster (org.voltdb.regressionsuites.LocalCluster)18 Client (org.voltdb.client.Client)17 Before (org.junit.Before)14 HashMap (java.util.HashMap)13 VoltTable (org.voltdb.VoltTable)13 ServerThread (org.voltdb.ServerThread)12 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)12 VoltCompiler (org.voltdb.compiler.VoltCompiler)11 HttpResponse (org.apache.http.HttpResponse)10 BeforeClass (org.junit.BeforeClass)8 ClientConfig (org.voltdb.client.ClientConfig)7 UserInfo (org.voltdb.compiler.VoltProjectBuilder.UserInfo)7