Search in sources :

Example 21 with Assignment

use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.

the class SyncSupervisorEvent method getAllAssignments.

private void getAllAssignments(Map<String, Integer> assignmentVersion, Map<String, Assignment> localZkAssignments, RunnableCallback callback) throws Exception {
    Map<String, Assignment> ret = new HashMap<String, Assignment>();
    Map<String, Integer> updateAssignmentVersion = new HashMap<String, Integer>();
    // get /assignments {topology_id}
    List<String> assignments = stormClusterState.assignments(callback);
    if (assignments == null) {
        assignmentVersion.clear();
        localZkAssignments.clear();
        LOG.debug("No assignment of ZK");
        return;
    }
    for (String topology_id : assignments) {
        Integer zkVersion = stormClusterState.assignment_version(topology_id, callback);
        LOG.debug(topology_id + "'s assigment version of zk is :" + zkVersion);
        Integer recordedVersion = assignmentVersion.get(topology_id);
        LOG.debug(topology_id + "'s assigment version of local is :" + recordedVersion);
        Assignment assignment = null;
        if (recordedVersion != null && zkVersion != null && recordedVersion.equals(zkVersion)) {
            assignment = localZkAssignments.get(topology_id);
        }
        //because the first version is 0
        if (assignment == null) {
            assignment = stormClusterState.assignment_info(topology_id, callback);
        }
        if (assignment == null) {
            LOG.error("Failed to get Assignment of " + topology_id + " from ZK");
            continue;
        }
        updateAssignmentVersion.put(topology_id, zkVersion);
        ret.put(topology_id, assignment);
    }
    assignmentVersion.clear();
    assignmentVersion.putAll(updateAssignmentVersion);
    localZkAssignments.clear();
    localZkAssignments.putAll(ret);
}
Also used : LocalAssignment(com.alibaba.jstorm.daemon.worker.LocalAssignment) Assignment(com.alibaba.jstorm.schedule.Assignment)

Example 22 with Assignment

use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.

the class SyncSupervisorEvent method getTopologyCodeLocations.

/**
     * get mastercodedir for every topology
     * 
     * @throws Exception
     * @returns Map: <topologyId, master-code-dir> from zookeeper
     */
public static Map<String, String> getTopologyCodeLocations(Map<String, Assignment> assignments, String supervisorId) throws Exception {
    Map<String, String> rtn = new HashMap<String, String>();
    for (Entry<String, Assignment> entry : assignments.entrySet()) {
        String topologyid = entry.getKey();
        Assignment assignmenInfo = entry.getValue();
        Set<ResourceWorkerSlot> workers = assignmenInfo.getWorkers();
        for (ResourceWorkerSlot worker : workers) {
            String node = worker.getNodeId();
            if (supervisorId.equals(node)) {
                rtn.put(topologyid, assignmenInfo.getMasterCodeDir());
                break;
            }
        }
    }
    return rtn;
}
Also used : LocalAssignment(com.alibaba.jstorm.daemon.worker.LocalAssignment) Assignment(com.alibaba.jstorm.schedule.Assignment) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 23 with Assignment

use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.

the class SyncSupervisorEvent method getLocalAssign.

/**
     * a port must be assigned one topology
     * 
     * @param stormClusterState
     * @param supervisorId
     * @throws Exception
     * @returns map: {port,LocalAssignment}
     */
private Map<Integer, LocalAssignment> getLocalAssign(StormClusterState stormClusterState, String supervisorId, Map<String, Assignment> assignments) throws Exception {
    Map<Integer, LocalAssignment> portLA = new HashMap<Integer, LocalAssignment>();
    for (Entry<String, Assignment> assignEntry : assignments.entrySet()) {
        String topologyId = assignEntry.getKey();
        Assignment assignment = assignEntry.getValue();
        Map<Integer, LocalAssignment> portTasks = readMyTasks(stormClusterState, topologyId, supervisorId, assignment);
        if (portTasks == null) {
            continue;
        }
        // a port must be assigned one storm
        for (Entry<Integer, LocalAssignment> entry : portTasks.entrySet()) {
            Integer port = entry.getKey();
            LocalAssignment la = entry.getValue();
            if (!portLA.containsKey(port)) {
                portLA.put(port, la);
            } else {
                throw new RuntimeException("Should not have multiple topologys assigned to one port");
            }
        }
    }
    return portLA;
}
Also used : LocalAssignment(com.alibaba.jstorm.daemon.worker.LocalAssignment) Assignment(com.alibaba.jstorm.schedule.Assignment) LocalAssignment(com.alibaba.jstorm.daemon.worker.LocalAssignment)

Example 24 with Assignment

use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.

the class ZooKeeperDataViewTest method viewAssignments.

@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));
    }
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) Test(org.junit.Test)

Aggregations

Assignment (com.alibaba.jstorm.schedule.Assignment)24 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)11 HashMap (java.util.HashMap)8 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)7 SupervisorInfo (com.alibaba.jstorm.daemon.supervisor.SupervisorInfo)6 IOException (java.io.IOException)6 LocalAssignment (com.alibaba.jstorm.daemon.worker.LocalAssignment)5 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)5 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 TException (org.apache.thrift.TException)5 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)4 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)4 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)4 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)4 NotAliveException (backtype.storm.generated.NotAliveException)4 TopologyAssignException (backtype.storm.generated.TopologyAssignException)4 InvalidParameterException (java.security.InvalidParameterException)4 SupervisorSummary (backtype.storm.generated.SupervisorSummary)3