Search in sources :

Example 26 with StormClusterState

use of com.alibaba.jstorm.cluster.StormClusterState in project jstorm by alibaba.

the class TopologyAssign method setTopologyStatus.

/**
     * start a topology: set active status of the topology
     */
public void setTopologyStatus(TopologyAssignEvent event) throws Exception {
    StormClusterState stormClusterState = nimbusData.getStormClusterState();
    String topologyId = event.getTopologyId();
    String topologyName = event.getTopologyName();
    String group = event.getGroup();
    StormStatus status = new StormStatus(StatusType.active);
    if (event.getOldStatus() != null) {
        status = event.getOldStatus();
    }
    boolean isEnable = ConfigExtension.isEnablePerformanceMetrics(nimbusData.getConf());
    StormBase stormBase = stormClusterState.storm_base(topologyId, null);
    if (stormBase == null) {
        stormBase = new StormBase(topologyName, TimeUtils.current_time_secs(), status, group);
        stormBase.setEnableMonitor(isEnable);
        stormClusterState.activate_storm(topologyId, stormBase);
    } else {
        stormClusterState.update_storm(topologyId, status);
        stormClusterState.set_storm_monitor(topologyId, isEnable);
        // when monitor/rebalance/startup topologyName is null
        if (topologyName == null) {
            event.setTopologyName(stormBase.getStormName());
        }
    }
    LOG.info("Update " + topologyId + " " + status);
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) StormStatus(com.alibaba.jstorm.cluster.StormStatus) StormBase(com.alibaba.jstorm.cluster.StormBase)

Example 27 with StormClusterState

use of com.alibaba.jstorm.cluster.StormClusterState in project jstorm by alibaba.

the class NimbusUtils method updateTopologyTaskHb.

public static void updateTopologyTaskHb(NimbusData data, String topologyId) {
    StormClusterState clusterState = data.getStormClusterState();
    TopologyTaskHbInfo topologyTaskHb = null;
    try {
        topologyTaskHb = clusterState.topology_heartbeat(topologyId);
    } catch (Exception e) {
        LOG.error("updateTopologyTaskHb: Failed to get topology task heartbeat info", e);
    }
    if (topologyTaskHb != null) {
        data.getTasksHeartbeat().put(topologyId, topologyTaskHb);
    }
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) TopologyTaskHbInfo(backtype.storm.generated.TopologyTaskHbInfo) NotAliveException(backtype.storm.generated.NotAliveException) InvalidParameterException(java.security.InvalidParameterException)

Example 28 with StormClusterState

use of com.alibaba.jstorm.cluster.StormClusterState in project jstorm by alibaba.

the class NimbusUtils method cleanupCorruptTopologies.

/**
     * clean the topology which is in ZK but not in local dir
     *
     * @throws Exception
     */
public static void cleanupCorruptTopologies(NimbusData data) throws Exception {
    StormClusterState stormClusterState = data.getStormClusterState();
    BlobStore blobStore = data.getBlobStore();
    // we have only topology relative files , so we don't need filter
    Set<String> code_ids = Sets.newHashSet(BlobStoreUtils.code_ids(blobStore.listKeys()));
    // get topology in ZK /storms
    Set<String> active_ids = Sets.newHashSet(data.getStormClusterState().active_storms());
    //get topology in zk by blobs
    Set<String> blobsIdsOnZk = Sets.newHashSet(data.getStormClusterState().blobstore(null));
    Set<String> topologyIdsOnZkbyBlobs = BlobStoreUtils.code_ids(blobsIdsOnZk.iterator());
    Set<String> corrupt_ids = Sets.difference(active_ids, code_ids);
    Set<String> redundantIds = Sets.difference(topologyIdsOnZkbyBlobs, code_ids);
    Set<String> unionIds = Sets.union(corrupt_ids, redundantIds);
    // clean the topology which is in ZK but not in local dir
    for (String corrupt : unionIds) {
        LOG.info("Corrupt topology {} has state on zookeeper but doesn't have a local dir on Nimbus. Cleaning up...", corrupt);
        stormClusterState.remove_storm(corrupt);
        if (blobStore instanceof LocalFsBlobStore) {
            List<String> blobKeys = BlobStoreUtils.getKeyListFromId(data, corrupt);
            for (String key : blobKeys) {
                stormClusterState.remove_blobstore_key(key);
                stormClusterState.remove_key_version(key);
            }
        }
    }
    LOG.info("Successfully cleanup all old toplogies");
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) LocalFsBlobStore(com.alibaba.jstorm.blobstore.LocalFsBlobStore) BlobStore(com.alibaba.jstorm.blobstore.BlobStore) LocalFsBlobStore(com.alibaba.jstorm.blobstore.LocalFsBlobStore)

Example 29 with StormClusterState

use of com.alibaba.jstorm.cluster.StormClusterState in project jstorm by alibaba.

the class TopologyAssign method mkAssignment.

/**
     * make assignments for a topology The nimbus core function, this function has been totally rewrite
     * 
     * @throws Exception
     */
public Assignment mkAssignment(TopologyAssignEvent event) throws Exception {
    String topologyId = event.getTopologyId();
    LOG.info("Determining assignment for " + topologyId);
    TopologyAssignContext context = prepareTopologyAssign(event);
    Set<ResourceWorkerSlot> assignments = null;
    if (!StormConfig.local_mode(nimbusData.getConf())) {
        IToplogyScheduler scheduler = schedulers.get(DEFAULT_SCHEDULER_NAME);
        assignments = scheduler.assignTasks(context);
    } else {
        assignments = mkLocalAssignment(context);
    }
    Assignment assignment = null;
    if (assignments != null && assignments.size() > 0) {
        Map<String, String> nodeHost = getTopologyNodeHost(context.getCluster(), context.getOldAssignment(), assignments);
        Map<Integer, Integer> startTimes = getTaskStartTimes(context, nimbusData, topologyId, context.getOldAssignment(), assignments);
        String codeDir = (String) nimbusData.getConf().get(Config.STORM_LOCAL_DIR);
        assignment = new Assignment(codeDir, assignments, nodeHost, startTimes);
        //  the topology binary changed.
        if (event.isScaleTopology()) {
            assignment.setAssignmentType(Assignment.AssignmentType.ScaleTopology);
        }
        StormClusterState stormClusterState = nimbusData.getStormClusterState();
        stormClusterState.set_assignment(topologyId, assignment);
        // update task heartbeat's start time
        NimbusUtils.updateTaskHbStartTime(nimbusData, assignment, topologyId);
        // @@@ TODO
        // Update metrics information in ZK when rebalance or reassignment
        // Only update metrics monitor status when creating topology
        // if (context.getAssignType() ==
        // TopologyAssignContext.ASSIGN_TYPE_REBALANCE
        // || context.getAssignType() ==
        // TopologyAssignContext.ASSIGN_TYPE_MONITOR)
        // NimbusUtils.updateMetricsInfo(nimbusData, topologyId, assignment);
        NimbusUtils.updateTopologyTaskTimeout(nimbusData, topologyId);
        LOG.info("Successfully make assignment for topology id " + topologyId + ": " + assignment);
    }
    return assignment;
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) IToplogyScheduler(com.alibaba.jstorm.schedule.IToplogyScheduler) TopologyAssignContext(com.alibaba.jstorm.schedule.TopologyAssignContext) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 30 with StormClusterState

use of com.alibaba.jstorm.cluster.StormClusterState in project jstorm by alibaba.

the class JStormHealthReporter method run.

@Override
public void run() {
    StormClusterState clusterState = workerData.getZkCluster();
    String topologyId = workerData.getTopologyId();
    Map<Integer, HealthCheckRegistry> taskHealthCheckMap = JStormHealthCheck.getTaskhealthcheckmap();
    int cnt = 0;
    for (Map.Entry<Integer, HealthCheckRegistry> entry : taskHealthCheckMap.entrySet()) {
        Integer taskId = entry.getKey();
        Map<String, Result> results = entry.getValue().runHealthChecks();
        for (Map.Entry<String, Result> result : results.entrySet()) {
            if (!result.getValue().isHealthy()) {
                try {
                    clusterState.report_task_error(topologyId, taskId, result.getValue().getMessage(), ErrorConstants.WARN, ErrorConstants.CODE_QUEUE_FULL, ErrorConstants.DURATION_SECS_QUEUE_FULL);
                    cnt++;
                } catch (Exception e) {
                    LOG.error("Failed to update health data in ZK for topo-{} task-{}.", topologyId, taskId, e);
                }
            }
        }
    }
    if (cnt > 0) {
        LOG.info("Successfully updated {} health data to ZK for topology:{}", cnt, topologyId);
    }
}
Also used : StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Map(java.util.Map) Result(com.codahale.metrics.health.HealthCheck.Result)

Aggregations

StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)32 IOException (java.io.IOException)12 NotAliveException (backtype.storm.generated.NotAliveException)10 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)10 TException (org.apache.thrift.TException)10 InvalidParameterException (java.security.InvalidParameterException)9 HashMap (java.util.HashMap)9 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)8 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)8 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)8 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)8 TopologyAssignException (backtype.storm.generated.TopologyAssignException)8 FileNotFoundException (java.io.FileNotFoundException)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 LocalFsBlobStore (com.alibaba.jstorm.blobstore.LocalFsBlobStore)7 Assignment (com.alibaba.jstorm.schedule.Assignment)7 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)7 Map (java.util.Map)7 TreeMap (java.util.TreeMap)7 BlobStore (com.alibaba.jstorm.blobstore.BlobStore)5