[#1] Remove unnecessary layer
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
parent
b307c2c899
commit
6f24f567c1
11 changed files with 103 additions and 158 deletions
|
@ -10,8 +10,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.Cryptography",
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.ModelsV2", "src\FrostFS.SDK.ModelsV2\FrostFS.SDK.ModelsV2.csproj", "{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}"
|
||||
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
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
EndGlobal
|
||||
|
|
|
@ -3,7 +3,6 @@ using FrostFS.Container;
|
|||
using FrostFS.Netmap;
|
||||
using FrostFS.Object;
|
||||
using FrostFS.SDK.ClientV2.Interfaces;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Session;
|
||||
|
@ -38,13 +37,12 @@ public partial class Client: IFrostFSClient
|
|||
CheckFrostFsVersionSupport();
|
||||
}
|
||||
|
||||
private void CheckFrostFsVersionSupport()
|
||||
private async void CheckFrostFsVersionSupport()
|
||||
{
|
||||
var localNodeInfo = GetLocalNodeInfoAsync().Result;
|
||||
var frostFsVersion = localNodeInfo.Body.Version.ToModel();
|
||||
if (!frostFsVersion.IsSupported(Version))
|
||||
var localNodeInfo = await GetLocalNodeInfoAsync();
|
||||
if (!localNodeInfo.Version.IsSupported(Version))
|
||||
{
|
||||
var msg = $"FrostFS {frostFsVersion} is not supported.";
|
||||
var msg = $"FrostFS {localNodeInfo.Version} is not supported.";
|
||||
Console.WriteLine(msg);
|
||||
throw new ApplicationException(msg);
|
||||
}
|
||||
|
|
|
@ -1,20 +1,15 @@
|
|||
using FrostFS.Container;
|
||||
using FrostFS.Object;
|
||||
using FrostFS.Refs;
|
||||
using DeleteResponse = FrostFS.Container.DeleteResponse;
|
||||
using GetResponse = FrostFS.Container.GetResponse;
|
||||
using PutResponse = FrostFS.Container.PutResponse;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Interfaces;
|
||||
|
||||
public interface IFrostFSClient
|
||||
{
|
||||
Task<ListResponse> ListContainersAsync();
|
||||
Task<PutResponse> CreateContainerAsync(Container.Container container);
|
||||
Task<GetResponse> GetContainerAsync(ContainerID containerId);
|
||||
Task<DeleteResponse> DeleteContainerAsync(ContainerID containerId);
|
||||
Task<HeadResponse> GetObjectHeadAsync(ContainerID containerId, ObjectID objectId);
|
||||
Task<Object.Object> GetObjectAsync(ContainerID containerId, ObjectID objectId);
|
||||
Task<Object.PutResponse> PutObjectAsync(Header header, Stream payload);
|
||||
Task<Object.DeleteResponse> DeleteObjectAsync(ContainerID containerId, ObjectID objectId);
|
||||
Task<ModelsV2.Container> GetContainerAsync(ContainerId containerId);
|
||||
Task<ContainerId[]> ListContainersAsync();
|
||||
Task<ContainerId> CreateContainerAsync(ModelsV2.Container container);
|
||||
Task DeleteContainerAsync(ContainerId containerId);
|
||||
Task<ObjectHeader> GetObjectHeadAsync(ContainerId containerId, ObjectId objectId);
|
||||
Task<ModelsV2.Object> GetObjectAsync(ContainerId containerId, ObjectId objectId);
|
||||
Task<ObjectId> PutObjectAsync(ObjectHeader header, Stream payload);
|
||||
Task DeleteObjectAsync(ContainerId containerId, ObjectId objectId);
|
||||
}
|
21
src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/NodeInfo.cs
Normal file
21
src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/NodeInfo.cs
Normal 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()
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,26 +1,28 @@
|
|||
using FrostFS.Container;
|
||||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client
|
||||
{
|
||||
public async Task<GetResponse> GetContainerAsync(ContainerID cid)
|
||||
public async Task<ModelsV2.Container> GetContainerAsync(ContainerId cid)
|
||||
{
|
||||
var request = new GetRequest
|
||||
{
|
||||
Body = new GetRequest.Types.Body
|
||||
{
|
||||
ContainerId = cid
|
||||
ContainerId = cid.ToGrpcMessage()
|
||||
},
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
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
|
||||
{
|
||||
|
@ -31,38 +33,43 @@ public partial class Client
|
|||
};
|
||||
request.AddMetaHeader();
|
||||
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();
|
||||
container.Version = Version.ToGrpcMessage();
|
||||
var cntnr = container.ToGrpcMessage();
|
||||
cntnr.OwnerId = _owner.ToGrpcMessage();
|
||||
cntnr.Version = Version.ToGrpcMessage();
|
||||
var request = new PutRequest
|
||||
{
|
||||
Body = new PutRequest.Types.Body
|
||||
{
|
||||
Container = container,
|
||||
Signature = _key.SignRFC6979(container),
|
||||
Container = cntnr,
|
||||
Signature = _key.SignRFC6979(cntnr),
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
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
|
||||
{
|
||||
Body = new DeleteRequest.Types.Body
|
||||
{
|
||||
ContainerId = cid,
|
||||
Signature = _key.SignRFC6979(cid.Value)
|
||||
ContainerId = cid.ToGrpcMessage(),
|
||||
Signature = _key.SignRFC6979(cid.ToGrpcMessage().Value)
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _containerServiceClient.DeleteAsync(request);
|
||||
await _containerServiceClient.DeleteAsync(request);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
using FrostFS.Netmap;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client
|
||||
{
|
||||
public async Task<LocalNodeInfoResponse> GetLocalNodeInfoAsync()
|
||||
public async Task<ModelsV2.Netmap.NodeInfo> GetLocalNodeInfoAsync()
|
||||
{
|
||||
var request = new LocalNodeInfoRequest
|
||||
{
|
||||
|
@ -12,7 +13,8 @@ public partial class Client
|
|||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _netmapServiceClient.LocalNodeInfoAsync(request);
|
||||
var response = await _netmapServiceClient.LocalNodeInfoAsync(request);
|
||||
return response.Body.ToModel();
|
||||
}
|
||||
|
||||
public async Task<NetworkInfoResponse> GetNetworkInfoAsync()
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace FrostFS.SDK.ClientV2;
|
|||
|
||||
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
|
||||
{
|
||||
|
@ -19,17 +19,18 @@ public partial class Client
|
|||
{
|
||||
Address = new Address
|
||||
{
|
||||
ContainerId = cid,
|
||||
ObjectId = oid
|
||||
ContainerId = cid.ToGrpcMessage(),
|
||||
ObjectId = oid.ToGrpcMessage()
|
||||
}
|
||||
},
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
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 request = new GetRequest
|
||||
|
@ -39,22 +40,23 @@ public partial class Client
|
|||
Raw = false,
|
||||
Address = new Address
|
||||
{
|
||||
ContainerId = cid,
|
||||
ObjectId = oid
|
||||
ContainerId = cid.ToGrpcMessage(),
|
||||
ObjectId = oid.ToGrpcMessage()
|
||||
},
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.AddObjectSessionToken(
|
||||
sessionToken,
|
||||
cid,
|
||||
oid,
|
||||
cid.ToGrpcMessage(),
|
||||
oid.ToGrpcMessage(),
|
||||
ObjectSessionContext.Types.Verb.Get,
|
||||
_key
|
||||
);
|
||||
request.Sign(_key);
|
||||
|
||||
return await GetObject(request);
|
||||
var response = await GetObject(request);
|
||||
return response.ToModel();
|
||||
}
|
||||
|
||||
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);
|
||||
header.OwnerId = _owner.ToGrpcMessage();
|
||||
header.Version = Version.ToGrpcMessage();
|
||||
var hdr = header.ToGrpcMessage();
|
||||
hdr.OwnerId = _owner.ToGrpcMessage();
|
||||
hdr.Version = Version.ToGrpcMessage();
|
||||
var oid = new ObjectID
|
||||
{
|
||||
Value = header.Sha256()
|
||||
Value = hdr.Sha256()
|
||||
};
|
||||
var request = new PutRequest
|
||||
{
|
||||
|
@ -102,14 +105,14 @@ public partial class Client
|
|||
{
|
||||
Init = new PutRequest.Types.Body.Types.Init
|
||||
{
|
||||
Header = header
|
||||
Header = hdr
|
||||
},
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.AddObjectSessionToken(
|
||||
sessionToken,
|
||||
header.ContainerId,
|
||||
hdr.ContainerId,
|
||||
oid,
|
||||
ObjectSessionContext.Types.Verb.Put,
|
||||
_key
|
||||
|
@ -131,7 +134,8 @@ public partial class Client
|
|||
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)
|
||||
|
@ -146,7 +150,7 @@ public partial class Client
|
|||
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
|
||||
{
|
||||
|
@ -154,14 +158,14 @@ public partial class Client
|
|||
{
|
||||
Address = new Address
|
||||
{
|
||||
ContainerId = cid,
|
||||
ObjectId = oid
|
||||
ContainerId = cid.ToGrpcMessage(),
|
||||
ObjectId = oid.ToGrpcMessage()
|
||||
}
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _objectServiceClient.DeleteAsync(request);
|
||||
await _objectServiceClient.DeleteAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
9
src/FrostFS.SDK.ModelsV2/Enums/NodeState.cs
Normal file
9
src/FrostFS.SDK.ModelsV2/Enums/NodeState.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace FrostFS.SDK.ModelsV2.Enums;
|
||||
|
||||
public enum NodeState
|
||||
{
|
||||
Unspecified = 0,
|
||||
Online = 1,
|
||||
Offline = 2,
|
||||
Maintenance = 3
|
||||
}
|
9
src/FrostFS.SDK.ModelsV2/Netmap/NodeInfo.cs
Normal file
9
src/FrostFS.SDK.ModelsV2/Netmap/NodeInfo.cs
Normal 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; }
|
||||
}
|
|
@ -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>
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue