Search in sources :

Example 16 with ExecutorInfo

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

the class SlotTest method testRelaunch.

@Test
public void testRelaunch() throws Exception {
    try (SimulatedTime t = new SimulatedTime(1010)) {
        int port = 8080;
        String topoId = "CURRENT";
        List<ExecutorInfo> execList = mkExecutorInfoList(1, 2, 3, 4, 5);
        LocalAssignment assignment = mkLocalAssignment(topoId, execList, mkWorkerResources(100.0, 100.0, 100.0));
        ILocalizer localizer = mock(ILocalizer.class);
        Container container = mock(Container.class);
        ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
        LSWorkerHeartbeat oldhb = mkWorkerHB(topoId, port, execList, Time.currentTimeSecs() - 10);
        LSWorkerHeartbeat goodhb = mkWorkerHB(topoId, port, execList, Time.currentTimeSecs());
        when(container.readHeartbeat()).thenReturn(oldhb, oldhb, goodhb, goodhb);
        when(container.areAllProcessesDead()).thenReturn(false, true);
        ISupervisor iSuper = mock(ISupervisor.class);
        LocalState state = mock(LocalState.class);
        StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
        DynamicState dynamicState = new DynamicState(assignment, container, assignment);
        DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
        assertEquals(MachineState.KILL_AND_RELAUNCH, nextState.state);
        verify(container).kill();
        assertTrue(Time.currentTimeMillis() > 1000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.KILL_AND_RELAUNCH, nextState.state);
        verify(container).forceKill();
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
        verify(container).relaunch();
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
        assertTrue(Time.currentTimeMillis() > 3000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) ISupervisor(org.apache.storm.scheduler.ISupervisor) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) 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) Test(org.junit.Test)

Example 17 with ExecutorInfo

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

the class ClusterUtils method convertExecutorBeats.

/**
     * Ensures that we only return heartbeats for executors assigned to this worker
     * @param executors
     * @param workerHeartbeat
     * @return
     */
public static Map<ExecutorInfo, ExecutorBeat> convertExecutorBeats(List<ExecutorInfo> executors, ClusterWorkerHeartbeat workerHeartbeat) {
    Map<ExecutorInfo, ExecutorBeat> executorWhb = new HashMap<>();
    Map<ExecutorInfo, ExecutorStats> executorStatsMap = workerHeartbeat.get_executor_stats();
    for (ExecutorInfo executor : executors) {
        if (executorStatsMap.containsKey(executor)) {
            int time = workerHeartbeat.get_time_secs();
            int uptime = workerHeartbeat.get_uptime_secs();
            ExecutorStats executorStats = workerHeartbeat.get_executor_stats().get(executor);
            ExecutorBeat executorBeat = new ExecutorBeat(time, uptime, executorStats);
            executorWhb.put(executor, executorBeat);
        }
    }
    return executorWhb;
}
Also used : ExecutorInfo(org.apache.storm.generated.ExecutorInfo) HashMap(java.util.HashMap) ExecutorStats(org.apache.storm.generated.ExecutorStats)

Aggregations

ExecutorInfo (org.apache.storm.generated.ExecutorInfo)17 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 List (java.util.List)9 Map (java.util.Map)8 LocalAssignment (org.apache.storm.generated.LocalAssignment)8 Test (org.junit.Test)7 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)6 LocalState (org.apache.storm.utils.LocalState)6 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)5 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)5 ExecutorStats (org.apache.storm.generated.ExecutorStats)5 ILocalizer (org.apache.storm.localizer.ILocalizer)4 ISupervisor (org.apache.storm.scheduler.ISupervisor)4 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)4 File (java.io.File)3 IOException (java.io.IOException)2 IStormClusterState (org.apache.storm.cluster.IStormClusterState)2 AdvancedFSOps (org.apache.storm.daemon.supervisor.AdvancedFSOps)2 ExecutorSummary (org.apache.storm.generated.ExecutorSummary)2