Skip to content

Commit

Permalink
refactor: update API
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem committed Jul 27, 2023
1 parent 38a86a9 commit 6359061
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Common/src/ArmoniK.Core.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


<ItemGroup>
<PackageReference Include="ArmoniK.Api.Core" Version="3.11.0-featfilters.108.7af3868" />
<PackageReference Include="ArmoniK.Api.Core" Version="3.11.0-featfilters.113.d4eabe7" />
<PackageReference Include="Calzolari.Grpc.AspNetCore.Validation" Version="6.3.0" />
<PackageReference Include="Grpc.HealthCheck" Version="2.54.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
Expand Down
1 change: 0 additions & 1 deletion Common/src/Injection/ServiceCollectionExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,5 @@ public static IServiceCollection ValidateGrpcRequests(this IServiceCollection se
.AddValidator<ListResultsRequestValidator>()
.AddValidator<ListApplicationsRequestValidator>()
.AddValidator<ListPartitionsRequestValidator>()
.AddValidator<SessionsCountTasksByStatusRequestValidator>()
.AddGrpcValidation();
}
28 changes: 22 additions & 6 deletions Common/src/gRPC/FilterRangeExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static Expression<Func<T, bool>> ToFilter<T, TStatus>(this FilterStatusOp
TStatus value)
=> filterOperator switch
{
FilterStatusOperator.Unspecified => throw new ArgumentOutOfRangeException(),
FilterStatusOperator.Equal => ExpressionBuilders.MakeBinary(field,
value,
ExpressionType.Equal),
Expand All @@ -70,7 +69,6 @@ public static Expression<Func<T, bool>> ToFilter<T>(this FilterDateOperator
DateTime? value)
=> filterOperator switch
{
FilterDateOperator.Unspecified => throw new ArgumentOutOfRangeException(),
FilterDateOperator.Before => ExpressionBuilders.MakeBinary(field,
value,
ExpressionType.LessThan),
Expand Down Expand Up @@ -108,7 +106,6 @@ public static Expression<Func<T, bool>> ToFilter<T>(this FilterNumberOperator
long value)
=> filterOperator switch
{
FilterNumberOperator.Unspecified => throw new ArgumentOutOfRangeException(),
FilterNumberOperator.LessThan => ExpressionBuilders.MakeBinary(field,
value,
ExpressionType.LessThan),
Expand Down Expand Up @@ -165,8 +162,7 @@ public static Expression<Func<T, bool>> ToFilter<T>(this FilterStringOperator
FilterStringOperator.EndsWith => ExpressionBuilders.MakeCallString(field,
value,
nameof(string.EndsWith)),
FilterStringOperator.Unspecified => throw new ArgumentOutOfRangeException(),
_ => throw new ArgumentOutOfRangeException(),
_ => throw new ArgumentOutOfRangeException(),
};

/// <summary>
Expand All @@ -184,7 +180,6 @@ public static Expression<Func<T, bool>> ToFilter<T>(this FilterArrayOperator
string value)
=> filterOperator switch
{
FilterArrayOperator.Unspecified => throw new ArgumentOutOfRangeException(),
FilterArrayOperator.Contains => ExpressionBuilders.MakeCall(field,
value,
typeof(Enumerable),
Expand All @@ -196,4 +191,25 @@ public static Expression<Func<T, bool>> ToFilter<T>(this FilterArrayOperator
true),
_ => throw new ArgumentOutOfRangeException(),
};

/// <summary>
/// Generate a filter <see cref="Expression" /> for operations on arrays
/// </summary>
/// <typeparam name="T">Type of the value and field on which the operation is applied</typeparam>
/// <param name="filterOperator">The gRPC enum that selects the operation</param>
/// <param name="field">The <see cref="Expression" /> to select the field on which to apply the operation</param>
/// <param name="value">Value for the operation</param>
/// <returns>
/// The <see cref="Expression" /> that represents the operation on the field with the given value
/// </returns>
public static Expression<Func<T, bool>> ToFilter<T>(this FilterBooleanOperator filterOperator,
Expression<Func<T, object?>> field,
bool value)
=> filterOperator switch
{
FilterBooleanOperator.Is => ExpressionBuilders.MakeBinary(field,
value,
ExpressionType.Equal),
_ => throw new ArgumentOutOfRangeException(),
};
}
5 changes: 2 additions & 3 deletions Common/src/gRPC/ListPartitionsRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ public static Expression<Func<PartitionData, bool>> ToPartitionFilter(this Filte
filterField.FilterNumber.Value));
break;
case FilterField.ValueConditionOneofCase.FilterBoolean:
predicateAnd = predicateAnd.And(ExpressionBuilders.MakeBinary(filterField.Field.ToField(),
filterField.FilterBoolean.Value,
ExpressionType.Equal));
predicateAnd = predicateAnd.And(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(),
filterField.FilterBoolean.Value)));
break;
case FilterField.ValueConditionOneofCase.FilterArray:
predicateAnd = predicateAnd.And(filterField.FilterArray.Operator.ToFilter(filterField.Field.ToField(),
Expand Down
5 changes: 2 additions & 3 deletions Common/src/gRPC/ListSessionsRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ public static Expression<Func<SessionData, bool>> ToSessionDataFilter(this Filte
filterField.FilterNumber.Value));
break;
case FilterField.ValueConditionOneofCase.FilterBoolean:
predicateAnd = predicateAnd.And(ExpressionBuilders.MakeBinary(filterField.Field.ToField(),
filterField.FilterBoolean.Value,
ExpressionType.Equal));
predicateAnd = predicateAnd.And(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(),
filterField.FilterBoolean.Value)));
break;
case FilterField.ValueConditionOneofCase.FilterStatus:
predicateAnd = predicateAnd.And(filterField.FilterStatus.Operator.ToFilter(filterField.Field.ToField(),
Expand Down
5 changes: 2 additions & 3 deletions Common/src/gRPC/ListTasksRequestExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ public static Expression<Func<TaskData, bool>> ToTaskDataFilter(this Filters fil
filterField.FilterNumber.Value));
break;
case FilterField.ValueConditionOneofCase.FilterBoolean:
predicateAnd = predicateAnd.And(ExpressionBuilders.MakeBinary(filterField.Field.ToField(),
filterField.FilterBoolean.Value,
ExpressionType.Equal));
predicateAnd = predicateAnd.And(filterField.FilterBoolean.Operator.ToFilter(filterField.Field.ToField(),
filterField.FilterBoolean.Value)));
break;
case FilterField.ValueConditionOneofCase.FilterStatus:
predicateAnd = predicateAnd.And(filterField.FilterStatus.Operator.ToFilter(filterField.Field.ToField(),
Expand Down
41 changes: 0 additions & 41 deletions Common/src/gRPC/Services/GrpcSessionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using System.Linq;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Api.gRPC.V1.Sessions;

using Armonik.Api.Grpc.V1.SortDirection;
Expand All @@ -41,15 +40,12 @@ public class GrpcSessionsService : Sessions.SessionsBase
{
private readonly ILogger<GrpcSessionsService> logger_;
private readonly ISessionTable sessionTable_;
private readonly ITaskTable taskTable_;

public GrpcSessionsService(ISessionTable sessionTable,
ITaskTable taskTable,
ILogger<GrpcSessionsService> logger)
{
logger_ = logger;
sessionTable_ = sessionTable;
taskTable_ = taskTable;
}

[RequiresPermission(typeof(GrpcSessionsService),
Expand Down Expand Up @@ -171,41 +167,4 @@ request.Sort is null
"Unknown Exception, see application logs"));
}
}

[RequiresPermission(typeof(GrpcSessionsService),
nameof(CountTasksByStatus))]
public override async Task<CountTasksByStatusResponse> CountTasksByStatus(CountTasksByStatusRequest request,
ServerCallContext context)
{
try
{
return new CountTasksByStatusResponse
{
Status =
{
(await taskTable_.CountTasksAsync(data => data.SessionId == request.SessionId,
context.CancellationToken)
.ConfigureAwait(false)).Select(count => new StatusCount
{
Status = count.Status,
Count = count.Count,
}),
},
};
}
catch (ArmoniKException e)
{
logger_.LogWarning(e,
"Error while counting tasks in session");
throw new RpcException(new Status(StatusCode.Internal,
"Internal Armonik Exception, see application logs"));
}
catch (Exception e)
{
logger_.LogWarning(e,
"Error while counting tasks in session");
throw new RpcException(new Status(StatusCode.Unknown,
"Unknown Exception, see application logs"));
}
}
}

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/Bench/Server/src/ArmoniK.Samples.Bench.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArmoniK.Api.Worker" Version="3.11.0-featfilters.108.7af3868" />
<PackageReference Include="ArmoniK.Api.Worker" Version="3.11.0-featfilters.113.d4eabe7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArmoniK.Api.Client" Version="3.11.0-featfilters.108.7af3868" />
<PackageReference Include="ArmoniK.Api.Client" Version="3.11.0-featfilters.113.d4eabe7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArmoniK.Api.Worker" Version="3.11.0-featfilters.108.7af3868" />
<PackageReference Include="ArmoniK.Api.Worker" Version="3.11.0-featfilters.113.d4eabe7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Htc.Mock" Version="3.0.0-alpha11" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArmoniK.Api.Client" Version="3.11.0-featfilters.108.7af3868" />
<PackageReference Include="ArmoniK.Api.Client" Version="3.11.0-featfilters.113.d4eabe7" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="ArmoniK.Api.Worker" Version="3.11.0-featfilters.108.7af3868" />
<PackageReference Include="ArmoniK.Api.Worker" Version="3.11.0-featfilters.113.d4eabe7" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 6359061

Please sign in to comment.