@Override public byte[] serialize(Object obj) { try { return JSONValue.toJSONString(obj).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
@Override public String toJSONString() { Map<String, Object> obj = new HashMap<>(); obj.put("task->component", _taskToComponent); // TODO: jsonify StormTopology // at the minimum should send source info return JSONValue.toJSONString(obj); }
private static String mergeIntoJson(Map<String, Object> into, Map<String, Object> newMap) { Map<String, Object> res = new HashMap<>(into); 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); } }
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); } }
@Override public T addResources(Map<String, Double> resources) { if (resources != null && !resources.isEmpty()) { String currConf = commons.get(id).get_json_conf(); Map<String, Object> conf = parseJson(currConf); Map<String, Double> currentResources = (Map<String, Double>) conf.computeIfAbsent(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, (k) -> new HashMap<>()); currentResources.putAll(resources); commons.get(id).set_json_conf(JSONValue.toJSONString(conf)); } return (T) this; }
public static ComponentCommon prepareComponentCommon(Map<GlobalStreamId, Grouping> inputs, Map<String, StreamInfo> outputs, Integer parallelismHint, Map<String, Object> conf) { Map<GlobalStreamId, Grouping> mappedInputs = new HashMap<>(); Map<String, StreamInfo> mappedOutputs = new HashMap<>(); if (inputs != null && !inputs.isEmpty()) { mappedInputs.putAll(inputs); } if (outputs != null && !outputs.isEmpty()) { mappedOutputs.putAll(outputs); } ComponentCommon component = new ComponentCommon(mappedInputs, mappedOutputs); if (parallelismHint != null) { component.set_parallelism_hint(parallelismHint); } if (conf != null) { component.set_json_conf(JSONValue.toJSONString(conf)); } return component; }
private 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); } Map<String, Object> conf = component.getComponentConfiguration(); if (conf != null) { common.set_json_conf(JSONValue.toJSONString(conf)); } commons.put(id, common); }
@SuppressWarnings("unchecked") public static boolean isValidConf(Map<String, Object> topoConfIn) { Map<String, Object> origTopoConf = normalizeConf(topoConfIn); try { Map<String, Object> deserTopoConf = normalizeConf( (Map<String, Object>) JSONValue.parseWithException(JSONValue.toJSONString(topoConfIn))); return isValidConf(origTopoConf, deserTopoConf); } catch (ParseException e) { LOG.error("Json serialized config could not be deserialized", e); } return false; }
return JSONValue.toJSONString(obj);
public void setData(String path, Object obj) { path = "/" + path; byte[] ser; try { ser = JSONValue.toJSONString(obj).getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } try { if (_curator.checkExists().forPath(path) != null) { _curator.setData().forPath(path, ser); } else { TransactionalState.createNode(_curator, path, ser, _zkAcls, CreateMode.PERSISTENT); } } catch (KeeperException.NodeExistsException nne) { LOG.warn("Node {} already created.", path); } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void parsePackagesProperties() throws Exception { Map<String, String> testInputMap = new HashMap<>(); testInputMap.put("org.apache.storm:storm-core:1.0.0", "storm-core-1.0.0.jar"); testInputMap.put("com.googlecode.json-simple:json-simple:1.1", "json-simple-1.1.jar"); String testJson = JSONValue.toJSONString(testInputMap); Map<String, File> parsed = sut.parseArtifactsProperties(testJson); assertEquals(2, parsed.size()); assertEquals("storm-core-1.0.0.jar", parsed.get("org.apache.storm:storm-core:1.0.0").getName()); assertEquals("json-simple-1.1.jar", parsed.get("com.googlecode.json-simple:json-simple:1.1").getName()); }
String result = JSONValue.toJSONString(state.results); Map<String, Object> retMap; try {
returnInfo.put("host", client.getHost()); returnInfo.put("port", client.getPort()); _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), i)); break; returnInfo.put("host", _local_drpc_id); returnInfo.put("port", 0); _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), 0));
spoutConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, ObjectReader.getInt(conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS))); common.set_json_conf(JSONValue.toJSONString(spoutConf)); common.put_to_streams(Acker.ACKER_INIT_STREAM_ID, Thrift.outputFields(Arrays.asList("id", "init-val", "spout-task")));
String serConf = JSONValue.toJSONString(topoConf); try (NimbusClient client = NimbusClient.getConfiguredClientAs(conf, asUser)) { if (topologyNameExists(name, client)) {
@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 String toJSONString() { Map obj = new HashMap(); obj.put("task->component", _taskToComponent); // TODO: jsonify StormTopology // at the minimum should send source info return JSONValue.toJSONString(obj); }