KYLIN 예행 스케줄 링 자동 BULID

KYLIN 은 RESTFUL 인 터 페 이 스 를 제공 합 니 다. 요청 & crontab 를 통 해 정기 적 인 스케줄 링 을 실현 할 수 있 습 니 다.
  url:
http://kylin.apache.org/docs15/howto/howto_use_restapi.html#get-job-status

실현 절차:
1. 셸 스 크 립 트 는 아래 코드 를 추가 하여 BULID 요청 을 실현 합 니 다.
java -jar KylinInterface.jar CUBE_NAME 20160806 20160807 BUILD

2, crontab 설정 자동 실행
다음은 jar 대응 코드 입 니 다.
package kylin;



import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.commons.codec.binary.Base64;


/*
 * auth  : lidan20
 * email : [email protected]
 * comp  : baidu
 * info  : http://kylin.apache.org/docs15/howto/howto_use_restapi.html#get-job-status
 * run   : java -jar KylinInterface.jar CUBE_NAME 20160806 20160807 BUILD
 */
public class KylinCube {


    public static void main(String[] args) {

        String AUTH     = "ADMIN:KYLIN";

        String cubename = args[0] ; //    cubename like  'CUBE_DWD_PAY_USER_DETAIL_DF_DETAIL'

        String starttime= getTime(args[1]);                  //    starttime like  'yyyyMMdd'

        String endtime  = getTime(args[2]);                    //    endtime like  'yyyyMMdd'

        String oper     = args[3];                       //    bulidtype like  'BUILD|MERGE|REFRESH'


        String PARAMS="{\"startTime\": "+starttime+",\"endTime\": "+ endtime +",\"buildType\": \"" + oper +"\"}";

        System.out.print(PARAMS);
        String PATH = "http://ip:7070/kylin/api/cubes/"+cubename+"/rebuild";


        //System.out.print(cubename+starttime+endtime+oper);
        System.out.println(Put(AUTH,PATH,PARAMS));
    }

    public static String getTime(String strdate) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        long unixtime=0;
        try {
             unixtime = sdf.parse(strdate).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return String.valueOf(unixtime);
    }

        public static String Put(String auth,String addr, String params) {
        String result = "";
        try {
            URL url = new URL(addr);
            HttpURLConnection connection = (HttpURLConnection) url
                    .openConnection();
            connection.setRequestMethod("PUT");
            connection.setDoOutput(true);
            //String auth = ACCOUNT + ":" + PWD;
            String code = new String(new Base64().encode(auth.getBytes()));
            connection.setRequestProperty("Authorization", "Basic " + code);
            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
            PrintWriter out = new PrintWriter(connection.getOutputStream());
            out.write(params);
            out.close();
            BufferedReader in;
            try {
                in = new BufferedReader(new InputStreamReader(
                        connection.getInputStream()));
            } catch (FileNotFoundException exception) {
                java.io.InputStream err = ((HttpURLConnection) connection).getErrorStream();
                if (err == null)
                    throw exception;
                in = new BufferedReader(new InputStreamReader(err));
            }
            StringBuffer response = new StringBuffer();
            String line;
            while ((line = in.readLine()) != null)
                response.append(line + "
"); in.close(); result = response.toString(); } catch (MalformedURLException e) { System.err.println(e.toString()); } catch (IOException e) { System.err.println(e.toString()); } return result; } }

좋은 웹페이지 즐겨찾기