美文网首页
Rest接口建立Model以及Cube

Rest接口建立Model以及Cube

作者: xcardata | 来源:发表于2018-03-02 14:23 被阅读0次

    建立Cube:

    Rest地址:localhost:7070/kylin/api/cubes

    请求类型:POST

    参数:

    project     

    cubeName    

    cubeDescData

    cubeDescData: 在页面版上,通过编辑Cube的json获取

    建立Model

    Rest地址:localhost:7070/kylin/api/models

    请求类型:POST

    参数:

    project     

    modelName    

    modelDescData

    modelDescData:

    在页面版上,建立完成Model后,log会打印出相应json代码

    localhost:7070/kylin/api/models?modelName=TestModelGET

    注意:需要把json中的  "  改成  /"

    贴上示例代码:

    public class KylinRestTest {

        public static String call(final String URL, final String METHOD) {

            String result = null;

            HttpURLConnection conn = null;

            try {

                URL target = new URL(URL);

                conn = (HttpURLConnection) target.openConnection();

                conn.setDoOutput(true);

                conn.setDoInput(true);

                conn.setRequestMethod(METHOD);

                conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

                String username = "ADMIN";

                String password = "KYLIN";

                String input = username + ":" + password;

                String encoding = new sun.misc.BASE64Encoder().encode(input.getBytes());

                conn.setRequestProperty("Authorization", "Basic " + encoding);

                //

                conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

    //            conn.connect();

    //            String obj = "{\"startTime\":\"0\",\"endTime\":\"1472832000000\",\"buildType\":\"BUILD\"}";

    //            String obj = "{\"startTime\":\"1472832000000\",\"endTime\":\"1473177600000\",\"buildType\":\"BUILD\"}";

    //            String obj = "{\"startTime\":\"1472832000000\",\"endTime\":\"1473177600000\",\"buildType\":\"BUILD\"}";

                String obj = "{\"startTime\":\"1475020800000\",\"endTime\":\"1475193600000\",\"buildType\":\"BUILD\"}";

    //            String obj = "{\"startTime\":\"1473177600000\",\"endTime\":\"1473465600000\",\"buildType\":\"REFRESH\"}";

    //            String obj = "{\"startTime\":\"1472832000000\",\"endTime\":\"1473177600000\",\"buildType\":\"MERGE\"}";

                conn.setRequestProperty("Content-Length", obj.toString().getBytes().length + "");  //设置文件请求的长度

                OutputStream out = conn.getOutputStream();

                out.write(obj.toString().getBytes());

                out.flush();

                out.close();

    //            conn.setRequestProperty("startTime", "0");

    //            conn.setRequestProperty("endTime", "1472832000000");

    //            conn.setRequestProperty("buildType", "BUILD");

                if (200 != conn.getResponseCode()) {

    //                throw new RuntimeException("failed, error code is " + conn.getResponseCode() + "\n" + conn.getErrorStream().toString() + "\n" + conn.getResponseMessage());

    //                throw new RuntimeException(conn.getErrorStream().toString());

    //                throw new RuntimeException(conn.getResponseMessage());

    //                throw new RuntimeException("failed, error code is " + conn.getResponseCode());

                    System.out.println(conn.getErrorStream());

                }

                byte[] temp = new byte[conn.getInputStream().available()];

                if (conn.getInputStream().read(temp) != -1) {

                    result = new String(temp);

                }

            } catch (MalformedURLException e) {

                e.printStackTrace();

            } catch (IOException e) {

                e.printStackTrace();

            } finally {

                conn.disconnect();

            }

            return result;

        }

        public static void main(String[] args) {

    //        System.out.println(call("http://192.168.88.215:7070/kylin/api/user/authentication", "POST"));

    //        System.out.println(call("http://192.168.88.215:7070/kylin/api/cubes?cubeName=test2MC&limit=15&offset=0", "GET"));

    //        System.out.println(call("http://192.168.88.215:7070/kylin/api/jobs/f7ffbe3d-7907-45f2-b815-dcca831f08b5", "GET"));

    //        System.out.println(call("http://192.168.88.215:7070/kylin/api/cubes/test2MC/build", "PUT"));

            System.out.println(call("http://192.168.88.215:7070/kylin/api/cubes/test2MC/build", "PUT"));

        }

    }

    相关文章

      网友评论

          本文标题:Rest接口建立Model以及Cube

          本文链接:https://www.haomeiwen.com/subject/sjjaxftx.html