public DeployInfo deploy(final DeployRequest... requests) throws IOException { try { String strCont = JSONSerDe.ser(new ArrayList<DeployRequest>(Arrays.asList(requests))); HttpContent content = new StringHttpContent(strCont); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/deploy"), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), DeployInfo.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
protected Map<String, Long> readValues(File file) throws JSONSerDeException, IOException { if (file.exists()) { return JSONSerDe.deSer(Files.toString(file, UTF8), MAP_STRING_LONG_TYPE_REF); } else { return null; } } }
public String jsonize() throws JSONSerDeException { return JSONSerDe.ser(mapify()); } }
protected JSONTablespaceDefinition loadTablespaceFile(String tablespaceFile) throws IOException, JSONSerDe.JSONSerDeException { Path file = new Path(tablespaceFile); FileSystem fS = FileSystem.get(file.toUri(), getConf()); if (!fS.exists(file)) { throw new IllegalArgumentException("Config input file: " + file + " doesn't exist!"); } String strContents = HadoopUtils.fileToString(fS, file); JSONTablespaceDefinition def = JSONSerDe.deSer(strContents, JSONTablespaceDefinition.class); return def; }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String sql = req.getParameter("sql"); String key = req.getParameter("key"); log.info("query, key[" + key + "] sql[" + sql + "]"); try { resp.getWriter().write(JSONSerDe.ser(client.query("pagecounts", key, sql, null))); } catch (JSONSerDeException e) { throw new IOException(e); } } }
public DeployInfo deploy(final DeployRequest... requests) throws IOException { try { String strCont = JSONSerDe.ser(new ArrayList<DeployRequest>(Arrays.asList(requests))); HttpContent content = new StringHttpContent(strCont); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/deploy"), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), DeployInfo.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
@SuppressWarnings({"unchecked", "rawtypes"}) @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String tablespace = req.getParameter("tablespace"); StringBuffer postBody = new StringBuffer(); String line = null; BufferedReader reader = req.getReader(); while ((line = reader.readLine()) != null) { postBody.append(line); } Map<String, Object> params; try { params = JSONSerDe.deSer(postBody.toString(), Map.class); String[] keys = (String[]) ((ArrayList) params.get("key")).toArray(new String[0]); String sql = (String) params.get("sql"); String callback = (String) params.get("callback"); String partition = (String) params.get("partition"); handle(req, resp, keys, tablespace, sql, callback, partition); } catch(JSONSerDeException e) { throw new IOException(e); } }
@Override public void store(String key, Map<String, Long> value) { log.info("Store: " + key + " value: " + value); try { /** * Save value as UTF8 String in a File */ Files.write(JSONSerDe.ser(value).getBytes(UTF8), getKeyFile(key)); } catch (IOException e) { throw new RuntimeException(e); } catch (JSONSerDeException e) { throw new RuntimeException(e); } }
public QueryStatus queryPost(String tablespace, String key, String query, String partition) throws IOException { Map<String, Object> params = new HashMap<String, Object>(); params.put("sql", query); params.put("key", new String[] { key }); params.put("partition", partition); try { HttpContent content = new StringHttpContent(JSONSerDe.ser(params)); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/query/" + tablespace), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch(JSONSerDeException e) { throw new IOException(e); } } }
public QueryStatus query(String tablespace, String key, String query, String partition) throws IOException { URI uri; try { uri = new URI("http", qNodesNoProtocol[(int) (Math.random() * qNodes.length)], "/api/query/" + tablespace, "&sql=" + query + (key != null ? "&key=" + key : "") + (partition != null ? "&partition=" + partition : ""), null); HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri.toASCIIString())); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch(JSONSerDeException e) { throw new IOException(e); } } catch(URISyntaxException e) { throw new IllegalArgumentException(e); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setHeader("content-type", "application/json;charset=UTF-8"); resp.setCharacterEncoding("UTF-8"); String action = req.getParameter("action"); String response = null; try { if (action.equals(ACTION_CANCEL_DEPLOYMENT)) { response = JSONSerDe.ser(qNodeHandler.cancelDeployment(req.getParameter("version"))); // JSONP support if (req.getParameter("callback") != null) { response = req.getParameter("callback") + "(" + response + ")"; } } else { throw new ServletException("Unknown action: " + action); } resp.getWriter().append(response); } catch (Exception e) { log.error(e); throw new ServletException(e); } }
public QueryStatus queryPost(String tablespace, String key, String query, String partition) throws IOException { Map<String, Object> params = new HashMap<String, Object>(); params.put("sql", query); params.put("key", new String[]{key}); params.put("partition", partition); try { HttpContent content = new StringHttpContent(JSONSerDe.ser(params)); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/query/" + tablespace), content); HttpResponse resp = request.execute(); return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch (JSONSerDeException e) { throw new IOException(e); } }
public QueryStatus query(String tablespace, String key, String query, String partition) throws IOException { URI uri; try { uri = new URI("http", qNodesNoProtocol[(int) (Math.random() * qNodes.length)], "/api/query/" + tablespace, "&sql=" + query + (key != null ? "&key=" + key : "") + (partition != null ? "&partition=" + partition : "") , null); HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(uri.toASCIIString())); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), QueryStatus.class); } catch (JSONSerDeException e) { throw new IOException(e); } } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
/** * Write the partition map and other metadata to the output folder. They will * be needed for deploying the dataset to Splout. */ protected void writeOutputMetadata(Configuration conf) throws IOException, JSONSerDeException { FileSystem fileSystem = outputPath.getFileSystem(conf); // Write the Partition map Path partitionMapPath = new Path(outputPath, OUT_PARTITION_MAP); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileSystem.create(partitionMapPath, true))); writer.write(JSONSerDe.ser(partitionMap)); writer.close(); // Write init statements, if applicable if (tablespace.getInitStatements() != null) { Path initStatementsPath = new Path(outputPath, OUT_INIT_STATEMENTS); writer = new BufferedWriter(new OutputStreamWriter(fileSystem.create(initStatementsPath, true))); writer.write(JSONSerDe.ser(tablespace.getInitStatements())); writer.close(); } // Write the Engine ID so we know what we are deploying exactly afterwards Path enginePath = new Path(outputPath, OUT_ENGINE); writer = new BufferedWriter(new OutputStreamWriter(fileSystem.create(enginePath, true))); writer.write(tablespace.getEngine().getClass().getName()); writer.close(); }
List<DeployRequest> deployReq = JSONSerDe.deSer(postBody.toString(), DEPLOY_REQ_REF); response = JSONSerDe.ser(qNodeHandler.deploy(deployReq)); } else if (action.equals(ACTION_ROLLBACK)) { ArrayList<SwitchVersionRequest> rReq = JSONSerDe.deSer(postBody.toString(), ROLLBACK_REQ_REF); response = JSONSerDe.ser(qNodeHandler.rollback(rReq)); } else { throw new ServletException("Unknown action: " + action);
public Tablespace tablespace(String tablespace) throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/tablespace/" + tablespace)); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), Tablespace.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
if (action.equals(ACTION_DNODE_STATUS)) { String dnode = req.getParameter("dnode"); response = JSONSerDe.ser(qNodeHandler.dnodeStatus(dnode)); } else if (action.equals(ACTION_ALL_TABLESPACE_VERSIONS)) { String tablespace = req.getParameter("tablespace"); response = JSONSerDe.ser(qNodeHandler.allTablespaceVersions(tablespace)); } else if (action.equals(ACTION_TABLESPACE_INFO)) { String tablespace = req.getParameter("tablespace"); response = JSONSerDe.ser(qNodeHandler.tablespace(tablespace)); } else if (action.equals(ACTION_TABLESPACES)) { response = JSONSerDe.ser(qNodeHandler.tablespaces()); } else if (action.equals(ACTION_DNODE_LIST)) { response = JSONSerDe.ser(qNodeHandler.getDNodeList()); } else if (action.equals(ACTION_OVERVIEW)) { response = JSONSerDe.ser(qNodeHandler.overview()); } else if (action.equals(ACTION_DEPLOYMENTS_STATUS)) { response = JSONSerDe.ser(qNodeHandler.deploymentsStatus()); } else if (action.equals(ACTION_CLEAN_OLD_VERSIONS)) { response = JSONSerDe.ser(qNodeHandler.cleanOldVersions()); } else { throw new ServletException("Unknown action: " + action);
@SuppressWarnings("unchecked") public List<String> dNodeList() throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/dnodelist")); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), ArrayList.class); } catch(JSONSerDeException e) { throw new IOException(e); } }
+ "], key[" + key + "], sql[" + sql + "] time[" + (System.currentTimeMillis() - startTime) + "] " + status); String response; response = JSONSerDe.ser(st); if (callback != null) { response = callback + "(" + response + ")";
public Tablespace tablespace(String tablespace) throws IOException { HttpRequest request = requestFactory.buildGetRequest(new GenericUrl( qNodes[(int) (Math.random() * qNodes.length)] + "/api/tablespace/" + tablespace)); HttpResponse resp = request.execute(); try { return JSONSerDe.deSer(asString(resp.getContent()), Tablespace.class); } catch (JSONSerDeException e) { throw new IOException(e); } }