Search in sources :

Example 36 with VoltProjectBuilder

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

the class TestJSONInterface method testSimple.

public void testSimple() throws Exception {
    try {
        String simpleSchema = "create table blah (" + "ival bigint default 23 not null, " + "sval varchar(200) default 'foo', " + "dateval timestamp, " + "fval float, " + "decval decimal, " + "PRIMARY KEY(ival));";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltDB.Configuration config = new VoltDB.Configuration();
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("blah", "ival");
        builder.addStmtProcedure("Insert", "insert into blah values (?,?,?,?,?);");
        builder.addProcedures(CrazyBlahProc.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"), 1, 1, 0, 0) != null;
        assertTrue(success);
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        ParameterSet pset;
        String responseJSON;
        Response response;
        // Call insert
        pset = ParameterSet.fromArrayNoCopy(1, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert again (with failure expected)
        responseJSON = callProcOverJSON("Insert", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status != ClientResponse.SUCCESS);
        // Call proc with complex params
        pset = ParameterSet.fromArrayNoCopy(1, 5, new double[] { 1.5, 6.0, 4 }, new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.BIGINT)), new BigDecimal(5), new BigDecimal[] {}, new TimestampType(System.currentTimeMillis()));
        responseJSON = callProcOverJSON("CrazyBlahProc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertEquals(ClientResponse.SUCCESS, response.status);
        // check the JSON itself makes sense
        JSONObject jsonObj = new JSONObject(responseJSON);
        JSONArray results = jsonObj.getJSONArray("results");
        assertEquals(4, response.results.length);
        JSONObject table = results.getJSONObject(0);
        JSONArray data = table.getJSONArray("data");
        assertEquals(1, data.length());
        JSONArray row = data.getJSONArray(0);
        assertEquals(1, row.length());
        long value = row.getLong(0);
        assertEquals(1, value);
        // try to pass a string as a date
        java.sql.Timestamp ts = new java.sql.Timestamp(System.currentTimeMillis());
        ts.setNanos(123456000);
        pset = ParameterSet.fromArrayNoCopy(1, 5, new double[] { 1.5, 6.0, 4 }, new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.BIGINT)), new BigDecimal(5), new BigDecimal[] {}, ts.toString());
        responseJSON = callProcOverJSON("CrazyBlahProc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertEquals(ClientResponse.SUCCESS, response.status);
        response.results[3].advanceRow();
        System.out.println(response.results[3].getTimestampAsTimestamp(0).getTime());
        assertEquals(123456, response.results[3].getTimestampAsTimestamp(0).getTime() % 1000000);
        // now try a null short value sent as a int  (param expects short)
        pset = ParameterSet.fromArrayNoCopy(1, VoltType.NULL_SMALLINT, new double[] { 1.5, 6.0, 4 }, new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.BIGINT)), new BigDecimal(5), new BigDecimal[] {}, new TimestampType(System.currentTimeMillis()));
        responseJSON = callProcOverJSON("CrazyBlahProc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertFalse(response.status == ClientResponse.SUCCESS);
        // now try an out of range long value (param expects short)
        pset = ParameterSet.fromArrayNoCopy(1, Long.MAX_VALUE - 100, new double[] { 1.5, 6.0, 4 }, new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.BIGINT)), new BigDecimal(5), new BigDecimal[] {}, new TimestampType(System.currentTimeMillis()));
        responseJSON = callProcOverJSON("CrazyBlahProc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertFalse(response.status == ClientResponse.SUCCESS);
        // now try bigdecimal with small value
        pset = ParameterSet.fromArrayNoCopy(1, 4, new double[] { 1.5, 6.0, 4 }, new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.BIGINT)), 5, new BigDecimal[] {}, new TimestampType(System.currentTimeMillis()));
        responseJSON = callProcOverJSON("CrazyBlahProc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        System.out.println(response.statusString);
        assertEquals(ClientResponse.SUCCESS, response.status);
        // now try null
        pset = ParameterSet.fromArrayNoCopy(1, 4, new double[] { 1.5, 6.0, 4 }, new VoltTable(new VoltTable.ColumnInfo("foo", VoltType.BIGINT)), 5, new BigDecimal[] {}, null);
        responseJSON = callProcOverJSON("CrazyBlahProc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        System.out.println(response.statusString);
        assertEquals(ClientResponse.SUCCESS, response.status);
        // now try jsonp
        responseJSON = callProcOverJSONRaw("Procedure=@Statistics&Parameters=[TABLE]&jsonp=fooBar", 200);
        System.out.println(responseJSON);
        assertTrue(responseJSON.startsWith("fooBar("));
        // now try adhoc
        pset = ParameterSet.fromArrayNoCopy("select * from blah");
        responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        System.out.println(response.statusString);
        assertEquals(ClientResponse.SUCCESS, response.status);
        // now try adhoc insert with a huge bigint
        pset = ParameterSet.fromArrayNoCopy("insert into blah values (974599638818488300, NULL, NULL, NULL, NULL);");
        responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        System.out.println(response.statusString);
        assertEquals(ClientResponse.SUCCESS, response.status);
        pset = ParameterSet.fromArrayNoCopy("select * from blah where ival = 974599638818488300;");
        responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        System.out.println(response.statusString);
        assertEquals(ClientResponse.SUCCESS, response.status);
        assertEquals(1, response.results.length);
        assertEquals(1, response.results[0].getRowCount());
        // Call @AdHoc with zero parameters
        pset = ParameterSet.emptyParameterSet();
        responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        assertTrue(responseJSON.contains("Adhoc system procedure requires at least the query parameter."));
        // Call @AdHoc with many parameters (more than 2)
        pset = ParameterSet.fromArrayNoCopy("select * from blah", "foo", "bar");
        responseJSON = callProcOverJSON("@AdHoc", pset, null, null, false);
        System.err.println(responseJSON);
        assertTrue(responseJSON.contains("Too many actual arguments were passed for the parameters in the sql " + "statement(s): (2 vs. 0)"));
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) JSONArray(org.json_voltpatches.JSONArray) BigDecimal(java.math.BigDecimal) ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) JSONObject(org.json_voltpatches.JSONObject) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) TimestampType(org.voltdb.types.TimestampType) File(java.io.File)

Example 37 with VoltProjectBuilder

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

the class TestJSONInterface method testDeploymentSecurityAuthorizationBasic.

public void testDeploymentSecurityAuthorizationBasic() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("foo", "bar");
        builder.addProcedures(DelayProc.class);
        builder.setHTTPDPort(8095);
        UserInfo[] users = new UserInfo[] { new UserInfo("user1", "admin", new String[] { "user" }), new UserInfo("user2", "admin", new String[] { "administrator" }) };
        builder.addUsers(users);
        // suite defines its own ADMINISTRATOR user
        builder.setSecurityEnabled(true, false);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        //Get deployment bad user
        String dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", "user1", "admin", "basic", 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", "user2", "admin", "basic", 200, "application/json");
        assertTrue(dep.contains("cluster"));
        //Download deployment bad user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user1", "admin", "basic", 401, "application/json");
        assertTrue(dep.contains("Permission denied"));
        //good user
        dep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment/download", "user2", "admin", "basic", 200, "text/xml");
        assertTrue(dep.contains("<deployment>"));
        assertTrue(dep.contains("</deployment>"));
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) File(java.io.File)

Example 38 with VoltProjectBuilder

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

the class TestJSONInterface method testBinaryProc.

public void testBinaryProc() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    b VARBINARY(256) DEFAULT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addLiteralSchema(simpleSchema);
        builder.addPartitionInfo("foo", "bar");
        builder.addStmtProcedure("Insert", "insert into foo values (?, ?);");
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        // try a good insert
        String varString = "Procedure=Insert&Parameters=[5,\"aa\"]";
        String response = callProcOverJSONRaw(varString, 200);
        System.out.println(response);
        Response r = responseFromJSON(response);
        assertEquals(ClientResponse.SUCCESS, r.status);
        // try two poorly hex-encoded inserts
        varString = "Procedure=Insert&Parameters=[6,\"aaa\"]";
        response = callProcOverJSONRaw(varString, 200);
        System.out.println(response);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.GRACEFUL_FAILURE, r.status);
        varString = "Procedure=Insert&Parameters=[7,\"aaay\"]";
        response = callProcOverJSONRaw(varString, 200);
        System.out.println(response);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.GRACEFUL_FAILURE, r.status);
        // try null binary inserts
        varString = "Procedure=Insert&Parameters=[8,NULL]";
        response = callProcOverJSONRaw(varString, 200);
        System.out.println(response);
        r = responseFromJSON(response);
        assertEquals(ClientResponse.SUCCESS, r.status);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration)

Example 39 with VoltProjectBuilder

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

the class TestJSONInterface method testUpdateDeployment.

public void testUpdateDeployment() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("foo", "bar");
        builder.addProcedures(DelayProc.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        //Get deployment
        String jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        //POST deployment with no content
        String pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 400, "application/json", null);
        assertTrue(pdep.contains("Failed"));
        Map<String, String> params = new HashMap<>();
        params.put("deployment", jdep);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        assertTrue(pdep.contains("Deployment Updated"));
        //POST deployment in admin mode
        params.put("admin", "true");
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        assertTrue(pdep.contains("Deployment Updated"));
        ObjectMapper mapper = new ObjectMapper();
        DeploymentType deptype = mapper.readValue(jdep, DeploymentType.class);
        //Test change heartbeat.
        if (deptype.getHeartbeat() == null) {
            HeartbeatType hb = new HeartbeatType();
            hb.setTimeout(99);
            deptype.setHeartbeat(hb);
        } else {
            deptype.getHeartbeat().setTimeout(99);
        }
        String ndeptype = mapper.writeValueAsString(deptype);
        params.put("deployment", ndeptype);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        System.out.println("POST result is: " + pdep);
        assertTrue(pdep.contains("Deployment Updated"));
        jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        deptype = mapper.readValue(jdep, DeploymentType.class);
        int nto = deptype.getHeartbeat().getTimeout();
        assertEquals(99, nto);
        //Test change Query timeout
        SystemSettingsType ss = deptype.getSystemsettings();
        if (ss == null) {
            ss = new SystemSettingsType();
            deptype.setSystemsettings(ss);
        }
        Query qv = ss.getQuery();
        if (qv == null) {
            qv = new Query();
            qv.setTimeout(99);
        } else {
            qv.setTimeout(99);
        }
        ss.setQuery(qv);
        deptype.setSystemsettings(ss);
        ndeptype = mapper.writeValueAsString(deptype);
        params.put("deployment", ndeptype);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        System.out.println("POST result is: " + pdep);
        assertTrue(pdep.contains("Deployment Updated"));
        jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        deptype = mapper.readValue(jdep, DeploymentType.class);
        nto = deptype.getSystemsettings().getQuery().getTimeout();
        assertEquals(99, nto);
        qv.setTimeout(88);
        ss.setQuery(qv);
        deptype.setSystemsettings(ss);
        ndeptype = mapper.writeValueAsString(deptype);
        params.put("deployment", ndeptype);
        pdep = postUrlOverJSON(protocolPrefix + "localhost:8095/deployment/", null, null, null, 200, "application/json", params);
        System.out.println("POST result is: " + pdep);
        assertTrue(pdep.contains("Deployment Updated"));
        jdep = getUrlOverJSON(protocolPrefix + "localhost:8095/deployment", null, null, null, 200, "application/json");
        assertTrue(jdep.contains("cluster"));
        deptype = mapper.readValue(jdep, DeploymentType.class);
        nto = deptype.getSystemsettings().getQuery().getTimeout();
        assertEquals(88, nto);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) Query(org.voltdb.compiler.deploymentfile.SystemSettingsType.Query) HashMap(java.util.HashMap) DeploymentType(org.voltdb.compiler.deploymentfile.DeploymentType) HeartbeatType(org.voltdb.compiler.deploymentfile.HeartbeatType) SystemSettingsType(org.voltdb.compiler.deploymentfile.SystemSettingsType) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 40 with VoltProjectBuilder

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

the class TestJSONInterface method testJSONDisabled.

public void testJSONDisabled() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE HELLOWORLD (\n" + "    HELLO VARCHAR(15),\n" + "    WORLD VARCHAR(15),\n" + "    DIALECT VARCHAR(15) NOT NULL,\n" + "    PRIMARY KEY (DIALECT)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("HELLOWORLD", "DIALECT");
        builder.addStmtProcedure("Insert", "insert into HELLOWORLD values (?,?,?);");
        builder.setHTTPDPort(8095);
        builder.setJSONAPIEnabled(false);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        // test not enabled
        ParameterSet pset = ParameterSet.fromArrayNoCopy("foo", "bar", "foobar");
        try {
            // HTTP_FORBIDDEN
            callProcOverJSON("Insert", pset, null, null, false, false, 403, ClientAuthScheme.HASH_SHA256);
        } catch (Exception e) {
            // make sure failed due to permissions on http
            assertTrue(e.getMessage().contains("403"));
        }
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) JSONException(org.json_voltpatches.JSONException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

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