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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations