Search in sources :

Example 1 with ProfileAction

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

the class Nimbus method getComponentPendingProfileActions.

@Override
public List<ProfileRequest> getComponentPendingProfileActions(String id, String componentId, ProfileAction action) throws TException {
    try {
        getComponentPendingProfileActionsCalls.mark();
        CommonTopoInfo info = getCommonTopoInfo(id, "getComponentPendingProfileActions");
        Map<String, String> nodeToHost = info.assignment.get_node_host();
        Map<List<? extends Number>, List<Object>> exec2hostPort = new HashMap<>();
        for (Entry<List<Long>, NodeInfo> entry : info.assignment.get_executor_node_port().entrySet()) {
            NodeInfo ni = entry.getValue();
            List<Object> hostPort = Arrays.asList(nodeToHost.get(ni.get_node()), ni.get_port_iterator().next().intValue());
            exec2hostPort.put(entry.getKey(), hostPort);
        }
        List<Map<String, Object>> nodeInfos = StatsUtil.extractNodeInfosFromHbForComp(exec2hostPort, info.taskToComponent, false, componentId);
        List<ProfileRequest> ret = new ArrayList<>();
        for (Map<String, Object> ni : nodeInfos) {
            String niHost = (String) ni.get("host");
            int niPort = ((Integer) ni.get("port")).intValue();
            ProfileRequest newestMatch = null;
            long reqTime = -1;
            for (ProfileRequest req : stormClusterState.getTopologyProfileRequests(id)) {
                String expectedHost = req.get_nodeInfo().get_node();
                int expectedPort = req.get_nodeInfo().get_port_iterator().next().intValue();
                ProfileAction expectedAction = req.get_action();
                if (niHost.equals(expectedHost) && niPort == expectedPort && action == expectedAction) {
                    long time = req.get_time_stamp();
                    if (time > reqTime) {
                        reqTime = time;
                        newestMatch = req;
                    }
                }
            }
            if (newestMatch != null) {
                ret.add(newestMatch);
            }
        }
        LOG.info("Latest profile actions for topology {} component {} {}", id, componentId, ret);
        return ret;
    } catch (Exception e) {
        LOG.warn("Get comp actions topology exception. (topology id='{}')", id, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProfileAction(org.apache.storm.generated.ProfileAction) ProfileRequest(org.apache.storm.generated.ProfileRequest) DataPoint(org.apache.storm.metric.api.DataPoint) 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) KeySequenceNumber(org.apache.storm.blobstore.KeySequenceNumber) NodeInfo(org.apache.storm.generated.NodeInfo) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TimeCacheMap(org.apache.storm.utils.TimeCacheMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 2 with ProfileAction

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

the class BasicContainer method runProfiling.

@Override
public boolean runProfiling(ProfileRequest request, boolean stop) throws IOException, InterruptedException {
    _type.assertFull();
    String targetDir = ConfigUtils.workerArtifactsRoot(_conf, _topologyId, _port);
    @SuppressWarnings("unchecked") Map<String, String> env = (Map<String, String>) _topoConf.get(Config.TOPOLOGY_ENVIRONMENT);
    if (env == null) {
        env = new HashMap<String, String>();
    }
    String str = ConfigUtils.workerArtifactsPidPath(_conf, _topologyId, _port);
    String workerPid = _ops.slurpString(new File(str)).trim();
    ProfileAction profileAction = request.get_action();
    String logPrefix = "ProfilerAction process " + _topologyId + ":" + _port + " PROFILER_ACTION: " + profileAction + " ";
    List<String> command = mkProfileCommand(profileAction, stop, workerPid, targetDir);
    File targetFile = new File(targetDir);
    if (command.size() > 0) {
        return runProfilingCommand(command, env, logPrefix, targetFile);
    }
    LOG.warn("PROFILING REQUEST NOT SUPPORTED {} IGNORED...", request);
    return true;
}
Also used : ProfileAction(org.apache.storm.generated.ProfileAction) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 ProfileAction (org.apache.storm.generated.ProfileAction)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 KeySequenceNumber (org.apache.storm.blobstore.KeySequenceNumber)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)1 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)1 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)1 NodeInfo (org.apache.storm.generated.NodeInfo)1 NotAliveException (org.apache.storm.generated.NotAliveException)1 ProfileRequest (org.apache.storm.generated.ProfileRequest)1