From 0d83541d821b4cb94db169fed0f0aec3370018d5 Mon Sep 17 00:00:00 2001 From: Ivan Pchelintsev Date: Thu, 16 May 2024 11:00:30 +0300 Subject: [PATCH] [#1] Optimize imports Signed-off-by: Ivan Pchelintsev --- src/FrostFS.SDK.ClientV2/Client.cs | 3 ++- .../Interfaces/IFrostFSClient.cs | 12 +++++++---- .../Mappers/GRPC/Container.cs | 6 +++--- .../Mappers/GRPC/ContainerId.cs | 2 +- .../Mappers/GRPC/MetaHeader.cs | 3 ++- .../Mappers/GRPC/Netmap/PlacementPolicy.cs | 3 ++- .../Mappers/GRPC/Object.cs | 4 ++-- .../Mappers/GRPC/ObjectId.cs | 2 +- .../Mappers/GRPC/OwnerId.cs | 2 +- .../Mappers/GRPC/Version.cs | 8 ++++--- src/FrostFS.SDK.ClientV2/RequestSigner.cs | 2 +- src/FrostFS.SDK.ClientV2/RequestVerifier.cs | 2 +- src/FrostFS.SDK.ClientV2/Services/Object.cs | 7 ++++--- src/FrostFS.SDK.Cryptography/Key.cs | 1 - src/FrostFS.SDK.ModelsV2/Container.cs | 5 +++-- src/FrostFS.SDK.ModelsV2/Object.cs | 21 ++++++++++++++++++- .../Interfaces/IRequest.cs | 2 -- .../container/Extension.Message.cs | 2 +- .../netmap/Extension.Message.cs | 4 ++-- src/FrostFS.SDK.Service/Service.cs | 10 ++------- 20 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/FrostFS.SDK.ClientV2/Client.cs b/src/FrostFS.SDK.ClientV2/Client.cs index b8a6def..5df849a 100644 --- a/src/FrostFS.SDK.ClientV2/Client.cs +++ b/src/FrostFS.SDK.ClientV2/Client.cs @@ -8,6 +8,7 @@ using FrostFS.SDK.ModelsV2; using FrostFS.Session; using Grpc.Core; using Grpc.Net.Client; +using Version = FrostFS.SDK.ModelsV2.Version; namespace FrostFS.SDK.ClientV2; @@ -16,7 +17,7 @@ public partial class Client: IFrostFSClient private GrpcChannel _channel; private readonly ECDsa _key; private readonly OwnerId _owner; - public readonly ModelsV2.Version Version = new (2, 13); + public readonly Version Version = new (2, 13); private ContainerService.ContainerServiceClient _containerServiceClient; private NetmapService.NetmapServiceClient _netmapServiceClient; diff --git a/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs b/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs index 3cac9ba..0d659ae 100644 --- a/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs +++ b/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs @@ -1,14 +1,18 @@ +using FrostFS.Container; 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; public interface IFrostFSClient { - Task ListContainersAsync(); - Task CreateContainerAsync(Container.Container container); - Task GetContainerAsync(ContainerID containerId); - Task DeleteContainerAsync(ContainerID containerId); + Task ListContainersAsync(); + Task CreateContainerAsync(Container.Container container); + Task GetContainerAsync(ContainerID containerId); + Task DeleteContainerAsync(ContainerID containerId); Task GetObjectHeadAsync(ContainerID containerId, ObjectID objectId); Task PutObjectAsync(ContainerID containerId, Stream data); Task DeleteObjectAsync(ContainerID containerId, ObjectID objectId); diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs index bb69aa0..c880b2f 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs @@ -1,6 +1,6 @@ -using System.Runtime.InteropServices.ComTypes; using FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap; using FrostFS.SDK.Cryptography; +using FrostFS.SDK.ModelsV2.Enums; using Google.Protobuf; namespace FrostFS.SDK.ClientV2.Mappers.GRPC; @@ -19,14 +19,14 @@ public static class ContainerMapper public static ModelsV2.Container ToModel(this Container.Container container) { - var basicAclName = Enum.GetName(typeof(ModelsV2.Enums.BasicACL), container.BasicAcl); + var basicAclName = Enum.GetName(typeof(BasicACL), container.BasicAcl); if (basicAclName is null) { throw new ArgumentException($"Unknown BasicACL rule. Value: '{container.BasicAcl}'."); } return new ModelsV2.Container( - Enum.Parse(basicAclName), + Enum.Parse(basicAclName), container.PlacementPolicy.ToModel() ) { diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ContainerId.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ContainerId.cs index eb26623..1bfd614 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ContainerId.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ContainerId.cs @@ -1,5 +1,5 @@ -using FrostFS.SDK.ModelsV2; using FrostFS.Refs; +using FrostFS.SDK.ModelsV2; using Google.Protobuf; namespace FrostFS.SDK.ClientV2.Mappers.GRPC; diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/MetaHeader.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/MetaHeader.cs index c32a466..d3bf04f 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/MetaHeader.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/MetaHeader.cs @@ -1,5 +1,6 @@ using FrostFS.SDK.ModelsV2; using FrostFS.Session; +using Version = FrostFS.Refs.Version; namespace FrostFS.SDK.ClientV2.Mappers.GRPC; @@ -9,7 +10,7 @@ public static class MetaHeaderMapper { return new RequestMetaHeader { - Version = new Refs.Version + Version = new Version { Major = (uint)metaHeader.Version.Major, Minor = (uint)metaHeader.Version.Minor, diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/PlacementPolicy.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/PlacementPolicy.cs index 7ca1d10..71f66ae 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/PlacementPolicy.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/PlacementPolicy.cs @@ -1,4 +1,5 @@ using FrostFS.Netmap; +using Replica = FrostFS.SDK.ModelsV2.Netmap.Replica; namespace FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap; @@ -23,7 +24,7 @@ public static class PlacementPolicyMapper public static ModelsV2.Netmap.PlacementPolicy ToModel(this PlacementPolicy placementPolicy) { - var replicas = new List(); + var replicas = new List(); foreach (var replica in placementPolicy.Replicas) { replicas.Add(replica.ToModel()); diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Object.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Object.cs index d476106..a457891 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Object.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Object.cs @@ -1,11 +1,11 @@ +using FrostFS.Object; using FrostFS.SDK.ModelsV2; -using FrostFS.SDK.ModelsV2.Enums; namespace FrostFS.SDK.ClientV2.Mappers.GRPC; public static class ObjectHeadMapper { - public static ObjectHead ToModel(this Object.Header head) + public static ObjectHead ToModel(this Header head) { // var obtype = Enum.Parse(head.ObjectType.ToString()); return new ObjectHead diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ObjectId.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ObjectId.cs index c6baae9..4c28035 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ObjectId.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ObjectId.cs @@ -1,5 +1,5 @@ -using FrostFS.SDK.ModelsV2; using FrostFS.Refs; +using FrostFS.SDK.ModelsV2; using Google.Protobuf; namespace FrostFS.SDK.ClientV2.Mappers.GRPC; diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/OwnerId.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/OwnerId.cs index 8259478..4bea66d 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/OwnerId.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/OwnerId.cs @@ -1,5 +1,5 @@ -using FrostFS.SDK.ModelsV2; using FrostFS.Refs; +using FrostFS.SDK.ModelsV2; using Google.Protobuf; namespace FrostFS.SDK.ClientV2.Mappers.GRPC; diff --git a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Version.cs b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Version.cs index db8601d..549ff1a 100644 --- a/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Version.cs +++ b/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Version.cs @@ -1,17 +1,19 @@ +using Version = FrostFS.Refs.Version; + namespace FrostFS.SDK.ClientV2.Mappers.GRPC; public static class VersionMapper { - public static Refs.Version ToGrpcMessage(this ModelsV2.Version version) + public static Version ToGrpcMessage(this ModelsV2.Version version) { - return new Refs.Version + return new Version { Major = (uint)version.Major, Minor = (uint)version.Minor }; } - public static ModelsV2.Version ToModel(this Refs.Version version) + public static ModelsV2.Version ToModel(this Version version) { return new ModelsV2.Version((int)version.Major, (int)version.Minor); } diff --git a/src/FrostFS.SDK.ClientV2/RequestSigner.cs b/src/FrostFS.SDK.ClientV2/RequestSigner.cs index ea4f4e2..88c64c3 100644 --- a/src/FrostFS.SDK.ClientV2/RequestSigner.cs +++ b/src/FrostFS.SDK.ClientV2/RequestSigner.cs @@ -1,7 +1,7 @@ using System.Security.Cryptography; using FrostFS.Refs; -using FrostFS.Session; using FrostFS.SDK.Cryptography; +using FrostFS.Session; using Google.Protobuf; using Org.BouncyCastle.Asn1.Sec; using Org.BouncyCastle.Crypto.Digests; diff --git a/src/FrostFS.SDK.ClientV2/RequestVerifier.cs b/src/FrostFS.SDK.ClientV2/RequestVerifier.cs index 400c16a..5301e76 100644 --- a/src/FrostFS.SDK.ClientV2/RequestVerifier.cs +++ b/src/FrostFS.SDK.ClientV2/RequestVerifier.cs @@ -1,7 +1,7 @@ using System.Security.Cryptography; using FrostFS.Refs; -using FrostFS.Session; using FrostFS.SDK.Cryptography; +using FrostFS.Session; using Google.Protobuf; using Org.BouncyCastle.Asn1.Sec; using Org.BouncyCastle.Crypto.Digests; diff --git a/src/FrostFS.SDK.ClientV2/Services/Object.cs b/src/FrostFS.SDK.ClientV2/Services/Object.cs index 499423f..1a4b548 100644 --- a/src/FrostFS.SDK.ClientV2/Services/Object.cs +++ b/src/FrostFS.SDK.ClientV2/Services/Object.cs @@ -2,6 +2,7 @@ using FrostFS.Object; using FrostFS.Refs; using FrostFS.SDK.ClientV2.Mappers.GRPC; using FrostFS.SDK.Cryptography; +using FrostFS.SDK.ModelsV2; using FrostFS.Session; using Google.Protobuf; using Grpc.Core; @@ -56,8 +57,8 @@ public partial class Client request.Sign(_key); using var stream = await InitObject(request); - var buffer = new byte[ModelsV2.Constants.ObjectChunkSize]; - var bufferLength = data.Read(buffer, 0, ModelsV2.Constants.ObjectChunkSize); + var buffer = new byte[Constants.ObjectChunkSize]; + var bufferLength = data.Read(buffer, 0, Constants.ObjectChunkSize); while (bufferLength > 0) { request.Body = new PutRequest.Types.Body @@ -67,7 +68,7 @@ public partial class Client request.VerifyHeader = null; request.Sign(_key); await stream.Write(request); - bufferLength = data.Read(buffer, 0, ModelsV2.Constants.ObjectChunkSize); + bufferLength = data.Read(buffer, 0, Constants.ObjectChunkSize); } return await stream.Close(); } diff --git a/src/FrostFS.SDK.Cryptography/Key.cs b/src/FrostFS.SDK.Cryptography/Key.cs index c5a3393..15b888f 100644 --- a/src/FrostFS.SDK.Cryptography/Key.cs +++ b/src/FrostFS.SDK.Cryptography/Key.cs @@ -2,7 +2,6 @@ using System.Numerics; using System.Security.Cryptography; using System.Text; -using Google.Protobuf; using Org.BouncyCastle.Asn1.Sec; namespace FrostFS.SDK.Cryptography; diff --git a/src/FrostFS.SDK.ModelsV2/Container.cs b/src/FrostFS.SDK.ModelsV2/Container.cs index 7d798d3..d205bf6 100644 --- a/src/FrostFS.SDK.ModelsV2/Container.cs +++ b/src/FrostFS.SDK.ModelsV2/Container.cs @@ -1,3 +1,4 @@ +using FrostFS.SDK.ModelsV2.Enums; using FrostFS.SDK.ModelsV2.Netmap; namespace FrostFS.SDK.ModelsV2; @@ -5,11 +6,11 @@ namespace FrostFS.SDK.ModelsV2; public class Container { public Guid Nonce { get; set; } - public Enums.BasicACL BasicAcl { get; set; } + public BasicACL BasicAcl { get; set; } public PlacementPolicy PlacementPolicy { get; set; } public Version? Version { get; set; } - public Container(Enums.BasicACL basicAcl, PlacementPolicy placementPolicy) + public Container(BasicACL basicAcl, PlacementPolicy placementPolicy) { Nonce = Guid.NewGuid(); BasicAcl = basicAcl; diff --git a/src/FrostFS.SDK.ModelsV2/Object.cs b/src/FrostFS.SDK.ModelsV2/Object.cs index 46664e6..b588eab 100644 --- a/src/FrostFS.SDK.ModelsV2/Object.cs +++ b/src/FrostFS.SDK.ModelsV2/Object.cs @@ -5,5 +5,24 @@ public class ObjectHead { public ContainerId ContainerId { get; set; } public long Size { get; set; } - public Version Version { get; set; } + public Version? Version { get; set; } +} + +public class Object : ObjectHead +{ + public Stream Payload { get; set; } + + public Object(ContainerId containerId, Stream payload) + { + ContainerId = containerId; + Payload = payload; + Size = Payload.Length; + } + + public Object(ContainerId containerId, byte[] payload) + { + ContainerId = containerId; + Payload = new MemoryStream(payload); + Size = Payload.Length; + } } \ No newline at end of file diff --git a/src/FrostFS.SDK.ProtosV2/Interfaces/IRequest.cs b/src/FrostFS.SDK.ProtosV2/Interfaces/IRequest.cs index 6dd9cf7..6c0b264 100644 --- a/src/FrostFS.SDK.ProtosV2/Interfaces/IRequest.cs +++ b/src/FrostFS.SDK.ProtosV2/Interfaces/IRequest.cs @@ -1,5 +1,3 @@ -using FrostFS.Session; - namespace FrostFS.Session { public interface IRequest : IVerificableMessage diff --git a/src/FrostFS.SDK.ProtosV2/container/Extension.Message.cs b/src/FrostFS.SDK.ProtosV2/container/Extension.Message.cs index fd6535c..3c54a01 100644 --- a/src/FrostFS.SDK.ProtosV2/container/Extension.Message.cs +++ b/src/FrostFS.SDK.ProtosV2/container/Extension.Message.cs @@ -1,5 +1,5 @@ -using Google.Protobuf; using FrostFS.Session; +using Google.Protobuf; namespace FrostFS.Container { diff --git a/src/FrostFS.SDK.ProtosV2/netmap/Extension.Message.cs b/src/FrostFS.SDK.ProtosV2/netmap/Extension.Message.cs index 350cf74..8ab7c04 100644 --- a/src/FrostFS.SDK.ProtosV2/netmap/Extension.Message.cs +++ b/src/FrostFS.SDK.ProtosV2/netmap/Extension.Message.cs @@ -1,5 +1,5 @@ -using Google.Protobuf; -using FrostFS.Session; +using FrostFS.Session; +using Google.Protobuf; namespace FrostFS.Netmap { diff --git a/src/FrostFS.SDK.Service/Service.cs b/src/FrostFS.SDK.Service/Service.cs index bc11d34..0cd0ad4 100644 --- a/src/FrostFS.SDK.Service/Service.cs +++ b/src/FrostFS.SDK.Service/Service.cs @@ -52,15 +52,9 @@ public class FrostFsService return getObjectHeadResponse.Body.Header.Header.ToModel(); } - public async Task PutObjectAsync(ContainerId containerId, Stream data) + public async Task PutObjectAsync(ModelsV2.Object obj) { - var putObjectResponse = await _client.PutObjectAsync(containerId.ToGrpcMessage(), data); - return ObjectId.FromHash(putObjectResponse.Body.ObjectId.Value.ToByteArray()); - } - - public async Task PutObjectAsync(ContainerId containerId, byte[] data) - { - var putObjectResponse = await _client.PutObjectAsync(containerId.ToGrpcMessage(), new MemoryStream(data)); + var putObjectResponse = await _client.PutObjectAsync(obj.ContainerId.ToGrpcMessage(), obj.Payload); return ObjectId.FromHash(putObjectResponse.Body.ObjectId.Value.ToByteArray()); }