Search in sources :

Example 1 with Supervisor

use of org.apache.storm.daemon.supervisor.Supervisor in project storm by apache.

the class LocalCluster method close.

@Override
public synchronized void close() throws Exception {
    if (nimbus != null) {
        nimbus.shutdown();
    }
    if (thriftServer != null) {
        LOG.info("shutting down thrift server");
        try {
            thriftServer.stop();
        } catch (Exception e) {
            LOG.info("failed to stop thrift", e);
        }
    }
    if (state != null) {
        state.close();
    }
    if (getClusterState() != null) {
        getClusterState().disconnect();
    }
    for (Supervisor s : supervisors) {
        s.shutdownAllWorkers(null, ReadClusterState.THREAD_DUMP_ON_ERROR);
        s.close();
    }
    ProcessSimulator.killAllProcesses();
    if (zookeeper != null) {
        LOG.info("Shutting down in process zookeeper");
        zookeeper.close();
        LOG.info("Done shutting down in process zookeeper");
    }
    for (TmpPath p : tmpDirs) {
        p.close();
    }
    if (this.trackId != null) {
        LOG.warn("Clearing tracked metrics for ID {}", this.trackId);
        LocalExecutor.clearTrackId();
        RegisteredGlobalState.clearState(this.trackId);
    }
    if (this.commonInstaller != null) {
        this.commonInstaller.close();
    }
    if (time != null) {
        time.close();
    }
}
Also used : Supervisor(org.apache.storm.daemon.supervisor.Supervisor) ISupervisor(org.apache.storm.scheduler.ISupervisor) StandaloneSupervisor(org.apache.storm.daemon.supervisor.StandaloneSupervisor) TmpPath(org.apache.storm.testing.TmpPath) AuthorizationException(org.apache.storm.generated.AuthorizationException) TException(org.apache.thrift.TException)

Example 2 with Supervisor

use of org.apache.storm.daemon.supervisor.Supervisor in project storm by apache.

the class KillWorkers method main.

public static void main(String[] args) throws Exception {
    Map<String, Object> conf = ConfigUtils.readStormConfig();
    conf.put(Config.STORM_LOCAL_DIR, new File((String) conf.get(Config.STORM_LOCAL_DIR)).getCanonicalPath());
    try (Supervisor supervisor = new Supervisor(conf, null, new StandaloneSupervisor())) {
        supervisor.shutdownAllWorkers(null, null);
    }
}
Also used : Supervisor(org.apache.storm.daemon.supervisor.Supervisor) StandaloneSupervisor(org.apache.storm.daemon.supervisor.StandaloneSupervisor) StandaloneSupervisor(org.apache.storm.daemon.supervisor.StandaloneSupervisor) File(java.io.File)

Example 3 with Supervisor

use of org.apache.storm.daemon.supervisor.Supervisor 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)

Example 4 with Supervisor

use of org.apache.storm.daemon.supervisor.Supervisor in project storm by apache.

the class LocalCluster method killSupervisor.

/**
     * Kill a specific supervisor.  This is intended mostly for internal testing.
     * @param id the id of the supervisor
     */
public synchronized void killSupervisor(String id) {
    for (Iterator<Supervisor> it = supervisors.iterator(); it.hasNext(); ) {
        Supervisor s = it.next();
        if (id.equals(s.getId())) {
            it.remove();
            s.close();
            //tmpDir will be handled separately
            return;
        }
    }
}
Also used : Supervisor(org.apache.storm.daemon.supervisor.Supervisor) ISupervisor(org.apache.storm.scheduler.ISupervisor) StandaloneSupervisor(org.apache.storm.daemon.supervisor.StandaloneSupervisor)

Aggregations

StandaloneSupervisor (org.apache.storm.daemon.supervisor.StandaloneSupervisor)4 Supervisor (org.apache.storm.daemon.supervisor.Supervisor)4 ISupervisor (org.apache.storm.scheduler.ISupervisor)3 TmpPath (org.apache.storm.testing.TmpPath)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 TException (org.apache.thrift.TException)1