Ejemplo n.º 1
0
 private async Task <Response> PostRequestAsync <TReq>(string endpoint, TReq request, RequestOptions options)
     where TReq : class
 {
     options.ArgumentNotNull("request options");
     endpoint.ArgumentNotNull("endpoint");
     return(await ExecuteMethodAsync("POST", null, endpoint, request, options));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HBaseClient" /> class.
 /// </summary>
 /// <remarks>
 /// To find the cluster vnet domain visit:
 /// https://azure.microsoft.com/en-us/documentation/articles/hdinsight-hbase-provision-vnet/
 /// </remarks>
 /// <param name="numRegionServers">The number of region servers in the cluster.</param>
 /// <param name="clusterDomain">The fully-qualified domain name of the cluster.</param>
 public HBaseClient(int numRegionServers, string clusterDomain = null)
     : this(null, RequestOptions.GetDefaultOptions(),
            new LoadBalancerRoundRobin(numRegionServers, clusterDomain))
 {
 }
Ejemplo n.º 3
0
 private async Task <T> GetRequestAndDeserializeAsync <T>(string endpoint, string query, RequestOptions options)
 {
     options.ArgumentNotNull("request options");
     endpoint.ArgumentNotNull("endpoint");
     using (var response = await _requester.IssueWebRequestAsync(endpoint, query, "GET", null, options))
     {
         using (var responseStream = response.WebResponse.GetResponseStream())
         {
             return(Serializer.Deserialize <T>(responseStream));
         }
     }
 }
Ejemplo n.º 4
0
 private async Task <Response> GetRequestAsync(string endpoint, string query, RequestOptions options)
 {
     options.ArgumentNotNull("request options");
     endpoint.ArgumentNotNull("endpoint");
     return(await _requester.IssueWebRequestAsync(endpoint, query, "GET", null, options));
 }
Ejemplo n.º 5
0
        private async Task <bool> StoreCellsAsyncInternal(string table, CellSet cells, RequestOptions options,
                                                          string key = null, string query = null)
        {
            var path = key == null ? table + "/somefalsekey" : table + "/" + key;

            // note the fake row key to insert a set of cells
            using (var webResponse = await PutRequestAsync(path, query, cells, options))
            {
                if (webResponse.WebResponse.StatusCode == HttpStatusCode.NotModified)
                {
                    return(false);
                }

                if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK)
                {
                    using (var output = new StreamReader(webResponse.WebResponse.GetResponseStream()))
                    {
                        var message = output.ReadToEnd();
                        throw new WebException(
                                  string.Format(
                                      "Couldn't insert into table {0}! Response code was: {1}, expected 200! Response body was: {2}",
                                      table,
                                      webResponse.WebResponse.StatusCode,
                                      message));
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
 private async Task <Response> DeleteRequestAsync <TReq>(string endpoint, TReq request, RequestOptions options)
     where TReq : class
 {
     return(await ExecuteMethodAsync("DELETE", null, endpoint, request, options));
 }
Ejemplo n.º 7
0
        private async Task <IEnumerable <CellSet> > StatelessScannerAsyncInternal(string tableName,
                                                                                  string optionalRowPrefix, string scanParameters, RequestOptions options)
        {
            using (var webResponse =
                       await GetRequestAsync(tableName + "/" + optionalRowPrefix + "*", scanParameters, options))
            {
                if (webResponse.WebResponse.StatusCode == HttpStatusCode.OK)
                {
                    return(ReadProtobufStream(webResponse.WebResponse.GetResponseStream()));
                }

                return(null);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HBaseClient" /> class.
 /// </summary>
 /// <param name="credentials">The credentials.</param>
 public HBaseClient(ClusterCredentials credentials)
     : this(credentials, RequestOptions.GetDefaultOptions())
 {
 }
Ejemplo n.º 9
0
 private async Task ModifyTableSchemaAsyncInternal(string table, TableSchema schema, RequestOptions options)
 {
     using (var webResponse = await PostRequestAsync(table + "/schema", schema, options))
     {
         if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK &&
             webResponse.WebResponse.StatusCode != HttpStatusCode.Created)
         {
             using (var output = new StreamReader(webResponse.WebResponse.GetResponseStream()))
             {
                 var message = output.ReadToEnd();
                 throw new WebException(
                           string.Format(
                               "Couldn't modify table schema {0}! Response code was: {1}, expected either 200 or 201! Response body was: {2}",
                               table,
                               webResponse.WebResponse.StatusCode,
                               message));
             }
         }
     }
 }
Ejemplo n.º 10
0
        private async Task <CellSet> ScannerGetNextAsyncInternal(ScannerInformation scannerInfo, RequestOptions options)
        {
            using (var webResponse = await GetRequestAsync(scannerInfo.TableName + "/scanner/" + scannerInfo.ScannerId,
                                                           null, options))
            {
                if (webResponse.WebResponse.StatusCode == HttpStatusCode.OK)
                {
                    return(Serializer.Deserialize <CellSet>(webResponse.WebResponse.GetResponseStream()));
                }

                return(null);
            }
        }
Ejemplo n.º 11
0
        public async Task <IEnumerable <CellSet> > StatelessScannerAsync(string tableName, string optionalRowPrefix = null,
                                                                         string scanParameters = null, RequestOptions options = null)
        {
            tableName.ArgumentNotNullNorEmpty("tableName");
            var optionToUse = options ?? _globalRequestOptions;
            var rowPrefix   = optionalRowPrefix ?? string.Empty;

            return(await optionToUse.RetryPolicy.ExecuteAsync(() =>
                                                              StatelessScannerAsyncInternal(tableName, rowPrefix, scanParameters, optionToUse)));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Scans the next set of messages.
 /// </summary>
 /// <param name="scannerInfo">the scanner information retrieved by #CreateScanner()</param>
 /// <param name="options">
 /// the request options, scan requests must set endpoint(Gateway mode) or host(VNET mode) to receive
 /// the scan request
 /// </param>
 /// <returns>a cellset, or null if the scanner is exhausted</returns>
 public async Task <CellSet> ScannerGetNextAsync(ScannerInformation scannerInfo, RequestOptions options)
 {
     scannerInfo.ArgumentNotNull("scannerInfo");
     options.ArgumentNotNull("options");
     return(await options.RetryPolicy.ExecuteAsync(() => ScannerGetNextAsyncInternal(scannerInfo, options)));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the cells asynchronous.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="rowKeys">The row keys.</param>
        /// <param name="options">The request options.</param>
        /// <returns>A cell set</returns>
        public async Task <CellSet> GetCellsAsync(string tableName, string[] rowKeys, RequestOptions options = null)
        {
            tableName.ArgumentNotNullNorEmpty("tableName");
            rowKeys.ArgumentNotNull("rowKey");

            var optionToUse = options ?? _globalRequestOptions;
            var endpoint    = tableName + "/multiget";

            string query = null;

            for (var i = 0; i < rowKeys.Length; i++)
            {
                var prefix = "&";
                if (i == 0)
                {
                    prefix = "";
                }

                query += prefix + "row=" + rowKeys[i];
            }

            return(await optionToUse.RetryPolicy.ExecuteAsync(() =>
                                                              GetRequestAndDeserializeAsync <CellSet>(endpoint, query, optionToUse)));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Deletes a table.
 /// If something went wrong, a WebException is thrown.
 /// </summary>
 /// <param name="table">the table name</param>
 public async Task DeleteTableAsync(string table, RequestOptions options = null)
 {
     table.ArgumentNotNullNorEmpty("table");
     var optionToUse = options ?? _globalRequestOptions;
     await optionToUse.RetryPolicy.ExecuteAsync(() => DeleteTableAsyncInternal(table, optionToUse));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Deletes scanner.
 /// </summary>
 /// <param name="tableName">the table the scanner is associated with.</param>
 /// <param name="scannerInfo">the scanner information retrieved by #CreateScanner()</param>
 /// <param name="options">
 /// the request options, scan requests must set endpoint(Gateway mode) or host(VNET mode) to receive
 /// the scan request
 /// </param>
 public async Task DeleteScannerAsync(string tableName, ScannerInformation scannerInfo, RequestOptions options)
 {
     tableName.ArgumentNotNullNorEmpty("tableName");
     scannerInfo.ArgumentNotNull("scannerInfo");
     options.ArgumentNotNull("options");
     await options.RetryPolicy.ExecuteAsync(() => DeleteScannerAsyncInternal(tableName, scannerInfo, options));
 }