Example usage for org.apache.hadoop.util ReflectionUtils printThreadInfo

List of usage examples for org.apache.hadoop.util ReflectionUtils printThreadInfo

Introduction

In this page you can find the example usage for org.apache.hadoop.util ReflectionUtils printThreadInfo.

Prototype

public synchronized static void printThreadInfo(PrintStream stream, String title) 

Source Link

Document

Print all of the thread's information and stack traces.

Usage

From source file:com.alibaba.wasp.fserver.FSDumpServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FServer fs = (FServer) getServletContext().getAttribute(FServer.FSERVER);
    assert fs != null : "No FS in context!";

    Configuration hrsconf = (Configuration) getServletContext().getAttribute(FServer.FSERVER_CONF);
    assert hrsconf != null : "No FS conf in context";

    response.setContentType("text/plain");
    OutputStream os = response.getOutputStream();
    PrintWriter out = new PrintWriter(os);

    out.println("Master status for " + fs.getServerName() + " as of " + new Date());

    out.println("\n\nVersion Info:");
    out.println(LINE);/*from  w w  w  . j av a2s. com*/
    dumpVersionInfo(out);

    out.println("\n\nTasks:");
    out.println(LINE);
    TaskMonitor.get().dumpAsText(out);

    out.println("\n\nExecutors:");
    out.println(LINE);
    dumpExecutors(fs.getExecutorService(), out);

    out.println("\n\nStacks:");
    out.println(LINE);
    ReflectionUtils.printThreadInfo(out, "");

    out.println("\n\nFS Configuration:");
    out.println(LINE);
    Configuration conf = fs.getConfiguration();
    out.flush();
    conf.writeXml(os);
    os.flush();

    out.println("\n\nLogs");
    out.println(LINE);
    long tailKb = getTailKbParam(request);
    LogMonitoring.dumpTailOfLogs(out, tailKb);

    out.println("\n\nFS Queue:");
    out.println(LINE);
    if (isShowQueueDump(hrsconf)) {
        dumpQueue(fs, out);
    }

    out.flush();
}

From source file:com.alibaba.wasp.master.FMasterDumpServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FMaster master = (FMaster) getServletContext().getAttribute(FMaster.MASTER);
    assert master != null : "No Master in context!";

    response.setContentType("text/plain");
    OutputStream os = response.getOutputStream();
    PrintWriter out = new PrintWriter(os);

    out.println("Master status for " + master.getServerName() + " as of " + new Date());

    out.println("\n\nVersion Info:");
    out.println(LINE);//w w w  . j av a 2 s.  c o m
    dumpVersionInfo(out);

    out.println("\n\nTasks:");
    out.println(LINE);
    TaskMonitor.get().dumpAsText(out);

    out.println("\n\nServers:");
    out.println(LINE);
    dumpServers(master, out);

    out.println("\n\nEntityGroups-in-transition:");
    out.println(LINE);
    dumpRIT(master, out);

    out.println("\n\nExecutors:");
    out.println(LINE);
    dumpExecutors(master.getExecutorService(), out);

    out.println("\n\nStacks:");
    out.println(LINE);
    ReflectionUtils.printThreadInfo(out, "");

    out.println("\n\nMaster configuration:");
    out.println(LINE);
    Configuration conf = master.getConfiguration();
    out.flush();
    conf.writeXml(os);
    os.flush();

    //    out.println("\n\nRecent fserver aborts:");
    //    out.println(LINE);
    //    master.getFServerFatalLogBuffer().dumpTo(out);

    out.println("\n\nLogs");
    out.println(LINE);
    long tailKb = getTailKbParam(request);
    LogMonitoring.dumpTailOfLogs(out, tailKb);

    out.flush();
}

From source file:org.apache.tajo.engine.utils.ThreadUtil.java

License:Apache License

/**
 * @param t Waits on the passed thread to die dumping a threaddump every
 * minute while its up./*from   ww  w . j a  v a 2s  .c om*/
 * @throws InterruptedException
 */
public static void threadDumpingIsAlive(final Thread t) throws InterruptedException {
    if (t == null) {
        return;
    }

    while (t.isAlive()) {
        t.join(60 * 1000);
        if (t.isAlive()) {
            ReflectionUtils.printThreadInfo(new PrintWriter(System.out),
                    "Automatic Stack Trace every 60 seconds waiting on " + t.getName());
        }
    }
}

From source file:org.lilyproject.hadooptestfw.HBaseProxy.java

License:Apache License

public void stop() throws Exception {
    if (mode == Mode.EMBED) {
        // Since HBase mini cluster shutdown has a tendency of sometimes failing (hanging waiting on master
        // to end), add a protection for this so that we do not run indefinitely. Especially important not to
        // annoy the other projects on our Hudson server.
        Thread stopHBaseThread = new Thread() {
            @Override/*from w  w w  .  j av  a 2 s. co m*/
            public void run() {
                try {
                    hbaseTestUtil.shutdownMiniCluster();
                    hbaseTestUtil = null;
                } catch (Exception e) {
                    System.out.println("Error shutting down mini cluster.");
                    e.printStackTrace();
                }
            }
        };
        stopHBaseThread.start();
        stopHBaseThread.join(60000);
        if (stopHBaseThread.isAlive()) {
            System.err.println("Unable to stop embedded mini cluster within predetermined timeout.");
            System.err.println("Dumping stack for future investigation.");
            ReflectionUtils.printThreadInfo(new PrintWriter(System.out), "Thread dump");
            System.out.println(
                    "Will now try to interrupt the mini-cluster-stop-thread and give it some more time to end.");
            stopHBaseThread.interrupt();
            stopHBaseThread.join(20000);
            throw new Exception("Failed to stop the mini cluster within the predetermined timeout.");
        }
    }

    // Close connections with HBase and HBase's ZooKeeper handles
    //HConnectionManager.deleteConnectionInfo(CONF, true);
    HConnectionManager.deleteAllConnections(true);

    // Close all HDFS connections
    FileSystem.closeAll();

    conf = null;

    if (clearData && testHome != null) {
        TestHomeUtil.cleanupTestHome(testHome);
    }

    ManagementFactory.getPlatformMBeanServer()
            .unregisterMBean(new ObjectName("LilyHBaseProxy:name=ReplicationPeer"));
}

From source file:org.lilyproject.lilyservertestfw.launcher.LilyLauncher.java

License:Apache License

@Override
public void resetLilyState() {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

    if (!resetRunning.compareAndSet(false, true)) {
        throw new RuntimeException("There is already a Lily state reset running.");
    }/*from  w  w  w .j a v  a2  s  .c o  m*/

    try {
        long before = System.currentTimeMillis();
        if (!enableLily || !enableHadoop || !enableSolr) {
            throw new Exception("resetLilyState is only supported when all services are running");
        }

        // Stop Lily
        System.out.println("Stopping Lily");
        lilyService.stop();
        System.out.println("Lily stopped");

        // Clear HBase tables
        System.out.println("Clearing HBase tables");
        CleanupUtil cleanupUtil = new CleanupUtil(hadoopService.getConf(), "localhost:2181");
        cleanupUtil.cleanTables();
        HConnectionManager.deleteConnection(hadoopService.getConf(), true);

        // Clear Lily ZooKeeper state
        System.out.println("Clearing Lily's ZooKeeper state");
        cleanupUtil.cleanZooKeeper();

        // Clear replication stat
        List<String> peerIds = cleanupUtil.cleanHBaseReplicas();
        for (String peerId : peerIds) {
            new ReplicationPeerUtil().waitOnReplicationPeerStopped(peerId);
        }

        // Clear Blobs on hdfs blobstore
        String dfsUri = "hdfs://localhost:8020/lily/blobs";
        System.out.println("Clearing HDFS Blob Store on " + dfsUri);
        cleanupUtil.cleanBlobStore(new URI(dfsUri));

        // Clear Solr state
        clearSolrState();

        // The following is useful to observe what threads were not stopped properly after stopping Lily
        if (System.getProperty("lily.launcher.threaddump-after-lily-stop") != null) {
            ReflectionUtils.printThreadInfo(new PrintWriter("launcher-threaddump-after-lily-stop"),
                    "Thread dump");
        }

        // Start Lily
        System.out.println("Starting Lily");
        lilyService.start(new ArrayList<String>());

        System.out.println("Reset Lily state took " + (System.currentTimeMillis() - before) + " ms");
    } catch (Exception e) {
        System.out.println("Error while resetting Lily state: " + e.getMessage());
        e.printStackTrace();
        throw new RuntimeException("Error while resetting Lily state: " + e.getMessage(), e);
    } finally {
        resetRunning.set(false);
    }
}