com.taobao.drc.clusterclient.clustermanager.APIProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of consumer-core Show documentation
Show all versions of consumer-core Show documentation
The java consumer core component for Data Transmission Service
/**
* 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());
}
}