Search in sources :

Example 1 with StormStatus

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

the class StatusTransition method transitionLock.

/**
     * Changing status
     *
     * @param args -- will be used in the status changing callback
     */
public <T> void transitionLock(String topologyId, boolean errorOnNoTransition, StatusType changeStatus, T... args) throws Exception {
    // get ZK's topology node's data, which is StormBase
    StormBase stormbase = data.getStormClusterState().storm_base(topologyId, null);
    if (stormbase == null) {
        LOG.error("Cannot apply event: changing status " + topologyId + " -> " + changeStatus.getStatus() + ", cause: failed to get StormBase from ZK");
        return;
    }
    StormStatus currentStatus = stormbase.getStatus();
    if (currentStatus == null) {
        LOG.error("Cannot apply event: changing status " + topologyId + " -> " + changeStatus.getStatus() + ", cause: topologyStatus is null in ZK");
        return;
    }
    // <currentStatus, Map<changingStatus, callback>>
    Map<StatusType, Map<StatusType, Callback>> callbackMap = stateTransitions(topologyId, currentStatus);
    // get current changingCallbacks
    Map<StatusType, Callback> changingCallbacks = callbackMap.get(currentStatus.getStatusType());
    if (changingCallbacks == null || !changingCallbacks.containsKey(changeStatus) || changingCallbacks.get(changeStatus) == null) {
        String msg = "No transition for event: changing status:" + changeStatus.getStatus() + ", current status: " + currentStatus.getStatusType() + ", topology-id: " + topologyId;
        LOG.info(msg);
        if (errorOnNoTransition) {
            throw new RuntimeException(msg);
        }
        return;
    }
    Callback callback = changingCallbacks.get(changeStatus);
    Object obj = callback.execute(args);
    if (obj != null && obj instanceof StormStatus) {
        StormStatus newStatus = (StormStatus) obj;
        // update status to ZK
        data.getStormClusterState().update_storm(topologyId, newStatus);
        LOG.info("Successfully updated " + topologyId + " to status " + newStatus);
    }
    LOG.info("Successfully apply event: changing status " + topologyId + " -> " + changeStatus.getStatus());
}
Also used : StormStatus(com.alibaba.jstorm.cluster.StormStatus) Callback(com.alibaba.jstorm.callback.Callback) StormBase(com.alibaba.jstorm.cluster.StormBase) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with StormStatus

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

the class DelayStatusTransitionCallback method execute.

@Override
public <T> Object execute(T... args) {
    int delaySecs = getDelaySeconds(args);
    LOG.info("Delaying event " + newType + " for " + delaySecs + " secs for " + topologyid);
    data.getScheduExec().schedule(new DelayEventRunnable(data, topologyid, nextAction, args), delaySecs, TimeUnit.SECONDS);
    return new StormStatus(delaySecs, newType);
}
Also used : StormStatus(com.alibaba.jstorm.cluster.StormStatus) DelayEventRunnable(com.alibaba.jstorm.schedule.DelayEventRunnable)

Example 3 with StormStatus

use of com.alibaba.jstorm.cluster.StormStatus 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)

Aggregations

StormStatus (com.alibaba.jstorm.cluster.StormStatus)3 StormBase (com.alibaba.jstorm.cluster.StormBase)2 Callback (com.alibaba.jstorm.callback.Callback)1 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)1 DelayEventRunnable (com.alibaba.jstorm.schedule.DelayEventRunnable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1