Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public void Dispose()
_cluster?.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Couchbase.Analytics.Performer.Internal.Exceptions;

public class GrpcUnimplementedException : Exception;
public class GrpcUnimplementedException : Exception;
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ public static LogEventLevel ParseLogLevelOrDefault(string? value, LogEventLevel
return serilogLevel;
}

if (Enum.TryParse<Microsoft.Extensions.Logging.LogLevel>(value, true, out var msLevel))
if (Enum.TryParse<LogLevel>(value, true, out var msLevel))
{
return msLevel switch
{
Microsoft.Extensions.Logging.LogLevel.Trace => LogEventLevel.Verbose,
Microsoft.Extensions.Logging.LogLevel.Debug => LogEventLevel.Debug,
Microsoft.Extensions.Logging.LogLevel.Information => LogEventLevel.Information,
Microsoft.Extensions.Logging.LogLevel.Warning => LogEventLevel.Warning,
Microsoft.Extensions.Logging.LogLevel.Error => LogEventLevel.Error,
Microsoft.Extensions.Logging.LogLevel.Critical => LogEventLevel.Fatal,
LogLevel.Trace => LogEventLevel.Verbose,
LogLevel.Debug => LogEventLevel.Debug,
LogLevel.Information => LogEventLevel.Information,
LogLevel.Warning => LogEventLevel.Warning,
LogLevel.Error => LogEventLevel.Error,
LogLevel.Critical => LogEventLevel.Fatal,
_ => defaultLevel
};
}

return defaultLevel;
}
}
}
2 changes: 1 addition & 1 deletion fit/Couchbase.Analytics.Performer/Internal/Modes/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ public enum Mode
{
PushBasedStreaming,
Buffered,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Couchbase.Analytics.Performer.Internal.Utils;
using Couchbase.AnalyticsClient.Options;
using Couchbase.AnalyticsClient.Results;
using Couchbase.Grpc.Protocol.Columnar;
using Couchbase.Core.Utils;
using Couchbase.Grpc.Protocol.Columnar;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Error = Couchbase.Grpc.Protocol.Columnar.Error;
Expand Down Expand Up @@ -64,7 +64,8 @@ public override Task<ExecuteQueryResponse> ExecuteQuery(ExecuteQueryRequest requ

_ongoingQueries.TryAdd(queryHandle, performerQuery);

var response = new ExecuteQueryResponse(){
var response = new ExecuteQueryResponse()
{
QueryHandle = queryHandle,
Metadata = new ResponseMetadata
{
Expand Down Expand Up @@ -179,7 +180,7 @@ public override Task<EmptyResultOrFailureResponse> QueryCancel(QueryCancelReques
performerQuery.CancellationTokenSource?.Cancel();
response.EmptySuccess = true;
}
catch (System.Exception ex)
catch (Exception)
{
//TODO: Map exceptions?
response.Error = new Error();
Expand Down Expand Up @@ -220,7 +221,8 @@ public override async Task<QueryResultMetadataResponse> QueryMetadata(QueryMetad
ElapsedNanos = (long)stopwatch.Elapsed.TotalNanoseconds,
Initiated = initiated
};
} catch (Exception ex)
}
catch (Exception ex)
{
response = new QueryResultMetadataResponse();
response.Failure = ex.ToProtoError();
Expand Down Expand Up @@ -266,4 +268,4 @@ public override Task<EmptyResultOrFailureResponse> CloseAllQueryResults(CloseAll

return Task.FromResult(response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
using Couchbase.Analytics.Performer.Internal.Modes;
using Couchbase.Analytics.Performer.Internal.Utils;
using Couchbase.AnalyticsClient;
using Couchbase.Core.Utils;
using Couchbase.Grpc.Protocol.Columnar;
using Couchbase.Grpc.Protocol.Shared;
using Couchbase.Core.Utils;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using Exception = System.Exception;

namespace Couchbase.Analytics.Performer.Internal.Services;

internal class AnalyticsPerformerService: ColumnarService.ColumnarServiceBase
internal class AnalyticsPerformerService : ColumnarService.ColumnarServiceBase
{
public AnalyticsPerformerService(ConcurrentDictionary<string, ClusterConnection> clusters)
{
Expand Down Expand Up @@ -51,19 +51,19 @@ public override Task<EmptyResultOrFailureResponse> ClusterNewInstance(ClusterNew
return new(request, cluster);
});

/* context.GetHttpContext().Response.OnCompleted(() =>
{
foreach (var tunable in request.Tunables)
{
Environment.SetEnvironmentVariable(tunable.Key, null);
}
/* context.GetHttpContext().Response.OnCompleted(() =>
{
foreach (var tunable in request.Tunables)
{
Environment.SetEnvironmentVariable(tunable.Key, null);
}

return Task.CompletedTask;
});*/
return Task.CompletedTask;
});*/

Serilog.Log.Information(
"Created or using new cluster instance in {Seconds}: {ConnectionString}",
stopWatch.Elapsed, request.ConnectionString);
Serilog.Log.Information(
"Created or using new cluster instance in {Seconds}: {ConnectionString}",
stopWatch.Elapsed, request.ConnectionString);

response.GetResponseMetaData(stopWatch, initiated);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ public override Task<EmptyResultOrFailureResponse> CloseAllClusters(CloseAllColu

public override Task<EchoResponse> Echo(EchoRequest request, ServerCallContext context)
{
Serilog.Log.Information("Calling Echo - {TestName} | {Message}",request.TestName, request.Message);
Serilog.Log.Information("Calling Echo - {TestName} | {Message}", request.TestName, request.Message);
return Task.FromResult(new EchoResponse());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static ClusterOptions ToSdkQueryOptions(this ClusterNewInstanceRequest re
return clusterOptions;
}

private static TimeoutOptions ToCore(this Couchbase.Grpc.Protocol.Columnar.ClusterNewInstanceRequest.Types.Options.Types.TimeoutOptions? protoTimeout)
private static TimeoutOptions ToCore(this ClusterNewInstanceRequest.Types.Options.Types.TimeoutOptions? protoTimeout)
{
var timeoutOptions = new TimeoutOptions();
if (protoTimeout is null) return timeoutOptions;
Expand All @@ -65,7 +65,7 @@ private static TimeoutOptions ToCore(this Couchbase.Grpc.Protocol.Columnar.Clust
}

private static SecurityOptions ToCore(
this Couchbase.Grpc.Protocol.Columnar.ClusterNewInstanceRequest.Types.Options.Types.SecurityOptions? protoSecurity)
this ClusterNewInstanceRequest.Types.Options.Types.SecurityOptions? protoSecurity)
{
var securityOptions = new SecurityOptions();
if (protoSecurity is null) return securityOptions;
Expand All @@ -74,7 +74,7 @@ private static SecurityOptions ToCore(
{
// what is this?
}
else if(protoSecurity.HasTrustOnlyCapella)
else if (protoSecurity.HasTrustOnlyCapella)
{
securityOptions = securityOptions.WithTrustOnlyCapella();
}
Expand Down Expand Up @@ -105,4 +105,4 @@ private static SecurityOptions ToCore(
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Couchbase.Analytics.Performer.Internal.Utils;

public static class ContentAsExtensions
{
public static ContentWas ContentAsToAnalyticsRow(this AnalyticsRow analyticsRow, Couchbase.Grpc.Protocol.Columnar.ContentAs contentAs)
public static ContentWas ContentAsToAnalyticsRow(this AnalyticsRow analyticsRow, ContentAs contentAs)
{
switch (contentAs.AsCase)
{
Expand Down Expand Up @@ -79,4 +79,4 @@ private static Value ConvertJsonToProtoValue(JsonElement element)
return new Value { NullValue = NullValue.NullValue };
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Couchbase.Grpc.Protocol.Columnar;
using Couchbase.Core.Utils;
using Couchbase.Grpc.Protocol.Columnar;
using Google.Protobuf.WellKnownTypes;

namespace Couchbase.Analytics.Performer.Internal.Utils;
Expand Down Expand Up @@ -28,4 +28,4 @@ public static EmptyResultOrFailureResponse GetResponseMetaData(this EmptyResultO

return emptyResultOrFailureResponse;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ private static bool IsColumnarError(this Exception exception)
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public static bool HasClusterLevel(this ExecuteQueryRequest request)
return request.LevelCase ==
ExecuteQueryRequest.LevelOneofCase.ClusterLevel;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Couchbase.AnalyticsClient.Options;
using Couchbase.AnalyticsClient.Query;
using Couchbase.Grpc.Protocol.Columnar;
using Couchbase.Core.Json;
using Couchbase.Grpc.Protocol.Columnar;
using Google.Protobuf.Collections;
using Google.Protobuf.WellKnownTypes;
using ArgumentOutOfRangeException = System.ArgumentOutOfRangeException;
Expand All @@ -10,7 +10,7 @@ namespace Couchbase.Analytics.Performer.Internal.Utils;

internal static class OptionsExtensions
{
public static QueryOptions ToQueryOptions(this Couchbase.Grpc.Protocol.Columnar.ExecuteQueryRequest.Types.Options? protoOptions)
public static QueryOptions ToQueryOptions(this ExecuteQueryRequest.Types.Options? protoOptions)
{
var queryOptions = new QueryOptions();
if (protoOptions is null) return queryOptions;
Expand Down Expand Up @@ -40,15 +40,15 @@ public static QueryOptions ToQueryOptions(this Couchbase.Grpc.Protocol.Columnar.
return queryOptions;
}

private static IDeserializer ToCore(this Couchbase.Grpc.Protocol.Columnar.Deserializer protoDeserializer)
private static IDeserializer ToCore(this Deserializer protoDeserializer)
{
return protoDeserializer.TypeCase switch
{
Couchbase.Grpc.Protocol.Columnar.Deserializer.TypeOneofCase.Json => new StjJsonDeserializer(),
Couchbase.Grpc.Protocol.Columnar.Deserializer.TypeOneofCase.Passthrough => new StjJsonDeserializer(),
Couchbase.Grpc.Protocol.Columnar.Deserializer.TypeOneofCase.Custom => throw new NotSupportedException("Custom deserializer is not supported in .NET"),
_ => throw new ArgumentOutOfRangeException(nameof(protoDeserializer.TypeCase), "Could not parse Deserializer")
};
{
Deserializer.TypeOneofCase.Json => new StjJsonDeserializer(),
Deserializer.TypeOneofCase.Passthrough => new StjJsonDeserializer(),
Deserializer.TypeOneofCase.Custom => throw new NotSupportedException("Custom deserializer is not supported in .NET"),
_ => throw new ArgumentOutOfRangeException(nameof(protoDeserializer.TypeCase), "Could not parse Deserializer")
};

}

Expand Down Expand Up @@ -131,4 +131,4 @@ private static Dictionary<string, object> ToCore(this MapField<string, Value> fi
}
return dictionary;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ public async Task<QueryRowResponse> GetNextRow()

return response;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ResponseMetaDataExtensions
{
public static QueryResultMetadataResponse.Types.QueryMetadata ToResponseMetaData(this QueryMetaData metadata)
{
var sdkMetrics = metadata.Metrics;
var sdkMetrics = metadata.Metrics!;
var protoMetadata = new QueryResultMetadataResponse.Types.QueryMetadata()
{
Metrics = new QueryResultMetadataResponse.Types.QueryMetadata.Types.Metrics
Expand Down Expand Up @@ -38,7 +38,7 @@ public static QueryResultMetadataResponse.Types.QueryMetadata ToResponseMetaData
{
foreach (var warnings in metadata.Warnings)
{
protoMetadata.Warnings.Add( new QueryResultMetadataResponse.Types.QueryMetadata.Types.Warning()
protoMetadata.Warnings.Add(new QueryResultMetadataResponse.Types.QueryMetadata.Types.Warning()
{
Code = (uint)warnings.Code,
Message = warnings.Message
Expand All @@ -47,4 +47,4 @@ public static QueryResultMetadataResponse.Types.QueryMetadata ToResponseMetaData
}
return protoMetadata;
}
}
}
4 changes: 2 additions & 2 deletions fit/Couchbase.Analytics.Performer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using Couchbase.Analytics.Performer.Internal.Connections;
using Couchbase.Analytics.Performer.Internal.Logging;
using Couchbase.Analytics.Performer.Internal.Services;
Expand Down Expand Up @@ -44,4 +44,4 @@ public static async Task Main(string[] args)
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ public enum CertificateTrustMode
/// Trust only the explicitly provided certificate collection.
/// </summary>
CertificatesOnly
}
}
15 changes: 7 additions & 8 deletions src/Couchbase.Analytics/Certificates/CertificateValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ public static partial class CertificateValidation
/// <remarks>
/// The certificate is automatically parsed from the PEM format and made available as an X509Certificate2 instance.
/// </remarks>
internal static readonly X509Certificate2 CapellaCaCert = new(
rawData: System.Text.Encoding.ASCII.GetBytes(CapellaCaCertPem),
password: (string?)null);
internal static readonly X509Certificate2 CapellaCaCert =
X509CertificateLoader.LoadCertificate(System.Text.Encoding.ASCII.GetBytes(CapellaCaCertPem));

/// <summary>
/// Creates a <see cref="RemoteCertificateValidationCallback"/> that validates server certificates according to the specified security options.
Expand Down Expand Up @@ -210,16 +209,16 @@ private static bool ValidateWithPlatformAndCapellaTrust(
}
else if (securityOptions.TrustMode == CertificateTrustMode.PemFilePath)
{
trustedCertificates.Add(new X509Certificate2(securityOptions.PathToPemFileValue));
trustedCertificates.Add(X509CertificateLoader.LoadCertificateFromFile(securityOptions.PathToPemFileValue!));
}
else if (securityOptions.TrustMode == CertificateTrustMode.PemString)
{
trustedCertificates.Add(new X509Certificate2(
rawData: System.Text.Encoding.ASCII.GetBytes(securityOptions.CertificateValue)));
trustedCertificates.Add(X509CertificateLoader.LoadCertificate(
System.Text.Encoding.ASCII.GetBytes(securityOptions.CertificateValue!)));
}
else if (securityOptions.TrustMode == CertificateTrustMode.CertificatesOnly)
{
trustedCertificates.AddRange(securityOptions.CertificatesValue);
trustedCertificates.AddRange(securityOptions.CertificatesValue!);
}

LogBuiltCustomTrustCollection(logger, trustedCertificates.Count);
Expand Down Expand Up @@ -422,4 +421,4 @@ private static void LogChainValidationErrors(X509Chain chain, X509Certificate2 s
private static partial void LogChainElementError(ILogger logger, string subject, X509ChainStatusFlags status, string statusInformation);

#endregion
}
}
Loading
Loading