Search in sources :

Example 41 with IStormClusterState

use of org.apache.storm.cluster.IStormClusterState in project storm by apache.

the class Nimbus method setLogConfig.

@Override
public void setLogConfig(String topoId, LogConfig config) throws TException {
    try {
        setLogConfigCalls.mark();
        Map<String, Object> topoConf = tryReadTopoConf(topoId, topoCache);
        topoConf = Utils.merge(conf, topoConf);
        String topoName = (String) topoConf.get(Config.TOPOLOGY_NAME);
        checkAuthorization(topoName, topoConf, "setLogConfig");
        IStormClusterState state = stormClusterState;
        LogConfig mergedLogConfig = state.topologyLogConfig(topoId, null);
        if (mergedLogConfig == null) {
            mergedLogConfig = new LogConfig();
        }
        if (mergedLogConfig.is_set_named_logger_level()) {
            Map<String, LogLevel> namedLoggers = mergedLogConfig.get_named_logger_level();
            for (LogLevel level : namedLoggers.values()) {
                level.set_action(LogLevelAction.UNCHANGED);
            }
        }
        if (config.is_set_named_logger_level()) {
            for (Entry<String, LogLevel> entry : config.get_named_logger_level().entrySet()) {
                LogLevel logConfig = entry.getValue();
                String loggerName = entry.getKey();
                LogLevelAction action = logConfig.get_action();
                if (loggerName.isEmpty()) {
                    throw new RuntimeException("Named loggers need a valid name. Use ROOT for the root logger");
                }
                switch(action) {
                    case UPDATE:
                        setLoggerTimeouts(logConfig);
                        mergedLogConfig.put_to_named_logger_level(loggerName, logConfig);
                        break;
                    case REMOVE:
                        Map<String, LogLevel> nl = mergedLogConfig.get_named_logger_level();
                        if (nl != null) {
                            nl.remove(loggerName);
                        }
                        break;
                    default:
                        // NOOP
                        break;
                }
            }
        }
        LOG.info("Setting log config for {}:{}", topoName, mergedLogConfig);
        state.setTopologyLogConfig(topoId, mergedLogConfig, topoConf);
    } catch (Exception e) {
        LOG.warn("set log config topology exception. (topology id='{}')", topoId, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.storm.thrift.TException) LogLevelAction(org.apache.storm.generated.LogLevelAction) IStormClusterState(org.apache.storm.cluster.IStormClusterState) LogLevel(org.apache.storm.generated.LogLevel) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException) LogConfig(org.apache.storm.generated.LogConfig)

Example 42 with IStormClusterState

use of org.apache.storm.cluster.IStormClusterState in project storm by apache.

the class Nimbus method setWorkerProfiler.

@Override
public void setWorkerProfiler(String topoId, ProfileRequest profileRequest) throws TException {
    try {
        setWorkerProfilerCalls.mark();
        Map<String, Object> topoConf = tryReadTopoConf(topoId, topoCache);
        topoConf = Utils.merge(conf, topoConf);
        String topoName = (String) topoConf.get(Config.TOPOLOGY_NAME);
        checkAuthorization(topoName, topoConf, "setWorkerProfiler");
        IStormClusterState state = stormClusterState;
        state.setWorkerProfileRequest(topoId, profileRequest);
    } catch (Exception e) {
        LOG.warn("set worker profiler topology exception. (topology id='{}')", topoId, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.storm.thrift.TException) IStormClusterState(org.apache.storm.cluster.IStormClusterState) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 43 with IStormClusterState

use of org.apache.storm.cluster.IStormClusterState in project storm by apache.

the class Nimbus method getTopologyInfoByNameImpl.

private TopologyInfo getTopologyInfoByNameImpl(String name, GetInfoOptions options) throws NotAliveException, AuthorizationException, Exception {
    IStormClusterState state = stormClusterState;
    String id = state.getTopoId(name).orElseThrow(() -> new WrappedNotAliveException(name + " is not alive"));
    return getTopologyInfoWithOptsImpl(id, options);
}
Also used : IStormClusterState(org.apache.storm.cluster.IStormClusterState) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException)

Example 44 with IStormClusterState

use of org.apache.storm.cluster.IStormClusterState in project storm by apache.

the class Nimbus method getTopologySummariesImpl.

private List<TopologySummary> getTopologySummariesImpl() throws IOException, TException {
    IStormClusterState state = stormClusterState;
    List<TopologySummary> topologySummaries = new ArrayList<>();
    Map<String, StormBase> bases = state.topologyBases();
    for (Entry<String, StormBase> entry : bases.entrySet()) {
        StormBase base = entry.getValue();
        if (base == null) {
            continue;
        }
        String topoId = entry.getKey();
        TopologySummary summary = getTopologySummaryImpl(topoId, base);
        topologySummaries.add(summary);
    }
    return topologySummaries;
}
Also used : ArrayList(java.util.ArrayList) StormBase(org.apache.storm.generated.StormBase) TopologySummary(org.apache.storm.generated.TopologySummary) IStormClusterState(org.apache.storm.cluster.IStormClusterState)

Example 45 with IStormClusterState

use of org.apache.storm.cluster.IStormClusterState in project storm by apache.

the class Nimbus method getTopologySummary.

@Override
public TopologySummary getTopologySummary(String id) throws NotAliveException, AuthorizationException, TException {
    try {
        getTopologySummaryCalls.mark();
        IStormClusterState state = stormClusterState;
        StormBase base = state.topologyBases().get(id);
        if (base == null) {
            throw new WrappedNotAliveException(id + " is not alive");
        }
        checkAuthorization(base.get_name(), null, "getTopologySummary");
        return getTopologySummaryImpl(id, base);
    } catch (Exception e) {
        LOG.warn("Get TopologySummaryById info exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.storm.thrift.TException) StormBase(org.apache.storm.generated.StormBase) IStormClusterState(org.apache.storm.cluster.IStormClusterState) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) IOException(java.io.IOException) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Aggregations

IStormClusterState (org.apache.storm.cluster.IStormClusterState)49 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)24 IOException (java.io.IOException)23 AuthorizationException (org.apache.storm.generated.AuthorizationException)21 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)21 NotAliveException (org.apache.storm.generated.NotAliveException)21 InterruptedIOException (java.io.InterruptedIOException)20 BindException (java.net.BindException)20 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)20 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)20 WrappedNotAliveException (org.apache.storm.utils.WrappedNotAliveException)20 HashMap (java.util.HashMap)19 TException (org.apache.storm.thrift.TException)19 IllegalStateException (org.apache.storm.generated.IllegalStateException)18 WrappedAlreadyAliveException (org.apache.storm.utils.WrappedAlreadyAliveException)18 WrappedAuthorizationException (org.apache.storm.utils.WrappedAuthorizationException)18 WrappedIllegalStateException (org.apache.storm.utils.WrappedIllegalStateException)18 WrappedInvalidTopologyException (org.apache.storm.utils.WrappedInvalidTopologyException)18 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)10