public String jsonize() throws JSONSerDeException { return JSONSerDe.ser(mapify()); } }
@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); } } }
@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); } }
@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); } }
/** * 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(); }
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);
+ "], key[" + key + "], sql[" + sql + "] time[" + (System.currentTimeMillis() - startTime) + "] " + status); String response; response = JSONSerDe.ser(st); if (callback != null) { response = callback + "(" + response + ")";
@Override public String abortDeploy(long version) throws DNodeException { try { synchronized (deployLock) { // No new deploys to be handled until we // cancel the current one Future<?> future = deploysBeingExecuted.get(version); if (future == null) { return JSONSerDe.ser(new DNodeStatusResponse("Not deployment running with version["+version+"]")); } future.cancel(true); return JSONSerDe.ser(new DNodeStatusResponse("status[OK]. Deploy with version["+version+"] cancelled.")); } } catch (JSONSerDeException e) { unexpectedException(e); throw new DNodeException(EXCEPTION_UNEXPECTED, e.getMessage()); } }
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); } }
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 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); } }
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 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); } }
/** * Thrift RPC method -> Given a list of {@link DeployAction}s and a version * identifying the deployment perform an asynchronous deploy. */ @Override public String deploy(final List<DeployAction> deployActions, final long version) throws DNodeException { try { synchronized (deployLock) { Thread deployWait = getDeployControllerThread(deployActions, version); deployWait.start(); } // Everything is asynchronous so this is quickly reached - it just means // the process has started return JSONSerDe.ser(new DNodeStatusResponse("Ok. Deploy initiated")); } catch (Throwable t) { unexpectedException(t); throw new DNodeException(EXCEPTION_UNEXPECTED, t.getMessage()); } }
throw new SQLException("Hard limit on number of results reached (" + maxResults + "), please use a LIMIT for this query."); return JSONSerDe.ser(list); } catch(SQLiteException e) { throw new SQLException(e);
/** * Thrift RPC method -> Given a list of {@link RollbackAction}s, perform a * synchronous rollback */ @Override public String rollback(List<RollbackAction> rollbackActions, String ignoreMe) throws DNodeException { // The DNode doesn't need to do anything special for rolling back a version. // It can serve any version that is stored locally. try { return JSONSerDe.ser(new DNodeStatusResponse("Ok. Rollback order received.")); } catch (JSONSerDeException e) { unexpectedException(e); throw new DNodeException(EXCEPTION_UNEXPECTED, e.getMessage()); } }
@Override public String deleteOldVersions(List<com.splout.db.thrift.TablespaceVersion> versions) throws DNodeException { for (com.splout.db.thrift.TablespaceVersion version : versions) { log.info("Going to remove " + version + " as I have been told to do so."); try { deleteLocalVersion(version); } catch (Throwable e) { unexpectedException(e); throw new DNodeException(EXCEPTION_UNEXPECTED, e.getMessage()); } } try { // Publish new DNodeInfo in distributed registry. // This makes QNodes notice that a new version is available... // PartitionMap and ReplicationMap will be built incrementally as DNodes // finish. dnodesRegistry.changeInfo(new DNodeInfo(config)); return JSONSerDe.ser(new DNodeStatusResponse("Ok. Delete old versions executed.")); } catch (JSONSerDeException e) { unexpectedException(e); throw new DNodeException(EXCEPTION_UNEXPECTED, e.getMessage()); } }
return JSONSerDe.ser(new DNodeStatusResponse("Ok. Test command " + commandStr + " received properly.")); } catch (JSONSerDeException e) { unexpectedException(e);
status.setFiles(new ArrayList<String>()); return JSONSerDe.ser(status); } catch (Throwable t) { unexpectedException(t);