Search in sources :

Example 6 with ISupervisor

use of org.apache.storm.scheduler.ISupervisor 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 7 with ISupervisor

use of org.apache.storm.scheduler.ISupervisor in project storm by apache.

the class LocalCluster method addSupervisor.

/**
     * Add another supervisor to the topology.  This is intended mostly for internal testing.
     * @param ports the number of ports/slots the supervisor should have
     * @param conf any config values that should be added/over written in the daemon conf of the cluster.
     * @param id the id of the new supervisor, so you can find it later.
     */
public synchronized Supervisor addSupervisor(Number ports, Map<String, Object> conf, String id) throws Exception {
    if (ports == null) {
        ports = 2;
    }
    TmpPath tmpDir = new TmpPath();
    tmpDirs.add(tmpDir);
    List<Integer> portNumbers = new ArrayList<>(ports.intValue());
    for (int i = 0; i < ports.intValue(); i++) {
        portNumbers.add(portCounter.getAndIncrement());
    }
    Map<String, Object> superConf = new HashMap<>(daemonConf);
    if (conf != null) {
        superConf.putAll(conf);
    }
    superConf.put(Config.STORM_LOCAL_DIR, tmpDir.getPath());
    superConf.put(Config.SUPERVISOR_SLOTS_PORTS, portNumbers);
    final String superId = id == null ? Utils.uuid() : id;
    ISupervisor isuper = new StandaloneSupervisor() {

        @Override
        public String generateSupervisorId() {
            return superId;
        }
    };
    if (!ConfigUtils.isLocalMode(superConf)) {
        throw new IllegalArgumentException("Cannot start server in distrubuted mode!");
    }
    Supervisor s = new Supervisor(superConf, sharedContext, isuper);
    s.launch();
    supervisors.add(s);
    return s;
}
Also used : Supervisor(org.apache.storm.daemon.supervisor.Supervisor) ISupervisor(org.apache.storm.scheduler.ISupervisor) StandaloneSupervisor(org.apache.storm.daemon.supervisor.StandaloneSupervisor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TmpPath(org.apache.storm.testing.TmpPath) ArrayList(java.util.ArrayList) StandaloneSupervisor(org.apache.storm.daemon.supervisor.StandaloneSupervisor) ISupervisor(org.apache.storm.scheduler.ISupervisor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ISupervisor (org.apache.storm.scheduler.ISupervisor)7 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)6 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)6 ILocalizer (org.apache.storm.localizer.ILocalizer)6 LocalState (org.apache.storm.utils.LocalState)6 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)6 Test (org.junit.Test)6 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)5 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)5 LocalAssignment (org.apache.storm.generated.LocalAssignment)5 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TopoProfileAction (org.apache.storm.daemon.supervisor.Slot.TopoProfileAction)1 StandaloneSupervisor (org.apache.storm.daemon.supervisor.StandaloneSupervisor)1 Supervisor (org.apache.storm.daemon.supervisor.Supervisor)1 NodeInfo (org.apache.storm.generated.NodeInfo)1 ProfileRequest (org.apache.storm.generated.ProfileRequest)1