Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents ad7b63c + 98e8fe2 commit abfcc23
Show file tree
Hide file tree
Showing 20 changed files with 155 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Momento.Sdk/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Configuration(ILoggerFactory loggerFactory, IRetryStrategy retryStrategy,
}

/// <summary>
/// Create a new instance of Configuration obejct with provided arguments: <see cref="Momento.Sdk.Config.IConfiguration.RetryStrategy" />, <see cref="Momento.Sdk.Config.IConfiguration.Middlewares" />, <see cref="Momento.Sdk.Config.IConfiguration.TransportStrategy"/>, and <see cref="Momento.Sdk.Config.IConfiguration.LoggerFactory"/>
/// Create a new instance of Configuration object with provided arguments: <see cref="Momento.Sdk.Config.IConfiguration.RetryStrategy" />, <see cref="Momento.Sdk.Config.IConfiguration.Middlewares" />, <see cref="Momento.Sdk.Config.IConfiguration.TransportStrategy"/>, and <see cref="Momento.Sdk.Config.IConfiguration.LoggerFactory"/>
/// </summary>
/// <param name="retryStrategy">Defines a contract for how and when to retry a request</param>
/// <param name="middlewares">The Middleware interface allows the Configuration to provide a higher-order function that wraps all requests.</param>
Expand Down
19 changes: 19 additions & 0 deletions src/Momento.Sdk/Exceptions/CacheExceptionMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@

namespace Momento.Sdk.Exceptions;

/// <summary>
/// This class maps low-level exceptions that occur during
/// <see cref="Momento.Sdk.SimpleCacheClient" /> requests to
/// Momento <see cref="Momento.Sdk.Exceptions.SdkException" />
/// exceptions. The <c>SdkException</c> is returned to the caller
/// as part of an <c>Error</c> response object.
/// </summary>
public class CacheExceptionMapper
{
private const string INTERNAL_SERVER_ERROR_MESSAGE = "Unexpected exception occurred while trying to fulfill the request.";
private const string SDK_ERROR_MESSAGE = "SDK Failed to process the request.";

private readonly ILogger _logger;

/// <summary>
/// This class maps low-level exceptions that occur during
/// <see cref="Momento.Sdk.SimpleCacheClient" /> requests to
/// Momento <see cref="Momento.Sdk.Exceptions.SdkException" />
/// exceptions. The <c>SdkException</c> is returned to the caller
/// as part of an <c>Error</c> response object.
/// </summary>
/// <param name="loggerFactory">Responsible for configuring logging.</param>
public CacheExceptionMapper(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<CacheExceptionMapper>();
}

/// <summary>
/// Convert a low-level exception to a Momento
/// <see cref="Momento.Sdk.Exceptions.SdkException" />.
/// </summary>
public SdkException Convert(Exception e)
{
_logger.LogDebug("Mapping exception to SdkException: {}", e);
Expand Down
7 changes: 2 additions & 5 deletions src/Momento.Sdk/Internal/ControlGrpcManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
#pragma warning disable 1591
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Interceptors;
using Grpc.Net.Client;
using Microsoft.Extensions.Logging;
using Momento.Protos.CacheClient;
using Momento.Protos.ControlClient;
using Momento.Sdk.Config.Middleware;
using Momento.Sdk.Internal;
using Momento.Sdk.Internal.Middleware;
using static System.Reflection.Assembly;

Expand Down
6 changes: 2 additions & 4 deletions src/Momento.Sdk/Internal/DataGrpcManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
#pragma warning disable 1591
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Interceptors;
using Grpc.Net.Client;
using Microsoft.Extensions.Logging;
using Momento.Protos.CacheClient;
Expand All @@ -13,7 +12,6 @@
using Momento.Sdk.Config.Retry;
using Momento.Sdk.Internal.Middleware;
using static System.Reflection.Assembly;
using static Grpc.Core.Interceptors.Interceptor;

namespace Momento.Sdk.Internal;

Expand Down
21 changes: 21 additions & 0 deletions src/Momento.Sdk/Internal/JwtUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Momento.Sdk.Internal;

/// <summary>
/// Provides methods for dealing with JWT tokens.
/// </summary>
public class JwtUtils
{
/// <summary>
Expand All @@ -32,13 +35,31 @@ public static Claims DecodeJwt(string jwt)
}
}

/// <summary>
/// Encapsulates claims embedded in a JWT token that specify host endpoints
/// for the control plane and the data plane.
/// </summary>
public class Claims
{

/// <summary>
/// Endpoint for issuing control plane requests.
/// </summary>
[JsonProperty(PropertyName = "cp", Required = Required.Always)]
public string ControlEndpoint { get; private set; }

/// <summary>
/// Endpoint for issuing data plane requests.
/// </summary>
[JsonProperty(PropertyName = "c", Required = Required.Always)]
public string CacheEndpoint { get; private set; }

/// <summary>
/// Encapsulates claims embedded in a JWT token that specify host endpoints
/// for the control plane and the data plane.
/// </summary>
/// <param name="cacheEndpoint">Data plane endpoint</param>
/// <param name="controlEndpoint">Control plane endpoint</param>
public Claims(string cacheEndpoint, string controlEndpoint)
{
this.CacheEndpoint = cacheEndpoint;
Expand Down
3 changes: 2 additions & 1 deletion src/Momento.Sdk/Internal/Middleware/MiddlewareExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#pragma warning disable 1591
using System;
using Grpc.Core;
using Momento.Sdk.Config.Middleware;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#pragma warning disable 1591
using System;
using System.Collections.Generic;
using Grpc.Core;
using Microsoft.Extensions.Logging;
Expand Down
4 changes: 3 additions & 1 deletion src/Momento.Sdk/Internal/ScsDataClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#pragma warning disable 1591
using System;
using System.Threading.Tasks;
using Google.Protobuf;
using Grpc.Core;
Expand All @@ -17,6 +18,7 @@ public class ScsDataClientBase : IDisposable
private readonly TimeSpan defaultTtl;
private readonly TimeSpan dataClientOperationTimeout;
private readonly ILogger _logger;

protected readonly CacheExceptionMapper _exceptionMapper;

public ScsDataClientBase(IConfiguration config, string authToken, string endpoint, TimeSpan defaultTtl)
Expand Down
25 changes: 22 additions & 3 deletions src/Momento.Sdk/Internal/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ public static void ArgumentStrictlyPositive(int? argument, string paramName)
/// </summary>
public class StructuralEqualityComparer<T> : IEqualityComparer<T>
{
/// <inheritdoc />
public bool Equals(T x, T y)
{
return StructuralComparisons.StructuralEqualityComparer.Equals(x, y);
}

/// <inheritdoc />
public int GetHashCode(T obj)
{
return StructuralComparisons.StructuralEqualityComparer.GetHashCode(obj);
Expand All @@ -140,6 +142,10 @@ public int GetHashCode(T obj)

namespace ExtensionMethods
{
/// <summary>
/// Defines extension methods to support the conversion of data to
/// various forms of ByteString.
/// </summary>
public static class ToByteStringExtensions
{
/// <summary>
Expand Down Expand Up @@ -199,11 +205,15 @@ public static IEnumerable<ByteString> ToEnumerableByteString(this IEnumerable<st
}
}

/// <summary>
/// Defines extension methods to operate on dictionaries with
/// byte array keys and values.
/// </summary>
public static class ByteArrayDictionaryExtensions
{
/// <summary>
/// DWIM equality implementation for dictionaries, cf <see href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.setequals?view=net-6.0">SetEquals</see>.
///
///
///
/// Tests whether the dictionaries contain the same content as opposed to the same
/// references.
Expand Down Expand Up @@ -231,11 +241,15 @@ public static bool DictionaryEquals(this Dictionary<byte[], byte[]> dictionary,
}
}

/// <summary>
/// Defines extension methods to operate on lists containing
/// byte arrays.
/// </summary>
public static class ByteArrayListExtensions
{
/// <summary>
/// DWIM equality implementation for lists, cf <see href="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.setequals?view=net-6.0">SetEquals</see>.
///
///
///
/// Tests whether the lists contain the same content as opposed to the same
/// references.
Expand All @@ -261,7 +275,12 @@ public static bool ListEquals(this List<byte[]> list, List<byte[]> other)
return Enumerable.Range(0, list.Count).All(index => list[index].SequenceEqual(other[index]));
}
}
public static class StringStringDictionaryExtensions

/// <summary>
/// Defines extension methods to operate on dictionaries with
/// string keys and values.
/// </summary>
public static class StringStringDictionaryExtensions
{
/// <summary>
/// Make a shallow copy of a dictionary.
Expand Down
2 changes: 1 addition & 1 deletion src/Momento.Sdk/Momento.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- Include documentation in build -->
<NoWarn>1591</NoWarn>
<!-- <NoWarn>1591</NoWarn> -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Include source and debug symbols-->
<IncludeSource>true</IncludeSource>
Expand Down
7 changes: 5 additions & 2 deletions src/Momento.Sdk/Responses/CacheDeleteResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ public class Success : CacheDeleteResponse { }
public class Error : CacheDeleteResponse
{
private readonly SdkException _error;

/// <include file="../docs.xml" path='docs/class[@name="Error"]/constructor/*' />
public Error(SdkException error)
{
_error = error;
}

/// <include file="../docs.xml" path='docs/class[@name="Error"]/prop[@name="Exception"]/*' />
public SdkException Exception
/// <include file="../docs.xml" path='docs/class[@name="Error"]/prop[@name="InnerException"]/*' />
public SdkException InnerException
{
get => _error;
}
Expand All @@ -51,6 +53,7 @@ public string Message
get => $"{_error.MessageWrapper}: {_error.Message}";
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: {this.Message}";
Expand Down
21 changes: 19 additions & 2 deletions src/Momento.Sdk/Responses/CacheGetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,18 @@ public abstract class CacheGetResponse
///</summary>
public class Hit : CacheGetResponse
{
/// <summary>
/// The value returned from the cache for the specified key. Use the
/// <c>ValueString</c> and <c>ValueByteArray</c> properites to access
/// this value as a string or byte array respectively.
/// </summary>
protected readonly ByteString value;


/// <summary>
/// Class <c>Hit</c> contains the results of a cache hit.
///</summary>
/// <param name="response">gRPC get request result</param>
public Hit(_GetResponse response)
{
this.value = response.CacheBody;
Expand All @@ -54,6 +64,7 @@ public string ValueString
get => value.ToStringUtf8();
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: {this.ValueString}";
Expand All @@ -65,20 +76,25 @@ public override string ToString()
///</summary>
public class Miss : CacheGetResponse
{
/// <summary>
/// Class <c>Miss</c> contains the results of a cache miss.
///</summary>
public Miss() { }
}

/// <include file="../docs.xml" path='docs/class[@name="Error"]/description/*' />
public class Error : CacheGetResponse
{
private readonly SdkException _error;

/// <include file="../docs.xml" path='docs/class[@name="Error"]/constructor/*' />
public Error(SdkException error)
{
_error = error;
}

/// <include file="../docs.xml" path='docs/class[@name="Error"]/prop[@name="Exception"]/*' />
public SdkException Exception
/// <include file="../docs.xml" path='docs/class[@name="Error"]/prop[@name="InnerException"]/*' />
public SdkException InnerException
{
get => _error;
}
Expand All @@ -95,6 +111,7 @@ public string Message
get => $"{_error.MessageWrapper}: {_error.Message}";
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: {this.Message}";
Expand Down
14 changes: 13 additions & 1 deletion src/Momento.Sdk/Responses/CacheInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

namespace Momento.Sdk.Responses;

/// <summary>
/// Contains a Momento cache's name.
/// </summary>
public class CacheInfo : IEquatable<CacheInfo>
{
/// <summary>
/// Holds the name of the cache.
/// </summary>
public string Name { get; }

/// <summary>
/// Contains a Momento cache's name.
/// </summary>
/// <param name="cacheName">The name of the cache.</param>
public CacheInfo(string cacheName) => Name = cacheName;

// override object.Equals
/// <inheritdoc />
public bool Equals(CacheInfo? other)
{
if (other == null)
Expand All @@ -19,6 +29,7 @@ public bool Equals(CacheInfo? other)
return this.Name == other.Name;
}

/// <inheritdoc />
public override bool Equals(Object? obj)
{
if (obj == null)
Expand All @@ -29,6 +40,7 @@ public override bool Equals(Object? obj)
return Equals(obj as CacheInfo);
}

/// <inheritdoc />
public override int GetHashCode()
{
return Name.GetHashCode();
Expand Down
7 changes: 5 additions & 2 deletions src/Momento.Sdk/Responses/CacheSetResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ public class Success : CacheSetResponse { }
public class Error : CacheSetResponse
{
private readonly SdkException _error;

/// <include file="../docs.xml" path='docs/class[@name="Error"]/constructor/*' />
public Error(SdkException error)
{
_error = error;
}

/// <include file="../docs.xml" path='docs/class[@name="Error"]/prop[@name="Exception"]/*' />
public SdkException Exception
/// <include file="../docs.xml" path='docs/class[@name="Error"]/prop[@name="InnerException"]/*' />
public SdkException InnerException
{
get => _error;
}
Expand All @@ -52,6 +54,7 @@ public string Message
get => $"{_error.MessageWrapper}: {_error.Message}";
}

/// <inheritdoc />
public override string ToString()
{
return $"{base.ToString()}: {this.Message}";
Expand Down
Loading

0 comments on commit abfcc23

Please sign in to comment.