public virtual RetryWrapper <GitObjectTaskResult> .InvocationResult TryDownloadLooseObject( string objectId, bool retryOnFailure, CancellationToken cancellationToken, string requestSource, Func <int, GitEndPointResponseData, RetryWrapper <GitObjectTaskResult> .CallbackResult> onSuccess) { long requestId = HttpRequestor.GetNewRequestId(); EventMetadata metadata = new EventMetadata(); metadata.Add("objectId", objectId); metadata.Add("retryOnFailure", retryOnFailure); metadata.Add("requestId", requestId); metadata.Add("requestSource", requestSource); this.Tracer.RelatedEvent(EventLevel.Informational, "DownloadLooseObject", metadata, Keywords.Network); return(this.TrySendProtocolRequest( requestId, onSuccess, eArgs => this.HandleDownloadAndSaveObjectError(retryOnFailure, requestId, eArgs), HttpMethod.Get, new Uri(this.CacheServer.ObjectsEndpointUrl + "/" + objectId), cancellationToken, requestBody: null, acceptType: null, retryOnFailure: retryOnFailure)); }
public virtual RetryWrapper <GitObjectTaskResult> .InvocationResult TryDownloadObjects( IEnumerable <string> objectIds, Func <int, GitEndPointResponseData, RetryWrapper <GitObjectTaskResult> .CallbackResult> onSuccess, Action <RetryWrapper <GitObjectTaskResult> .ErrorEventArgs> onFailure, bool preferBatchedLooseObjects) { long requestId = HttpRequestor.GetNewRequestId(); string objectIdsJson = CreateObjectIdJson(objectIds); int objectCount = objectIds.Count(); EventMetadata metadata = new EventMetadata(); metadata.Add("RequestId", requestId); if (objectCount < 10) { metadata.Add("ObjectIds", string.Join(", ", objectIds)); } else { metadata.Add("ObjectIdCount", objectCount); } this.Tracer.RelatedEvent(EventLevel.Informational, "DownloadObjects", metadata, Keywords.Network); return(this.TrySendProtocolRequest( requestId, onSuccess, onFailure, HttpMethod.Post, new Uri(this.CacheServer.ObjectsEndpointUrl), CancellationToken.None, objectIdsJson, preferBatchedLooseObjects ? CustomLooseObjectsHeader : null)); }
public GVFSConfig QueryGVFSConfig() { Uri gvfsConfigEndpoint; string gvfsConfigEndpointString = this.repoUrl + GVFSConstants.Endpoints.GVFSConfig; try { gvfsConfigEndpoint = new Uri(gvfsConfigEndpointString); } catch (UriFormatException e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Method", nameof(this.QueryGVFSConfig)); metadata.Add("ErrorMessage", e); metadata.Add("Url", gvfsConfigEndpointString); this.Tracer.RelatedError(metadata, Keywords.Network); return(null); } long requestId = HttpRequestor.GetNewRequestId(); RetryWrapper <GVFSConfig> retrier = new RetryWrapper <GVFSConfig>(this.RetryConfig.MaxAttempts); retrier.OnFailure += RetryWrapper <GVFSConfig> .StandardErrorHandler(this.Tracer, requestId, "QueryGvfsConfig"); RetryWrapper <GVFSConfig> .InvocationResult output = retrier.Invoke( tryCount => { GitEndPointResponseData response = this.SendRequest(requestId, gvfsConfigEndpoint, HttpMethod.Get, null); if (response.HasErrors) { return(new RetryWrapper <GVFSConfig> .CallbackResult(response.Error, response.ShouldRetry)); } try { using (StreamReader reader = new StreamReader(response.Stream)) { string configString = reader.RetryableReadToEnd(); GVFSConfig config = JsonConvert.DeserializeObject <GVFSConfig>(configString); return(new RetryWrapper <GVFSConfig> .CallbackResult(config)); } } catch (JsonReaderException e) { return(new RetryWrapper <GVFSConfig> .CallbackResult(e, false)); } }); return(output.Result); }
public virtual List <GitObjectSize> QueryForFileSizes(IEnumerable <string> objectIds) { long requestId = HttpRequestor.GetNewRequestId(); string objectIdsJson = ToJsonList(objectIds); Uri gvfsEndpoint = new Uri(this.enlistment.RepoUrl + GVFSConstants.Endpoints.GVFSSizes); EventMetadata metadata = new EventMetadata(); metadata.Add("RequestId", requestId); int objectIdCount = objectIds.Count(); if (objectIdCount > 10) { metadata.Add("ObjectIdCount", objectIdCount); } else { metadata.Add("ObjectIdJson", objectIdsJson); } this.Tracer.RelatedEvent(EventLevel.Informational, "QueryFileSizes", metadata, Keywords.Network); RetryWrapper <List <GitObjectSize> > retrier = new RetryWrapper <List <GitObjectSize> >(this.RetryConfig.MaxAttempts); retrier.OnFailure += RetryWrapper <List <GitObjectSize> > .StandardErrorHandler(this.Tracer, requestId, "QueryFileSizes"); RetryWrapper <List <GitObjectSize> > .InvocationResult requestTask = retrier.Invoke( tryCount => { GitEndPointResponseData response = this.SendRequest(requestId, gvfsEndpoint, HttpMethod.Post, objectIdsJson); if (response.HasErrors) { return(new RetryWrapper <List <GitObjectSize> > .CallbackResult(response.Error, response.ShouldRetry)); } using (StreamReader reader = new StreamReader(response.Stream)) { string objectSizesString = reader.RetryableReadToEnd(); List <GitObjectSize> objectSizes = JsonConvert.DeserializeObject <List <GitObjectSize> >(objectSizesString); return(new RetryWrapper <List <GitObjectSize> > .CallbackResult(objectSizes)); } }); return(requestTask.Result ?? new List <GitObjectSize>(0)); }
public virtual RetryWrapper <GitObjectTaskResult> .InvocationResult TryDownloadLooseObject( string objectId, Func <int, GitEndPointResponseData, RetryWrapper <GitObjectTaskResult> .CallbackResult> onSuccess) { long requestId = HttpRequestor.GetNewRequestId(); EventMetadata metadata = new EventMetadata(); metadata.Add("ObjectId", objectId); metadata.Add("RequestId", requestId); this.Tracer.RelatedEvent(EventLevel.Informational, "DownloadLooseObject", metadata, Keywords.Network); return(this.TrySendProtocolRequest( requestId, onSuccess, eArgs => this.HandleDownloadAndSaveObjectError(requestId, eArgs), HttpMethod.Get, new Uri(this.enlistment.ObjectsEndpointUrl + "/" + objectId))); }
public virtual GitRefs QueryInfoRefs(string branch) { long requestId = HttpRequestor.GetNewRequestId(); Uri infoRefsEndpoint; try { infoRefsEndpoint = new Uri(this.enlistment.RepoUrl + GVFSConstants.Endpoints.InfoRefs); } catch (UriFormatException) { return(null); } CancellationToken neverCanceledToken = new CancellationToken(canceled: false); RetryWrapper <GitRefs> retrier = new RetryWrapper <GitRefs>(this.RetryConfig.MaxAttempts, neverCanceledToken); retrier.OnFailure += RetryWrapper <GitRefs> .StandardErrorHandler(this.Tracer, requestId, "QueryInfoRefs"); RetryWrapper <GitRefs> .InvocationResult output = retrier.Invoke( tryCount => { GitEndPointResponseData response = this.SendRequest( requestId, infoRefsEndpoint, HttpMethod.Get, requestContent: null, cancellationToken: neverCanceledToken); if (response.HasErrors) { return(new RetryWrapper <GitRefs> .CallbackResult(response.Error, response.ShouldRetry)); } using (StreamReader reader = new StreamReader(response.Stream)) { List <string> infoRefsResponse = reader.RetryableReadAllLines(); return(new RetryWrapper <GitRefs> .CallbackResult(new GitRefs(infoRefsResponse, branch))); } }); return(output.Result); }
public virtual RetryWrapper <GitObjectTaskResult> .InvocationResult TryDownloadObjects( Func <IEnumerable <string> > objectIdGenerator, Func <int, GitEndPointResponseData, RetryWrapper <GitObjectTaskResult> .CallbackResult> onSuccess, Action <RetryWrapper <GitObjectTaskResult> .ErrorEventArgs> onFailure, bool preferBatchedLooseObjects) { // We pass the query generator in as a function because we don't want the consumer to know about JSON or network retry logic, // but we still want the consumer to be able to change the query on each retry if we fail during their onSuccess handler. long requestId = HttpRequestor.GetNewRequestId(); return(this.TrySendProtocolRequest( requestId, onSuccess, onFailure, HttpMethod.Post, new Uri(this.CacheServer.ObjectsEndpointUrl), CancellationToken.None, () => this.ObjectIdsJsonGenerator(requestId, objectIdGenerator), preferBatchedLooseObjects ? CustomLooseObjectsHeader : null)); }
public virtual RetryWrapper <GitObjectTaskResult> .InvocationResult TryDownloadLooseObject( string objectId, int maxAttempts, Func <int, GitEndPointResponseData, RetryWrapper <GitObjectTaskResult> .CallbackResult> onSuccess) { long requestId = HttpRequestor.GetNewRequestId(); EventMetadata metadata = new EventMetadata(); metadata.Add("ObjectId", objectId); metadata.Add("maxAttempts", maxAttempts == UseConfiguredMaxAttempts ? "UseConfiguredMaxAttempts" : maxAttempts.ToString()); metadata.Add("RequestId", requestId); this.Tracer.RelatedEvent(EventLevel.Informational, "DownloadLooseObject", metadata, Keywords.Network); return(this.TrySendProtocolRequest( requestId, onSuccess, eArgs => this.HandleDownloadAndSaveObjectError(requestId, eArgs), HttpMethod.Get, new Uri(this.CacheServer.ObjectsEndpointUrl + "/" + objectId), requestBody: null, acceptType: null, maxAttempts: maxAttempts)); }
public bool TryQueryGVFSConfig(bool logErrors, out ServerGVFSConfig serverGVFSConfig, out HttpStatusCode?httpStatus) { serverGVFSConfig = null; httpStatus = null; Uri gvfsConfigEndpoint; string gvfsConfigEndpointString = this.repoUrl + GVFSConstants.Endpoints.GVFSConfig; try { gvfsConfigEndpoint = new Uri(gvfsConfigEndpointString); } catch (UriFormatException e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Method", nameof(this.TryQueryGVFSConfig)); metadata.Add("Exception", e.ToString()); metadata.Add("Url", gvfsConfigEndpointString); this.Tracer.RelatedError(metadata, "UriFormatException when constructing Uri", Keywords.Network); return(false); } long requestId = HttpRequestor.GetNewRequestId(); RetryWrapper <ServerGVFSConfig> retrier = new RetryWrapper <ServerGVFSConfig>(this.RetryConfig.MaxAttempts, CancellationToken.None); if (logErrors) { retrier.OnFailure += RetryWrapper <ServerGVFSConfig> .StandardErrorHandler(this.Tracer, requestId, "QueryGvfsConfig"); } RetryWrapper <ServerGVFSConfig> .InvocationResult output = retrier.Invoke( tryCount => { using (GitEndPointResponseData response = this.SendRequest( requestId, gvfsConfigEndpoint, HttpMethod.Get, requestContent: null, cancellationToken: CancellationToken.None)) { if (response.HasErrors) { return(new RetryWrapper <ServerGVFSConfig> .CallbackResult(response.Error, response.ShouldRetry)); } try { string configString = response.RetryableReadToEnd(); ServerGVFSConfig config = JsonConvert.DeserializeObject <ServerGVFSConfig>(configString); return(new RetryWrapper <ServerGVFSConfig> .CallbackResult(config)); } catch (JsonReaderException e) { return(new RetryWrapper <ServerGVFSConfig> .CallbackResult(e, shouldRetry: false)); } } }); if (output.Succeeded) { serverGVFSConfig = output.Result; httpStatus = HttpStatusCode.OK; return(true); } GitObjectsHttpException httpException = output.Error as GitObjectsHttpException; if (httpException != null) { httpStatus = httpException.StatusCode; } return(false); }
public virtual List <GitObjectSize> QueryForFileSizes(IEnumerable <string> objectIds, CancellationToken cancellationToken) { long requestId = HttpRequestor.GetNewRequestId(); string objectIdsJson = ToJsonList(objectIds); Uri cacheServerEndpoint = new Uri(this.CacheServer.SizesEndpointUrl); Uri originEndpoint = new Uri(this.enlistment.RepoUrl + GVFSConstants.Endpoints.GVFSSizes); EventMetadata metadata = new EventMetadata(); metadata.Add("RequestId", requestId); int objectIdCount = objectIds.Count(); if (objectIdCount > 10) { metadata.Add("ObjectIdCount", objectIdCount); } else { metadata.Add("ObjectIdJson", objectIdsJson); } this.Tracer.RelatedEvent(EventLevel.Informational, "QueryFileSizes", metadata, Keywords.Network); RetryWrapper <List <GitObjectSize> > retrier = new RetryWrapper <List <GitObjectSize> >(this.RetryConfig.MaxAttempts, cancellationToken); retrier.OnFailure += RetryWrapper <List <GitObjectSize> > .StandardErrorHandler(this.Tracer, requestId, "QueryFileSizes"); RetryWrapper <List <GitObjectSize> > .InvocationResult requestTask = retrier.Invoke( tryCount => { Uri gvfsEndpoint; if (this.nextCacheServerAttemptTime < DateTime.Now) { gvfsEndpoint = cacheServerEndpoint; } else { gvfsEndpoint = originEndpoint; } using (GitEndPointResponseData response = this.SendRequest(requestId, gvfsEndpoint, HttpMethod.Post, objectIdsJson, cancellationToken)) { if (response.StatusCode == HttpStatusCode.NotFound) { this.nextCacheServerAttemptTime = DateTime.Now.AddDays(1); return(new RetryWrapper <List <GitObjectSize> > .CallbackResult(response.Error, true)); } if (response.HasErrors) { return(new RetryWrapper <List <GitObjectSize> > .CallbackResult(response.Error, response.ShouldRetry)); } string objectSizesString = response.RetryableReadToEnd(); List <GitObjectSize> objectSizes = JsonConvert.DeserializeObject <List <GitObjectSize> >(objectSizesString); return(new RetryWrapper <List <GitObjectSize> > .CallbackResult(objectSizes)); } }); return(requestTask.Result ?? new List <GitObjectSize>(0)); }
public bool TryQueryGVFSConfig(out GVFSConfig gvfsConfig) { gvfsConfig = null; Uri gvfsConfigEndpoint; string gvfsConfigEndpointString = this.repoUrl + GVFSConstants.Endpoints.GVFSConfig; try { gvfsConfigEndpoint = new Uri(gvfsConfigEndpointString); } catch (UriFormatException e) { EventMetadata metadata = new EventMetadata(); metadata.Add("Method", nameof(this.TryQueryGVFSConfig)); metadata.Add("Exception", e.ToString()); metadata.Add("Url", gvfsConfigEndpointString); this.Tracer.RelatedError(metadata, "UriFormatException when constructing Uri", Keywords.Network); return(false); } CancellationToken neverCanceledToken = new CancellationToken(canceled: false); long requestId = HttpRequestor.GetNewRequestId(); RetryWrapper <GVFSConfig> retrier = new RetryWrapper <GVFSConfig>(this.RetryConfig.MaxAttempts, neverCanceledToken); retrier.OnFailure += RetryWrapper <GVFSConfig> .StandardErrorHandler(this.Tracer, requestId, "QueryGvfsConfig"); RetryWrapper <GVFSConfig> .InvocationResult output = retrier.Invoke( tryCount => { GitEndPointResponseData response = this.SendRequest( requestId, gvfsConfigEndpoint, HttpMethod.Get, requestContent: null, cancellationToken: neverCanceledToken); if (response.HasErrors) { return(new RetryWrapper <GVFSConfig> .CallbackResult(response.Error, response.ShouldRetry)); } try { using (StreamReader reader = new StreamReader(response.Stream)) { string configString = reader.RetryableReadToEnd(); GVFSConfig config = JsonConvert.DeserializeObject <GVFSConfig>(configString); return(new RetryWrapper <GVFSConfig> .CallbackResult(config)); } } catch (JsonReaderException e) { return(new RetryWrapper <GVFSConfig> .CallbackResult(e, false)); } }); if (output.Succeeded) { gvfsConfig = output.Result; return(true); } return(false); }