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;
}
});
}
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);
}
}
Aggregations