Skip to content

Commit

Permalink
Merge pull request #15 from anliu/master
Browse files Browse the repository at this point in the history
expose alternative base uri
  • Loading branch information
thomasjungblut committed Dec 8, 2014
2 parents 737dd73 + 0dba5c6 commit 2b25168
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Microsoft.HBase.Client/HBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public sealed class HBaseClient : IHBaseClient
private readonly WebRequester _requester;
private readonly IRetryPolicyFactory _retryPolicyFactory;

/// <summary>
/// Base uri for hbase rest api
/// </summary>
public string RestEndpointBase { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="HBaseClient"/> class.
/// </summary>
Expand Down Expand Up @@ -97,7 +102,7 @@ public async Task<ScannerInformation> CreateScannerAsync(string tableName, Scann
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
using (HttpWebResponse response = await PostRequestAsync(tableName + "/scanner", scannerSettings, WebRequester.RestEndpointBaseZero))
using (HttpWebResponse response = await PostRequestAsync(tableName + "/scanner", scannerSettings, RestEndpointBase ?? WebRequester.RestEndpointBaseZero))
{
if (response.StatusCode != HttpStatusCode.Created)
{
Expand Down Expand Up @@ -159,7 +164,7 @@ public async Task<bool> CreateTableAsync(TableSchema schema)
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
using (HttpWebResponse webResponse = await PutRequestAsync(schema.name + "/schema", schema))
using (HttpWebResponse webResponse = await PutRequestAsync(schema.name + "/schema", schema, RestEndpointBase))
{
if (webResponse.StatusCode == HttpStatusCode.Created)
{
Expand Down Expand Up @@ -219,7 +224,7 @@ public async Task DeleteTableAsync(string table)
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
using (HttpWebResponse webResponse = await DeleteRequestAsync<TableSchema>(table + "/schema", null))
using (HttpWebResponse webResponse = await DeleteRequestAsync<TableSchema>(table + "/schema", null, RestEndpointBase))
{
if (webResponse.StatusCode != HttpStatusCode.OK)
{
Expand Down Expand Up @@ -278,7 +283,7 @@ public async Task<CellSet> GetCellsAsync(string tableName, string rowKey)
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
return await GetRequestAndDeserializeAsync<CellSet>(tableName + "/" + rowKey);
return await GetRequestAndDeserializeAsync<CellSet>(tableName + "/" + rowKey, RestEndpointBase);
}
catch (Exception e)
{
Expand Down Expand Up @@ -312,7 +317,7 @@ public async Task<StorageClusterStatus> GetStorageClusterStatusAsync()
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
return await GetRequestAndDeserializeAsync<StorageClusterStatus>("/status/cluster");
return await GetRequestAndDeserializeAsync<StorageClusterStatus>("/status/cluster", RestEndpointBase);
}
catch (Exception e)
{
Expand Down Expand Up @@ -349,7 +354,7 @@ public async Task<TableInfo> GetTableInfoAsync(string table)
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
return await GetRequestAndDeserializeAsync<TableInfo>(table + "/regions");
return await GetRequestAndDeserializeAsync<TableInfo>(table + "/regions", RestEndpointBase);
}
catch (Exception e)
{
Expand Down Expand Up @@ -387,7 +392,7 @@ public async Task<TableSchema> GetTableSchemaAsync(string table)
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
return await GetRequestAndDeserializeAsync<TableSchema>(table + "/schema");
return await GetRequestAndDeserializeAsync<TableSchema>(table + "/schema", RestEndpointBase);
}
catch (Exception e)
{
Expand Down Expand Up @@ -421,7 +426,7 @@ public org.apache.hadoop.hbase.rest.protobuf.generated.Version GetVersion()
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
return await GetRequestAndDeserializeAsync<org.apache.hadoop.hbase.rest.protobuf.generated.Version>("version");
return await GetRequestAndDeserializeAsync<org.apache.hadoop.hbase.rest.protobuf.generated.Version>("version", RestEndpointBase);
}
catch (Exception e)
{
Expand Down Expand Up @@ -454,9 +459,8 @@ public async Task<TableList> ListTablesAsync()
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
return await GetRequestAndDeserializeAsync<TableList>("");
return await GetRequestAndDeserializeAsync<TableList>("", RestEndpointBase);
}

catch (Exception e)
{
if (!retryPolicy.ShouldRetryAttempt(e))
Expand Down Expand Up @@ -496,7 +500,7 @@ public async Task ModifyTableSchemaAsync(string table, TableSchema schema)
IRetryPolicy retryPolicy = _retryPolicyFactory.Create();
try
{
using (HttpWebResponse webResponse = await PostRequestAsync(table + "/schema", schema))
using (HttpWebResponse webResponse = await PostRequestAsync(table + "/schema", schema, RestEndpointBase))
{
if (webResponse.StatusCode != HttpStatusCode.OK || webResponse.StatusCode != HttpStatusCode.Created)
{
Expand Down Expand Up @@ -553,7 +557,7 @@ public async Task<CellSet> ScannerGetNextAsync(ScannerInformation scannerInfo)
{
using (
HttpWebResponse webResponse =
await GetRequestAsync(scannerInfo.TableName + "/scanner/" + scannerInfo.ScannerId, WebRequester.RestEndpointBaseZero))
await GetRequestAsync(scannerInfo.TableName + "/scanner" + scannerInfo.ScannerId, RestEndpointBase ?? WebRequester.RestEndpointBaseZero))
{
if (webResponse.StatusCode == HttpStatusCode.OK)
{
Expand Down Expand Up @@ -600,7 +604,7 @@ public async Task StoreCellsAsync(string table, CellSet cells)
try
{
// note the fake row key to insert a set of cells
using (HttpWebResponse webResponse = await PutRequestAsync(table + "/somefalsekey", cells))
using (HttpWebResponse webResponse = await PutRequestAsync(table + "/somefalsekey", cells, RestEndpointBase))
{
if (webResponse.StatusCode != HttpStatusCode.OK)
{
Expand Down

0 comments on commit 2b25168

Please sign in to comment.