45 lines
No EOL
1.3 KiB
C#
45 lines
No EOL
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
|
|
using FrostFS.Netmap;
|
|
using FrostFS.SDK.Client.Mappers.GRPC;
|
|
|
|
namespace FrostFS.SDK.Client;
|
|
|
|
public static class NodeInfoMapper
|
|
{
|
|
public static FrostFsNodeInfo ToModel(this LocalNodeInfoResponse.Types.Body node)
|
|
{
|
|
if (node is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(node));
|
|
}
|
|
|
|
return node.NodeInfo.ToModel(node.Version);
|
|
}
|
|
|
|
public static FrostFsNodeInfo ToModel(this NodeInfo nodeInfo, Refs.Version version)
|
|
{
|
|
if (nodeInfo is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(nodeInfo));
|
|
}
|
|
|
|
NodeState state = nodeInfo.State switch
|
|
{
|
|
NodeInfo.Types.State.Unspecified => NodeState.Unspecified,
|
|
NodeInfo.Types.State.Online => NodeState.Online,
|
|
NodeInfo.Types.State.Offline => NodeState.Offline,
|
|
NodeInfo.Types.State.Maintenance => NodeState.Maintenance,
|
|
_ => throw new ArgumentException($"Unknown NodeState. Value: '{nodeInfo.State}'.")
|
|
};
|
|
|
|
return new FrostFsNodeInfo(
|
|
version: version.ToModel(),
|
|
state: state,
|
|
addresses: [.. nodeInfo.Addresses],
|
|
attributes: nodeInfo.Attributes.ToDictionary(n => n.Key, n => n.Value),
|
|
publicKey: nodeInfo.PublicKey.Memory
|
|
);
|
|
}
|
|
} |