[#1] Remove unnecessary layer

Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
Ivan Pchelintsev 2024-05-16 18:23:40 +03:00
parent b307c2c899
commit 6f24f567c1
11 changed files with 103 additions and 158 deletions

View file

@ -10,8 +10,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.Cryptography",
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.ModelsV2", "src\FrostFS.SDK.ModelsV2\FrostFS.SDK.ModelsV2.csproj", "{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.ModelsV2", "src\FrostFS.SDK.ModelsV2\FrostFS.SDK.ModelsV2.csproj", "{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.Service", "src\FrostFS.SDK.Service\FrostFS.SDK.Service.csproj", "{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -38,9 +36,5 @@ Global
{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Debug|Any CPU.Build.0 = Debug|Any CPU {3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Release|Any CPU.ActiveCfg = Release|Any CPU {3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Release|Any CPU.Build.0 = Release|Any CPU {3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Release|Any CPU.Build.0 = Release|Any CPU
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View file

@ -3,7 +3,6 @@ using FrostFS.Container;
using FrostFS.Netmap; using FrostFS.Netmap;
using FrostFS.Object; using FrostFS.Object;
using FrostFS.SDK.ClientV2.Interfaces; using FrostFS.SDK.ClientV2.Interfaces;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.Cryptography; using FrostFS.SDK.Cryptography;
using FrostFS.SDK.ModelsV2; using FrostFS.SDK.ModelsV2;
using FrostFS.Session; using FrostFS.Session;
@ -38,13 +37,12 @@ public partial class Client: IFrostFSClient
CheckFrostFsVersionSupport(); CheckFrostFsVersionSupport();
} }
private void CheckFrostFsVersionSupport() private async void CheckFrostFsVersionSupport()
{ {
var localNodeInfo = GetLocalNodeInfoAsync().Result; var localNodeInfo = await GetLocalNodeInfoAsync();
var frostFsVersion = localNodeInfo.Body.Version.ToModel(); if (!localNodeInfo.Version.IsSupported(Version))
if (!frostFsVersion.IsSupported(Version))
{ {
var msg = $"FrostFS {frostFsVersion} is not supported."; var msg = $"FrostFS {localNodeInfo.Version} is not supported.";
Console.WriteLine(msg); Console.WriteLine(msg);
throw new ApplicationException(msg); throw new ApplicationException(msg);
} }

View file

@ -1,20 +1,15 @@
using FrostFS.Container; using FrostFS.SDK.ModelsV2;
using FrostFS.Object;
using FrostFS.Refs;
using DeleteResponse = FrostFS.Container.DeleteResponse;
using GetResponse = FrostFS.Container.GetResponse;
using PutResponse = FrostFS.Container.PutResponse;
namespace FrostFS.SDK.ClientV2.Interfaces; namespace FrostFS.SDK.ClientV2.Interfaces;
public interface IFrostFSClient public interface IFrostFSClient
{ {
Task<ListResponse> ListContainersAsync(); Task<ModelsV2.Container> GetContainerAsync(ContainerId containerId);
Task<PutResponse> CreateContainerAsync(Container.Container container); Task<ContainerId[]> ListContainersAsync();
Task<GetResponse> GetContainerAsync(ContainerID containerId); Task<ContainerId> CreateContainerAsync(ModelsV2.Container container);
Task<DeleteResponse> DeleteContainerAsync(ContainerID containerId); Task DeleteContainerAsync(ContainerId containerId);
Task<HeadResponse> GetObjectHeadAsync(ContainerID containerId, ObjectID objectId); Task<ObjectHeader> GetObjectHeadAsync(ContainerId containerId, ObjectId objectId);
Task<Object.Object> GetObjectAsync(ContainerID containerId, ObjectID objectId); Task<ModelsV2.Object> GetObjectAsync(ContainerId containerId, ObjectId objectId);
Task<Object.PutResponse> PutObjectAsync(Header header, Stream payload); Task<ObjectId> PutObjectAsync(ObjectHeader header, Stream payload);
Task<Object.DeleteResponse> DeleteObjectAsync(ContainerID containerId, ObjectID objectId); Task DeleteObjectAsync(ContainerId containerId, ObjectId objectId);
} }

View file

@ -0,0 +1,21 @@
using FrostFS.SDK.ModelsV2.Enums;
using FrostFS.SDK.ModelsV2.Netmap;
namespace FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
public static class NodeInfoMapper
{
public static NodeInfo ToModel(this FrostFS.Netmap.LocalNodeInfoResponse.Types.Body nodeInfo)
{
var nodeStateName = Enum.GetName(typeof(NodeState), nodeInfo.NodeInfo.State);
if (nodeStateName is null)
{
throw new ArgumentException($"Unknown NodeState. Value: '{nodeInfo.NodeInfo.State}'.");
}
return new NodeInfo
{
State = Enum.Parse<NodeState>(nodeStateName),
Version = nodeInfo.Version.ToModel()
};
}
}

View file

@ -1,26 +1,28 @@
using FrostFS.Container; using FrostFS.Container;
using FrostFS.Refs; using FrostFS.Refs;
using FrostFS.SDK.ClientV2.Mappers.GRPC; using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.ModelsV2;
namespace FrostFS.SDK.ClientV2; namespace FrostFS.SDK.ClientV2;
public partial class Client public partial class Client
{ {
public async Task<GetResponse> GetContainerAsync(ContainerID cid) public async Task<ModelsV2.Container> GetContainerAsync(ContainerId cid)
{ {
var request = new GetRequest var request = new GetRequest
{ {
Body = new GetRequest.Types.Body Body = new GetRequest.Types.Body
{ {
ContainerId = cid ContainerId = cid.ToGrpcMessage()
}, },
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _containerServiceClient.GetAsync(request); var response = await _containerServiceClient.GetAsync(request);
return response.Body.Container.ToModel();
} }
public async Task<ListResponse> ListContainersAsync() public async Task<ContainerId[]> ListContainersAsync()
{ {
var request = new ListRequest var request = new ListRequest
{ {
@ -31,38 +33,43 @@ public partial class Client
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _containerServiceClient.ListAsync(request); var response = await _containerServiceClient.ListAsync(request);
return response.Body.ContainerIds.Select(
cid => ContainerId.FromHash(cid.Value.ToByteArray())
).ToArray();
} }
public async Task<PutResponse> CreateContainerAsync(Container.Container container) public async Task<ContainerId> CreateContainerAsync(ModelsV2.Container container)
{ {
container.OwnerId = _owner.ToGrpcMessage(); var cntnr = container.ToGrpcMessage();
container.Version = Version.ToGrpcMessage(); cntnr.OwnerId = _owner.ToGrpcMessage();
cntnr.Version = Version.ToGrpcMessage();
var request = new PutRequest var request = new PutRequest
{ {
Body = new PutRequest.Types.Body Body = new PutRequest.Types.Body
{ {
Container = container, Container = cntnr,
Signature = _key.SignRFC6979(container), Signature = _key.SignRFC6979(cntnr),
} }
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _containerServiceClient.PutAsync(request); var response = await _containerServiceClient.PutAsync(request);
return ContainerId.FromHash(response.Body.ContainerId.Value.ToByteArray());
} }
public async Task<DeleteResponse> DeleteContainerAsync(ContainerID cid) public async Task DeleteContainerAsync(ContainerId cid)
{ {
var request = new DeleteRequest var request = new DeleteRequest
{ {
Body = new DeleteRequest.Types.Body Body = new DeleteRequest.Types.Body
{ {
ContainerId = cid, ContainerId = cid.ToGrpcMessage(),
Signature = _key.SignRFC6979(cid.Value) Signature = _key.SignRFC6979(cid.ToGrpcMessage().Value)
} }
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _containerServiceClient.DeleteAsync(request); await _containerServiceClient.DeleteAsync(request);
} }
} }

View file

@ -1,10 +1,11 @@
using FrostFS.Netmap; using FrostFS.Netmap;
using FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
namespace FrostFS.SDK.ClientV2; namespace FrostFS.SDK.ClientV2;
public partial class Client public partial class Client
{ {
public async Task<LocalNodeInfoResponse> GetLocalNodeInfoAsync() public async Task<ModelsV2.Netmap.NodeInfo> GetLocalNodeInfoAsync()
{ {
var request = new LocalNodeInfoRequest var request = new LocalNodeInfoRequest
{ {
@ -12,7 +13,8 @@ public partial class Client
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _netmapServiceClient.LocalNodeInfoAsync(request); var response = await _netmapServiceClient.LocalNodeInfoAsync(request);
return response.Body.ToModel();
} }
public async Task<NetworkInfoResponse> GetNetworkInfoAsync() public async Task<NetworkInfoResponse> GetNetworkInfoAsync()

View file

@ -11,7 +11,7 @@ namespace FrostFS.SDK.ClientV2;
public partial class Client public partial class Client
{ {
public async Task<HeadResponse> GetObjectHeadAsync(ContainerID cid, ObjectID oid) public async Task<ObjectHeader> GetObjectHeadAsync(ContainerId cid, ObjectId oid)
{ {
var request = new HeadRequest var request = new HeadRequest
{ {
@ -19,17 +19,18 @@ public partial class Client
{ {
Address = new Address Address = new Address
{ {
ContainerId = cid, ContainerId = cid.ToGrpcMessage(),
ObjectId = oid ObjectId = oid.ToGrpcMessage()
} }
}, },
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _objectServiceClient.HeadAsync(request); var response = await _objectServiceClient.HeadAsync(request);
return response.Body.Header.Header.ToModel();
} }
public async Task<Object.Object> GetObjectAsync(ContainerID cid, ObjectID oid) public async Task<ModelsV2.Object> GetObjectAsync(ContainerId cid, ObjectId oid)
{ {
var sessionToken = await CreateSessionAsync(uint.MaxValue); var sessionToken = await CreateSessionAsync(uint.MaxValue);
var request = new GetRequest var request = new GetRequest
@ -39,22 +40,23 @@ public partial class Client
Raw = false, Raw = false,
Address = new Address Address = new Address
{ {
ContainerId = cid, ContainerId = cid.ToGrpcMessage(),
ObjectId = oid ObjectId = oid.ToGrpcMessage()
}, },
} }
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.AddObjectSessionToken( request.AddObjectSessionToken(
sessionToken, sessionToken,
cid, cid.ToGrpcMessage(),
oid, oid.ToGrpcMessage(),
ObjectSessionContext.Types.Verb.Get, ObjectSessionContext.Types.Verb.Get,
_key _key
); );
request.Sign(_key); request.Sign(_key);
return await GetObject(request); var response = await GetObject(request);
return response.ToModel();
} }
private async Task<Object.Object> GetObject(GetRequest request) private async Task<Object.Object> GetObject(GetRequest request)
@ -87,14 +89,15 @@ public partial class Client
}; };
} }
public async Task<PutResponse> PutObjectAsync(Header header, Stream payload) public async Task<ObjectId> PutObjectAsync(ObjectHeader header, Stream payload)
{ {
var sessionToken = await CreateSessionAsync(uint.MaxValue); var sessionToken = await CreateSessionAsync(uint.MaxValue);
header.OwnerId = _owner.ToGrpcMessage(); var hdr = header.ToGrpcMessage();
header.Version = Version.ToGrpcMessage(); hdr.OwnerId = _owner.ToGrpcMessage();
hdr.Version = Version.ToGrpcMessage();
var oid = new ObjectID var oid = new ObjectID
{ {
Value = header.Sha256() Value = hdr.Sha256()
}; };
var request = new PutRequest var request = new PutRequest
{ {
@ -102,14 +105,14 @@ public partial class Client
{ {
Init = new PutRequest.Types.Body.Types.Init Init = new PutRequest.Types.Body.Types.Init
{ {
Header = header Header = hdr
}, },
} }
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.AddObjectSessionToken( request.AddObjectSessionToken(
sessionToken, sessionToken,
header.ContainerId, hdr.ContainerId,
oid, oid,
ObjectSessionContext.Types.Verb.Put, ObjectSessionContext.Types.Verb.Put,
_key _key
@ -131,7 +134,8 @@ public partial class Client
bufferLength = payload.Read(buffer, 0, Constants.ObjectChunkSize); bufferLength = payload.Read(buffer, 0, Constants.ObjectChunkSize);
} }
return await stream.Close(); var response = await stream.Close();
return ObjectId.FromHash(response.Body.ObjectId.Value.ToByteArray());
} }
private async Task<ObjectStreamer> PutObjectInit(PutRequest initRequest) private async Task<ObjectStreamer> PutObjectInit(PutRequest initRequest)
@ -146,7 +150,7 @@ public partial class Client
return new ObjectStreamer { Call = call }; return new ObjectStreamer { Call = call };
} }
public async Task<DeleteResponse> DeleteObjectAsync(ContainerID cid, ObjectID oid) public async Task DeleteObjectAsync(ContainerId cid, ObjectId oid)
{ {
var request = new DeleteRequest var request = new DeleteRequest
{ {
@ -154,14 +158,14 @@ public partial class Client
{ {
Address = new Address Address = new Address
{ {
ContainerId = cid, ContainerId = cid.ToGrpcMessage(),
ObjectId = oid ObjectId = oid.ToGrpcMessage()
} }
} }
}; };
request.AddMetaHeader(); request.AddMetaHeader();
request.Sign(_key); request.Sign(_key);
return await _objectServiceClient.DeleteAsync(request); await _objectServiceClient.DeleteAsync(request);
} }
} }

View file

@ -0,0 +1,9 @@
namespace FrostFS.SDK.ModelsV2.Enums;
public enum NodeState
{
Unspecified = 0,
Online = 1,
Offline = 2,
Maintenance = 3
}

View file

@ -0,0 +1,9 @@
using FrostFS.SDK.ModelsV2.Enums;
namespace FrostFS.SDK.ModelsV2.Netmap;
public class NodeInfo
{
public NodeState State { get; set; }
public Version Version { get; set; }
}

View file

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FrostFS.SDK.ClientV2\FrostFS.SDK.ClientV2.csproj" />
</ItemGroup>
</Project>

View file

@ -1,81 +0,0 @@
using FrostFS.SDK.ClientV2;
using FrostFS.SDK.ClientV2.Interfaces;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.ModelsV2;
namespace FrostFS.SDK.Service;
// TODO: Проверять ответы Grpc
public class FrostFsService
{
private readonly IFrostFSClient _client;
public FrostFsService(IFrostFSClient client)
{
_client = client;
}
public async Task<ContainerId[]> ListContainersAsync()
{
var listContainersResponse = await _client.ListContainersAsync();
return listContainersResponse.Body.ContainerIds.Select(
cid => ContainerId.FromHash(cid.Value.ToByteArray())
).ToArray();
}
public async Task<ContainerId> CreateContainerAsync(ModelsV2.Container container)
{
var createContainerResponse = await _client.CreateContainerAsync(container.ToGrpcMessage());
return ContainerId.FromHash(createContainerResponse.Body.ContainerId.Value.ToByteArray());
}
public async Task<ModelsV2.Container> GetContainerAsync(ContainerId containerId)
{
var getContainerResponse = await _client.GetContainerAsync(containerId.ToGrpcMessage());
return getContainerResponse.Body.Container.ToModel();
}
public async Task DeleteContainerAsync(ContainerId containerId)
{
var deleteContainerResponse = await _client.DeleteContainerAsync(containerId.ToGrpcMessage());
}
public async Task<ObjectHeader> GetObjectHeadAsync(ContainerId containerId, ObjectId objectId)
{
var getObjectHeadResponse = await _client.GetObjectHeadAsync(
containerId.ToGrpcMessage(),
objectId.ToGrpcMessage()
);
return getObjectHeadResponse.Body.Header.Header.ToModel();
}
public async Task<ModelsV2.Object> GetObjectAsync(ContainerId containerId, ObjectId objectId)
{
var obj = await _client.GetObjectAsync(
containerId.ToGrpcMessage(),
objectId.ToGrpcMessage()
);
return obj.ToModel();
}
public async Task<ObjectId> PutObjectAsync(ObjectHeader header, Stream payload)
{
var putObjectResponse = await _client.PutObjectAsync(header.ToGrpcMessage(), payload);
return ObjectId.FromHash(putObjectResponse.Body.ObjectId.Value.ToByteArray());
}
public async Task<ObjectId> PutObjectAsync(ObjectHeader header, byte[] payload)
{
var putObjectResponse = await _client.PutObjectAsync(header.ToGrpcMessage(), new MemoryStream(payload));
return ObjectId.FromHash(putObjectResponse.Body.ObjectId.Value.ToByteArray());
}
public async Task DeleteObjectAsync(ContainerId containerId, ObjectId objectId)
{
var deleteObjectResponse = await _client.DeleteObjectAsync(
containerId.ToGrpcMessage(),
objectId.ToGrpcMessage()
);
}
}