Java Code Examples for backtype.storm.utils.Utils#to_json()

The following examples show how to use backtype.storm.utils.Utils#to_json() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkerAssignment.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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)));
}
 
Example 2
Source File: Httpserver.java    From jstorm with Apache License 2.0 5 votes vote down vote up
void handleShowConf(HttpExchange t, Map<String, String> paramMap) throws IOException {
    byte[] json;
    try {
        String tmp = Utils.to_json(conf);
        json = tmp.getBytes();
    } catch (Exception e) {
        LOG.error("Failed to get configuration", e);
        handlFailure(t, "Failed to get configuration");
        return;
    }

    sendResponse(t, HttpURLConnection.HTTP_OK, json);
}
 
Example 3
Source File: WorkerAssignment.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public String toJSONString() {
    Map<String, String> map = new HashMap<>();

    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);
}
 
Example 4
Source File: restart.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args == null || args.length == 0) {
        throw new InvalidParameterException("Please 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();
        }
    }
}
 
Example 5
Source File: JStormUtils.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public static String to_json(Map m) {
    return Utils.to_json(m);
}
 
Example 6
Source File: GeneralTopologyContext.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public String toJSONString() {
    Map obj = new HashMap();
    obj.put("task->component", _taskToComponent);
    return Utils.to_json(obj);
}