示例#1
0
 public ElasticsearchResponse <T> DoRequest <T>(HttpMethod method, string path, PostData <object> data = null, IRequestParameters requestParameters = null)
     where T : class =>
 this.Transport.Request <T>(method, path, data, requestParameters);
示例#2
0
 public Task <ElasticsearchResponse <T> > DoRequestAsync <T>(HttpMethod method, string path, CancellationToken cancellationToken, PostData <object> data = null, IRequestParameters requestParameters = null)
     where T : class =>
 this.Transport.RequestAsync <T>(method, path, cancellationToken, data, requestParameters);
 public RequestData(HttpMethod method, string path, PostData data, IConnectionConfigurationValues global, IRequestParameters local, IMemoryStreamFactory memoryStreamFactory)
     : this(method, path, data, global, local?.RequestConfiguration, memoryStreamFactory)
 {
     this.CustomConverter = local?.DeserializationOverride;
     this.Path            = this.CreatePathWithQueryStrings(path, this.ConnectionSettings, local);
 }
        public TResponse Request <TResponse>(HttpMethod method, string path, PostData data = null, IRequestParameters requestParameters = null)
            where TResponse : class, IElasticsearchResponse, new()
        {
            using (var pipeline = this.PipelineProvider.Create(this.Settings, this.DateTimeProvider, this.MemoryStreamFactory, requestParameters))
            {
                pipeline.FirstPoolUsage(this.Settings.BootstrapLock);

                var requestData = new RequestData(method, path, data, this.Settings, requestParameters, this.MemoryStreamFactory);
                this.Settings.OnRequestDataCreated?.Invoke(requestData);
                TResponse response = null;

                var seenExceptions = new List <PipelineException>();
                foreach (var node in pipeline.NextNode())
                {
                    requestData.Node = node;
                    try
                    {
                        pipeline.SniffOnStaleCluster();
                        Ping(pipeline, node);
                        response = pipeline.CallElasticsearch <TResponse>(requestData);
                        if (!response.ApiCall.SuccessOrKnownError)
                        {
                            pipeline.MarkDead(node);
                            pipeline.SniffOnConnectionFailure();
                        }
                    }
                    catch (PipelineException pipelineException) when(!pipelineException.Recoverable)
                    {
                        if (response == null)
                        {
                            response = pipelineException.Response as TResponse;
                        }
                        pipeline.MarkDead(node);
                        seenExceptions.Add(pipelineException);
                        break;
                    }
                    catch (PipelineException pipelineException)
                    {
                        if (response == null)
                        {
                            response = pipelineException.Response as TResponse;
                        }
                        pipeline.MarkDead(node);
                        seenExceptions.Add(pipelineException);
                    }
                    catch (Exception killerException)
                    {
                        throw new UnexpectedElasticsearchClientException(killerException, seenExceptions)
                              {
                                  Request    = requestData,
                                  Response   = response?.ApiCall,
                                  AuditTrail = pipeline?.AuditTrail
                              };
                    }
                    if (response == null || !response.ApiCall.SuccessOrKnownError)
                    {
                        continue;
                    }
                    pipeline.MarkAlive(node);
                    break;
                }
                return(FinalizeResponse(requestData, pipeline, seenExceptions, response));
            }
        }
示例#5
0
        public async Task <TResponse> RequestAsync <TResponse>(HttpMethod method, string path, CancellationToken cancellationToken,
                                                               PostData data = null, IRequestParameters requestParameters = null
                                                               )
            where TResponse : class, IElasticsearchResponse, new()
        {
            using (var pipeline = PipelineProvider.Create(Settings, DateTimeProvider, MemoryStreamFactory, requestParameters))
            {
                await pipeline.FirstPoolUsageAsync(Settings.BootstrapLock, cancellationToken).ConfigureAwait(false);

                var requestData = new RequestData(method, path, data, Settings, requestParameters, MemoryStreamFactory);
                Settings.OnRequestDataCreated?.Invoke(requestData);
                TResponse response = null;

                var seenExceptions = new List <PipelineException>();
                foreach (var node in pipeline.NextNode())
                {
                    requestData.Node = node;
                    try
                    {
                        await pipeline.SniffOnStaleClusterAsync(cancellationToken).ConfigureAwait(false);
                        await PingAsync(pipeline, node, cancellationToken).ConfigureAwait(false);

                        response = await pipeline.CallElasticsearchAsync <TResponse>(requestData, cancellationToken).ConfigureAwait(false);

                        if (!response.ApiCall.SuccessOrKnownError)
                        {
                            pipeline.MarkDead(node);
                            await pipeline.SniffOnConnectionFailureAsync(cancellationToken).ConfigureAwait(false);
                        }
                    }
                    catch (PipelineException pipelineException) when(!pipelineException.Recoverable)
                    {
                        HandlePipelineException(ref response, pipelineException, pipeline, node, seenExceptions);
                        break;
                    }
                    catch (PipelineException pipelineException)
                    {
                        HandlePipelineException(ref response, pipelineException, pipeline, node, seenExceptions);
                    }
                    catch (Exception killerException)
                    {
                        if (killerException is OperationCanceledException && cancellationToken.IsCancellationRequested)
                        {
                            pipeline.AuditCancellationRequested();
                        }

                        throw new UnexpectedElasticsearchClientException(killerException, seenExceptions)
                              {
                                  Request    = requestData,
                                  Response   = response?.ApiCall,
                                  AuditTrail = pipeline.AuditTrail
                              };
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        pipeline.AuditCancellationRequested();
                        break;
                    }
                    if (response == null || !response.ApiCall.SuccessOrKnownError)
                    {
                        continue;
                    }

                    pipeline.MarkAlive(node);
                    break;
                }
                return(FinalizeResponse(requestData, pipeline, seenExceptions, response));
            }
        }
 public Task <TResponse> DoRequestAsync <TResponse>(HttpMethod method, string path, CancellationToken cancellationToken, PostData data = null,
                                                    IRequestParameters requestParameters = null
                                                    )
     where TResponse : class, IElasticsearchResponse, new() =>
 Transport.RequestAsync <TResponse>(method, path, cancellationToken, data, requestParameters);
 public TResponse DoRequest <TResponse>(HttpMethod method, string path, PostData data = null, IRequestParameters requestParameters = null)
     where TResponse : class, IElasticsearchResponse, new() =>
 Transport.Request <TResponse>(method, path, data, requestParameters);
示例#8
0
        public async Task <ElasticsearchResponse <TReturn> > RequestAsync <TReturn>(HttpMethod method, string path, PostData <object> data = null, IRequestParameters requestParameters = null)
            where TReturn : class
        {
            using (var pipeline = this.PipelineProvider.Create(this.Settings, this.DateTimeProvider, this.MemoryStreamFactory, requestParameters))
            {
                await pipeline.FirstPoolUsageAsync(this.Settings.BootstrapLock).ConfigureAwait(false);

                var requestData = new RequestData(method, path, data, this.Settings, requestParameters, this.MemoryStreamFactory);
                ElasticsearchResponse <TReturn> response = null;

                var seenExceptions = new List <PipelineException>();
                foreach (var node in pipeline.NextNode())
                {
                    requestData.Node = node;
                    try
                    {
                        await pipeline.SniffOnStaleClusterAsync().ConfigureAwait(false);
                        await PingAsync(pipeline, node).ConfigureAwait(false);

                        response = await pipeline.CallElasticsearchAsync <TReturn>(requestData).ConfigureAwait(false);

                        if (!response.SuccessOrKnownError)
                        {
                            pipeline.MarkDead(node);
                            await pipeline.SniffOnConnectionFailureAsync().ConfigureAwait(false);
                        }
                    }
                    catch (PipelineException pipelineException) when(!pipelineException.Recoverable)
                    {
                        pipeline.MarkDead(node);
                        seenExceptions.Add(pipelineException);
                        break;
                    }
                    catch (PipelineException pipelineException)
                    {
                        pipeline.MarkDead(node);
                        seenExceptions.Add(pipelineException);
                    }
                    catch (Exception killerException)
                    {
                        throw new UnexpectedElasticsearchClientException(killerException, seenExceptions)
                              {
                                  Request    = requestData,
                                  Response   = response,
                                  AuditTrail = pipeline.AuditTrail
                              };
                    }
                    if (response != null && response.SuccessOrKnownError)
                    {
                        pipeline.MarkAlive(node);
                        break;
                    }
                }
                if (response == null || !response.Success)
                {
                    pipeline.BadResponse(ref response, requestData, seenExceptions);
                }

                this.Settings.OnRequestCompleted?.Invoke(response);

                return(response);
            }
        }
示例#9
0
 public RequestData(HttpMethod method, string path, PostData <object> data, IConnectionConfigurationValues global, IMemoryStreamFactory memoryStreamFactory)
     : this(method, path, data, global, (IRequestConfiguration)null, memoryStreamFactory)
 {
 }