Search in sources :

Example 1 with ProfileRequest

use of org.apache.storm.generated.ProfileRequest 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 ProfileRequest

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

the class ReadClusterState method run.

@Override
public synchronized void run() {
    try {
        Runnable syncCallback = new EventManagerPushCallback(this, syncSupEventManager);
        List<String> stormIds = stormClusterState.assignments(syncCallback);
        Map<String, VersionedData<Assignment>> assignmentsSnapshot = getAssignmentsSnapshot(stormClusterState, stormIds, assignmentVersions.get(), syncCallback);
        Map<Integer, LocalAssignment> allAssignments = readAssignments(assignmentsSnapshot);
        if (allAssignments == null) {
            //Something odd happened try again later
            return;
        }
        Map<String, List<ProfileRequest>> topoIdToProfilerActions = getProfileActions(stormClusterState, stormIds);
        HashSet<Integer> assignedPorts = new HashSet<>();
        LOG.debug("Synchronizing supervisor");
        LOG.debug("All assignment: {}", allAssignments);
        LOG.debug("Topology Ids -> Profiler Actions {}", topoIdToProfilerActions);
        for (Integer port : allAssignments.keySet()) {
            if (iSuper.confirmAssigned(port)) {
                assignedPorts.add(port);
            }
        }
        HashSet<Integer> allPorts = new HashSet<>(assignedPorts);
        allPorts.addAll(slots.keySet());
        Map<Integer, Set<TopoProfileAction>> filtered = new HashMap<>();
        for (Entry<String, List<ProfileRequest>> entry : topoIdToProfilerActions.entrySet()) {
            String topoId = entry.getKey();
            if (entry.getValue() != null) {
                for (ProfileRequest req : entry.getValue()) {
                    NodeInfo ni = req.get_nodeInfo();
                    if (host.equals(ni.get_node())) {
                        Long port = ni.get_port().iterator().next();
                        Set<TopoProfileAction> actions = filtered.get(port.intValue());
                        if (actions == null) {
                            actions = new HashSet<>();
                            filtered.put(port.intValue(), actions);
                        }
                        actions.add(new TopoProfileAction(topoId, req));
                    }
                }
            }
        }
        for (Integer port : allPorts) {
            Slot slot = slots.get(port);
            if (slot == null) {
                slot = mkSlot(port);
                slots.put(port, slot);
                slot.start();
            }
            slot.setNewAssignment(allAssignments.get(port));
            slot.addProfilerActions(filtered.get(port));
        }
    } catch (Exception e) {
        LOG.error("Failed to Sync Supervisor", e);
        throw new RuntimeException(e);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) TopoProfileAction(org.apache.storm.daemon.supervisor.Slot.TopoProfileAction) HashSet(java.util.HashSet) ProfileRequest(org.apache.storm.generated.ProfileRequest) VersionedData(org.apache.storm.cluster.VersionedData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeInfo(org.apache.storm.generated.NodeInfo) LocalAssignment(org.apache.storm.generated.LocalAssignment)

Example 3 with ProfileRequest

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

the class SlotTest method testRunWithProfileActions.

@Test
public void testRunWithProfileActions() throws Exception {
    try (SimulatedTime t = new SimulatedTime(1010)) {
        int port = 8080;
        String cTopoId = "CURRENT";
        List<ExecutorInfo> cExecList = mkExecutorInfoList(1, 2, 3, 4, 5);
        LocalAssignment cAssignment = mkLocalAssignment(cTopoId, cExecList, mkWorkerResources(100.0, 100.0, 100.0));
        Container cContainer = mock(Container.class);
        //NOT going to timeout for a while
        LSWorkerHeartbeat chb = mkWorkerHB(cTopoId, port, cExecList, Time.currentTimeSecs() + 100);
        when(cContainer.readHeartbeat()).thenReturn(chb, chb, chb, chb, chb, chb);
        when(cContainer.runProfiling(any(ProfileRequest.class), anyBoolean())).thenReturn(true);
        ILocalizer localizer = mock(ILocalizer.class);
        ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
        ISupervisor iSuper = mock(ISupervisor.class);
        LocalState state = mock(LocalState.class);
        StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
        Set<TopoProfileAction> profileActions = new HashSet<>();
        ProfileRequest request = new ProfileRequest();
        request.set_action(ProfileAction.JPROFILE_STOP);
        NodeInfo info = new NodeInfo();
        info.set_node("localhost");
        info.add_to_port(port);
        request.set_nodeInfo(info);
        //3 seconds from now
        request.set_time_stamp(Time.currentTimeMillis() + 3000);
        TopoProfileAction profile = new TopoProfileAction(cTopoId, request);
        profileActions.add(profile);
        Set<TopoProfileAction> expectedPending = new HashSet<>();
        expectedPending.add(profile);
        DynamicState dynamicState = new DynamicState(cAssignment, cContainer, cAssignment).withProfileActions(profileActions, Collections.<TopoProfileAction>emptySet());
        DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        verify(cContainer).runProfiling(request, false);
        assertEquals(expectedPending, nextState.pendingStopProfileActions);
        assertEquals(expectedPending, nextState.profileActions);
        assertTrue(Time.currentTimeMillis() > 1000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertEquals(expectedPending, nextState.pendingStopProfileActions);
        assertEquals(expectedPending, nextState.profileActions);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertEquals(expectedPending, nextState.pendingStopProfileActions);
        assertEquals(expectedPending, nextState.profileActions);
        assertTrue(Time.currentTimeMillis() > 3000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        verify(cContainer).runProfiling(request, true);
        assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.pendingStopProfileActions);
        assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.profileActions);
        assertTrue(Time.currentTimeMillis() > 4000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.pendingStopProfileActions);
        assertEquals(Collections.<TopoProfileAction>emptySet(), nextState.profileActions);
        assertTrue(Time.currentTimeMillis() > 5000);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) ProfileRequest(org.apache.storm.generated.ProfileRequest) ISupervisor(org.apache.storm.scheduler.ISupervisor) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) NodeInfo(org.apache.storm.generated.NodeInfo) ILocalizer(org.apache.storm.localizer.ILocalizer) LocalAssignment(org.apache.storm.generated.LocalAssignment) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) LocalState(org.apache.storm.utils.LocalState) TopoProfileAction(org.apache.storm.daemon.supervisor.Slot.TopoProfileAction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ProfileRequest

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

the class BasicContainerTest method testRunProfiling.

@Test
public void testRunProfiling() throws Exception {
    final long pid = 100;
    final String topoId = "test_topology";
    final int port = 8080;
    final String workerId = "worker-id";
    final String stormLocal = ContainerTest.asAbsPath("tmp", "testing");
    final String topoRoot = ContainerTest.asAbsPath(stormLocal, topoId, String.valueOf(port));
    final File workerArtifactsPid = ContainerTest.asAbsFile(topoRoot, "worker.pid");
    final Map<String, Object> superConf = new HashMap<>();
    superConf.put(Config.STORM_LOCAL_DIR, stormLocal);
    superConf.put(Config.STORM_WORKERS_ARTIFACTS_DIR, stormLocal);
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
    when(ops.slurpString(workerArtifactsPid)).thenReturn(String.valueOf(pid));
    LocalState ls = mock(LocalState.class);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, workerId, new HashMap<>(), ops, "profile");
    //HEAP DUMP
    ProfileRequest req = new ProfileRequest();
    req.set_action(ProfileAction.JMAP_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, mc.profileCmds.size());
    CommandRun cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "jmap", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    //JSTACK DUMP
    req.set_action(ProfileAction.JSTACK_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "jstack", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    //RESTART
    req.set_action(ProfileAction.JVM_RESTART);
    mc.runProfiling(req, false);
    assertEquals(1, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "kill"), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    //JPROFILE DUMP
    req.set_action(ProfileAction.JPROFILE_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "dump", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    //JPROFILE START
    req.set_action(ProfileAction.JPROFILE_STOP);
    mc.runProfiling(req, false);
    assertEquals(1, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "start"), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    //JPROFILE STOP
    req.set_action(ProfileAction.JPROFILE_STOP);
    mc.runProfiling(req, true);
    assertEquals(1, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "stop", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
}
Also used : HashMap(java.util.HashMap) ProfileRequest(org.apache.storm.generated.ProfileRequest) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) File(java.io.File) Test(org.junit.Test)

Aggregations

ProfileRequest (org.apache.storm.generated.ProfileRequest)4 HashMap (java.util.HashMap)3 LocalAssignment (org.apache.storm.generated.LocalAssignment)3 NodeInfo (org.apache.storm.generated.NodeInfo)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 TopoProfileAction (org.apache.storm.daemon.supervisor.Slot.TopoProfileAction)2 LocalState (org.apache.storm.utils.LocalState)2 Test (org.junit.Test)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 Map (java.util.Map)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 KeySequenceNumber (org.apache.storm.blobstore.KeySequenceNumber)1 VersionedData (org.apache.storm.cluster.VersionedData)1