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

The following examples show how to use backtype.storm.utils.Utils#maybe_deserialize() . 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: ZookeeperManager.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public static String getZKNodeData(String clusterName, String path) {
    String out = null;
    try {
        ClusterState clusterState = getAndCreateClusterState(clusterName);
        if (clusterState == null) {
            throw new IllegalStateException("Cluster state is null");
        }

        byte[] data = clusterState.get_data(PathUtils.normalize_path(path), false);
        if (data != null && data.length > 0) {
            Object obj = Utils.maybe_deserialize(data);
            if (obj != null){
                out = gson.toJson(obj);
            } else {
                out = new String(data);
            }
        }
    } catch (Exception e) {
        LOG.error("Get zookeeper data error!", e);
    }
    return out;
}
 
Example 2
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Test
public void viewTaskbeats() throws Exception {
    if (SKIP == true) {
        return;
    }
    List<String> assignments = zkobj.getChildren(zk,
            Cluster.TASKBEATS_SUBTREE, false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.taskbeat_storm_root(child),
                false);
        TopologyTaskHbInfo taskHbInfo = (TopologyTaskHbInfo) Utils
                .maybe_deserialize(data);
        System.out.println(gson.toJson(taskHbInfo));
    }

}
 
Example 3
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Test
public void viewTasks() throws Exception {
    if (SKIP == true) {
        return;
    }

    List<String> assignments = zkobj.getChildren(zk, Cluster.TASKS_SUBTREE,
            false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.storm_task_root(child),
                false);
        Map<Integer, TaskInfo> taskInfoMap = (Map<Integer, TaskInfo>) Utils
                .maybe_deserialize(data);
        System.out.println(gson.toJson(taskInfoMap));
    }
}
 
Example 4
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Test
public void viewSupervisors() throws Exception {
    if (SKIP == true) {
        return;
    }

    List<String> assignments = zkobj.getChildren(zk,
            Cluster.SUPERVISORS_SUBTREE, false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.supervisor_path(child),
                false);
        SupervisorInfo supervisorInfo = (SupervisorInfo) Utils
                .maybe_deserialize(data);
        System.out.println(gson.toJson(supervisorInfo));
    }
}
 
Example 5
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 6 votes vote down vote up
private void viewNode(Node parent) throws Exception {

        List<String> elements = zkobj.getChildren(zk, parent.getPath(), false);
        for (String element : elements) {
            Node node = new Node(
                    (parent.getPath().length() > 1 ? parent.getPath() : "")
                            + Cluster.ZK_SEPERATOR + element);
            byte[] data = zkobj.getData(zk, node.getPath(), false);
            if (data != null && data.length > 0) {
                Object obj = Utils.maybe_deserialize(data);
                node.setData(obj);
            }
            parent.addNode(node);
            viewNode(node);
        }
    }
 
Example 6
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Test
public void viewAssignments() throws Exception {
    if (SKIP == true) {
        return;
    }
    List<String> assignments = zkobj.getChildren(zk,
            Cluster.ASSIGNMENTS_SUBTREE, false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.assignment_path(child),
                false);
        Assignment assignment = (Assignment) Utils.maybe_deserialize(data);
        System.out.println(gson.toJson(assignment));
    }
}
 
Example 7
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Test
public void viewTopology() throws Exception {
    if (SKIP == true) {
        return;
    }
    List<String> assignments = zkobj.getChildren(zk, Cluster.STORMS_SUBTREE,
            false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.storm_path(child), false);
        StormBase stormBase = (StormBase) Utils.maybe_deserialize(data);
        System.out.println(gson.toJson(stormBase));
    }
}
 
Example 8
Source File: ZooKeeperDataViewTest.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Test
public void viewMetrics() throws Exception {
    if (SKIP == true) {
        return;
    }

    List<String> assignments = zkobj.getChildren(zk, Cluster.METRIC_SUBTREE,
            false);
    for (String child : assignments) {
        byte[] data = zkobj.getData(zk, Cluster.metric_path(child), false);
        Integer size = (Integer) Utils.maybe_deserialize(data);
        System.out.println(size.toString());
    }
}
 
Example 9
Source File: StormZkClusterState.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public Object getObject(String path, boolean callback) throws Exception {
    byte[] data = cluster_state.get_data(path, callback);

    return Utils.maybe_deserialize(data);
}
 
Example 10
Source File: StormZkClusterState.java    From jstorm with Apache License 2.0 4 votes vote down vote up
public Object getObjectSync(String path, boolean callback) throws Exception {
    byte[] data = cluster_state.get_data_sync(path, callback);

    return Utils.maybe_deserialize(data);
}
 
Example 11
Source File: StormZkClusterState.java    From jstorm with Apache License 2.0 4 votes vote down vote up
@Override
public Map get_nimbus_detail(String hostPort, boolean watch) throws Exception {
    byte[] data = cluster_state.get_data(Cluster.NIMBUS_SLAVE_DETAIL_SUBTREE + Cluster.ZK_SEPERATOR + hostPort, watch);
    return (Map) Utils.maybe_deserialize(data);
}