/**
 * Copyright (c) 2017, Stupid Bird and/or its affiliates. All rights reserved.
 * STUPID BIRD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * @Project : demo
 * @Package : net.lizhaoweb.demo.hadoop.hbase.hfile
 * @author <a href="http://www.lizhaoweb.net">李召(John.Lee)</a>
 * @EMAIL 404644381@qq.com
 * @Time : 20:30
 */
package net.lizhaoweb.demo.hadoop.hbase.hfile;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.util.ToolRunner;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Locale;

import static org.fusesource.jansi.Ansi.Color.YELLOW;
import static org.fusesource.jansi.Ansi.ansi;

/**
 * @author <a href="http://www.lizhaoweb.cn">李召(John.Lee)</a>
 * @version 1.0.0.0.1
 * @EMAIL 404644381@qq.com
 * @notes Created on 2017年07月27日<br>
 * Revision of last commit:$Revision$<br>
 * Author of last commit:$Author$<br>
 * Date of last commit:$Date$<br>
 */
public class TestHFileScheduler {

    private static final String FORMAT_PRINT_TIME_CONSUMING = "执行 %s 用时 %s 毫秒";
    private static final String FORMAT_COLOR_PRINT_TIME_CONSUMING = "@|blue 执行|@ @|green %s|@ @|blue 用时|@ @|red %s|@ @|blue 毫秒|@\n";

    private DecimalFormat decimalFormat;

    private Configuration conf;
    private Configuration hBaseConf;

    @Before
    public void init() throws IOException {
        System.out.println();
        System.setProperty("hadoop.home.dir", "D:\\GreenProfram\\HadoopEcosphere\\applications\\hadoop2.6_x64-for-win");
        Locale.setDefault(Locale.CHINA);
        this.decimalFormat = new DecimalFormat();

        this.conf = new Configuration();
        this.hBaseConf = HBaseConfiguration.create(this.conf);
    }

    @Test
    public void run() {
        long start = System.currentTimeMillis();
        String[] args = {
//                "hdfsCluster=hdfs://localhost:9000",
                "hdfsIn=hdfs://localhost:9000/home/data/hadoop/flume/mysql/medias1",
                "hdfsIn=hdfs://localhost:9000/home/data/hadoop/flume/mysql/medias2",
                "hdfsIn=hdfs://localhost:9000/home/data/hadoop/flume/mysql/medias3",
                "hdfsOut=hdfs://localhost:9000/home/data/hadoop/flume/mysql/mediasO"
//                ,
//
//                "hBaseRootDir=hdfs://devpd1:8020/hbase",
//                "hBaseZookeeper=devpd1",
//
//                "hbaseSharePath=/user/oozie/share/lib/lib_20170601134717/hbase"
        };

        try {
            ToolRunner.run(this.hBaseConf, new HFileScheduler(), args);
        } catch (Exception e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();

        String printMessage = String.format(FORMAT_PRINT_TIME_CONSUMING, Thread.currentThread().getStackTrace()[1].getMethodName(), this.decimalFormat.format(end - start));
        System.out.println(ansi().eraseScreen().fg(YELLOW).a(printMessage).reset());

        String ansiPrintMessage = String.format(FORMAT_COLOR_PRINT_TIME_CONSUMING, Thread.currentThread().getStackTrace()[1].getMethodName(), this.decimalFormat.format(end - start));
        System.out.println(ansi().eraseScreen().render(ansiPrintMessage));
    }
}