Search in sources :

Example 1 with TmpPath

use of org.apache.storm.testing.TmpPath 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 TmpPath

use of org.apache.storm.testing.TmpPath 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

StandaloneSupervisor (org.apache.storm.daemon.supervisor.StandaloneSupervisor)2 Supervisor (org.apache.storm.daemon.supervisor.Supervisor)2 ISupervisor (org.apache.storm.scheduler.ISupervisor)2 TmpPath (org.apache.storm.testing.TmpPath)2 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