use of org.apache.storm.generated.ErrorInfo in project storm by apache.
the class Nimbus method getTopologyInfoWithOpts.
@Override
public TopologyInfo getTopologyInfoWithOpts(String topoId, GetInfoOptions options) throws NotAliveException, AuthorizationException, TException {
try {
getTopologyInfoWithOptsCalls.mark();
CommonTopoInfo common = getCommonTopoInfo(topoId, "getTopologyInfo");
if (common.base == null) {
throw new NotAliveException(topoId);
}
IStormClusterState state = stormClusterState;
NumErrorsChoice numErrChoice = OR(options.get_num_err_choice(), NumErrorsChoice.ALL);
Map<String, List<ErrorInfo>> errors = new HashMap<>();
for (String component : common.allComponents) {
switch(numErrChoice) {
case NONE:
errors.put(component, Collections.emptyList());
break;
case ONE:
List<ErrorInfo> errList = new ArrayList<>();
ErrorInfo info = state.lastError(topoId, component);
if (info != null) {
errList.add(info);
}
errors.put(component, errList);
break;
case ALL:
errors.put(component, state.errors(topoId, component));
break;
default:
LOG.warn("Got invalid NumErrorsChoice '{}'", numErrChoice);
errors.put(component, state.errors(topoId, component));
break;
}
}
List<ExecutorSummary> summaries = new ArrayList<>();
if (common.assignment != null) {
for (Entry<List<Long>, NodeInfo> entry : common.assignment.get_executor_node_port().entrySet()) {
NodeInfo ni = entry.getValue();
ExecutorInfo execInfo = toExecInfo(entry.getKey());
String host = entry.getValue().get_node();
Map<String, Object> heartbeat = common.beats.get(StatsUtil.convertExecutor(entry.getKey()));
if (heartbeat == null) {
heartbeat = Collections.emptyMap();
}
ExecutorSummary summ = new ExecutorSummary(execInfo, common.taskToComponent.get(execInfo.get_task_start()), ni.get_node(), ni.get_port_iterator().next().intValue(), (Integer) heartbeat.getOrDefault("uptime", 0));
//heartbeats "stats"
Map<String, Object> hb = (Map<String, Object>) heartbeat.get("heartbeat");
if (hb != null) {
Map ex = (Map) hb.get("stats");
if (ex != null) {
ExecutorStats stats = StatsUtil.thriftifyExecutorStats(ex);
summ.set_stats(stats);
}
}
summaries.add(summ);
}
}
TopologyInfo topoInfo = new TopologyInfo(topoId, common.topoName, Time.deltaSecs(common.launchTimeSecs), summaries, extractStatusStr(common.base), errors);
if (common.base.is_set_owner()) {
topoInfo.set_owner(common.base.get_owner());
}
String schedStatus = idToSchedStatus.get().get(topoId);
if (schedStatus != null) {
topoInfo.set_sched_status(schedStatus);
}
TopologyResources resources = getResourcesForTopology(topoId, common.base);
if (resources != null) {
topoInfo.set_requested_memonheap(resources.getRequestedMemOnHeap());
topoInfo.set_requested_memoffheap(resources.getRequestedMemOffHeap());
topoInfo.set_requested_cpu(resources.getRequestedCpu());
topoInfo.set_assigned_memonheap(resources.getAssignedMemOnHeap());
topoInfo.set_assigned_memoffheap(resources.getAssignedMemOffHeap());
topoInfo.set_assigned_cpu(resources.getAssignedCpu());
}
if (common.base.is_set_component_debug()) {
topoInfo.set_component_debug(common.base.get_component_debug());
}
topoInfo.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId)));
return topoInfo;
} catch (Exception e) {
LOG.warn("Get topo info exception. (topology id='{}')", topoId, e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.generated.ErrorInfo in project storm by apache.
the class TestStatsUtil method aggTopoExecsStats_boltAndSpoutsHaveLastErrorReported.
/**
* Targeted validation against StatsUtil.aggTopoExecsStats()
* to verify that when a bolt or spout has an error reported,
* it is included in the returned TopologyPageInfo result.
*/
@Test
public void aggTopoExecsStats_boltAndSpoutsHaveLastErrorReported() {
// Define inputs
final String expectedBoltErrorMsg = "This is my test bolt error message";
final int expectedBoltErrorTime = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
final int expectedBoltErrorPort = 4321;
final String expectedBoltErrorHost = "my.errored.host";
final String expectedSpoutErrorMsg = "This is my test spout error message";
final int expectedSpoutErrorTime = (int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
final int expectedSpoutErrorPort = 1234;
final String expectedSpoutErrorHost = "my.errored.host2";
// Define our Last Error for the bolt
final ErrorInfo expectedBoltLastError = new ErrorInfo(expectedBoltErrorMsg, expectedBoltErrorTime);
expectedBoltLastError.set_port(expectedBoltErrorPort);
expectedBoltLastError.set_host(expectedBoltErrorHost);
// Define our Last Error for the spout
final ErrorInfo expectedSpoutLastError = new ErrorInfo(expectedSpoutErrorMsg, expectedSpoutErrorTime);
expectedSpoutLastError.set_port(expectedSpoutErrorPort);
expectedSpoutLastError.set_host(expectedSpoutErrorHost);
// Create mock StormClusterState
final IStormClusterState mockStormClusterState = mock(IStormClusterState.class);
when(mockStormClusterState.lastError(eq("my-storm-id"), eq("my-component"))).thenReturn(expectedBoltLastError);
when(mockStormClusterState.lastError(eq("my-storm-id"), eq("my-spout"))).thenReturn(expectedSpoutLastError);
// Setup inputs.
makeTopoInfoWithSpout();
// Call method under test.
final TopologyPageInfo topologyPageInfo = StatsUtil.aggTopoExecsStats("my-storm-id", exec2NodePort, task2Component, beats, null, ":all-time", false, mockStormClusterState);
// Validate result
assertNotNull(topologyPageInfo, "Should never be null");
assertEquals("my-storm-id", topologyPageInfo.get_id());
assertEquals(8, topologyPageInfo.get_num_tasks(), "Should have 7 tasks.");
assertEquals(2, topologyPageInfo.get_num_workers(), "Should have 2 workers.");
assertEquals(2, topologyPageInfo.get_num_executors(), "Should have only a single executor.");
// Validate Spout aggregate statistics
assertNotNull(topologyPageInfo.get_id_to_spout_agg_stats(), "Should be non-null");
assertEquals(1, topologyPageInfo.get_id_to_spout_agg_stats().size());
assertEquals(1, topologyPageInfo.get_id_to_spout_agg_stats_size());
assertTrue(topologyPageInfo.get_id_to_spout_agg_stats().containsKey("my-spout"));
assertNotNull(topologyPageInfo.get_id_to_spout_agg_stats().get("my-spout"));
ComponentAggregateStats componentStats = topologyPageInfo.get_id_to_spout_agg_stats().get("my-spout");
assertEquals(ComponentType.SPOUT, componentStats.get_type(), "Should be of type spout");
assertNotNull(componentStats.get_last_error(), "Last error should not be null");
ErrorInfo lastError = componentStats.get_last_error();
assertEquals(expectedSpoutErrorMsg, lastError.get_error());
assertEquals(expectedSpoutErrorHost, lastError.get_host());
assertEquals(expectedSpoutErrorPort, lastError.get_port());
assertEquals(expectedSpoutErrorTime, lastError.get_error_time_secs());
// Validate Bolt aggregate statistics
assertNotNull(topologyPageInfo.get_id_to_bolt_agg_stats(), "Should be non-null");
assertEquals(1, topologyPageInfo.get_id_to_bolt_agg_stats().size());
assertEquals(1, topologyPageInfo.get_id_to_bolt_agg_stats_size());
assertTrue(topologyPageInfo.get_id_to_bolt_agg_stats().containsKey("my-component"));
assertNotNull(topologyPageInfo.get_id_to_bolt_agg_stats().get("my-component"));
componentStats = topologyPageInfo.get_id_to_bolt_agg_stats().get("my-component");
assertEquals(ComponentType.BOLT, componentStats.get_type(), "Should be of type bolt");
assertNotNull(componentStats.get_last_error(), "Last error should not be null");
lastError = componentStats.get_last_error();
assertEquals(expectedBoltErrorMsg, lastError.get_error());
assertEquals(expectedBoltErrorHost, lastError.get_host());
assertEquals(expectedBoltErrorPort, lastError.get_port());
assertEquals(expectedBoltErrorTime, lastError.get_error_time_secs());
// Verify mock interactions
verify(mockStormClusterState, times(1)).lastError(eq("my-storm-id"), eq("my-component"));
verify(mockStormClusterState, times(1)).lastError(eq("my-storm-id"), eq("my-spout"));
}
use of org.apache.storm.generated.ErrorInfo in project storm by apache.
the class GetErrors method main.
/**
* Only get errors for a topology.
* @param args Used to accept the topology name.
* @throws Exception on errors.
*/
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.Iface client) throws Exception {
GetInfoOptions opts = new GetInfoOptions();
opts.set_num_err_choice(NumErrorsChoice.ONE);
Map<String, Object> outputMap = new HashMap<>();
try {
TopologyInfo topologyInfo = client.getTopologyInfoByNameWithOpts(name, opts);
String topologyName = topologyInfo.get_name();
Map<String, List<ErrorInfo>> topologyErrors = topologyInfo.get_errors();
outputMap.put("Topology Name", topologyName);
outputMap.put("Comp-Errors", getComponentErrors(topologyErrors));
} catch (NotAliveException notAliveException) {
outputMap.put("Failure", "No topologies running with name " + name);
}
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.ErrorInfo in project storm by apache.
the class UIHelpersTest method test_getTopologySpoutAggStatsMap_includesLastError.
/**
* Very narrow test case to validate that 'last error' fields are populated for a spout
* with an error is present.
*/
@Test
void test_getTopologySpoutAggStatsMap_includesLastError() {
// Define inputs
final String expectedSpoutId = "MySpoutId";
final String expectedErrorMsg = "This is my test error message";
final int expectedErrorTime = Time.currentTimeSecs();
final int errorElapsedTimeSecs = 13;
final int expectedErrorElapsedTime = expectedErrorTime + errorElapsedTimeSecs;
final int expectedErrorPort = 4321;
final String expectedErrorHost = "my.errored.host";
// Define our Last Error
final ErrorInfo expectedLastError = new ErrorInfo(expectedErrorMsg, expectedErrorTime);
expectedLastError.set_port(expectedErrorPort);
expectedLastError.set_host(expectedErrorHost);
// Build stats instance for our spout
final ComponentAggregateStats aggregateStats = buildSpoutAggregateStatsBase();
aggregateStats.set_last_error(expectedLastError);
addSpoutStats(expectedSpoutId, aggregateStats);
// Advance time by 'errorElapsedTimeSecs'
Time.advanceTimeSecs(errorElapsedTimeSecs);
// Call method under test.
final Map<String, Object> result = UIHelpers.getTopologySummary(topoPageInfo, WINDOW, new HashMap<>(), "spp");
// Validate
assertNotNull(result, "Should never return null");
// Validate our Spout result
final Map<String, Object> spoutResult = getSpoutStatsFromTopologySummaryResult(result, expectedSpoutId);
assertNotNull(spoutResult, "Should have an entry for spout");
// Verify each piece
assertEquals(expectedSpoutId, spoutResult.get("spoutId"));
assertEquals(expectedSpoutId, spoutResult.get("encodedSpoutId"));
// Verify error
assertEquals(expectedErrorMsg, spoutResult.get("lastError"));
assertEquals(expectedErrorPort, spoutResult.get("errorPort"));
assertEquals(expectedErrorHost, spoutResult.get("errorHost"));
assertEquals(expectedErrorTime, spoutResult.get("errorTime"));
assertEquals(expectedErrorElapsedTime, spoutResult.get("errorLapsedSecs"));
}
use of org.apache.storm.generated.ErrorInfo in project storm by apache.
the class UIHelpersTest method test_getTopologyBoltAggStatsMap_includesLastError.
/**
* Very narrow test case to validate that 'last error' fields are populated for a bolt
* with an error is present.
*/
@Test
void test_getTopologyBoltAggStatsMap_includesLastError() {
// Define inputs
final String expectedBoltId = "MyBoltId";
final String expectedErrorMsg = "This is my test error message";
final int expectedErrorTime = Time.currentTimeSecs();
final int errorElapsedTimeSecs = 13;
final int expectedErrorElapsedTime = expectedErrorTime + errorElapsedTimeSecs;
final int expectedErrorPort = 4321;
final String expectedErrorHost = "my.errored.host";
// Define our Last Error
final ErrorInfo expectedLastError = new ErrorInfo(expectedErrorMsg, expectedErrorTime);
expectedLastError.set_port(expectedErrorPort);
expectedLastError.set_host(expectedErrorHost);
// Build stats instance for our bolt
final ComponentAggregateStats aggregateStats = buildBoltAggregateStatsBase();
aggregateStats.set_last_error(expectedLastError);
addBoltStats(expectedBoltId, aggregateStats);
// Advance time by 'errorElapsedTimeSecs'
Time.advanceTimeSecs(errorElapsedTimeSecs);
// Call method under test.
final Map<String, Object> result = UIHelpers.getTopologySummary(topoPageInfo, WINDOW, new HashMap<>(), "spp");
// Validate
assertNotNull(result, "Should never return null");
// Validate our Bolt result
final Map<String, Object> boltResult = getBoltStatsFromTopologySummaryResult(result, expectedBoltId);
assertNotNull(boltResult, "Should have an entry for bolt");
// Verify each piece
assertEquals(expectedBoltId, boltResult.get("boltId"));
assertEquals(expectedBoltId, boltResult.get("encodedBoltId"));
// Verify error
assertEquals(expectedErrorMsg, boltResult.get("lastError"));
assertEquals(expectedErrorPort, boltResult.get("errorPort"));
assertEquals(expectedErrorHost, boltResult.get("errorHost"));
assertEquals(expectedErrorTime, boltResult.get("errorTime"));
assertEquals(expectedErrorElapsedTime, boltResult.get("errorLapsedSecs"));
}
Aggregations