use of org.apache.storm.generated.ExecutorStats in project storm by apache.
the class StatsUtil method thriftifyZkWorkerHb.
// =====================================================================================
// thriftify stats methods
// =====================================================================================
public static ClusterWorkerHeartbeat thriftifyZkWorkerHb(Map<String, Object> heartbeat) {
ClusterWorkerHeartbeat ret = new ClusterWorkerHeartbeat();
ret.set_uptime_secs(getByKeyOr0(heartbeat, UPTIME).intValue());
ret.set_storm_id((String) getByKey(heartbeat, "storm-id"));
ret.set_time_secs(getByKeyOr0(heartbeat, TIME_SECS).intValue());
Map<ExecutorInfo, ExecutorStats> convertedStats = new HashMap<>();
Map<List<Integer>, ExecutorStats> executorStats = getMapByKey(heartbeat, EXECUTOR_STATS);
if (executorStats != null) {
for (Map.Entry<List<Integer>, ExecutorStats> entry : executorStats.entrySet()) {
List<Integer> executor = entry.getKey();
ExecutorStats stats = entry.getValue();
if (null != stats) {
convertedStats.put(new ExecutorInfo(executor.get(0), executor.get(1)), stats);
}
}
}
ret.set_executor_stats(convertedStats);
return ret;
}
use of org.apache.storm.generated.ExecutorStats 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.ExecutorStats in project storm by apache.
the class TopoWrap method getAllTimeEmittedCount.
public long getAllTimeEmittedCount(final String componentId) throws TException {
TopologyInfo info = getInfo();
final List<ExecutorSummary> executors = info.get_executors();
return executors.stream().filter(summary -> summary != null && summary.get_component_id().equals(componentId)).mapToLong(summary -> {
ExecutorStats executorStats = summary.get_stats();
if (executorStats == null) {
return 0L;
}
Map<String, Map<String, Long>> emitted = executorStats.get_emitted();
if (emitted == null) {
return 0L;
}
Map<String, Long> allTime = emitted.get(":all-time");
if (allTime == null) {
return 0L;
}
return allTime.get(Utils.DEFAULT_STREAM_ID);
}).sum();
}
use of org.apache.storm.generated.ExecutorStats in project storm by apache.
the class ClientStatsUtil method mkEmptyExecutorZkHbs.
/**
* Make an map of executors to empty stats, in preparation for doing a heartbeat.
* @param executors the executors as keys of the map
* @return and empty map of executors to stats
*/
public static Map<List<Integer>, ExecutorStats> mkEmptyExecutorZkHbs(Set<List<Long>> executors) {
Map<List<Integer>, ExecutorStats> ret = new HashMap<>();
for (Object executor : executors) {
List startEnd = (List) executor;
ret.put(convertExecutor(startEnd), null);
}
return ret;
}
use of org.apache.storm.generated.ExecutorStats in project storm by apache.
the class StatsUtil method convertExecutorsStats.
/**
* convert executors stats into a HashMap, note that ExecutorStats are remained unchanged.
*/
public static Map<List<Integer>, ExecutorStats> convertExecutorsStats(Map<ExecutorInfo, ExecutorStats> stats) {
Map<List<Integer>, ExecutorStats> ret = new HashMap<>();
for (Map.Entry<ExecutorInfo, ExecutorStats> entry : stats.entrySet()) {
ExecutorInfo executorInfo = entry.getKey();
ExecutorStats executorStats = entry.getValue();
ret.put(Lists.newArrayList(executorInfo.get_task_start(), executorInfo.get_task_end()), executorStats);
}
return ret;
}
Aggregations