All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.taobao.drc.clusterclient.clustermanager.APIProxy Maven / Gradle / Ivy

There is a newer version: 5.0.0.1.beta
Show newest version
/**
 * Alibaba.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package com.taobao.drc.clusterclient.clustermanager;

import com.taobao.drc.clusterclient.httpclient.HttpClient;
import org.apache.http.client.config.RequestConfig;
import java.io.IOException;

/**
 * @author haikuo.zhk
 * @version $Id: APIClient.java, v 0.1 2016年5月22日 下午12:13:52 haikuo.zhk Exp $
 */
public class APIProxy {
    private final HttpClient httpClient;

    private final String cmUrl;

    public APIProxy(String cmUrl) {
        // cmUrl for shanghai
        //this(new HttpClient(), /*cmUrl*/"http://139.196.166.197:8080");
        this(new HttpClient(), cmUrl);

    }

    public APIProxy(HttpClient httpClient, String cmUrl) {
        this.httpClient = httpClient;
        this.cmUrl = cmUrl;
    }

    private String joinPath(String path) {
        return cmUrl + path;
    }

    private  R post(AbstractControllerRequest request, Class responseClass, RequestConfig requestConfig) throws IOException {
        return httpClient.post(joinPath(request.getPath()), request.getContent(), responseClass, request.getAPIVersion(), requestConfig);
    }

    public BatchCommitResponse batchCommit(BatchCommitRequest request) throws IOException {
        return post(request, BatchCommitResponse.class, request.getRequestConfig());
    }

    public BatchGetPartitionResponse batchGetPartitions(BatchGetPartitionRequest request) throws IOException {
        return post(request, BatchGetPartitionResponse.class, request.getRequestConfig());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy