private async Task <DocumentServiceResponse> ProcessUpsertAsync(IStoreModel storeProxy, DocumentServiceRequest serviceRequest, CancellationToken cancellationToken) { DocumentServiceResponse response = await storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken); this.client.DocumentClient.CaptureSessionToken(serviceRequest, response); return(response); }
internal Task <DocumentServiceResponse> ProcessMessageAsync( CosmosRequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest(); //TODO: extrace auth into a separate handler string authorization = ((IAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationToken( serviceRequest.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), request.Method.ToString(), serviceRequest.Headers, AuthorizationTokenType.PrimaryMasterKey); serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization; IStoreModel storeProxy = this.client.DocumentClient.GetStoreProxy(serviceRequest); if (request.OperationType == OperationType.Upsert) { return(this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken)); } else { return(storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken)); } }
internal async Task <ResponseMessage> ProcessMessageAsync( RequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest(); ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow); serviceRequest.RequestContext.ClientRequestStatistics = clientSideRequestStatisticsTraceDatum; //TODO: extrace auth into a separate handler string authorization = await((ICosmosAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationTokenAsync( serviceRequest.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), request.Method.ToString(), serviceRequest.Headers, AuthorizationTokenType.PrimaryMasterKey, request.Trace); serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization; IStoreModel storeProxy = this.client.DocumentClient.GetStoreProxy(serviceRequest); using (ITrace processMessageAsyncTrace = request.Trace.StartChild( name: $"{storeProxy.GetType().FullName} Transport Request", component: TraceComponent.Transport, level: Tracing.TraceLevel.Info)) { request.Trace = processMessageAsyncTrace; processMessageAsyncTrace.AddDatum("Client Side Request Stats", clientSideRequestStatisticsTraceDatum); DocumentServiceResponse response = null; try { response = request.OperationType == OperationType.Upsert ? await this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken) : await storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken); } finally { processMessageAsyncTrace.UpdateRegionContacted(clientSideRequestStatisticsTraceDatum); } return(response.ToCosmosResponseMessage( request, serviceRequest.RequestContext.RequestChargeTracker)); } }
internal async Task <ResponseMessage> ProcessMessageAsync( RequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest(); //TODO: extrace auth into a separate handler string authorization = await((ICosmosAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationTokenAsync( serviceRequest.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), request.Method.ToString(), serviceRequest.Headers, AuthorizationTokenType.PrimaryMasterKey, request.DiagnosticsContext); serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization; IStoreModel storeProxy = this.client.DocumentClient.GetStoreProxy(serviceRequest); using (ITrace processMessageAsyncTrace = request.Trace.StartChild( name: $"{storeProxy.GetType().FullName} Transport Request", TraceComponent.Transport, Tracing.TraceLevel.Info)) { using (request.DiagnosticsContext.CreateScope(storeProxy.GetType().FullName)) { DocumentServiceResponse response = request.OperationType == OperationType.Upsert ? await this.ProcessUpsertAsync(storeProxy, serviceRequest, cancellationToken) : await storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken); return(response.ToCosmosResponseMessage( request, serviceRequest.RequestContext.RequestChargeTracker, processMessageAsyncTrace)); } } }
internal async Task <ResponseMessage> ProcessMessageAsync( RequestMessage request, CancellationToken cancellationToken) { if (request == null) { throw new ArgumentNullException(nameof(request)); } DocumentServiceRequest serviceRequest = request.ToDocumentServiceRequest(); ClientSideRequestStatisticsTraceDatum clientSideRequestStatisticsTraceDatum = new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, request.Trace.Summary); serviceRequest.RequestContext.ClientRequestStatistics = clientSideRequestStatisticsTraceDatum; //TODO: extrace auth into a separate handler string authorization = await((ICosmosAuthorizationTokenProvider)this.client.DocumentClient).GetUserAuthorizationTokenAsync( serviceRequest.ResourceAddress, PathsHelper.GetResourcePath(request.ResourceType), request.Method.ToString(), serviceRequest.Headers, AuthorizationTokenType.PrimaryMasterKey, request.Trace); serviceRequest.Headers[HttpConstants.HttpHeaders.Authorization] = authorization; IStoreModel storeProxy = this.client.DocumentClient.GetStoreProxy(serviceRequest); using (ITrace processMessageAsyncTrace = request.Trace.StartChild( name: $"{storeProxy.GetType().FullName} Transport Request", component: TraceComponent.Transport, level: Tracing.TraceLevel.Info)) { request.Trace = processMessageAsyncTrace; processMessageAsyncTrace.AddDatum("Client Side Request Stats", clientSideRequestStatisticsTraceDatum); DocumentServiceResponse response = null; try { response = await storeProxy.ProcessMessageAsync(serviceRequest, cancellationToken); } catch (DocumentClientException dce) { // Enrich diagnostics context in-case of auth failures if (dce.StatusCode == System.Net.HttpStatusCode.Unauthorized || dce.StatusCode == System.Net.HttpStatusCode.Forbidden) { TimeSpan authProvideLifeSpan = this.client.DocumentClient.cosmosAuthorization.GetAge(); processMessageAsyncTrace.AddDatum("AuthProvider LifeSpan InSec", authProvideLifeSpan.TotalSeconds); } throw; } finally { processMessageAsyncTrace.UpdateRegionContacted(clientSideRequestStatisticsTraceDatum); } ResponseMessage responseMessage = response.ToCosmosResponseMessage( request, serviceRequest.RequestContext.RequestChargeTracker); // Enrich diagnostics context in-case of auth failures if (responseMessage?.StatusCode == System.Net.HttpStatusCode.Unauthorized || responseMessage?.StatusCode == System.Net.HttpStatusCode.Forbidden) { TimeSpan authProvideLifeSpan = this.client.DocumentClient.cosmosAuthorization.GetAge(); processMessageAsyncTrace.AddDatum("AuthProvider LifeSpan InSec", authProvideLifeSpan.TotalSeconds); } return(responseMessage); } }