Skip to content

Commit

Permalink
refactor: Remove usage of gRPC defined ResultStatus in internal inter…
Browse files Browse the repository at this point in the history
…faces
  • Loading branch information
aneojgurhem committed Sep 26, 2023
1 parent a0a62ef commit b8eb8a9
Show file tree
Hide file tree
Showing 29 changed files with 161 additions and 66 deletions.
1 change: 0 additions & 1 deletion Adaptors/Memory/src/ResultTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using System.Threading;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Core.Base.DataStructures;
using ArmoniK.Core.Common.Exceptions;
using ArmoniK.Core.Common.Storage;
Expand Down
1 change: 0 additions & 1 deletion Adaptors/MongoDB/src/ResultTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using System.Threading.Tasks;

using ArmoniK.Api.Common.Utils;
using ArmoniK.Api.gRPC.V1;
using ArmoniK.Core.Adapters.MongoDB.Common;
using ArmoniK.Core.Adapters.MongoDB.Table.DataModel;
using ArmoniK.Core.Base.DataStructures;
Expand Down
1 change: 1 addition & 0 deletions Adaptors/MongoDB/tests/BsonSerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using NUnit.Framework;

using Output = ArmoniK.Core.Common.Storage.Output;
using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;
using TaskOptions = ArmoniK.Core.Base.DataStructures.TaskOptions;
using TaskStatus = ArmoniK.Core.Common.Storage.TaskStatus;

Expand Down
2 changes: 0 additions & 2 deletions Common/src/Storage/Events/NewResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using ArmoniK.Api.gRPC.V1;

namespace ArmoniK.Core.Common.Storage.Events;

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions Common/src/Storage/Events/ResultStatusUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using ArmoniK.Api.gRPC.V1;

namespace ArmoniK.Core.Common.Storage.Events;

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Common/src/Storage/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
using System;
using System.Collections.Generic;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Api.gRPC.V1.Results;
using ArmoniK.Core.Common.gRPC.Convertors;

using static Google.Protobuf.WellKnownTypes.Timestamp;

Expand Down Expand Up @@ -55,7 +55,7 @@ public static implicit operator ResultRaw(Result result)
=> new()
{
SessionId = result.SessionId,
Status = result.Status,
Status = result.Status.ToGrpcStatus(),
CreatedAt = FromDateTime(result.CreationDate),
Name = result.Name,
OwnerTaskId = result.OwnerTaskId,
Expand Down
28 changes: 28 additions & 0 deletions Common/src/Storage/ResultIdStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of the ArmoniK project
//
// Copyright (C) ANEO, 2021-2023. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

namespace ArmoniK.Core.Common.Storage;

/// <summary>
/// Holds result Id and status
/// </summary>
/// <param name="ResultId">Result Id</param>
/// <param name="Status">Result status</param>
public record ResultIdStatus(string ResultId,
ResultStatus Status)
{
}
2 changes: 0 additions & 2 deletions Common/src/Storage/ResultLifeCycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
using System.Threading;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;

using Microsoft.Extensions.Logging;

namespace ArmoniK.Core.Common.Storage;
Expand Down
33 changes: 33 additions & 0 deletions Common/src/Storage/ResultStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of the ArmoniK project
//
// Copyright (C) ANEO, 2021-2023. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

namespace ArmoniK.Core.Common.Storage;

public enum ResultStatus
{
/// <summary>Result is in an unspecified state.</summary>
Unspecified,

/// <summary>Result is created and task is created, submitted or dispatched.</summary>
Created,

/// <summary>Result is completed with a completed task.</summary>
Completed,

/// <summary>Result is aborted.</summary>
Aborted,
}
2 changes: 0 additions & 2 deletions Common/src/Storage/ResultStatusCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using ArmoniK.Api.gRPC.V1;

namespace ArmoniK.Core.Common.Storage;

public record ResultStatusCount(ResultStatus Status,
Expand Down
16 changes: 6 additions & 10 deletions Common/src/Storage/ResultTableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Threading;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1.Submitter;
using ArmoniK.Core.Common.Exceptions;

namespace ArmoniK.Core.Common.Storage;
Expand Down Expand Up @@ -87,16 +86,13 @@ public static async Task<IEnumerable<string>> GetDependents(this IResultTable re
/// <returns>
/// A map between the ids of the results found and their status
/// </returns>
public static async Task<IEnumerable<GetResultStatusReply.Types.IdStatus>> GetResultStatus(this IResultTable resultTable,
IEnumerable<string> ids,
string sessionId,
CancellationToken cancellationToken = default)
public static async Task<IEnumerable<ResultIdStatus>> GetResultStatus(this IResultTable resultTable,
IEnumerable<string> ids,
string sessionId,
CancellationToken cancellationToken = default)
=> await resultTable.GetResults(result => ids.Contains(result.ResultId),
result => new GetResultStatusReply.Types.IdStatus
{
ResultId = result.ResultId,
Status = result.Status,
},
result => new ResultIdStatus(result.ResultId,
result.Status),
cancellationToken)
.ToListAsync(cancellationToken)
.ConfigureAwait(false);
Expand Down
50 changes: 50 additions & 0 deletions Common/src/gRPC/Convertors/ResultStatusExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file is part of the ArmoniK project
//
// Copyright (C) ANEO, 2021-2023. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;

using ArmoniK.Api.gRPC.V1;

namespace ArmoniK.Core.Common.gRPC.Convertors;

public static class ResultStatusExt
{
public static ResultStatus ToGrpcStatus(this Storage.ResultStatus status)
=> status switch
{
Storage.ResultStatus.Unspecified => ResultStatus.Unspecified,
Storage.ResultStatus.Created => ResultStatus.Created,
Storage.ResultStatus.Completed => ResultStatus.Completed,
Storage.ResultStatus.Aborted => ResultStatus.Aborted,
_ => throw new ArgumentOutOfRangeException(nameof(status),
status,
null),
};

public static Storage.ResultStatus ToInternalStatus(this ResultStatus status)
=> status switch
{
ResultStatus.Unspecified => Storage.ResultStatus.Unspecified,
ResultStatus.Created => Storage.ResultStatus.Created,
ResultStatus.Completed => Storage.ResultStatus.Completed,
ResultStatus.Aborted => Storage.ResultStatus.Aborted,
ResultStatus.Notfound => Storage.ResultStatus.Unspecified,
_ => throw new ArgumentOutOfRangeException(nameof(status),
status,
null),
};
}
6 changes: 4 additions & 2 deletions Common/src/gRPC/Services/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using ArmoniK.Api.gRPC.V1.Agent;
using ArmoniK.Core.Base;
using ArmoniK.Core.Common.Exceptions;
using ArmoniK.Core.Common.gRPC.Convertors;
using ArmoniK.Core.Common.StateMachines;
using ArmoniK.Core.Common.Storage;
using ArmoniK.Utils;
Expand All @@ -39,6 +40,7 @@

using static Google.Protobuf.WellKnownTypes.Timestamp;

using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;
using TaskOptions = ArmoniK.Core.Base.DataStructures.TaskOptions;

namespace ArmoniK.Core.Common.gRPC.Services;
Expand Down Expand Up @@ -329,7 +331,7 @@ await resultTable_.Create(results,
CreatedAt = FromDateTime(result.CreationDate),
Name = result.Name,
SessionId = result.SessionId,
Status = result.Status,
Status = result.Status.ToGrpcStatus(),
ResultId = result.ResultId,
}),
},
Expand Down Expand Up @@ -431,7 +433,7 @@ await resultTable_.Create(results,
{
results.Select(r => new ResultMetaData
{
Status = r.Status,
Status = r.Status.ToGrpcStatus(),
CreatedAt = FromDateTime(r.CreationDate),
Name = r.Name,
ResultId = r.ResultId,
Expand Down
2 changes: 2 additions & 0 deletions Common/src/gRPC/Services/GrpcResultsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;

using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;

namespace ArmoniK.Core.Common.gRPC.Services;

[Authorize(AuthenticationSchemes = Authenticator.SchemeName)]
Expand Down
12 changes: 8 additions & 4 deletions Common/src/gRPC/Services/GrpcSubmitterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,14 @@ public override async Task<GetResultStatusReply> GetResultStatus(GetResultStatus
{
IdStatuses =
{
await resultTable_.GetResultStatus(request.ResultIds,
request.SessionId,
context.CancellationToken)
.ConfigureAwait(false),
(await resultTable_.GetResultStatus(request.ResultIds,
request.SessionId,
context.CancellationToken)
.ConfigureAwait(false)).Select(status => new GetResultStatusReply.Types.IdStatus
{
ResultId = status.ResultId,
Status = status.Status.ToGrpcStatus(),
}),
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion Common/src/gRPC/Services/Submitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
using Microsoft.Extensions.Logging;

using Output = ArmoniK.Api.gRPC.V1.Output;
using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;
using TaskOptions = ArmoniK.Core.Base.DataStructures.TaskOptions;
using TaskStatus = ArmoniK.Core.Common.Storage.TaskStatus;

Expand Down Expand Up @@ -474,7 +475,6 @@ public async Task<AvailabilityReply> WaitForAvailabilityAsync(ResultRequest
},
};
case ResultStatus.Unspecified:
case ResultStatus.Notfound: // TODO: define a specific error type ?
default:
throw new ArgumentOutOfRangeException(nameof(result.Status));
}
Expand Down
6 changes: 3 additions & 3 deletions Common/src/gRPC/Services/WatchToGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ await Task.Factory.StartNew(async () =>
NewResult =
new EventSubscriptionResponse.Types.NewResult
{
Status = cur.Status,
Status = cur.Status.ToGrpcStatus(),
OwnerId = cur.OwnerId,
ResultId = cur.ResultId,
},
Expand Down Expand Up @@ -221,7 +221,7 @@ await Task.Factory.StartNew(async () =>
ResultStatusUpdate
{
ResultId = cur.ResultId,
Status = cur.Status,
Status = cur.Status.ToGrpcStatus(),
},
SessionId = cur.SessionId,
});
Expand Down Expand Up @@ -327,7 +327,7 @@ await Task.Factory.StartNew(async () =>
{
NewResult = new EventSubscriptionResponse.Types.NewResult
{
Status = cur.Status,
Status = cur.Status.ToGrpcStatus(),
OwnerId = cur.OwnerTaskId,
ResultId = cur.ResultId,
},
Expand Down
1 change: 0 additions & 1 deletion Common/tests/Helpers/SimpleResultTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Threading;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Core.Base.DataStructures;
using ArmoniK.Core.Common.Storage;

Expand Down
1 change: 0 additions & 1 deletion Common/tests/Helpers/SimpleResultWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System.Threading;
using System.Threading.Tasks;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Core.Base.DataStructures;
using ArmoniK.Core.Common.Storage;
using ArmoniK.Core.Common.Storage.Events;
Expand Down
1 change: 0 additions & 1 deletion Common/tests/ListResultsRequestExt/ToResultFieldTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using System;
using System.Collections.Generic;

using ArmoniK.Api.gRPC.V1;
using ArmoniK.Api.gRPC.V1.Results;
using ArmoniK.Api.gRPC.V1.SortDirection;
using ArmoniK.Core.Common.gRPC;
Expand Down
8 changes: 5 additions & 3 deletions Common/tests/ListResultsRequestExt/ToResultFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

using NUnit.Framework;

using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;

namespace ArmoniK.Core.Common.Tests.ListResultsRequestExt;

[TestFixture(TestOf = typeof(ToResultFilterTest))]
Expand Down Expand Up @@ -90,13 +92,13 @@ TestCaseData CaseFalse(FilterField filterField)

yield return CaseTrue(ListResultsHelper.CreateListResultsFilterStatus(ResultRawEnumField.Status,
FilterStatusOperator.Equal,
ResultStatus.Created));
Api.gRPC.V1.ResultStatus.Created));
yield return CaseFalse(ListResultsHelper.CreateListResultsFilterStatus(ResultRawEnumField.Status,
FilterStatusOperator.Equal,
ResultStatus.Aborted));
Api.gRPC.V1.ResultStatus.Aborted));
yield return CaseTrue(ListResultsHelper.CreateListResultsFilterStatus(ResultRawEnumField.Status,
FilterStatusOperator.NotEqual,
ResultStatus.Aborted));
Api.gRPC.V1.ResultStatus.Aborted));

yield return CaseTrue(ListResultsHelper.CreateListResultsFilterString(ResultRawEnumField.SessionId,
FilterStringOperator.Equal,
Expand Down
1 change: 1 addition & 0 deletions Common/tests/Pollster/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
using NUnit.Framework;

using Agent = ArmoniK.Core.Common.gRPC.Services.Agent;
using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;
using TaskOptions = ArmoniK.Api.gRPC.V1.TaskOptions;
using TaskRequest = ArmoniK.Core.Common.gRPC.Services.TaskRequest;
using TaskStatus = ArmoniK.Core.Common.Storage.TaskStatus;
Expand Down
1 change: 1 addition & 0 deletions Common/tests/Pollster/PollsterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using NUnit.Framework;

using Output = ArmoniK.Api.gRPC.V1.Output;
using ResultStatus = ArmoniK.Core.Common.Storage.ResultStatus;
using TaskOptions = ArmoniK.Core.Base.DataStructures.TaskOptions;
using TaskRequest = ArmoniK.Core.Common.gRPC.Services.TaskRequest;
using TaskStatus = ArmoniK.Core.Common.Storage.TaskStatus;
Expand Down
Loading

0 comments on commit b8eb8a9

Please sign in to comment.