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

The following examples show how to use backtype.storm.utils.Utils#from_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: UIUtils.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> getNimbusConf(String clusterName) {
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);

        String jsonConf = client.getClient().getNimbusConf();
        Map<String, Object> nimbusConf =
                (Map<String, Object>) Utils.from_json(jsonConf);
        return nimbusConf;
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        LOG.error(e.getMessage(), e);
        return UIUtils.readUiConfig();
    }
}
 
Example 3
Source File: UIUtils.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> getTopologyConf(String clusterName, String topologyId) {
    NimbusClient client = null;
    try {
        client = NimbusClientManager.getNimbusClient(clusterName);

        String jsonConf = client.getClient().getTopologyConf(topologyId);
        Map<String, Object> topologyConf =
                (Map<String, Object>) Utils.from_json(jsonConf);
        return topologyConf;
    } catch (Exception e) {
        NimbusClientManager.removeClient(clusterName);
        LOG.error(e.getMessage(), e);
        return getNimbusConf(clusterName);
    }
}
 
Example 4
Source File: GeneralTopologyContext.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public int maxTopologyMessageTimeout() {
    Integer max = Utils.getInt(_stormConf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS));
    for (String spout : getRawTopology().get_spouts().keySet()) {
        ComponentCommon common = getComponentCommon(spout);
        String jsonConf = common.get_json_conf();
        if (jsonConf != null) {
            Map conf = (Map) Utils.from_json(jsonConf);
            Object comp = conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS);
            if (comp != null) {
                max = Math.max(Utils.getInt(comp), max);
            }
        }
    }
    return max;
}
 
Example 5
Source File: gray_upgrade.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private static void upgradeTopology(String topologyName, String component, List<String> workers, int workerNum)
        throws Exception {
    Map conf = Utils.readStormConfig();
    NimbusClient client = NimbusClient.getConfiguredClient(conf);
    try {
        String topologyId = client.getClient().getTopologyId(topologyName);
        Map stormConf = (Map) Utils.from_json(client.getClient().getTopologyConf(topologyId));
        // check if TM is a separate worker
        TopologyInfo topologyInfo = client.getClient().getTopologyInfo(topologyId);
        for (TaskSummary taskSummary : topologyInfo.get_tasks()) {
            if (!taskSummary.get_status().equalsIgnoreCase("active")) {
                CommandLineUtil.error("Some of the tasks are not in ACTIVE state, cannot perform the upgrade!");
                return;
            }
        }

        if (!ConfigExtension.isTmSingleWorker(stormConf, topologyInfo.get_topology().get_numWorkers())) {
            CommandLineUtil.error("Gray upgrade requires that topology master to be a single worker, " +
                    "cannot perform the upgrade!");
            return;
        }

        client.getClient().grayUpgrade(topologyName, component, workers, workerNum);
        CommandLineUtil.success("Successfully submit command gray_upgrade " + topologyName);
    } catch (Exception ex) {
        CommandLineUtil.error("Failed to perform gray_upgrade: " + ex.getMessage());
        ex.printStackTrace();
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
 
Example 6
Source File: ConfAPIController.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@RequestMapping("/supervisor/{host}/configuration")
public Map supervisorConf(@PathVariable String name, @PathVariable String host) {
    int port = UIUtils.getSupervisorPort(name);
    String json = UIUtils.getSupervisorConf(host, port).getData();
    return (Map) Utils.from_json(json);
}
 
Example 7
Source File: JStormUtils.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public static Object from_json(String json) {
    return Utils.from_json(json);
}
 
Example 8
Source File: WorkerAssignment.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public static WorkerAssignment parseFromObj(Object obj) {
    if (obj == null) {
        return null;
    }
    if (!(obj instanceof Map)) {
        return null;
    }

    try {
        Map<String, String> map = (Map<String, String>) obj;

        String supervisorId = map.get(NODEID_TAG);
        String hostname = map.get(HOSTNAME_TAG);
        Integer port = JStormUtils.parseInt(map.get(PORT_TAG));
        String jvm = map.get(JVM_TAG);
        Long mem = JStormUtils.parseLong(map.get(MEM_TAG));
        Integer cpu = JStormUtils.parseInt(map.get(CPU_TAG));
        Map<String, Object> componentToNum = (Map<String, Object>) Utils.from_json(map.get(COMPONENTTONUM_TAG));

        WorkerAssignment ret = new WorkerAssignment(supervisorId, port);

        ret.hostName = hostname;
        ret.setNodeId(supervisorId);
        ret.setJvm(jvm);
        if (port != null) {
            ret.setPort(port);
        }
        if (mem != null) {
            ret.setMem(mem);
        }
        if (cpu != null) {
            ret.setCpu(cpu);
        }

        for (Entry<String, Object> entry : componentToNum.entrySet()) {
            ret.addComponent(entry.getKey(), JStormUtils.parseInt(entry.getValue()));
        }
        return ret;
    } catch (Exception e) {
        LOG.error("Failed to convert to WorkerAssignment,  raw:" + obj, e);
        return null;
    }

}