Skip to content

Commit

Permalink
pull master
Browse files Browse the repository at this point in the history
  • Loading branch information
REDMOND\gaausfel committed Nov 19, 2019
2 parents 5dd1463 + 7184723 commit 221f66d
Show file tree
Hide file tree
Showing 80 changed files with 2,446 additions and 1,625 deletions.
714 changes: 340 additions & 374 deletions Microsoft.Azure.Cosmos/src/DocumentClient.cs

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Microsoft.Azure.Cosmos/src/FeedResponseBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Microsoft.Azure.Cosmos
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Documents;
Expand Down Expand Up @@ -84,7 +82,7 @@ public static DocumentFeedResponse<T> ConvertCosmosElementFeed<T>(
// If the resource type is an offer and the requested type is either a Offer or OfferV2 or dynamic
// create a OfferV2 object and cast it to T. This is a temporary fix until offers is moved to v3 API.
if (resourceType == ResourceType.Offer &&
(typeof(T).IsSubclassOf(typeof(Resource)) || typeof(T) == typeof(object)))
(typeof(T).IsSubclassOf(typeof(Documents.Resource)) || typeof(T) == typeof(object)))
{
typedResults = JsonConvert.DeserializeObject<List<OfferV2>>(jsonText, settings).Cast<T>();
}
Expand Down
28 changes: 23 additions & 5 deletions Microsoft.Azure.Cosmos/src/GatewayStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ internal static async Task<DocumentClientException> CreateDocumentClientExceptio
if (string.Equals(responseMessage.Content?.Headers?.ContentType?.MediaType, "application/json", StringComparison.OrdinalIgnoreCase))
{
Stream readStream = await responseMessage.Content.ReadAsStreamAsync();
Error error = Resource.LoadFrom<Error>(readStream);
Error error = Documents.Resource.LoadFrom<Error>(readStream);
return new DocumentClientException(
error,
responseMessage.Headers,
Expand Down Expand Up @@ -324,19 +324,21 @@ private async Task<HttpResponseMessage> InvokeClientAsync(
DateTime sendTimeUtc = DateTime.UtcNow;
Guid localGuid = Guid.NewGuid(); // For correlating HttpRequest and HttpResponse Traces

Guid requestedActivityId = Trace.CorrelationManager.ActivityId;
this.eventSource.Request(
Guid.Empty,
requestedActivityId,
localGuid,
requestMessage.RequestUri.ToString(),
resourceType.ToResourceTypeString(),
requestMessage.Headers);

TimeSpan durationTimeSpan;
try
{
HttpResponseMessage responseMessage = await this.httpClient.SendAsync(requestMessage, cancellationToken);

DateTime receivedTimeUtc = DateTime.UtcNow;
double durationInMilliSeconds = (receivedTimeUtc - sendTimeUtc).TotalMilliseconds;
durationTimeSpan = receivedTimeUtc - sendTimeUtc;

IEnumerable<string> headerValues;
Guid activityId = Guid.Empty;
Expand All @@ -350,7 +352,7 @@ private async Task<HttpResponseMessage> InvokeClientAsync(
activityId,
localGuid,
(short)responseMessage.StatusCode,
durationInMilliSeconds,
durationTimeSpan.TotalMilliseconds,
responseMessage.Headers);

return responseMessage;
Expand All @@ -360,7 +362,23 @@ private async Task<HttpResponseMessage> InvokeClientAsync(
if (!cancellationToken.IsCancellationRequested)
{
// throw timeout if the cancellationToken is not canceled (i.e. httpClient timed out)
throw new RequestTimeoutException(ex, requestMessage.RequestUri);
durationTimeSpan = DateTime.UtcNow - sendTimeUtc;
string message = $"GatewayStoreClient Request Timeout. Start Time:{sendTimeUtc}; Total Duration:{durationTimeSpan}; Http Client Timeout:{this.httpClient.Timeout}; Activity id: {requestedActivityId}; Inner Message: {ex.Message};";
throw new RequestTimeoutException(message, ex, requestMessage.RequestUri);
}
else
{
throw;
}
}
catch (OperationCanceledException ex)
{
if (!cancellationToken.IsCancellationRequested)
{
// throw timeout if the cancellationToken is not canceled (i.e. httpClient timed out)
durationTimeSpan = DateTime.UtcNow - sendTimeUtc;
string message = $"GatewayStoreClient Request Timeout. Start Time:{sendTimeUtc}; Total Duration:{durationTimeSpan}; Http Client Timeout:{this.httpClient.Timeout}; Activity id: {requestedActivityId}; Inner Message: {ex.Message};";
throw new RequestTimeoutException(message, ex, requestMessage.RequestUri);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Handler/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void EnsureErrorMessage()
{
try
{
Error error = Resource.LoadFrom<Error>(this.content);
Error error = Documents.Resource.LoadFrom<Error>(this.content);
if (error != null)
{
// Error format is not consistent across modes
Expand Down
16 changes: 8 additions & 8 deletions Microsoft.Azure.Cosmos/src/IDocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the Database if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the Database if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="databaseLink"/> is always "/dbs/{db identifier}" only
/// the values within the {} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1364,7 +1364,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the DocumentCollection if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the DocumentCollection if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="documentCollectionLink"/> is always "/dbs/{db identifier}/colls/{coll identifier}" only
/// the values within the {} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1462,7 +1462,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the Document if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the Document if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="documentLink"/> is always "dbs/{db identifier}/colls/{coll identifier}/docs/{doc identifier}" only
/// the values within the {} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1562,7 +1562,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the Document if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the Document if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="documentLink"/> is always "dbs/{db identifier}/colls/{coll identifier}/docs/{doc identifier}" only
/// the values within the {} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1661,7 +1661,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the Stored Procedure if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the Stored Procedure if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="storedProcedureLink"/> is always "/dbs/{db identifier}/colls/{coll identifier}/sprocs/{sproc identifier}"
/// only the values within the {...} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1759,7 +1759,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the Trigger if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the Trigger if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="triggerLink"/> is always "/dbs/{db identifier}/colls/{coll identifier}/triggers/{trigger identifier}"
/// only the values within the {...} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1857,7 +1857,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the User Defined Function if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the User Defined Function if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="functionLink"/> is always "/dbs/{db identifier}/colls/{coll identifier}/udfs/{udf identifier}"
/// only the values within the {...} change depending on which method you wish to use to address the resource.
Expand Down Expand Up @@ -1955,7 +1955,7 @@ Task<ResourceResponse<UserDefinedFunction>> ReplaceUserDefinedFunctionAsync(
/// </para>
/// <para>
/// The example shown uses ID-based links, where the link is composed of the ID properties used when the resources were created.
/// You can still use the <see cref="Resource.SelfLink"/> property of the Conflict if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// You can still use the <see cref="Documents.Resource.SelfLink"/> property of the Conflict if you prefer. A self-link is a URI for a resource that is made up of Resource Identifiers (or the _rid properties).
/// ID-based links and SelfLink will both work.
/// The format for <paramref name="conflictLink"/> is always "/dbs/{db identifier}/colls/{collectioon identifier}/conflicts/{conflict identifier}"
/// only the values within the {...} change depending on which method you wish to use to address the resource.
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<PropertyGroup>
<DefineConstants Condition=" '$(IsNightly)' == 'true' or '$(IsPreview)' == 'true' ">$(DefineConstants);PREVIEW</DefineConstants>
<DefineConstants Condition=" '$(SignAssembly)' == 'true' ">$(DefineConstants);SignAssembly</DefineConstants>
<DefineConstants Condition=" '$(DelaySign)' == 'true' ">DelaySignKeys</DefineConstants>
<DefineConstants Condition=" '$(DelaySign)' == 'true' ">$(DefineConstants);DelaySignKeys</DefineConstants>
<DefineConstants>$(DefineConstants);DOCDBCLIENT;COSMOSCLIENT;NETSTANDARD20</DefineConstants>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos.Query.Aggregation
{
using System;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

/// <summary>
Expand Down Expand Up @@ -58,7 +59,8 @@ public static TryCatch<IAggregator> TryCreate(string continuationToken)
{
if (!AverageInfo.TryParse(continuationToken, out averageInfo))
{
return TryCatch<IAggregator>.FromException(new ArgumentException($"Invalid continuation token: {continuationToken}"));
return TryCatch<IAggregator>.FromException(
new MalformedContinuationTokenException($"Invalid continuation token: {continuationToken}"));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Microsoft.Azure.Cosmos.Query.Aggregation
{
using System;
using System.Globalization;
using System.Net;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

/// <summary>
Expand Down Expand Up @@ -74,7 +74,7 @@ public static TryCatch<IAggregator> TryCreate(string continuationToken)
if (!long.TryParse(continuationToken, out partialCount))
{
return TryCatch<IAggregator>.FromException(
new Exception($@"Invalid count continuation token: ""{continuationToken}""."));
new MalformedContinuationTokenException($@"Invalid count continuation token: ""{continuationToken}""."));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Microsoft.Azure.Cosmos.Query.Aggregation
{
using System;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

/// <summary>
Expand Down Expand Up @@ -194,7 +195,7 @@ private static TryCatch<IAggregator> TryCreate(bool isMinAggregation, string con
if (!CosmosElement.TryParse(continuationToken, out globalMinMax))
{
return TryCatch<IAggregator>.FromException(
new Exception($"Malformed continuation token: {continuationToken}"));
new MalformedContinuationTokenException($"Malformed continuation token: {continuationToken}"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Microsoft.Azure.Cosmos.Query
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.Json;
using Microsoft.Azure.Cosmos.Query.Aggregation;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

/// <summary>
Expand Down Expand Up @@ -188,7 +188,8 @@ public static TryCatch<SingleGroupAggregator> TryCreate(
if (!CosmosElement.TryParse(continuationToken, out aliasToContinuationToken))
{
return TryCatch<SingleGroupAggregator>.FromException(
new Exception($"{nameof(SelectListAggregateValues)} continuation token is malformed: {continuationToken}."));
new MalformedContinuationTokenException(
$"{nameof(SelectListAggregateValues)} continuation token is malformed: {continuationToken}."));
}
}
else
Expand All @@ -207,7 +208,8 @@ public static TryCatch<SingleGroupAggregator> TryCreate(
if (!(aliasToContinuationToken[alias] is CosmosString parsedAliasContinuationToken))
{
return TryCatch<SingleGroupAggregator>.FromException(
new Exception($"{nameof(SelectListAggregateValues)} continuation token is malformed: {continuationToken}."));
new MalformedContinuationTokenException(
$"{nameof(SelectListAggregateValues)} continuation token is malformed: {continuationToken}."));
}

aliasContinuationToken = parsedAliasContinuationToken.Value;
Expand Down Expand Up @@ -406,15 +408,15 @@ public static TryCatch<AggregateValue> TryCreate(string continuationToken)
out CosmosObject rawContinuationToken))
{
return TryCatch<AggregateValue>.FromException(
new ArgumentException($"Invalid {nameof(ScalarAggregateValue)}: {continuationToken}"));
new MalformedContinuationTokenException($"Invalid {nameof(ScalarAggregateValue)}: {continuationToken}"));
}

if (!rawContinuationToken.TryGetValue<CosmosBoolean>(
nameof(ScalarAggregateValue.initialized),
out CosmosBoolean rawInitialized))
{
return TryCatch<AggregateValue>.FromException(
new ArgumentException($"Invalid {nameof(ScalarAggregateValue)}: {continuationToken}"));
new MalformedContinuationTokenException($"Invalid {nameof(ScalarAggregateValue)}: {continuationToken}"));
}

if (!rawContinuationToken.TryGetValue(nameof(ScalarAggregateValue.value), out value))
Expand Down
Loading

0 comments on commit 221f66d

Please sign in to comment.