Search in sources :

Example 6 with Daemon

use of org.apache.accumulo.core.util.Daemon in project accumulo by apache.

the class SecurityUtil method startTicketRenewalThread.

/**
 * Start a thread that periodically attempts to renew the current Kerberos user's ticket.
 *
 * @param ugi
 *          The current Kerberos user.
 * @param renewalPeriod
 *          The amount of time between attempting renewals.
 */
static void startTicketRenewalThread(final UserGroupInformation ugi, final long renewalPeriod) {
    Thread t = new Daemon(new LoggingRunnable(renewalLog, new Runnable() {

        @Override
        public void run() {
            while (true) {
                try {
                    renewalLog.debug("Invoking renewal attempt for Kerberos ticket");
                    // While we run this "frequently", the Hadoop implementation will only perform the login at 80% of ticket lifetime.
                    ugi.checkTGTAndReloginFromKeytab();
                } catch (IOException e) {
                    // Should failures to renew the ticket be retried more quickly?
                    renewalLog.error("Failed to renew Kerberos ticket", e);
                }
                // Wait for a bit before checking again.
                try {
                    Thread.sleep(renewalPeriod);
                } catch (InterruptedException e) {
                    renewalLog.error("Renewal thread interrupted", e);
                    Thread.currentThread().interrupt();
                    return;
                }
            }
        }
    }));
    t.setName("Kerberos Ticket Renewal");
    t.start();
}
Also used : LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable) Daemon(org.apache.accumulo.core.util.Daemon) LoggingRunnable(org.apache.accumulo.fate.util.LoggingRunnable) IOException(java.io.IOException)

Example 7 with Daemon

use of org.apache.accumulo.core.util.Daemon in project accumulo by apache.

the class Halt method halt.

public static void halt(final int status, Runnable runnable) {
    try {
        // give ourselves a little time to try and do something
        new Daemon() {

            @Override
            public void run() {
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
                Runtime.getRuntime().halt(status);
            }
        }.start();
        if (runnable != null)
            runnable.run();
        Runtime.getRuntime().halt(status);
    } finally {
        // In case something else decides to throw a Runtime exception
        Runtime.getRuntime().halt(-1);
    }
}
Also used : Daemon(org.apache.accumulo.core.util.Daemon)

Example 8 with Daemon

use of org.apache.accumulo.core.util.Daemon 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

Daemon (org.apache.accumulo.core.util.Daemon)8 LoggingRunnable (org.apache.accumulo.fate.util.LoggingRunnable)5 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)2 KeeperException (org.apache.zookeeper.KeeperException)2 DataOutputStream (java.io.DataOutputStream)1 EOFException (java.io.EOFException)1 OutputStream (java.io.OutputStream)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)1 CryptoModule (org.apache.accumulo.core.security.crypto.CryptoModule)1 CryptoModuleParameters (org.apache.accumulo.core.security.crypto.CryptoModuleParameters)1 NoFlushOutputStream (org.apache.accumulo.core.security.crypto.NoFlushOutputStream)1