Search in sources :

Example 1 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class Nimbus method cleanTopologyHistory.

/**
 * Deletes topologies from history older than mins minutes.
 *
 * @param mins the number of mins for old topologies
 */
private void cleanTopologyHistory(int mins) {
    int cutoffAgeSecs = Time.currentTimeSecs() - (mins * 60);
    synchronized (topologyHistoryLock) {
        LocalState state = topologyHistoryState;
        state.filterOldTopologies(cutoffAgeSecs);
    }
}
Also used : LocalState(org.apache.storm.utils.LocalState) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) DataPoint(org.apache.storm.metric.api.DataPoint)

Example 2 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class Container method readHeartbeat.

/**
 * Read the Heartbeat for the current container.
 *
 * @return the Heartbeat
 *
 * @throws IOException on any error
 */
public LSWorkerHeartbeat readHeartbeat() throws IOException {
    LocalState localState = ConfigUtils.workerState(conf, workerId);
    LSWorkerHeartbeat hb = localState.getWorkerHeartBeat();
    LOG.trace("{}: Reading heartbeat {}", workerId, hb);
    return hb;
}
Also used : LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) LocalState(org.apache.storm.utils.LocalState)

Example 3 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class SlotTest method testEmptyToEmpty.

@Test
public void testEmptyToEmpty() throws Exception {
    try (SimulatedTime t = new SimulatedTime(1010)) {
        AsyncLocalizer localizer = mock(AsyncLocalizer.class);
        LocalState state = mock(LocalState.class);
        BlobChangingCallback cb = mock(BlobChangingCallback.class);
        ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
        ISupervisor iSuper = mock(ISupervisor.class);
        SlotMetrics slotMetrics = new SlotMetrics(new StormMetricsRegistry());
        StaticState staticState = new StaticState(localizer, 1000, 1000, 1000, 1000, containerLauncher, "localhost", 8080, iSuper, state, cb, null, null, slotMetrics);
        DynamicState dynamicState = new DynamicState(null, null, null, slotMetrics);
        DynamicState nextState = Slot.handleEmpty(dynamicState, staticState);
        assertEquals(MachineState.EMPTY, nextState.state);
        assertTrue(Time.currentTimeMillis() > 1000);
    }
}
Also used : BlobChangingCallback(org.apache.storm.localizer.BlobChangingCallback) SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) AsyncLocalizer(org.apache.storm.localizer.AsyncLocalizer) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) LocalState(org.apache.storm.utils.LocalState) ISupervisor(org.apache.storm.scheduler.ISupervisor) Test(org.junit.Test)

Example 4 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class SlotTest method testLaunchContainerFromEmpty.

@Test
public void testLaunchContainerFromEmpty() throws Exception {
    try (SimulatedTime t = new SimulatedTime(1010)) {
        int port = 8080;
        String topoId = "NEW";
        List<ExecutorInfo> execList = mkExecutorInfoList(1, 2, 3, 4, 5);
        LocalAssignment newAssignment = mkLocalAssignment(topoId, execList, mkWorkerResources(100.0, 100.0, 100.0));
        AsyncLocalizer localizer = mock(AsyncLocalizer.class);
        BlobChangingCallback cb = mock(BlobChangingCallback.class);
        Container container = mock(Container.class);
        LocalState state = mock(LocalState.class);
        ContainerLauncher containerLauncher = mock(ContainerLauncher.class);
        when(containerLauncher.launchContainer(port, newAssignment, state)).thenReturn(container);
        LSWorkerHeartbeat hb = mkWorkerHB(topoId, port, execList, Time.currentTimeSecs());
        when(container.readHeartbeat()).thenReturn(hb, hb);
        @SuppressWarnings("unchecked") CompletableFuture<Void> blobFuture = mock(CompletableFuture.class);
        when(localizer.requestDownloadTopologyBlobs(newAssignment, port, cb)).thenReturn(blobFuture);
        ISupervisor iSuper = mock(ISupervisor.class);
        SlotMetrics slotMetrics = new SlotMetrics(new StormMetricsRegistry());
        StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state, cb, null, null, slotMetrics);
        DynamicState dynamicState = new DynamicState(null, null, null, slotMetrics).withNewAssignment(newAssignment);
        DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
        verify(localizer).requestDownloadTopologyBlobs(newAssignment, port, cb);
        assertEquals(MachineState.WAITING_FOR_BLOB_LOCALIZATION, nextState.state);
        assertSame("pendingDownload not set properly", blobFuture, nextState.pendingDownload);
        assertEquals(newAssignment, nextState.pendingLocalization);
        assertEquals(0, Time.currentTimeMillis());
        nextState = Slot.stateMachineStep(nextState, staticState);
        verify(blobFuture).get(1000, TimeUnit.MILLISECONDS);
        verify(containerLauncher).launchContainer(port, newAssignment, state);
        assertEquals(MachineState.WAITING_FOR_WORKER_START, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(newAssignment, nextState.currentAssignment);
        assertSame(container, nextState.container);
        assertEquals(0, Time.currentTimeMillis());
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(newAssignment, nextState.currentAssignment);
        assertSame(container, nextState.container);
        assertEquals(0, Time.currentTimeMillis());
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(newAssignment, nextState.currentAssignment);
        assertSame(container, nextState.container);
        assertTrue(Time.currentTimeMillis() > 1000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.RUNNING, nextState.state);
        assertSame("pendingDownload is not null", null, nextState.pendingDownload);
        assertSame(null, nextState.pendingLocalization);
        assertSame(newAssignment, nextState.currentAssignment);
        assertSame(container, nextState.container);
        assertTrue(Time.currentTimeMillis() > 2000);
    }
}
Also used : SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) ISupervisor(org.apache.storm.scheduler.ISupervisor) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) BlobChangingCallback(org.apache.storm.localizer.BlobChangingCallback) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) LocalAssignment(org.apache.storm.generated.LocalAssignment) AsyncLocalizer(org.apache.storm.localizer.AsyncLocalizer) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Example 5 with LocalState

use of org.apache.storm.utils.LocalState 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));
        BlobChangingCallback cb = mock(BlobChangingCallback.class);
        Container cContainer = mock(Container.class);
        LSWorkerHeartbeat chb = mkWorkerHB(cTopoId, port, cExecList, Time.currentTimeSecs());
        when(cContainer.readHeartbeat()).thenReturn(chb);
        when(cContainer.areAllProcessesDead()).thenReturn(false, 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));
        AsyncLocalizer localizer = mock(AsyncLocalizer.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") CompletableFuture<Void> blobFuture = mock(CompletableFuture.class);
        when(localizer.requestDownloadTopologyBlobs(nAssignment, port, cb)).thenReturn(blobFuture);
        ISupervisor iSuper = mock(ISupervisor.class);
        SlotMetrics slotMetrics = new SlotMetrics(new StormMetricsRegistry());
        StaticState staticState = new StaticState(localizer, 5000, 120000, 1000, 1000, containerLauncher, "localhost", port, iSuper, state, cb, null, null, slotMetrics);
        DynamicState dynamicState = new DynamicState(cAssignment, cContainer, nAssignment, slotMetrics);
        DynamicState nextState = Slot.stateMachineStep(dynamicState, staticState);
        assertEquals(MachineState.KILL, nextState.state);
        verify(cContainer).kill();
        verify(localizer).requestDownloadTopologyBlobs(nAssignment, port, cb);
        assertSame("pendingDownload not set properly", blobFuture, 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", blobFuture, nextState.pendingDownload);
        assertEquals(nAssignment, nextState.pendingLocalization);
        assertTrue(Time.currentTimeMillis() > 2000);
        nextState = Slot.stateMachineStep(nextState, staticState);
        assertEquals(MachineState.WAITING_FOR_BLOB_LOCALIZATION, nextState.state);
        verify(cContainer).cleanUp();
        verify(localizer).releaseSlotFor(cAssignment, port);
        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) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) StaticState(org.apache.storm.daemon.supervisor.Slot.StaticState) ISupervisor(org.apache.storm.scheduler.ISupervisor) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) BlobChangingCallback(org.apache.storm.localizer.BlobChangingCallback) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) LocalAssignment(org.apache.storm.generated.LocalAssignment) AsyncLocalizer(org.apache.storm.localizer.AsyncLocalizer) DynamicState(org.apache.storm.daemon.supervisor.Slot.DynamicState) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Aggregations

LocalState (org.apache.storm.utils.LocalState)27 Test (org.junit.Test)20 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)17 LocalAssignment (org.apache.storm.generated.LocalAssignment)16 HashMap (java.util.HashMap)10 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)9 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)8 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)8 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)8 AsyncLocalizer (org.apache.storm.localizer.AsyncLocalizer)8 BlobChangingCallback (org.apache.storm.localizer.BlobChangingCallback)8 ISupervisor (org.apache.storm.scheduler.ISupervisor)8 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)8 File (java.io.File)6 ResourceIsolationInterface (org.apache.storm.container.ResourceIsolationInterface)4 MockResourceIsolationManager (org.apache.storm.daemon.supervisor.ContainerTest.MockResourceIsolationManager)4 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)3 StormTopology (org.apache.storm.generated.StormTopology)3 TmpPath (org.apache.storm.testing.TmpPath)3 IOException (java.io.IOException)2