Search in sources :

Example 1 with GetInfoOptions

use of org.apache.storm.generated.GetInfoOptions in project storm by apache.

the class GetErrors method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        throw new IllegalArgumentException("Topology name must be provided.");
    }
    final String name = args[0];
    NimbusClient.withConfiguredClient(new NimbusClient.WithNimbus() {

        @Override
        public void run(Nimbus.Client client) throws Exception {
            GetInfoOptions opts = new GetInfoOptions();
            opts.set_num_err_choice(NumErrorsChoice.ONE);
            String topologyId = Utils.getTopologyId(name, client);
            TopologyInfo topologyInfo = null;
            if (topologyId != null) {
                topologyInfo = client.getTopologyInfoWithOpts(topologyId, opts);
            }
            Map<String, Object> outputMap = new HashMap<>();
            if (topologyId == null || topologyInfo == null) {
                outputMap.put("Failure", "No topologies running with name " + name);
            } else {
                String topologyName = topologyInfo.get_name();
                Map<String, List<ErrorInfo>> topologyErrors = topologyInfo.get_errors();
                outputMap.put("Topology Name", topologyName);
                outputMap.put("Comp-Errors", getComponentErrors(topologyErrors));
            }
            System.out.println(JSONValue.toJSONString(outputMap));
        }

        private Map<String, String> getComponentErrors(Map<String, List<ErrorInfo>> topologyErrors) {
            Map<String, String> componentErrorMap = new HashMap<>();
            for (Map.Entry<String, List<ErrorInfo>> compNameToCompErrors : topologyErrors.entrySet()) {
                String compName = compNameToCompErrors.getKey();
                List<ErrorInfo> compErrors = compNameToCompErrors.getValue();
                if (compErrors != null && !compErrors.isEmpty()) {
                    ErrorInfo latestError = compErrors.get(0);
                    componentErrorMap.put(compName, latestError.get_error());
                }
            }
            return componentErrorMap;
        }
    });
}
Also used : GetInfoOptions(org.apache.storm.generated.GetInfoOptions) ErrorInfo(org.apache.storm.generated.ErrorInfo) NimbusClient(org.apache.storm.utils.NimbusClient) Nimbus(org.apache.storm.generated.Nimbus) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) TopologyInfo(org.apache.storm.generated.TopologyInfo)

Example 2 with GetInfoOptions

use of org.apache.storm.generated.GetInfoOptions in project storm by apache.

the class Nimbus method getTopologyInfo.

@Override
public TopologyInfo getTopologyInfo(String id) throws NotAliveException, AuthorizationException, TException {
    try {
        getTopologyInfoCalls.mark();
        GetInfoOptions options = new GetInfoOptions();
        options.set_num_err_choice(NumErrorsChoice.ALL);
        return getTopologyInfoWithOpts(id, options);
    } catch (Exception e) {
        LOG.warn("get topology ino exception. (topology id={})", id, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) GetInfoOptions(org.apache.storm.generated.GetInfoOptions) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Aggregations

GetInfoOptions (org.apache.storm.generated.GetInfoOptions)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 ErrorInfo (org.apache.storm.generated.ErrorInfo)1 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)1 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)1 Nimbus (org.apache.storm.generated.Nimbus)1 NotAliveException (org.apache.storm.generated.NotAliveException)1 TopologyInfo (org.apache.storm.generated.TopologyInfo)1 NimbusClient (org.apache.storm.utils.NimbusClient)1 TException (org.apache.thrift.TException)1