Search in sources :

Example 11 with LoggingRunnable

use of org.apache.accumulo.fate.util.LoggingRunnable in project accumulo by apache.

the class Monitor method run.

public void run(String hostname) {
    Monitor.START_TIME = System.currentTimeMillis();
    int[] ports = config.getSystemConfiguration().getPort(Property.MONITOR_PORT);
    for (int port : ports) {
        try {
            log.debug("Creating monitor on port {}", port);
            server = new EmbeddedWebServer(hostname, port);
            server.addServlet(getDefaultServlet(), "/resources/*");
            server.addServlet(getRestServlet(), "/rest/*");
            server.addServlet(getViewServlet(), "/*");
            server.start();
            break;
        } catch (Throwable ex) {
            log.error("Unable to start embedded web server", ex);
        }
    }
    if (!server.isRunning()) {
        throw new RuntimeException("Unable to start embedded web server on ports: " + Arrays.toString(ports));
    }
    try {
        getMonitorLock();
    } catch (Exception e) {
        log.error("Failed to get Monitor ZooKeeper lock");
        throw new RuntimeException(e);
    }
    String advertiseHost = hostname;
    if (advertiseHost.equals("0.0.0.0")) {
        try {
            advertiseHost = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            log.error("Unable to get hostname", e);
        }
    }
    log.debug("Using {} to advertise monitor location in ZooKeeper", advertiseHost);
    try {
        String monitorAddress = HostAndPort.fromParts(advertiseHost, server.getPort()).toString();
        ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, monitorAddress.getBytes(UTF_8), NodeExistsPolicy.OVERWRITE);
        log.info("Set monitor address in zookeeper to {}", monitorAddress);
    } catch (Exception ex) {
        log.error("Unable to set monitor HTTP address in zookeeper", ex);
    }
    if (null != advertiseHost) {
        LogService.startLogListener(Monitor.getContext().getConfiguration(), instance.getInstanceID(), advertiseHost);
    } else {
        log.warn("Not starting log4j listener as we could not determine address to use");
    }
    new Daemon(new LoggingRunnable(log, new ZooKeeperStatus()), "ZooKeeperStatus").start();
    // need to regularly fetch data so plot data is updated
    new Daemon(new LoggingRunnable(log, new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    Monitor.fetchData();
                } catch (Exception e) {
                    log.warn("{}", e.getMessage(), e);
                }
                sleepUninterruptibly(333, TimeUnit.MILLISECONDS);
            }
        }
    }), "Data fetcher").start();
    new Daemon(new LoggingRunnable(log, new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    Monitor.fetchScans();
                } catch (Exception e) {
                    log.warn("{}", e.getMessage(), e);
                }
                sleepUninterruptibly(5, TimeUnit.SECONDS);
            }
        }
    }), "Scan scanner").start();
    monitorInitialized.set(true);
}
Also used : UnknownHostException(java.net.UnknownHostException) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException) LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable) Daemon(org.apache.accumulo.core.util.Daemon) LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable)

Aggregations

LoggingRunnable (org.apache.accumulo.fate.util.LoggingRunnable)11 IOException (java.io.IOException)6 Daemon (org.apache.accumulo.core.util.Daemon)5 Path (org.apache.hadoop.fs.Path)4 TreeMap (java.util.TreeMap)3 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)3 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 TabletLocation (org.apache.accumulo.core.client.impl.TabletLocator.TabletLocation)2 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)2 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)2 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)2 NamingThreadFactory (org.apache.accumulo.core.util.NamingThreadFactory)2 TraceRunnable (org.apache.htrace.wrappers.TraceRunnable)2 DataOutputStream (java.io.DataOutputStream)1 EOFException (java.io.EOFException)1 OutputStream (java.io.OutputStream)1