[#1] provide naming conventions

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-07-23 22:24:17 +03:00
parent a7fab6f314
commit bf2f19f08d
103 changed files with 416 additions and 417 deletions

View 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;
}
}

View 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);
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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);
}
}

View 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);
}
}

View 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();
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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());
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}