forked from TrueCloudLab/frostfs-sdk-java
[#1] add client environment
add client cut code cleanup Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
dc0eef770c
commit
b0db7df192
95 changed files with 1202 additions and 560 deletions
38
models/pom.xml
Normal file
38
models/pom.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>info.FrostFS.sdk</groupId>
|
||||
<artifactId>FrostFS-sdk-java</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>models</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.14.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.FrostFS.sdk</groupId>
|
||||
<artifactId>cryptography</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.FrostFS.sdk</groupId>
|
||||
<artifactId>protos</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
21
models/src/main/java/info/FrostFS/sdk/UUIDExtension.java
Normal file
21
models/src/main/java/info/FrostFS/sdk/UUIDExtension.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package info.FrostFS.sdk;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDExtension {
|
||||
|
||||
public static UUID asUuid(byte[] bytes) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||
long firstLong = bb.getLong();
|
||||
long secondLong = bb.getLong();
|
||||
return new UUID(firstLong, secondLong);
|
||||
}
|
||||
|
||||
public static byte[] asBytes(UUID id) {
|
||||
ByteBuffer bb = ByteBuffer.allocate(16);
|
||||
bb.putLong(id.getMostSignificantBits());
|
||||
bb.putLong(id.getLeastSignificantBits());
|
||||
return bb.array();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package info.FrostFS.sdk.constants;
|
||||
|
||||
public class AppConst {
|
||||
public static final int OBJECT_CHUNK_SIZE = 3 * (1 << 20);
|
||||
public static final int SHA256_HASH_LENGTH = 32;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package info.FrostFS.sdk.constants;
|
||||
|
||||
public class XHeaderConst {
|
||||
public static final String RESERVED_XHEADER_PREFIX = "__SYSTEM__";
|
||||
public static final String XHEADER_NETMAP_EPOCH = RESERVED_XHEADER_PREFIX + "NETMAP_EPOCH";
|
||||
public static final String XHEADER_NETMAP_LOOKUP_DEPTH = RESERVED_XHEADER_PREFIX + "NETMAP_LOOKUP_DEPTH";
|
||||
}
|
41
models/src/main/java/info/FrostFS/sdk/dto/MetaHeader.java
Normal file
41
models/src/main/java/info/FrostFS/sdk/dto/MetaHeader.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
public class MetaHeader {
|
||||
private Version version;
|
||||
private int epoch;
|
||||
private int ttl;
|
||||
|
||||
public MetaHeader(Version version, int epoch, int ttl) {
|
||||
this.version = version;
|
||||
this.epoch = epoch;
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
public static MetaHeader getDefault() {
|
||||
return new MetaHeader(new Version(2, 13), 0, 2);
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Version version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getEpoch() {
|
||||
return epoch;
|
||||
}
|
||||
|
||||
public void setEpoch(int epoch) {
|
||||
this.epoch = epoch;
|
||||
}
|
||||
|
||||
public int getTtl() {
|
||||
return ttl;
|
||||
}
|
||||
|
||||
public void setTtl(int ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
}
|
25
models/src/main/java/info/FrostFS/sdk/dto/OwnerId.java
Normal file
25
models/src/main/java/info/FrostFS/sdk/dto/OwnerId.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import info.FrostFS.sdk.Base58;
|
||||
|
||||
import static info.FrostFS.sdk.KeyExtension.publicKeyToAddress;
|
||||
|
||||
public class OwnerId {
|
||||
private final String value;
|
||||
|
||||
public OwnerId(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static OwnerId fromKey(byte[] publicKey) {
|
||||
return new OwnerId(publicKeyToAddress(publicKey));
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public byte[] toHash() {
|
||||
return Base58.decode(value);
|
||||
}
|
||||
}
|
19
models/src/main/java/info/FrostFS/sdk/dto/SessionToken.java
Normal file
19
models/src/main/java/info/FrostFS/sdk/dto/SessionToken.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
public class SessionToken {
|
||||
private final byte[] id;
|
||||
private final byte[] sessionKey;
|
||||
|
||||
public SessionToken(byte[] id, byte[] sessionKey) {
|
||||
this.id = id;
|
||||
this.sessionKey = sessionKey;
|
||||
}
|
||||
|
||||
public byte[] getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public byte[] getSessionKey() {
|
||||
return sessionKey;
|
||||
}
|
||||
}
|
33
models/src/main/java/info/FrostFS/sdk/dto/Signature.java
Normal file
33
models/src/main/java/info/FrostFS/sdk/dto/Signature.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import info.FrostFS.sdk.enums.SignatureScheme;
|
||||
|
||||
public class Signature {
|
||||
private byte[] key;
|
||||
private byte[] sign;
|
||||
private SignatureScheme scheme;
|
||||
|
||||
public byte[] getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(byte[] key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public byte[] getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(byte[] sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public SignatureScheme getScheme() {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public void setScheme(SignatureScheme scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
}
|
69
models/src/main/java/info/FrostFS/sdk/dto/Split.java
Normal file
69
models/src/main/java/info/FrostFS/sdk/dto/Split.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Split {
|
||||
private final List<ObjectId> children;
|
||||
private SplitId splitId;
|
||||
private ObjectId parent;
|
||||
private ObjectId previous;
|
||||
private Signature parentSignature;
|
||||
private ObjectHeader parentHeader;
|
||||
|
||||
public Split() {
|
||||
this(new SplitId());
|
||||
}
|
||||
|
||||
public Split(SplitId splitId) {
|
||||
this.splitId = splitId;
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
|
||||
public SplitId getSplitId() {
|
||||
return splitId;
|
||||
}
|
||||
|
||||
private void setSplitId(SplitId splitId) {
|
||||
this.splitId = splitId;
|
||||
}
|
||||
|
||||
public ObjectId getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(ObjectId parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public ObjectId getPrevious() {
|
||||
return previous;
|
||||
}
|
||||
|
||||
public void setPrevious(ObjectId previous) {
|
||||
this.previous = previous;
|
||||
}
|
||||
|
||||
public Signature getParentSignature() {
|
||||
return parentSignature;
|
||||
}
|
||||
|
||||
public void setParentSignature(Signature parentSignature) {
|
||||
this.parentSignature = parentSignature;
|
||||
}
|
||||
|
||||
public ObjectHeader getParentHeader() {
|
||||
return parentHeader;
|
||||
}
|
||||
|
||||
public void setParentHeader(ObjectHeader parentHeader) {
|
||||
this.parentHeader = parentHeader;
|
||||
}
|
||||
|
||||
public List<ObjectId> getChildren() {
|
||||
return children;
|
||||
}
|
||||
}
|
44
models/src/main/java/info/FrostFS/sdk/dto/SplitId.java
Normal file
44
models/src/main/java/info/FrostFS/sdk/dto/SplitId.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static info.FrostFS.sdk.UUIDExtension.asBytes;
|
||||
import static info.FrostFS.sdk.UUIDExtension.asUuid;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class SplitId {
|
||||
private final UUID id;
|
||||
|
||||
public SplitId(UUID uuid) {
|
||||
this.id = uuid;
|
||||
}
|
||||
|
||||
public SplitId() {
|
||||
this.id = UUID.randomUUID();
|
||||
}
|
||||
|
||||
private SplitId(byte[] binary) {
|
||||
this.id = asUuid(binary);
|
||||
}
|
||||
|
||||
private SplitId(String str) {
|
||||
this.id = UUID.fromString(str);
|
||||
}
|
||||
|
||||
public static SplitId createFromBinary(byte[] binaryData) {
|
||||
return new SplitId(binaryData);
|
||||
}
|
||||
|
||||
public static SplitId createFromString(String stringData) {
|
||||
return new SplitId(stringData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
public byte[] toBinary() {
|
||||
return isNull(id) ? null : asBytes(id);
|
||||
}
|
||||
}
|
45
models/src/main/java/info/FrostFS/sdk/dto/Status.java
Normal file
45
models/src/main/java/info/FrostFS/sdk/dto/Status.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import info.FrostFS.sdk.enums.StatusCode;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class Status {
|
||||
private StatusCode code;
|
||||
private String message;
|
||||
|
||||
public Status(StatusCode code, String message) {
|
||||
this.code = code;
|
||||
this.message = isNull(message) ? "" : message;
|
||||
}
|
||||
|
||||
public Status(StatusCode code) {
|
||||
this.code = code;
|
||||
this.message = "";
|
||||
}
|
||||
|
||||
public StatusCode getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(StatusCode code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Response status: %s. Message: %s.", code, message);
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return StatusCode.SUCCESS.equals(code);
|
||||
}
|
||||
}
|
36
models/src/main/java/info/FrostFS/sdk/dto/Version.java
Normal file
36
models/src/main/java/info/FrostFS/sdk/dto/Version.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package info.FrostFS.sdk.dto;
|
||||
|
||||
public class Version {
|
||||
private int major;
|
||||
private int minor;
|
||||
|
||||
public Version(int major, int minor) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
}
|
||||
|
||||
public void setMajor(int major) {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return minor;
|
||||
}
|
||||
|
||||
public void setMinor(int minor) {
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "v" + major + "." + minor;
|
||||
}
|
||||
|
||||
public boolean isSupported(Version version) {
|
||||
return major == version.getMajor();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package info.FrostFS.sdk.dto.container;
|
||||
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.enums.BasicAcl;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Container {
|
||||
private UUID nonce;
|
||||
private BasicAcl basicAcl;
|
||||
private PlacementPolicy placementPolicy;
|
||||
private Version version;
|
||||
|
||||
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy) {
|
||||
this.nonce = UUID.randomUUID();
|
||||
this.basicAcl = basicAcl;
|
||||
this.placementPolicy = placementPolicy;
|
||||
}
|
||||
|
||||
public UUID getNonce() {
|
||||
return nonce;
|
||||
}
|
||||
|
||||
public void setNonce(UUID nonce) {
|
||||
this.nonce = nonce;
|
||||
}
|
||||
|
||||
public BasicAcl getBasicAcl() {
|
||||
return basicAcl;
|
||||
}
|
||||
|
||||
public void setBasicAcl(BasicAcl basicAcl) {
|
||||
this.basicAcl = basicAcl;
|
||||
}
|
||||
|
||||
public PlacementPolicy getPlacementPolicy() {
|
||||
return placementPolicy;
|
||||
}
|
||||
|
||||
public void setPlacementPolicy(PlacementPolicy placementPolicy) {
|
||||
this.placementPolicy = placementPolicy;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Version version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package info.FrostFS.sdk.dto.container;
|
||||
|
||||
import info.FrostFS.sdk.Base58;
|
||||
import info.FrostFS.sdk.constants.AppConst;
|
||||
|
||||
public class ContainerId {
|
||||
private String value;
|
||||
|
||||
public ContainerId(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ContainerId fromHash(byte[] hash) {
|
||||
if (hash.length != AppConst.SHA256_HASH_LENGTH) {
|
||||
throw new IllegalArgumentException("ContainerID must be a sha256 hash.");
|
||||
}
|
||||
return new ContainerId(Base58.encode(hash));
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public byte[] toHash() {
|
||||
return Base58.decode(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetmapSnapshot {
|
||||
private final Long epoch;
|
||||
private final List<NodeInfo> nodeInfoCollection;
|
||||
|
||||
public NetmapSnapshot(Long epoch, List<NodeInfo> nodeInfoCollection) {
|
||||
this.epoch = epoch;
|
||||
this.nodeInfoCollection = nodeInfoCollection;
|
||||
}
|
||||
|
||||
public Long getEpoch() {
|
||||
return epoch;
|
||||
}
|
||||
|
||||
public List<NodeInfo> getNodeInfoCollection() {
|
||||
return nodeInfoCollection;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.enums.NodeState;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NodeInfo {
|
||||
private final NodeState state;
|
||||
private final Version version;
|
||||
private final List<String> addresses;
|
||||
private final Map<String, String> attributes;
|
||||
private final byte[] publicKey;
|
||||
|
||||
public NodeInfo(NodeState state, Version version, List<String> addresses,
|
||||
Map<String, String> attributes, byte[] publicKey) {
|
||||
this.state = state;
|
||||
this.version = version;
|
||||
this.addresses = addresses;
|
||||
this.attributes = attributes;
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
public NodeState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public List<String> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
public class PlacementPolicy {
|
||||
private final Replica[] replicas;
|
||||
private final boolean unique;
|
||||
|
||||
public PlacementPolicy(boolean unique, Replica[] replicas) {
|
||||
this.replicas = replicas;
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
public Replica[] getReplicas() {
|
||||
return replicas;
|
||||
}
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class Replica {
|
||||
private int count;
|
||||
private String selector;
|
||||
|
||||
public Replica(int count, String selector) {
|
||||
this.count = count;
|
||||
this.selector = isNull(selector) ? "" : selector;
|
||||
}
|
||||
|
||||
public Replica(int count) {
|
||||
this.count = count;
|
||||
this.selector = "";
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getSelector() {
|
||||
return selector;
|
||||
}
|
||||
|
||||
public void setSelector(String selector) {
|
||||
this.selector = selector;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import static info.FrostFS.sdk.Helper.getSha256Instance;
|
||||
|
||||
public class LargeObject extends ObjectFrostFS {
|
||||
private final MessageDigest payloadHash;
|
||||
|
||||
public LargeObject(ContainerId cid) {
|
||||
super(cid, new byte[]{});
|
||||
this.payloadHash = getSha256Instance();
|
||||
}
|
||||
|
||||
public void appendBlock(byte[] bytes, int count) {
|
||||
this.getHeader().increasePayloadLength(count);
|
||||
this.payloadHash.update(bytes, 0, count);
|
||||
}
|
||||
|
||||
public void calculateHash() {
|
||||
this.getHeader().setPayloadCheckSum(this.payloadHash.digest());
|
||||
}
|
||||
|
||||
public long getPayloadLength() {
|
||||
return getHeader().getPayloadLength();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.dto.Split;
|
||||
import info.FrostFS.sdk.dto.SplitId;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LinkObject extends ObjectFrostFS {
|
||||
|
||||
public LinkObject(ContainerId cid, SplitId splitId, LargeObject largeObject) {
|
||||
super(cid, new byte[]{});
|
||||
var split = new Split(splitId);
|
||||
split.setParentHeader(largeObject.getHeader());
|
||||
this.getHeader().setSplit(split);
|
||||
}
|
||||
|
||||
public void addChildren(List<ObjectId> objectIds) {
|
||||
this.getHeader().getSplit().getChildren().addAll(objectIds);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
public class ObjectAttribute {
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public ObjectAttribute(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.dto.OwnerId;
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.enums.ObjectMatchType;
|
||||
|
||||
public class ObjectFilter {
|
||||
private static final String HEADER_PREFIX = "$Object:";
|
||||
|
||||
private ObjectMatchType matchType;
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
|
||||
public ObjectFilter(ObjectMatchType matchType, String key, String value) {
|
||||
this.matchType = matchType;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ObjectFilter ObjectIdFilter(ObjectMatchType matchType, ObjectId objectId) {
|
||||
return new ObjectFilter(matchType, HEADER_PREFIX + "objectID", objectId.getValue());
|
||||
}
|
||||
|
||||
public static ObjectFilter OwnerFilter(ObjectMatchType matchType, OwnerId ownerId) {
|
||||
return new ObjectFilter(matchType, HEADER_PREFIX + "ownerID", ownerId.getValue());
|
||||
}
|
||||
|
||||
public static ObjectFilter RootFilter() {
|
||||
return new ObjectFilter(ObjectMatchType.UNSPECIFIED, HEADER_PREFIX + "ROOT", "");
|
||||
}
|
||||
|
||||
public static ObjectFilter VersionFilter(ObjectMatchType matchType, Version version) {
|
||||
return new ObjectFilter(matchType, HEADER_PREFIX + "version", version.toString());
|
||||
}
|
||||
|
||||
public ObjectMatchType getMatchType() {
|
||||
return matchType;
|
||||
}
|
||||
|
||||
public void setMatchType(ObjectMatchType matchType) {
|
||||
this.matchType = matchType;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.dto.Split;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.enums.ObjectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectFrostFS {
|
||||
private ObjectHeader header;
|
||||
private ObjectId objectId;
|
||||
private byte[] payload;
|
||||
|
||||
public ObjectFrostFS(ObjectHeader header, ObjectId objectId, byte[] payload) {
|
||||
this.header = header;
|
||||
this.objectId = objectId;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public ObjectFrostFS(ContainerId container, byte[] payload) {
|
||||
this.payload = payload;
|
||||
this.header = new ObjectHeader(container, new ArrayList<>());
|
||||
}
|
||||
|
||||
public ObjectFrostFS(ContainerId container, byte[] payload, ObjectType objectType) {
|
||||
this.payload = payload;
|
||||
this.header = new ObjectHeader(container, objectType, new ArrayList<>());
|
||||
}
|
||||
|
||||
public ObjectHeader getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(ObjectHeader header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public ObjectId getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
private void setObjectId(ObjectId objectId) {
|
||||
this.objectId = objectId;
|
||||
}
|
||||
|
||||
public byte[] getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(byte[] payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public void setSplit(Split split) {
|
||||
header.setSplit(split);
|
||||
}
|
||||
|
||||
public void addAttribute(String key, String value) {
|
||||
header.getAttributes().add(new ObjectAttribute(key, value));
|
||||
}
|
||||
|
||||
public void addAttribute(ObjectAttribute attribute) {
|
||||
header.getAttributes().add(attribute);
|
||||
}
|
||||
|
||||
public void addAttributes(List<ObjectAttribute> attributes) {
|
||||
header.getAttributes().addAll(attributes);
|
||||
}
|
||||
|
||||
public void setParent(LargeObject largeObject) {
|
||||
if (isNull(header.getSplit())) {
|
||||
throw new IllegalArgumentException("The object is not initialized properly");
|
||||
}
|
||||
|
||||
header.getSplit().setParentHeader(largeObject.getHeader());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.dto.OwnerId;
|
||||
import info.FrostFS.sdk.dto.Split;
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.enums.ObjectType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ObjectHeader {
|
||||
private List<ObjectAttribute> attributes;
|
||||
private ContainerId containerId;
|
||||
private long size;
|
||||
private ObjectType objectType;
|
||||
private Version version;
|
||||
private OwnerId ownerId;
|
||||
private long payloadLength;
|
||||
private byte[] payloadCheckSum;
|
||||
private Split split;
|
||||
|
||||
public ObjectHeader(ContainerId containerId, ObjectType objectType,
|
||||
List<ObjectAttribute> attributes, long size, Version version) {
|
||||
this.attributes = attributes;
|
||||
this.containerId = containerId;
|
||||
this.size = size;
|
||||
this.objectType = objectType;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public ObjectHeader(ContainerId containerId, ObjectType type, List<ObjectAttribute> attributes) {
|
||||
this.attributes = attributes;
|
||||
this.containerId = containerId;
|
||||
this.objectType = type;
|
||||
}
|
||||
|
||||
public ObjectHeader(ContainerId containerId, List<ObjectAttribute> attributes) {
|
||||
this.attributes = attributes;
|
||||
this.containerId = containerId;
|
||||
this.objectType = ObjectType.REGULAR;
|
||||
}
|
||||
|
||||
public OwnerId getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(OwnerId ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public long getPayloadLength() {
|
||||
return payloadLength;
|
||||
}
|
||||
|
||||
public void setPayloadLength(long payloadLength) {
|
||||
this.payloadLength = payloadLength;
|
||||
}
|
||||
|
||||
public void increasePayloadLength(long payloadLength) {
|
||||
this.payloadLength += payloadLength;
|
||||
}
|
||||
|
||||
public byte[] getPayloadCheckSum() {
|
||||
return payloadCheckSum;
|
||||
}
|
||||
|
||||
public void setPayloadCheckSum(byte[] payloadCheckSum) {
|
||||
this.payloadCheckSum = payloadCheckSum;
|
||||
}
|
||||
|
||||
public Split getSplit() {
|
||||
return split;
|
||||
}
|
||||
|
||||
public void setSplit(Split split) {
|
||||
this.split = split;
|
||||
}
|
||||
|
||||
public List<ObjectAttribute> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(List<ObjectAttribute> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public ContainerId getContainerId() {
|
||||
return containerId;
|
||||
}
|
||||
|
||||
public void setContainerId(ContainerId containerId) {
|
||||
this.containerId = containerId;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public ObjectType getObjectType() {
|
||||
return objectType;
|
||||
}
|
||||
|
||||
public void setObjectType(ObjectType objectType) {
|
||||
this.objectType = objectType;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Version version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.Base58;
|
||||
import info.FrostFS.sdk.constants.AppConst;
|
||||
|
||||
public class ObjectId {
|
||||
private final String value;
|
||||
|
||||
public ObjectId(String id) {
|
||||
this.value = id;
|
||||
}
|
||||
|
||||
public static ObjectId fromHash(byte[] hash) {
|
||||
if (hash.length != AppConst.SHA256_HASH_LENGTH) {
|
||||
throw new IllegalArgumentException("ObjectId must be a sha256 hash.");
|
||||
}
|
||||
return new ObjectId(Base58.encode(hash));
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public byte[] toHash() {
|
||||
return Base58.decode(value);
|
||||
}
|
||||
}
|
33
models/src/main/java/info/FrostFS/sdk/enums/BasicAcl.java
Normal file
33
models/src/main/java/info/FrostFS/sdk/enums/BasicAcl.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package info.FrostFS.sdk.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum BasicAcl {
|
||||
PRIVATE(0x1C8C8CCC),
|
||||
PUBLIC_RO(0x1FBF8CFF),
|
||||
PUBLIC_RW(0x1FBFBFFF),
|
||||
PUBLIC_APPEND(0x1FBF9FFF),
|
||||
;
|
||||
|
||||
private static final Map<Integer, BasicAcl> ENUM_MAP_BY_VALUE;
|
||||
|
||||
static {
|
||||
Map<Integer, BasicAcl> map = new HashMap<>();
|
||||
for (BasicAcl basicAcl : BasicAcl.values()) {
|
||||
map.put(basicAcl.value, basicAcl);
|
||||
}
|
||||
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public final int value;
|
||||
|
||||
BasicAcl(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static BasicAcl get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(value);
|
||||
}
|
||||
}
|
33
models/src/main/java/info/FrostFS/sdk/enums/NodeState.java
Normal file
33
models/src/main/java/info/FrostFS/sdk/enums/NodeState.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package info.FrostFS.sdk.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum NodeState {
|
||||
UNSPECIFIED(0),
|
||||
ONLINE(1),
|
||||
OFFLINE(2),
|
||||
MAINTENANCE(3),
|
||||
;
|
||||
|
||||
private static final Map<Integer, NodeState> ENUM_MAP_BY_VALUE;
|
||||
|
||||
static {
|
||||
Map<Integer, NodeState> map = new HashMap<>();
|
||||
for (NodeState nodeState : NodeState.values()) {
|
||||
map.put(nodeState.value, nodeState);
|
||||
}
|
||||
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public final int value;
|
||||
|
||||
NodeState(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static NodeState get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package info.FrostFS.sdk.enums;
|
||||
|
||||
public enum ObjectMatchType {
|
||||
UNSPECIFIED(0),
|
||||
EQUALS(1),
|
||||
NOT_EQUALS(2),
|
||||
KEY_ABSENT(3),
|
||||
STARTS_WITH(4),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
ObjectMatchType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
32
models/src/main/java/info/FrostFS/sdk/enums/ObjectType.java
Normal file
32
models/src/main/java/info/FrostFS/sdk/enums/ObjectType.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package info.FrostFS.sdk.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ObjectType {
|
||||
REGULAR(0),
|
||||
TOMBSTONE(1),
|
||||
LOCK(3),
|
||||
;
|
||||
|
||||
private static final Map<Integer, ObjectType> ENUM_MAP_BY_VALUE;
|
||||
|
||||
static {
|
||||
Map<Integer, ObjectType> map = new HashMap<>();
|
||||
for (ObjectType objectType : ObjectType.values()) {
|
||||
map.put(objectType.value, objectType);
|
||||
}
|
||||
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public final int value;
|
||||
|
||||
ObjectType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ObjectType get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package info.FrostFS.sdk.enums;
|
||||
|
||||
public enum SignatureScheme {
|
||||
ECDSA_SHA512(0),
|
||||
ECDSA_RFC6979_SHA256(1),
|
||||
ECDSA_RFC6979_SHA256_WALLET_CONNECT(2),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
SignatureScheme(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
46
models/src/main/java/info/FrostFS/sdk/enums/StatusCode.java
Normal file
46
models/src/main/java/info/FrostFS/sdk/enums/StatusCode.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package info.FrostFS.sdk.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum StatusCode {
|
||||
SUCCESS(0),
|
||||
INTERNAL(1024),
|
||||
WRONG_MAGIC_NUMBER(1025),
|
||||
SIGNATURE_VERIFICATION_FAILURE(1026),
|
||||
NODE_UNDER_MAINTENANCE(1027),
|
||||
OBJECT_ACCESS_DENIED(2048),
|
||||
OBJECT_NOT_FOUND(2049),
|
||||
OBJECT_LOCKED(2050),
|
||||
LOCK_NOT_REGULAR_OBJECT(2051),
|
||||
OBJECT_ALREADY_REMOVED(2052),
|
||||
OUT_OF_RANGE(2053),
|
||||
CONTAINER_NOT_FOUND(3072),
|
||||
E_ACL_NOT_FOUND(3073),
|
||||
CONTAINER_ACCESS_DENIED(3074),
|
||||
TOKEN_NOT_FOUND(4096),
|
||||
TOKEN_EXPIRED(4097),
|
||||
APE_MANAGER_ACCESS_DENIED(5120),
|
||||
;
|
||||
|
||||
private static final Map<Integer, StatusCode> ENUM_MAP_BY_VALUE;
|
||||
|
||||
static {
|
||||
Map<Integer, StatusCode> map = new HashMap<>();
|
||||
for (StatusCode statusCode : StatusCode.values()) {
|
||||
map.put(statusCode.value, statusCode);
|
||||
}
|
||||
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public final int value;
|
||||
|
||||
StatusCode(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static StatusCode get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.session.Types;
|
||||
import info.FrostFS.sdk.dto.MetaHeader;
|
||||
|
||||
public class MetaHeaderMapper {
|
||||
|
||||
public static Types.RequestMetaHeader toGrpcMessage(MetaHeader metaHeader) {
|
||||
return Types.RequestMetaHeader.newBuilder()
|
||||
.setVersion(VersionMapper.toGrpcMessage(metaHeader.getVersion()))
|
||||
.setEpoch(metaHeader.getEpoch())
|
||||
.setTtl(metaHeader.getTtl())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.dto.OwnerId;
|
||||
|
||||
public class OwnerIdMapper {
|
||||
|
||||
public static Types.OwnerID toGrpcMessage(OwnerId ownerId) {
|
||||
return Types.OwnerID.newBuilder()
|
||||
.setValue(ByteString.copyFrom(ownerId.toHash()))
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import com.google.protobuf.CodedOutputStream;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import frostFS.session.Types;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SessionMapper {
|
||||
|
||||
public static byte[] serialize(Types.SessionToken token) {
|
||||
try {
|
||||
byte[] bytes = new byte[token.getSerializedSize()];
|
||||
CodedOutputStream stream = CodedOutputStream.newInstance(bytes);
|
||||
token.writeTo(stream);
|
||||
return bytes;
|
||||
} catch (IOException exp) {
|
||||
throw new IllegalArgumentException(exp.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static Types.SessionToken deserializeSessionToken(byte[] bytes) {
|
||||
try {
|
||||
return Types.SessionToken.newBuilder().mergeFrom(bytes).build();
|
||||
} catch (InvalidProtocolBufferException exp) {
|
||||
throw new IllegalArgumentException(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.dto.Signature;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class SignatureMapper {
|
||||
|
||||
public static Types.Signature ToGrpcMessage(Signature signature) {
|
||||
var scheme = Types.SignatureScheme.forNumber(signature.getScheme().value);
|
||||
if (isNull(scheme)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown SignatureScheme. Value: %s.", signature.getScheme().name())
|
||||
);
|
||||
}
|
||||
|
||||
return Types.Signature.newBuilder()
|
||||
.setKey(ByteString.copyFrom(signature.getKey()))
|
||||
.setSign(ByteString.copyFrom(signature.getSign()))
|
||||
.setScheme(scheme)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.status.Types;
|
||||
import info.FrostFS.sdk.dto.Status;
|
||||
import info.FrostFS.sdk.enums.StatusCode;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class StatusMapper {
|
||||
|
||||
public static Status toModel(Types.Status status) {
|
||||
if (isNull(status)) return new Status(StatusCode.SUCCESS);
|
||||
|
||||
var statusCode = StatusCode.get(status.getCode());
|
||||
if (isNull(statusCode)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown StatusCode. Value: %s.", status.getCode())
|
||||
);
|
||||
}
|
||||
|
||||
return new Status(statusCode, status.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
|
||||
public class VersionMapper {
|
||||
|
||||
public static Types.Version toGrpcMessage(Version version) {
|
||||
return Types.Version.newBuilder()
|
||||
.setMajor(version.getMajor())
|
||||
.setMinor(version.getMinor())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Version toModel(Types.Version version) {
|
||||
return new Version(version.getMajor(), version.getMinor());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package info.FrostFS.sdk.mappers.container;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
|
||||
public class ContainerIdMapper {
|
||||
|
||||
public static Types.ContainerID toGrpcMessage(ContainerId containerId) {
|
||||
return Types.ContainerID.newBuilder()
|
||||
.setValue(ByteString.copyFrom(containerId.toHash()))
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package info.FrostFS.sdk.mappers.container;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.container.Types;
|
||||
import info.FrostFS.sdk.dto.container.Container;
|
||||
import info.FrostFS.sdk.enums.BasicAcl;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
import info.FrostFS.sdk.mappers.netmap.PlacementPolicyMapper;
|
||||
|
||||
import static info.FrostFS.sdk.UUIDExtension.asBytes;
|
||||
import static info.FrostFS.sdk.UUIDExtension.asUuid;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ContainerMapper {
|
||||
|
||||
public static Types.Container toGrpcMessage(Container container) {
|
||||
return Types.Container.newBuilder()
|
||||
.setBasicAcl(container.getBasicAcl().value)
|
||||
.setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy()))
|
||||
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Container toModel(Types.Container containerGrpc) {
|
||||
var basicAcl = BasicAcl.get(containerGrpc.getBasicAcl());
|
||||
if (isNull(basicAcl)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown BasicACL rule. Value: %s.", containerGrpc.getBasicAcl())
|
||||
);
|
||||
}
|
||||
|
||||
var container = new Container(basicAcl, PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()));
|
||||
container.setNonce(asUuid(containerGrpc.getNonce().toByteArray()));
|
||||
container.setVersion(VersionMapper.toModel(containerGrpc.getVersion()));
|
||||
return container;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Service;
|
||||
import info.FrostFS.sdk.dto.netmap.NetmapSnapshot;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NetmapSnapshotMapper {
|
||||
|
||||
public static NetmapSnapshot toModel(Service.NetmapSnapshotResponse netmap) {
|
||||
return new NetmapSnapshot(
|
||||
netmap.getBody().getNetmap().getEpoch(),
|
||||
netmap.getBody().getNetmap().getNodesList().stream()
|
||||
.map(node -> NodeInfoMapper.toModel(node, netmap.getMetaHeader().getVersion()))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Service;
|
||||
import frostFS.netmap.Types.NodeInfo.Attribute;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.dto.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.enums.NodeState;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class NodeInfoMapper {
|
||||
|
||||
public static NodeInfo toModel(Service.LocalNodeInfoResponse.Body nodeInfo) {
|
||||
return toModel(nodeInfo.getNodeInfo(), nodeInfo.getVersion());
|
||||
}
|
||||
|
||||
public static NodeInfo toModel(frostFS.netmap.Types.NodeInfo nodeInfo, Types.Version version) {
|
||||
NodeState nodeState = NodeState.get(nodeInfo.getState().getNumber());
|
||||
if (isNull(nodeState)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown NodeState. Value: %s.", nodeInfo.getState())
|
||||
);
|
||||
}
|
||||
|
||||
return new NodeInfo(
|
||||
nodeState,
|
||||
VersionMapper.toModel(version),
|
||||
nodeInfo.getAddressesList(),
|
||||
nodeInfo.getAttributesList().stream().collect(Collectors.toMap(Attribute::getKey, Attribute::getValue)),
|
||||
nodeInfo.getPublicKey().toByteArray()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Types;
|
||||
import info.FrostFS.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.dto.netmap.Replica;
|
||||
|
||||
public class PlacementPolicyMapper {
|
||||
|
||||
public static Types.PlacementPolicy toGrpcMessage(PlacementPolicy placementPolicy) {
|
||||
var pp = Types.PlacementPolicy.newBuilder()
|
||||
.setUnique(placementPolicy.isUnique());
|
||||
|
||||
for (Replica replica : placementPolicy.getReplicas()) {
|
||||
pp.addReplicas(ReplicaMapper.toGrpcMessage(replica));
|
||||
}
|
||||
|
||||
return pp.build();
|
||||
}
|
||||
|
||||
public static PlacementPolicy toModel(Types.PlacementPolicy placementPolicy) {
|
||||
return new PlacementPolicy(
|
||||
placementPolicy.getUnique(),
|
||||
placementPolicy.getReplicasList().stream().map(ReplicaMapper::toModel).toArray(Replica[]::new)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Types;
|
||||
import info.FrostFS.sdk.dto.netmap.Replica;
|
||||
|
||||
public class ReplicaMapper {
|
||||
|
||||
public static Types.Replica toGrpcMessage(Replica replica) {
|
||||
return Types.Replica.newBuilder()
|
||||
.setCount(replica.getCount())
|
||||
.setSelector(replica.getSelector())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Replica toModel(Types.Replica replica) {
|
||||
return new Replica(replica.getCount(), replica.getSelector());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.dto.object.ObjectAttribute;
|
||||
|
||||
public class ObjectAttributeMapper {
|
||||
|
||||
public static Types.Header.Attribute toGrpcMessage(ObjectAttribute attribute) {
|
||||
return Types.Header.Attribute.newBuilder()
|
||||
.setKey(attribute.getKey())
|
||||
.setValue(attribute.getValue())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ObjectAttribute toModel(Types.Header.Attribute attribute) {
|
||||
return new ObjectAttribute(attribute.getKey(), attribute.getValue());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import frostFS.object.Service;
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFilter;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectFilterMapper {
|
||||
|
||||
public static Service.SearchRequest.Body.Filter toGrpcMessage(ObjectFilter filter) {
|
||||
var objectMatchType = Types.MatchType.forNumber(filter.getMatchType().value);
|
||||
if (isNull(objectMatchType)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown MatchType. Value: %s.", filter.getMatchType().name())
|
||||
);
|
||||
}
|
||||
|
||||
return Service.SearchRequest.Body.Filter.newBuilder()
|
||||
.setMatchType(objectMatchType)
|
||||
.setKey(filter.getKey())
|
||||
.setValue(filter.getValue())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFrostFS;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
|
||||
public class ObjectFrostFSMapper {
|
||||
|
||||
public static ObjectFrostFS toModel(Types.Object obj) {
|
||||
return new ObjectFrostFS(
|
||||
ObjectHeaderMapper.toModel(obj.getHeader()),
|
||||
ObjectId.fromHash(obj.getObjectId().getValue().toByteArray()),
|
||||
obj.getPayload().toByteArray()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.dto.object.ObjectAttribute;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.enums.ObjectType;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
import info.FrostFS.sdk.mappers.container.ContainerIdMapper;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectHeaderMapper {
|
||||
|
||||
public static Types.Header toGrpcMessage(ObjectHeader header) {
|
||||
var objectType = Types.ObjectType.forNumber(header.getObjectType().value);
|
||||
if (isNull(objectType)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown ObjectType. Value: %s.", header.getObjectType().name())
|
||||
);
|
||||
}
|
||||
|
||||
var head = Types.Header.newBuilder()
|
||||
.setContainerId(ContainerIdMapper.toGrpcMessage(header.getContainerId()))
|
||||
.setObjectType(objectType);
|
||||
|
||||
for (ObjectAttribute objectAttribute : header.getAttributes()) {
|
||||
head.addAttributes(ObjectAttributeMapper.toGrpcMessage(objectAttribute));
|
||||
}
|
||||
|
||||
return head.build();
|
||||
}
|
||||
|
||||
public static ObjectHeader toModel(Types.Header header) {
|
||||
var objectType = ObjectType.get(header.getObjectTypeValue());
|
||||
if (isNull(objectType)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown ObjectType. Value: %s.", header.getObjectType())
|
||||
);
|
||||
}
|
||||
|
||||
return new ObjectHeader(
|
||||
ContainerId.fromHash(header.getContainerId().getValue().toByteArray()),
|
||||
objectType,
|
||||
header.getAttributesList().stream().map(ObjectAttributeMapper::toModel).collect(Collectors.toList()),
|
||||
header.getPayloadLength(),
|
||||
VersionMapper.toModel(header.getVersion())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
|
||||
public class ObjectIdMapper {
|
||||
|
||||
public static Types.ObjectID toGrpcMessage(ObjectId objectId) {
|
||||
return Types.ObjectID.newBuilder()
|
||||
.setValue(ByteString.copyFrom(objectId.toHash()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ObjectId toModel(Types.ObjectID objectId) {
|
||||
return ObjectId.fromHash(objectId.getValue().toByteArray());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue