Search in sources :

Example 6 with ExecutorInfo

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

the class SlotTest method testReschedule.

@Test
public void testReschedule() 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);
        LSWorkerHeartbeat chb = mkWorkerHB(cTopoId, port, cExecList, Time.currentTimeSecs());
        when(cContainer.readHeartbeat()).thenReturn(chb);
        when(cContainer.areAllProcessesDead()).thenReturn(false, true);
        String nTopoId = "NEW";
        List<ExecutorInfo> nExecList = mkExecutorInfoList(1, 2, 3, 4, 5);
        LocalAssignment nAssignment = mkLocalAssignment(nTopoId, nExecList, mkWorkerResources(100.0, 100.0, 100.0));
        ILocalizer localizer = mock(ILocalizer.class);
        Container nContainer = mock(Container.class);
        LocalState state = mock(LocalState.class);
        ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
        when(containerLauncher.launchContainer(port, nAssignment, state)).thenReturn(nContainer);
        LSWorkerHeartbeat nhb = mkWorkerHB(nTopoId, 100, nExecList, Time.currentTimeSecs());
        when(nContainer.readHeartbeat()).thenReturn(nhb, nhb);
        @SuppressWarnings("unchecked") Future<Void> baseFuture = mock(Future.class);
        when(localizer.requestDownloadBaseTopologyBlobs(nAssignment, port)).thenReturn(baseFuture);
        @SuppressWarnings("unchecked") Future<Void> blobFuture = mock(Future.class);
        when(localizer.requestDownloadTopologyBlobs(nAssignment, port)).thenReturn(blobFuture);
        ISupervisor iSuper = mock(ISupervisor.class);
        StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state);
        DynamicState dynamicState = new DynamicState(cAssignment, cContainer, nAssignment);
        DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
        assertEquals(MachineState.KILL, nextState.state);
        verify(cContainer).kill();
        verify(localizer).requestDownloadBaseTopologyBlobs(nAssignment, port);
        assertSame("pendingDownload not set properly", baseFuture, nextState.pendingDownload);
        assertEquals(nAssignment, nextState.pendingLocalization);
        assertTrue(Time.currentTimeMillis() > 1000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.KILL, nextState.state);
        verify(cContainer).forceKill();
        assertSame("pendingDownload not set properly", baseFuture, nextState.pendingDownload);
        assertEquals(nAssignment, nextState.pendingLocalization);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.WAITING_FOR_BASIC_LOCALIZATION, nextState.state);
        verify(cContainer).cleanUp();
        verify(localizer).releaseSlotFor(cAssignment, port);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.WAITING_FOR_BLOB_LOCALIZATION, nextState.state);
        verify(baseFuture).get(1000, TimeUnit.MILLISECONDS);
        verify(localizer).requestDownloadTopologyBlobs(nAssignment, port);
        assertSame("pendingDownload not set properly", blobFuture, nextState.pendingDownload);
        assertEquals(nAssignment, nextState.pendingLocalization);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        verify(blobFuture).get(1000, TimeUnit.MILLISECONDS);
        verify(containerLauncher).launchContainer(port, nAssignment, state);
        assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(nAssignment, nextState.currentAssignment);
        assertSame(nContainer, nextState.container);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(nAssignment, nextState.currentAssignment);
        assertSame(nContainer, nextState.container);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(nAssignment, nextState.currentAssignment);
        assertSame(nContainer, nextState.container);
        assertTrue(Time.currentTimeMillis() > 3000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(nAssignment, nextState.currentAssignment);
        assertSame(nContainer, nextState.container);
        assertTrue(Time.currentTimeMillis() > 4000);
    }
}
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 7 with ExecutorInfo

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

the class StatsUtil method thriftifyStats.

public static Map thriftifyStats(List stats) {
    Map ret = new HashMap();
    for (Object o : stats) {
        List stat = (List) o;
        List executor = (List) stat.get(0);
        int start = ((Number) executor.get(0)).intValue();
        int end = ((Number) executor.get(1)).intValue();
        Map executorStat = (Map) stat.get(1);
        ExecutorInfo executorInfo = new ExecutorInfo(start, end);
        ret.put(executorInfo, thriftifyExecutorStats(executorStat));
    }
    return ret;
}
Also used : ExecutorInfo(org.apache.storm.generated.ExecutorInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ExecutorInfo

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

the class StatsUtil method thriftifyExecAggStats.

private static ExecutorAggregateStats thriftifyExecAggStats(String compId, String compType, Map m) {
    ExecutorAggregateStats stats = new ExecutorAggregateStats();
    ExecutorSummary executorSummary = new ExecutorSummary();
    List executor = (List) getByKey(m, EXECUTOR_ID);
    executorSummary.set_executor_info(new ExecutorInfo(((Number) executor.get(0)).intValue(), ((Number) executor.get(1)).intValue()));
    executorSummary.set_component_id(compId);
    executorSummary.set_host((String) getByKey(m, HOST));
    executorSummary.set_port(getByKeyOr0(m, PORT).intValue());
    int uptime = getByKeyOr0(m, UPTIME).intValue();
    executorSummary.set_uptime_secs(uptime);
    stats.set_exec_summary(executorSummary);
    if (compType.equals(SPOUT)) {
        stats.set_stats(thriftifySpoutAggStats(m));
    } else {
        stats.set_stats(thriftifyBoltAggStats(m));
    }
    return stats;
}
Also used : ExecutorInfo(org.apache.storm.generated.ExecutorInfo) ExecutorAggregateStats(org.apache.storm.generated.ExecutorAggregateStats) ArrayList(java.util.ArrayList) List(java.util.List) ExecutorSummary(org.apache.storm.generated.ExecutorSummary)

Example 9 with ExecutorInfo

use of org.apache.storm.generated.ExecutorInfo 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;
}
Also used : ExecutorInfo(org.apache.storm.generated.ExecutorInfo) HashMap(java.util.HashMap) ExecutorStats(org.apache.storm.generated.ExecutorStats) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ExecutorInfo

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

the class StatsUtil method convertExecutorBeats.

// =====================================================================================
// convert thrift stats to java maps
// =====================================================================================
/**
     * convert thrift executor heartbeats into a java HashMap
     */
public static Map<List<Integer>, Map<String, Object>> convertExecutorBeats(Map<ExecutorInfo, ExecutorBeat> beats) {
    Map<List<Integer>, Map<String, Object>> ret = new HashMap<>();
    for (Map.Entry<ExecutorInfo, ExecutorBeat> beat : beats.entrySet()) {
        ExecutorInfo executorInfo = beat.getKey();
        ExecutorBeat executorBeat = beat.getValue();
        ret.put(Lists.newArrayList(executorInfo.get_task_start(), executorInfo.get_task_end()), convertZkExecutorHb(executorBeat));
    }
    return ret;
}
Also used : ExecutorInfo(org.apache.storm.generated.ExecutorInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ExecutorBeat(org.apache.storm.cluster.ExecutorBeat) HashMap(java.util.HashMap) Map(java.util.Map)

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