Search in sources :

Example 56 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class MiscUtils method formatHostMetadataFromJSON.

public static String formatHostMetadataFromJSON(String json) {
    try {
        JSONObject obj = new JSONObject(json);
        StringBuilder sb = new StringBuilder();
        JSONArray interfaces = (JSONArray) obj.get("interfaces");
        for (int ii = 0; ii < interfaces.length(); ii++) {
            sb.append(interfaces.getString(ii));
            if (ii + 1 < interfaces.length()) {
                sb.append(" ");
            }
        }
        sb.append(" ");
        sb.append(obj.getString("clientPort")).append(',');
        sb.append(obj.getString("adminPort")).append(',');
        sb.append(obj.getString("httpPort"));
        return sb.toString();
    } catch (Exception e) {
        hostLog.warn("Unable to format host metadata " + json, e);
    }
    return "";
}
Also used : JSONObject(org.json_voltpatches.JSONObject) JSONArray(org.json_voltpatches.JSONArray) URISyntaxException(java.net.URISyntaxException) BindException(java.net.BindException) IOException(java.io.IOException) LicenseException(org.voltdb.licensetool.LicenseException)

Example 57 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class plannerTester method loadPlanFromFile.

public static AbstractPlanNode loadPlanFromFile(String path, ArrayList<String> getsql) {
    BufferedReader reader;
    try {
        reader = new BufferedReader(new FileReader(path));
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
        String message = "ERROR: Plan file " + path + " doesn't exist.\n" + "Use -s (the Compile/Save option) or 'ant plannertestrefresh'" + " ' to generate plans to the baseline directory.\n";
        System.err.print(message);
        try {
            m_reportWriter.write(message);
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        return null;
    }
    try {
        String json = "";
        try {
            String line = reader.readLine();
            getsql.add(line);
            while ((line = reader.readLine()) != null) {
                json += line;
            }
        } catch (IOException e2) {
            e2.printStackTrace();
            return null;
        }
        try {
            PlanNodeTree pnt = new PlanNodeTree();
            JSONObject jobj = new JSONObject(json);
            Database db = s_singleton.getDatabase();
            pnt.loadFromJSONPlan(jobj, db);
            return pnt.getRootPlanNode();
        } catch (JSONException e3) {
            e3.printStackTrace();
            System.out.println("Failed on input from file: " + path + " with JSON text: \n'" + json + "'");
            return null;
        }
    } finally {
        try {
            reader.close();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
    }
}
Also used : JSONObject(org.json_voltpatches.JSONObject) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Database(org.voltdb.catalog.Database) JSONException(org.json_voltpatches.JSONException) FileReader(java.io.FileReader) IOException(java.io.IOException) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Example 58 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class testLoadPlanNodeFromJSON method testLoadQueryPlanTree.

public void testLoadQueryPlanTree(String sql) throws JSONException {
    AbstractPlanNode pn = compile(sql);
    PlanNodeTree pnt = new PlanNodeTree(pn);
    String str = pnt.toJSONString();
    JSONObject jsonPlan = new JSONObject(str);
    PlanNodeTree pnt1 = new PlanNodeTree();
    pnt1.loadFromJSONPlan(jsonPlan, getDatabase());
    String str1 = pnt1.toJSONString();
    assertTrue(str.equals(str1));
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) JSONObject(org.json_voltpatches.JSONObject) PlanNodeTree(org.voltdb.plannodes.PlanNodeTree)

Example 59 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class testPlannerTester method testGetScanNodeList.

/// Unit test some of the techniques used by plannerTester
public void testGetScanNodeList() {
    AbstractPlanNode pn = null;
    pn = compile("select * from l where lname=? and b=0 order by id asc limit ?;");
    ArrayList<AbstractScanPlanNode> collected = pn.getScanNodeList();
    System.out.println(collected);
    System.out.println(collected.size());
    for (AbstractPlanNode n : collected) {
        System.out.println(n.toExplainPlanString());
    }
    assertTrue(collected.size() == 1);
    JSONObject j;
    try {
        j = new JSONObject(collected.get(0).toJSONString());
        System.out.println(j.getString("PLAN_NODE_TYPE"));
        assertTrue(j.getString("PLAN_NODE_TYPE").equalsIgnoreCase("INDEXSCAN"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : AbstractPlanNode(org.voltdb.plannodes.AbstractPlanNode) AbstractScanPlanNode(org.voltdb.plannodes.AbstractScanPlanNode) JSONObject(org.json_voltpatches.JSONObject) JSONException(org.json_voltpatches.JSONException)

Example 60 with JSONObject

use of org.json_voltpatches.JSONObject in project voltdb by VoltDB.

the class TestSystemCatalogSuite method testTablesSelector.

public void testTablesSelector() throws IOException, ProcCallException, JSONException {
    Client client = getClient();
    VoltTable results = client.callProcedure("@SystemCatalog", "TABLES").getResults()[0];
    assertEquals(10, results.getColumnCount());
    // Tables are returned in alphabetical order, because the underlying CatalogMap
    // is backed by java.util.TreeMap
    results.advanceRow();
    assertEquals("AA_T", results.get("TABLE_NAME", VoltType.STRING));
    assertEquals("{\"partitionColumn\":\"A1\",\"drEnabled\":\"true\"}", results.get("REMARKS", VoltType.STRING));
    results.advanceRow();
    assertEquals("BB_V", results.get("TABLE_NAME", VoltType.STRING));
    assertEquals(new JSONObject("{\"partitionColumn\":\"A1\",\"sourceTable\":\"AA_T\"}").toString(), results.get("REMARKS", VoltType.STRING));
    results.advanceRow();
    assertEquals("CC_T_WITH_EXEC_DELETE", results.get("TABLE_NAME", VoltType.STRING));
    assertEquals("{\"partitionColumn\":\"A1\"," + "\"limitPartitionRowsDeleteStmt\":\"DELETE FROM CC_T_WITH_EXEC_DELETE WHERE A1=0;\"}", results.get("REMARKS", VoltType.STRING));
    assertEquals(false, results.advanceRow());
}
Also used : JSONObject(org.json_voltpatches.JSONObject) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Aggregations

JSONObject (org.json_voltpatches.JSONObject)123 JSONException (org.json_voltpatches.JSONException)45 JSONArray (org.json_voltpatches.JSONArray)30 IOException (java.io.IOException)20 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)18 HashMap (java.util.HashMap)17 File (java.io.File)14 Map (java.util.Map)14 ByteBuffer (java.nio.ByteBuffer)13 ExecutionException (java.util.concurrent.ExecutionException)12 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 TreeSet (java.util.TreeSet)6 JSONStringer (org.json_voltpatches.JSONStringer)6 HashSet (java.util.HashSet)5 BinaryPayloadMessage (org.voltcore.messaging.BinaryPayloadMessage)5 ImmutableList (com.google_voltpatches.common.collect.ImmutableList)4 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)4 InetAddress (java.net.InetAddress)4