本文整理汇总了Java中backtype.storm.utils.Utils.to_json方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.to_json方法的具体用法?Java Utils.to_json怎么用?Java Utils.to_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类backtype.storm.utils.Utils
的用法示例。
在下文中一共展示了Utils.to_json方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRequest
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
private boolean sendRequest(int collection_flag, String error_message,
List<Map<String,Object>> msgList) throws Exception {
boolean ret = false;
if (msgList.size() == 0) return ret;
Map jsonObj = buildAliMonitorMsg(collection_flag, error_message);
addMsgData(jsonObj, msgList);
String jsonMsg = Utils.to_json(jsonObj);
LOG.info(jsonMsg);
if (post == true) {
String url = buildURL();
ret = httpPost(url, jsonMsg);
} else {
String request = buildRqstAddr();
StringBuilder postAddr= new StringBuilder();
postAddr.append(request);
postAddr.append(URLEncoder.encode(jsonMsg,null));
ret = httpGet(postAddr);
}
return ret;
}
示例2: sendRequest
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
private boolean sendRequest(int collection_flag, String error_message,
List<Map<String,Object>> msgList) throws Exception {
boolean ret = false;
if (msgList.size() == 0) return ret;
Map jsonObj = buildAliMonitorMsg(collection_flag, error_message);
addMsgData(jsonObj, msgList);
String jsonMsg = Utils.to_json(jsonObj);
LOG.info(jsonMsg);
if (post == true) {
String url = buildURL();
ret = httpPost(url, jsonMsg);
} else {
String request = buildRqstAddr();
StringBuilder postAddr= new StringBuilder();
postAddr.append(request);
postAddr.append(URLEncoder.encode(jsonMsg));
ret = httpGet(postAddr);
}
return ret;
}
示例3: main
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
if (args == null || args.length == 0) {
throw new InvalidParameterException("Should input topology name");
}
String topologyName = args[0];
NimbusClient client = null;
try {
Map conf = Utils.readStormConfig();
client = NimbusClient.getConfiguredClient(conf);
if (args.length == 1) {
client.getClient().restart(topologyName, null);
} else {
Map loadConf = LoadConf(args[1]);
String jsonConf = Utils.to_json(loadConf);
System.out.println("New configuration:\n" + jsonConf);
client.getClient().restart(topologyName, jsonConf);
}
System.out.println("Successfully submit command restart "
+ topologyName);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (client != null) {
client.close();
}
}
}
示例4: complete
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
@Override
public void complete(ReturnResultsState state, TridentCollector collector) {
// only one of the multireducers will receive the tuples
if(state.returnInfo!=null) {
String result = Utils.to_json(state.results);
Map retMap = (Map) Utils.from_json(state.returnInfo);
final String host = (String) retMap.get("host");
final int port = Utils.getInt(retMap.get("port"));
String id = (String) retMap.get("id");
DistributedRPCInvocations.Iface client;
if(local) {
client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
} else {
List server = new ArrayList() {/**
*
*/
private static final long serialVersionUID = -2178334393663496091L;
{
add(host);
add(port);
}};
if(!_clients.containsKey(server)) {
_clients.put(server, new DRPCInvocationsClient(host, port));
}
client = _clients.get(server);
}
try {
client.result(id, result);
} catch(TException e) {
collector.reportError(e);
}
}
}
示例5: toJSONString
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
@Override
public String toJSONString() {
Map obj = new HashMap();
obj.put("task->component", _taskToComponent);
// TODO: jsonify StormTopology
// at the minimum should send source info
return Utils.to_json(obj);
}
示例6: main
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
if (args == null || args.length == 0) {
throw new InvalidParameterException("Should input topology name");
}
String topologyName = args[0];
NimbusClient client = null;
try {
Map conf = Utils.readStormConfig();
client = NimbusClient.getConfiguredClient(conf);
System.out.println("It will take 15 ~ 100 seconds to restart, please wait patiently\n");
if (args.length == 1) {
client.getClient().restart(topologyName, null);
} else {
Map loadConf = Utils.loadConf(args[1]);
String jsonConf = Utils.to_json(loadConf);
System.out.println("New configuration:\n" + jsonConf);
client.getClient().restart(topologyName, jsonConf);
}
System.out.println("Successfully submit command restart " + topologyName);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (client != null) {
client.close();
}
}
}
示例7: complete
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
@Override
public void complete(ReturnResultsState state, TridentCollector collector) {
// only one of the multireducers will receive the tuples
if(state.returnInfo!=null) {
String result = Utils.to_json(state.results);
Map retMap = (Map) Utils.from_json(state.returnInfo);
final String host = (String) retMap.get("host");
final int port = Utils.getInt(retMap.get("port"));
String id = (String) retMap.get("id");
DistributedRPCInvocations.Iface client;
if(local) {
client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
} else {
List server = new ArrayList() {{
add(host);
add(port);
}};
if(!_clients.containsKey(server)) {
_clients.put(server, new DRPCInvocationsClient(host, port));
}
client = _clients.get(server);
}
try {
client.result(id, result);
} catch(TException e) {
collector.reportError(e);
}
}
}
示例8: main
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
if (args == null || args.length == 0) {
throw new InvalidParameterException("Should input topology name");
}
String topologyName = args[0];
NimbusClient client = null;
try {
Map conf = Utils.readStormConfig();
client = NimbusClient.getConfiguredClient(conf);
System.out.println("It will take 15 ~ 100 seconds to restart, please wait patiently\n");
if (args.length == 1) {
client.getClient().restart(topologyName, null);
} else {
Map loadConf = LoadConf(args[1]);
String jsonConf = Utils.to_json(loadConf);
System.out.println("New configuration:\n" + jsonConf);
client.getClient().restart(topologyName, jsonConf);
}
System.out.println("Successfully submit command restart "
+ topologyName);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (client != null) {
client.close();
}
}
}
示例9: to_json
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
public static String to_json(Map m) {
return Utils.to_json(m);
}
示例10: toJSONString
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
@Override
public String toJSONString() {
// StringBuilder sb = new StringBuilder();
// sb.append("[");
// sb.append("\"" + this.getNodeId() + "\"");
// sb.append(",");
// sb.append("\"" + this.hostName + "\"");
// sb.append(",");
// sb.append("\"" + String.valueOf(this.getPort()) + "\"");
// sb.append(",");
// sb.append("\"" + this.jvm + "\"");
// sb.append(",");
// sb.append("\"" + String.valueOf(this.mem) + "\"");
// sb.append(",");
// sb.append("\"" + String.valueOf(this.cpu) + "\"");
// sb.append(",");
// sb.append("{");
// for (Entry<String, Integer> entry : componentToNum.entrySet()) {
// sb.append("\"" + entry.getKey() + "\":");
// sb.append("\"" + String.valueOf(entry.getValue()) + "\"");
// sb.append(",");
// }
// sb.append("}");
// sb.append("]");
Map<String, String> map = new HashMap<String, String>();
map.put(COMPONENTTONUM_TAG, Utils.to_json(componentToNum));
map.put(MEM_TAG, String.valueOf(mem));
map.put(CPU_TAG, String.valueOf(cpu));
map.put(HOSTNAME_TAG, hostName);
map.put(JVM_TAG, jvm);
map.put(NODEID_TAG, getNodeId());
map.put(PORT_TAG, String.valueOf(getPort()));
return Utils.to_json(map);
}
示例11: main
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
public static void main(String[] args) {
WorkerAssignment input = new WorkerAssignment();
input.setJvm("sb");
input.setCpu(1);
input.setMem(2);
input.addComponent("2b", 2);
String outString = Utils.to_json(input);
System.out.println(input);
//String outString = "[componentToNum={},mem=1610612736,cpu=1,hostName=mobilejstorm-60-1,jvm=<null>,nodeId=<null>,port=0]";
Object object = Utils.from_json(outString);
System.out.println(object);
System.out.println(parseFromObj(object));
System.out.print(input.equals(parseFromObj(object)));
}
示例12: main
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
public static void main(String[] args) {
WorkerAssignment input = new WorkerAssignment();
input.setJvm("sb");
input.setCpu(1);
input.setMem(2);
input.addComponent("2b", 2);
String outString = Utils.to_json(input);
System.out.println(input);
// String outString =
// "[componentToNum={},mem=1610612736,cpu=1,hostName=mobilejstorm-60-1,jvm=<null>,nodeId=<null>,port=0]";
Object object = Utils.from_json(outString);
System.out.println(object);
System.out.println(parseFromObj(object));
System.out.print(input.equals(parseFromObj(object)));
}
示例13: updateTopology
import backtype.storm.utils.Utils; //导入方法依赖的package包/类
private static void updateTopology(String topologyName, String pathJar,
String pathConf) {
NimbusClient client = null;
Map loadMap = null;
if (pathConf != null) {
loadMap = Utils.loadConf(pathConf);
} else {
loadMap = new HashMap();
}
Map conf = Utils.readStormConfig();
conf.putAll(loadMap);
client = NimbusClient.getConfiguredClient(conf);
try {
// update jar
String uploadLocation = null;
if (pathJar != null) {
System.out.println("Jar update to master yet. Submitting jar of " + pathJar);
String path = client.getClient().beginFileUpload();
String[] pathCache = path.split("/");
uploadLocation = path + "/stormjar-" + pathCache[pathCache.length - 1] + ".jar";
List<String> lib = (List<String>) conf .get(GenericOptionsParser.TOPOLOGY_LIB_NAME);
Map<String, String> libPath = (Map<String, String>) conf .get(GenericOptionsParser.TOPOLOGY_LIB_PATH);
if (lib != null && lib.size() != 0) {
for (String libName : lib) {
String jarPath = path + "/lib/" + libName;
client.getClient().beginLibUpload(jarPath);
StormSubmitter.submitJar(conf, libPath.get(libName), jarPath, client);
}
} else {
if (pathJar == null) {
// no lib, no client jar
throw new RuntimeException( "No client app jar, please upload it");
}
}
if (pathJar != null) {
StormSubmitter.submitJar(conf, pathJar, uploadLocation, client);
} else {
// no client jar, but with lib jar
client.getClient().finishFileUpload(uploadLocation);
}
}
// update topology
String jsonConf = Utils.to_json(loadMap);
System.out.println("New configuration:\n" + jsonConf);
client.getClient().updateTopology(topologyName, uploadLocation,
jsonConf);
System.out.println("Successfully submit command update " + topologyName);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (client != null) {
client.close();
}
}
}