package org.jerrymouse.gaes.mavenPlugin.mojos.hadoop;

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.jerrymouse.gaes.mavenPlugin.base.MojoBase;

/**
 * @goal hadoop-clean-tables
 */
public class HadoopCleanTables extends MojoBase {

	@Override
	protected void hadoopExecute() {
		try {
			HBaseConfiguration hBaseConfiguration = new HBaseConfiguration();
			HBaseAdmin hBaseAdmin = new HBaseAdmin(hBaseConfiguration);
			HTableDescriptor[] hTableDescriptors = hBaseAdmin.listTables();
			for (HTableDescriptor hTableDescriptor : hTableDescriptors) {
				hBaseAdmin.disableTable(hTableDescriptor.getName());
				hBaseAdmin.deleteTable(hTableDescriptor.getName());
			}
		} catch (MasterNotRunningException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void normalExecute() {
	}

	@Override
	protected void gaeExecute() {
	}
}
