package edu.mayo.hadoop.commons.hbase;

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.log4j.Logger;

import edu.mayo.hadoop.commons.minicluster.MiniClusterUtil;

/**
 * Find a HBase configuration based on simple heuristics.
 * <p>
 * This class will determine an HBase configuration to return. A simple set of
 * rules are as follows:
 * <p>
 * <ul>
 * <li>if <code>/etc/hbase/conf</code> exists, use that configuration (HDP)</li>
 * <li>else start up a <a href=
 * "http://www.lopakalogic.com/articles/hadoop-articles/hadoop-testing-with-minicluster/">
 * mini-cluster</a></li>
 * </ul>
 * </p>
 * Created by Daniel Blezek on 2/23/16.
 */
public class AutoConfigure {
    static Logger logger = Logger.getLogger(AutoConfigure.class);

    public static org.apache.hadoop.conf.Configuration getConfiguration() throws Exception {

        // Check for a site wide configuration for HDP
        String configPath = "/etc/hbase/conf/hbase-site.xml";
        if (Files.exists(Paths.get(configPath))) {
            logger.debug("Found " + configPath + " configuring HBase");
            org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
            conf.addResource(new Path(configPath));
            return conf;
        }

        // Return a mini-cluster
        Properties props = new Properties();

        for (String resourceName : new String[]{"/hbase.properties", "/hdfs.properties", "/yarn.properties", "/zookeeper.properties"}) {
            try (InputStream stream = AutoConfigure.class.getResourceAsStream(resourceName)) {
                props.putAll(MiniClusterUtil.loadPropertiesStream(stream));
            }
        }

        //cleanup directories from runs that where unstable.
        MiniClusterUtil.deleteLocalHBaseDir(props);
        MiniClusterUtil.deleteLocalZookeeperDir(props);


        MiniClusterUtil.startHBASE(props);
        return MiniClusterUtil.getHbaseLocalCluster().getHbaseConfiguration();
    }
}

@@ -37,122 +37,8 @@
 e;%0A%0A
-import java.io.InputStream;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0Aimport java.util.Properties;%0A%0A
 impo
@@ -151,16 +151,130 @@
 ogger;%0A%0A
+import java.io.InputStream;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0Aimport java.util.Properties;%0A%0A
 import e
@@ -473,19 +473,16 @@
 e set of
-%0A *
  rules a
@@ -614,16 +614,19 @@
 art up a
+%0A *
  %3Ca href
@@ -626,19 +626,16 @@
 %3Ca href=
-%0A *
  %22http:/
@@ -714,19 +714,16 @@
 uster/%22%3E
-%0A *
  mini-cl
@@ -731,16 +731,20 @@
 ster%3C/a%3E
+%0A * 
 %3C/li%3E%0A *
@@ -1592,16 +1592,32 @@
 erties%22,
+%0A               
  %22/zooke
@@ -1843,16 +1843,17 @@
       //
+ 
 cleanup 
@@ -2004,17 +2004,16 @@
 rops);%0A%0A
-%0A
         
@@ -2131,11 +2131,102 @@
 );%0A    %7D
+%0A%0A    public static void stop() throws Exception %7B%0A        MiniClusterUtil.stopAll();%0A    %7D
 %0A%7D%0A

Add stop method to AutoConfigure shutdowning down minicluster