Search in sources :

Example 11 with Assignment

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

the class DefaultTopologyScheduler method freeUsed.

/**
     * @@@ Here maybe exist one problem, some dead slots have been free
     * 
     * @param context
     */
protected void freeUsed(TopologyAssignContext context) {
    Set<Integer> canFree = new HashSet<Integer>();
    canFree.addAll(context.getAllTaskIds());
    canFree.removeAll(context.getUnstoppedTaskIds());
    Map<String, SupervisorInfo> cluster = context.getCluster();
    Assignment oldAssigns = context.getOldAssignment();
    for (Integer task : canFree) {
        ResourceWorkerSlot worker = oldAssigns.getWorkerByTaskId(task);
        if (worker == null) {
            LOG.warn("When free rebalance resource, no ResourceAssignment of task " + task);
            continue;
        }
        SupervisorInfo supervisorInfo = cluster.get(worker.getNodeId());
        if (supervisorInfo == null) {
            continue;
        }
        supervisorInfo.getAvailableWorkerPorts().add(worker.getPort());
    }
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) SupervisorInfo(com.alibaba.jstorm.daemon.supervisor.SupervisorInfo) HashSet(java.util.HashSet)

Example 12 with Assignment

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

the class UpdateTopologyTransitionCallback method execute.

@Override
public <T> Object execute(T... args) {
    StormClusterState clusterState = data.getStormClusterState();
    try {
        Map userConf = (Map) args[0];
        Map topoConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
        topoConf.putAll(userConf);
        Assignment assignment = clusterState.assignment_info(topologyId, null);
        assignment.setAssignmentType(AssignmentType.UpdateTopology);
        assignment.updateTimeStamp();
        clusterState.set_assignment(topologyId, assignment);
        LOG.info("Successfully update topology information to ZK for " + topologyId);
    } catch (Exception e) {
        LOG.error("Failed to update topology.", e);
    }
    return currentStatus;
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) Map(java.util.Map)

Example 13 with Assignment

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

the class Cluster method get_all_assignment.

public static Map<String, Assignment> get_all_assignment(StormClusterState stormClusterState, RunnableCallback callback) throws Exception {
    Map<String, Assignment> ret = new HashMap<String, Assignment>();
    // get /assignments {topology_id}
    List<String> assignments = stormClusterState.assignments(callback);
    if (assignments == null) {
        LOG.debug("No assignment of ZK");
        return ret;
    }
    for (String topology_id : assignments) {
        Assignment assignment = stormClusterState.assignment_info(topology_id, callback);
        if (assignment == null) {
            LOG.error("Failed to get Assignment of " + topology_id + " from ZK");
            continue;
        }
        ret.put(topology_id, assignment);
    }
    return ret;
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) HashMap(java.util.HashMap)

Example 14 with Assignment

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

the class ServiceHandler method getTopologyTasksToSupervisorIds.

@Override
public Map<Integer, String> getTopologyTasksToSupervisorIds(String topologyName) throws NotAliveException, TException {
    StormClusterState stormClusterState = data.getStormClusterState();
    String topologyId = getTopologyId(topologyName);
    Map<Integer, String> ret = new HashMap<>();
    try {
        Assignment assignment = stormClusterState.assignment_info(topologyId, null);
        Set<ResourceWorkerSlot> workers = assignment.getWorkers();
        for (ResourceWorkerSlot worker : workers) {
            String supervisorId = worker.getNodeId();
            for (Integer task : worker.getTasks()) {
                ret.put(task, supervisorId);
            }
        }
    } catch (Exception ex) {
        LOG.error("Error:", ex);
    }
    return ret;
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InvalidParameterException(java.security.InvalidParameterException) FailedAssignTopologyException(com.alibaba.jstorm.utils.FailedAssignTopologyException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) TopologyAssignException(backtype.storm.generated.TopologyAssignException) FileNotFoundException(java.io.FileNotFoundException) NotAliveException(backtype.storm.generated.NotAliveException) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 15 with Assignment

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

the class ServiceHandler method getClusterInfo.

/**
     * get cluster's summary, it will contain SupervisorSummary and TopologySummary
     *
     * @return ClusterSummary
     */
@Override
public ClusterSummary getClusterInfo() throws TException {
    long start = System.nanoTime();
    try {
        StormClusterState stormClusterState = data.getStormClusterState();
        Map<String, Assignment> assignments = new HashMap<String, Assignment>();
        // get TopologySummary
        List<TopologySummary> topologySummaries = NimbusUtils.getTopologySummary(stormClusterState, assignments);
        // all supervisors
        Map<String, SupervisorInfo> supervisorInfos = Cluster.get_all_SupervisorInfo(stormClusterState, null);
        // generate SupervisorSummaries
        List<SupervisorSummary> supervisorSummaries = NimbusUtils.mkSupervisorSummaries(supervisorInfos, assignments);
        NimbusSummary nimbusSummary = NimbusUtils.getNimbusSummary(stormClusterState, supervisorSummaries, data);
        return new ClusterSummary(nimbusSummary, supervisorSummaries, topologySummaries);
    } catch (TException e) {
        LOG.info("Failed to get ClusterSummary ", e);
        throw e;
    } catch (Exception e) {
        LOG.info("Failed to get ClusterSummary ", e);
        throw new TException(e);
    } finally {
        long end = System.nanoTime();
        SimpleJStormMetric.updateNimbusHistogram("getClusterInfo", (end - start) / TimeUtils.NS_PER_US);
    }
}
Also used : TException(org.apache.thrift.TException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ClusterSummary(backtype.storm.generated.ClusterSummary) SupervisorSummary(backtype.storm.generated.SupervisorSummary) NimbusSummary(backtype.storm.generated.NimbusSummary) SupervisorInfo(com.alibaba.jstorm.daemon.supervisor.SupervisorInfo) InvalidParameterException(java.security.InvalidParameterException) FailedAssignTopologyException(com.alibaba.jstorm.utils.FailedAssignTopologyException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) TopologyAssignException(backtype.storm.generated.TopologyAssignException) FileNotFoundException(java.io.FileNotFoundException) NotAliveException(backtype.storm.generated.NotAliveException) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) Assignment(com.alibaba.jstorm.schedule.Assignment) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) TopologySummary(backtype.storm.generated.TopologySummary)

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