public static String to_json(Object m) { // return JSON.toJSONString(m); return JSONValue.toJSONString(m); }
public static String mergeIntoJson(Map into, Map newMap) { Map res = new HashMap(into); if (newMap != null) res.putAll(newMap); return JSONValue.toJSONString(res); }
@Override public byte[] serialize(Object obj) { try { return JSONValue.toJSONString(obj).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
private static String mergeIntoJson(Map into, Map newMap) { Map res = new HashMap(into); if(newMap!=null) res.putAll(newMap); return JSONValue.toJSONString(res); } }
@Override public byte[] serialize(OpaqueValue obj) { List toSer = new ArrayList(3); toSer.add(obj.currTxid); toSer.add(obj.curr); toSer.add(obj.prev); try { return JSONValue.toJSONString(toSer).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
public String toJSONString() { Map obj = new HashMap(); obj.put("taskid", _taskId); obj.put("task->component", _taskToComponent); // TODO: jsonify StormTopology // at the minimum should send source info return JSONValue.toJSONString(obj); }
public static String getJsonResponseBody(Object data, String callback, boolean needSerialize) { String serializedData = needSerialize ? JSONValue.toJSONString(data) : (String) data; return callback != null ? wrapJsonInCallback(callback, serializedData) : serializedData; }
@Override public String getNimbusConf() throws AuthorizationException, TException { try { getNimbusConfCalls.mark(); checkAuthorization(null, null, "getNimbusConf"); return JSONValue.toJSONString(conf); } catch (Exception e) { LOG.warn("get nimbus conf exception.", e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
public void writeJSON(String path, Map<Object, Object> data) { LOG.info("Writing " + path + " the data " + data.toString()); writeBytes(path, JSONValue.toJSONString(data).getBytes(Charset.forName("UTF-8"))); }
private void writeMessage(Object msg) throws IOException { writeString(JSONValue.toJSONString(msg)); }
@Override public byte[] serialize(TransactionalValue obj) { List toSer = new ArrayList(2); toSer.add(obj.getTxid()); toSer.add(obj.getVal()); try { return JSONValue.toJSONString(toSer).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
void commitState (String stream, String shardId, Map<Object, Object> state) { byte[] bytes = JSONValue.toJSONString(state).getBytes(Charset.forName("UTF-8")); try { String path = getZkPath(stream, shardId); if (curatorFramework.checkExists().forPath(path) == null) { curatorFramework.create() .creatingParentsIfNeeded() .withMode(CreateMode.PERSISTENT) .forPath(path, bytes); } else { curatorFramework.setData().forPath(path, bytes); } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public String getTopologyConf(String id) throws NotAliveException, AuthorizationException, TException { try { getTopologyConfCalls.mark(); Map<String, Object> topoConf = tryReadTopoConf(id, topoCache); Map<String, Object> checkConf = Utils.merge(conf, topoConf); String topoName = (String) checkConf.get(Config.TOPOLOGY_NAME); checkAuthorization(topoName, checkConf, "getTopologyConf"); return JSONValue.toJSONString(topoConf); } catch (Exception e) { LOG.warn("Get topo conf exception. (topology id='{}')", id, e); if (e instanceof TException) { throw (TException) e; } throw new RuntimeException(e); } }
private static void handleGetCommand(IStateStorage cluster, String path) { String message; byte[] hb = cluster.get_worker_hb(path, false); if (hb != null) { Map<String, Object> heartbeatMap = StatsUtil.convertZkWorkerHb(Utils.deserialize(hb, ClusterWorkerHeartbeat.class)); message = JSONValue.toJSONString(heartbeatMap); } else { message = "No Heartbeats found"; } LOG.info(message); } }
private static StormTopology normalizeTopology(Map<String, Object> topoConf, StormTopology topology) throws InvalidTopologyException { StormTopology ret = topology.deepCopy(); for (Object comp : StormCommon.allComponents(ret).values()) { Map<String, Object> mergedConf = StormCommon.componentConf(comp); mergedConf.put(Config.TOPOLOGY_TASKS, ServerUtils.getComponentParallelism(topoConf, comp)); String jsonConf = JSONValue.toJSONString(mergedConf); StormCommon.getComponentCommon(comp).set_json_conf(jsonConf); } return ret; }
protected void initCommon(String id, IComponent component, Number parallelism) throws IllegalArgumentException { ComponentCommon common = new ComponentCommon(); common.set_inputs(new HashMap<GlobalStreamId, Grouping>()); if (parallelism != null) { int dop = parallelism.intValue(); if(dop < 1) { throw new IllegalArgumentException("Parallelism must be positive."); } common.set_parallelism_hint(dop); } else { common.set_parallelism_hint(1); } Map conf = component.getComponentConfiguration(); if(conf!=null) common.set_json_conf(JSONValue.toJSONString(conf)); _commons.put(id, common); }
@Override public void run(Nimbus.Iface client) throws Exception { GetInfoOptions opts = new GetInfoOptions(); opts.set_num_err_choice(NumErrorsChoice.ONE); String topologyId = Utils.getTopologyId(name, client); TopologyInfo topologyInfo = null; if (topologyId != null) { topologyInfo = client.getTopologyInfoWithOpts(topologyId, opts); } Map<String, Object> outputMap = new HashMap<>(); if (topologyId == null || topologyInfo == null) { outputMap.put("Failure", "No topologies running with name " + name); } else { String topologyName = topologyInfo.get_name(); Map<String, List<ErrorInfo>> topologyErrors = topologyInfo.get_errors(); outputMap.put("Topology Name", topologyName); outputMap.put("Comp-Errors", getComponentErrors(topologyErrors)); } System.out.println(JSONValue.toJSONString(outputMap)); }
@Override public LocalTopology submitTopologyWithOpts(String topologyName, Map<String, Object> conf, StormTopology topology, SubmitOptions submitOpts) throws TException { if (!Utils.isValidConf(conf)) { throw new IllegalArgumentException("Topology conf is not json-serializable"); } getNimbus().submitTopologyWithOpts(topologyName, null, JSONValue.toJSONString(conf), Utils.addVersions(topology), submitOpts); return new LocalTopology(topologyName, topology); }
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { try { initializeSubprocess(context); _collector = collector; sendToSubprocess(JSONValue.toJSONString(stormConf)); sendToSubprocess(context.toJSONString()); } catch (IOException e) { throw new RuntimeException("Error when launching multilang subprocess", e); } }
@Override public LocalTopology submitTopology(String topologyName, Map<String, Object> conf, StormTopology topology) throws TException { if (!Utils.isValidConf(conf)) { throw new IllegalArgumentException("Topology conf is not json-serializable"); } getNimbus().submitTopology(topologyName, null, JSONValue.toJSONString(conf), Utils.addVersions(topology)); ISubmitterHook hook = (ISubmitterHook) Utils.getConfiguredClass(conf, Config.STORM_TOPOLOGY_SUBMISSION_NOTIFIER_PLUGIN); if (hook != null) { TopologyInfo topologyInfo = Utils.getTopologyInfo(topologyName, null, conf); try { hook.notify(topologyInfo, conf, topology); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } return new LocalTopology(topologyName, topology); }