[#XX] add client environment
add client cut code cleanup Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
520b49bb6f
commit
ca7ba79817
95 changed files with 1202 additions and 560 deletions
32
README.md
32
README.md
|
@ -22,9 +22,9 @@ neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>
|
|||
|
||||
```java
|
||||
import info.FrostFS.sdk.enums.BasicAcl;
|
||||
import info.FrostFS.sdk.jdo.Container;
|
||||
import info.FrostFS.sdk.jdo.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.jdo.netmap.Replica;
|
||||
import info.FrostFS.sdk.dto.container.Container;
|
||||
import info.FrostFS.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.dto.netmap.Replica;
|
||||
import info.FrostFS.sdk.services.FrostFSClient;
|
||||
|
||||
public class ContainerExample {
|
||||
|
@ -36,16 +36,16 @@ public class ContainerExample {
|
|||
|
||||
// Create container
|
||||
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
||||
var containerId = frostFSClient.createContainerAsync(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
|
||||
// Get container
|
||||
var container = frostFSClient.getContainerAsync(containerId);
|
||||
var container = frostFSClient.getContainer(containerId);
|
||||
|
||||
// List containers
|
||||
var containerIds = frostFSClient.listContainersAsync();
|
||||
var containerIds = frostFSClient.listContainers();
|
||||
|
||||
// Delete container
|
||||
frostFSClient.deleteContainerAsync(containerId);
|
||||
frostFSClient.deleteContainer(containerId);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -54,10 +54,10 @@ public class ContainerExample {
|
|||
|
||||
```java
|
||||
import info.FrostFS.sdk.enums.ObjectType;
|
||||
import info.FrostFS.sdk.jdo.ContainerId;
|
||||
import info.FrostFS.sdk.jdo.ObjectAttribute;
|
||||
import info.FrostFS.sdk.jdo.ObjectFilter;
|
||||
import info.FrostFS.sdk.jdo.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.dto.object.ObjectAttribute;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFilter;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.services.FrostFSClient;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
@ -71,24 +71,24 @@ public class ObjectExample {
|
|||
FrostFSClient frostFSClient = new FrostFSClient(grpcClient, client);
|
||||
|
||||
// Put object
|
||||
info.FrostFS.sdk.jdo.ObjectId objectId;
|
||||
info.FrostFS.sdk.dto.object.ObjectId objectId;
|
||||
try (FileInputStream fis = new FileInputStream("cat.jpg")) {
|
||||
var cat = new ObjectHeader(
|
||||
containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")}
|
||||
);
|
||||
objectId = frostFSClient.putObjectAsync(cat, fis);
|
||||
objectId = frostFSClient.putObject(cat, fis);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Get object
|
||||
var obj = frostFSClient.getObjectAsync(containerId, objectId);
|
||||
var obj = frostFSClient.getObject(containerId, objectId);
|
||||
|
||||
// Get object header
|
||||
var objectHeader = frostFSClient.getObjectHeadAsync(containerId, objectId);
|
||||
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
||||
|
||||
// Search regular objects
|
||||
var objectIds = frostFSClient.searchObjectsAsync(containerId, ObjectFilter.RootFilter());
|
||||
var objectIds = frostFSClient.searchObjects(containerId, ObjectFilter.RootFilter());
|
||||
}
|
||||
}
|
||||
```
|
|
@ -25,9 +25,19 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.FrostFS.sdk</groupId>
|
||||
<artifactId>modelsV2</artifactId>
|
||||
<artifactId>models</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.17.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,14 +1,22 @@
|
|||
package info.FrostFS.sdk;
|
||||
|
||||
import info.FrostFS.sdk.dto.container.Container;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.enums.BasicAcl;
|
||||
import info.FrostFS.sdk.enums.ObjectType;
|
||||
import info.FrostFS.sdk.jdo.*;
|
||||
import info.FrostFS.sdk.jdo.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.jdo.netmap.Replica;
|
||||
import info.FrostFS.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.dto.netmap.Replica;
|
||||
import info.FrostFS.sdk.dto.object.ObjectAttribute;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFrostFS;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
import info.FrostFS.sdk.services.FrostFSClient;
|
||||
import info.FrostFS.sdk.tools.ClientSettings;
|
||||
import info.FrostFS.sdk.tools.PutObjectParameters;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
@ -18,37 +26,42 @@ public class Main {
|
|||
/*
|
||||
var res2 = frostFSClient.searchObjectsAsync(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"));
|
||||
*/
|
||||
|
||||
ObjectFrostFs res3 = frostFSClient
|
||||
.getObjectAsync(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"), new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"));
|
||||
|
||||
|
||||
var ttttt = frostFSClient.getNetworkSettingsAsync();
|
||||
Container container2 = frostFSClient.getContainerAsync(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"));
|
||||
|
||||
|
||||
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
||||
var containerId = frostFSClient.createContainerAsync(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
Thread.sleep(1000);
|
||||
|
||||
FileInputStream file = null;
|
||||
try {
|
||||
file = new FileInputStream("/home/ori/Desktop/cat.jpg");
|
||||
var cat = new ObjectHeader(containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")});
|
||||
frostFSClient.putObjectAsync(cat, file);
|
||||
var cat = new ObjectHeader(containerId, ObjectType.REGULAR, Collections.singletonList(new ObjectAttribute("Filename", "cat3.jpg")));
|
||||
|
||||
var params = new PutObjectParameters(cat, file, false, 1024);
|
||||
var tty = frostFSClient.putObject(params);
|
||||
|
||||
System.out.println(1);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
var res = frostFSClient.searchObjectsAsync(containerId);
|
||||
|
||||
var res = frostFSClient.searchObjects(containerId);
|
||||
|
||||
ObjectFrostFS res3 = frostFSClient
|
||||
.getObject(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"), new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww"));
|
||||
|
||||
|
||||
Container container = frostFSClient.getContainerAsync(containerId);
|
||||
List<ContainerId> containerIds = frostFSClient.listContainersAsync();
|
||||
var ttttt = frostFSClient.getNetworkSettings();
|
||||
Container container2 = frostFSClient.getContainer(new ContainerId("EQGx2QeYHJb53uRwYGzcQaW191sZpdNrjutk6veUSV2R"));
|
||||
|
||||
|
||||
|
||||
|
||||
Container container = frostFSClient.getContainer(containerId);
|
||||
List<ContainerId> containerIds = frostFSClient.listContainers();
|
||||
/*
|
||||
frostFSClient.deleteContainerAsync(containerId);
|
||||
*/
|
||||
containerIds = frostFSClient.listContainersAsync();
|
||||
containerIds = frostFSClient.listContainers();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
|
@ -2,8 +2,9 @@ package info.FrostFS.sdk;
|
|||
|
||||
import com.google.protobuf.AbstractMessage;
|
||||
import frostFS.session.Types;
|
||||
import info.FrostFS.sdk.jdo.MetaHeader;
|
||||
import info.FrostFS.sdk.dto.MetaHeader;
|
||||
import info.FrostFS.sdk.mappers.MetaHeaderMapper;
|
||||
import info.FrostFS.sdk.tools.ECDsa;
|
||||
|
||||
import static info.FrostFS.sdk.RequestSigner.signMessagePart;
|
||||
import static java.util.Objects.isNull;
|
||||
|
@ -27,7 +28,7 @@ public class RequestConstructor {
|
|||
frostFS.refs.Types.ContainerID cid,
|
||||
frostFS.refs.Types.ObjectID oid,
|
||||
Types.ObjectSessionContext.Verb verb,
|
||||
byte[] publicKey, byte[] privateKey) {
|
||||
ECDsa key) {
|
||||
var headerField = request.getDescriptorForType().findFieldByName("meta_header");
|
||||
var header = (Types.RequestMetaHeader) request.getField(headerField);
|
||||
if (header.getSessionToken().getSerializedSize() > 0) {
|
||||
|
@ -41,7 +42,7 @@ public class RequestConstructor {
|
|||
|
||||
var body = sessionToken.getBody().toBuilder().setObject(ctx).build();
|
||||
sessionToken = sessionToken.toBuilder()
|
||||
.setSignature(signMessagePart(publicKey, privateKey, body))
|
||||
.setSignature(signMessagePart(key, body))
|
||||
.setBody(body)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package info.FrostFS.sdk;
|
|||
import com.google.protobuf.AbstractMessage;
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.session.Types;
|
||||
import info.FrostFS.sdk.tools.ECDsa;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.bouncycastle.asn1.sec.SECNamedCurves;
|
||||
import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
|
||||
|
@ -14,19 +15,18 @@ import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
|
|||
import java.math.BigInteger;
|
||||
import java.security.Signature;
|
||||
|
||||
import static info.FrostFS.sdk.KeyExtension.loadPrivateKey;
|
||||
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
|
||||
import static org.bouncycastle.util.BigIntegers.asUnsignedByteArray;
|
||||
|
||||
public class RequestSigner {
|
||||
public static final int RFC6979_SIGNATURE_SIZE = 64;
|
||||
|
||||
public static byte[] signData(byte[] privateKey, byte[] data) {
|
||||
public static byte[] signData(ECDsa key, byte[] data) {
|
||||
var hash = new byte[65];
|
||||
hash[0] = 0x04;
|
||||
try {
|
||||
Signature signature = Signature.getInstance("NONEwithECDSAinP1363Format");
|
||||
signature.initSign(loadPrivateKey(privateKey));
|
||||
signature.initSign(key.getPrivateKey());
|
||||
signature.update(DigestUtils.sha512(data));
|
||||
byte[] sig = signature.sign();
|
||||
System.arraycopy(sig, 0, hash, 1, sig.length);
|
||||
|
@ -37,12 +37,12 @@ public class RequestSigner {
|
|||
return hash;
|
||||
}
|
||||
|
||||
public static byte[] signRFC6979(byte[] privateKey, byte[] data) {
|
||||
public static byte[] signRFC6979(ECDsa key, byte[] data) {
|
||||
var digest = createSHA256();
|
||||
var secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
|
||||
var ecParameters = new ECDomainParameters(secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN());
|
||||
var ecPrivateKey = new ECPrivateKeyParameters(new BigInteger(1, privateKey), ecParameters);
|
||||
var ecPrivateKey = new ECPrivateKeyParameters(new BigInteger(1, key.getPrivateKeyByte()), ecParameters);
|
||||
var signer = new ECDSASigner(new HMacDSAKCalculator(digest));
|
||||
var hash = new byte[digest.getDigestSize()];
|
||||
|
||||
|
@ -62,36 +62,29 @@ public class RequestSigner {
|
|||
return signature;
|
||||
}
|
||||
|
||||
public static frostFS.refs.Types.SignatureRFC6979 signRFC6979(byte[] publicKey,
|
||||
byte[] privateKey,
|
||||
AbstractMessage message) {
|
||||
public static frostFS.refs.Types.SignatureRFC6979 signRFC6979(ECDsa key, AbstractMessage message) {
|
||||
return frostFS.refs.Types.SignatureRFC6979.newBuilder()
|
||||
.setKey(ByteString.copyFrom(publicKey))
|
||||
.setSign(ByteString.copyFrom(signRFC6979(privateKey, message.toByteArray())))
|
||||
.setKey(ByteString.copyFrom(key.getPublicKeyByte()))
|
||||
.setSign(ByteString.copyFrom(signRFC6979(key, message.toByteArray())))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static frostFS.refs.Types.SignatureRFC6979 signRFC6979(byte[] publicKey,
|
||||
byte[] privateKey,
|
||||
ByteString data) {
|
||||
public static frostFS.refs.Types.SignatureRFC6979 signRFC6979(ECDsa key, ByteString data) {
|
||||
return frostFS.refs.Types.SignatureRFC6979.newBuilder()
|
||||
.setKey(ByteString.copyFrom(publicKey))
|
||||
.setSign(ByteString.copyFrom(signRFC6979(privateKey, data.toByteArray())))
|
||||
.setKey(ByteString.copyFrom(key.getPublicKeyByte()))
|
||||
.setSign(ByteString.copyFrom(signRFC6979(key, data.toByteArray())))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static frostFS.refs.Types.Signature signMessagePart(byte[] publicKey,
|
||||
byte[] privateKey,
|
||||
AbstractMessage data) {
|
||||
public static frostFS.refs.Types.Signature signMessagePart(ECDsa key, AbstractMessage data) {
|
||||
var data2Sign = data.getSerializedSize() == 0 ? new byte[]{} : data.toByteArray();
|
||||
|
||||
return frostFS.refs.Types.Signature.newBuilder()
|
||||
.setKey(ByteString.copyFrom(publicKey))
|
||||
.setSign(ByteString.copyFrom(signData(privateKey, data2Sign)))
|
||||
.setKey(ByteString.copyFrom(key.getPublicKeyByte()))
|
||||
.setSign(ByteString.copyFrom(signData(key, data2Sign)))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void sign(AbstractMessage.Builder request, byte[] publicKey, byte[] privateKey) {
|
||||
public static void sign(AbstractMessage.Builder request, ECDsa key) {
|
||||
var meta = (AbstractMessage) request.getField(request.getDescriptorForType().findFieldByName("meta_header"));
|
||||
var body = (AbstractMessage) request.getField(request.getDescriptorForType().findFieldByName("body"));
|
||||
var verify = (AbstractMessage) request.getField(request.getDescriptorForType().findFieldByName("verify_header"));
|
||||
|
@ -109,7 +102,7 @@ public class RequestSigner {
|
|||
if (verifyOrigin.getSerializedSize() == 0) {
|
||||
verifyBuilder.setField(
|
||||
verifyBuilder.getDescriptorForType().findFieldByName("body_signature"),
|
||||
signMessagePart(publicKey, privateKey, body)
|
||||
signMessagePart(key, body)
|
||||
);
|
||||
} else {
|
||||
verifyBuilder.setField(verifyBuilder.getDescriptorForType().findFieldByName("origin"), verifyOrigin);
|
||||
|
@ -117,11 +110,11 @@ public class RequestSigner {
|
|||
|
||||
verifyBuilder.setField(
|
||||
verifyBuilder.getDescriptorForType().findFieldByName("meta_signature"),
|
||||
signMessagePart(publicKey, privateKey, meta)
|
||||
signMessagePart(key, meta)
|
||||
);
|
||||
verifyBuilder.setField(
|
||||
verifyBuilder.getDescriptorForType().findFieldByName("origin_signature"),
|
||||
signMessagePart(publicKey, privateKey, verifyOrigin)
|
||||
signMessagePart(key, verifyOrigin)
|
||||
);
|
||||
|
||||
request.setField(request.getDescriptorForType().findFieldByName("verify_header"), verifyBuilder.build());
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.security.PublicKey;
|
|||
import java.security.Signature;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static info.FrostFS.sdk.KeyExtension.getPublicKeyByPublic;
|
||||
import static info.FrostFS.sdk.KeyExtension.getPublicKeyFromBytes;
|
||||
import static java.util.Objects.isNull;
|
||||
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
|
||||
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
|
||||
|
@ -99,7 +99,7 @@ public class Verifier {
|
|||
public static boolean verifyMessagePart(Types.Signature sig, AbstractMessage data) {
|
||||
if (sig.getSerializedSize() == 0 || sig.getKey().isEmpty() || sig.getSign().isEmpty()) return false;
|
||||
|
||||
var publicKey = getPublicKeyByPublic(sig.getKey().toByteArray());
|
||||
var publicKey = getPublicKeyFromBytes(sig.getKey().toByteArray());
|
||||
|
||||
var data2Verify = data.getSerializedSize() == 0 ? new byte[]{} : data.toByteArray();
|
||||
return verifyData(publicKey, data2Verify, sig.getSign().toByteArray());
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package info.FrostFS.sdk.services;
|
||||
|
||||
import info.FrostFS.sdk.jdo.Container;
|
||||
import info.FrostFS.sdk.jdo.ContainerId;
|
||||
import info.FrostFS.sdk.dto.container.Container;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ContainerClient {
|
||||
Container getContainerAsync(ContainerId cid);
|
||||
Container getContainer(ContainerId cid);
|
||||
|
||||
List<ContainerId> listContainersAsync();
|
||||
List<ContainerId> listContainers();
|
||||
|
||||
ContainerId createContainerAsync(Container container);
|
||||
ContainerId createContainer(Container container);
|
||||
|
||||
void deleteContainerAsync(ContainerId cid);
|
||||
void deleteContainer(ContainerId cid);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package info.FrostFS.sdk.services;
|
|||
import info.FrostFS.sdk.tools.ClientEnvironment;
|
||||
|
||||
public class ContextAccessor {
|
||||
protected ClientEnvironment context;
|
||||
private final ClientEnvironment context;
|
||||
|
||||
public ContextAccessor(ClientEnvironment context) {
|
||||
this.context = context;
|
||||
|
@ -12,8 +12,4 @@ public class ContextAccessor {
|
|||
public ClientEnvironment getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(ClientEnvironment context) {
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package info.FrostFS.sdk.services;
|
||||
|
||||
import frostFS.session.Types;
|
||||
import info.FrostFS.sdk.ClientSettings;
|
||||
import info.FrostFS.sdk.jdo.*;
|
||||
import info.FrostFS.sdk.jdo.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.jdo.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.services.impl.ContainerService;
|
||||
import info.FrostFS.sdk.services.impl.NetmapService;
|
||||
import info.FrostFS.sdk.services.impl.ObjectService;
|
||||
import info.FrostFS.sdk.services.impl.SessionService;
|
||||
import info.FrostFS.sdk.tools.ClientSettings;
|
||||
import info.FrostFS.sdk.tools.PutObjectParameters;
|
||||
import info.FrostFS.sdk.dto.container.Container;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.dto.SessionToken;
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.dto.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.dto.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFilter;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFrostFS;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
import info.FrostFS.sdk.services.impl.*;
|
||||
import info.FrostFS.sdk.tools.ClientEnvironment;
|
||||
import info.FrostFS.sdk.tools.NetworkSettings;
|
||||
import io.grpc.Channel;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import static info.FrostFS.sdk.GrpcClient.initGrpcChannel;
|
||||
|
@ -24,7 +28,7 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
|||
private final NetmapService netmapService;
|
||||
private final ObjectService objectService;
|
||||
private final SessionService sessionService;
|
||||
private final ClientEnvironment clientEnvironment;
|
||||
private final ObjectTools objectTools;
|
||||
|
||||
public FrostFSClient(ClientSettings clientSettings) {
|
||||
if (isNull(clientSettings)) {
|
||||
|
@ -32,20 +36,22 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
|||
}
|
||||
|
||||
clientSettings.validate();
|
||||
|
||||
Channel channel = initGrpcChannel(clientSettings.getHost(), clientSettings.getCreds());
|
||||
|
||||
this.clientEnvironment =
|
||||
ClientEnvironment clientEnvironment =
|
||||
new ClientEnvironment(clientSettings.getKey(), channel, new Version(2, 13), this);
|
||||
|
||||
this.containerService = new ContainerService(clientEnvironment);
|
||||
this.netmapService = new NetmapService(clientEnvironment);
|
||||
this.sessionService = new SessionService(clientEnvironment);
|
||||
this.objectService = new ObjectService(clientEnvironment);
|
||||
this.objectTools = new ObjectTools(clientEnvironment);
|
||||
checkFrostFsVersionSupport(clientEnvironment.getVersion());
|
||||
}
|
||||
|
||||
private void checkFrostFsVersionSupport(Version version) {
|
||||
var localNodeInfo = netmapService.getLocalNodeInfoAsync();
|
||||
var localNodeInfo = netmapService.getLocalNodeInfo();
|
||||
if (!localNodeInfo.getVersion().isSupported(version)) {
|
||||
var msg = String.format("FrostFS %s is not supported.", localNodeInfo.getVersion());
|
||||
System.out.println(msg);
|
||||
|
@ -54,81 +60,76 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
|||
}
|
||||
|
||||
@Override
|
||||
public Container getContainerAsync(ContainerId cid) {
|
||||
return containerService.getContainerAsync(cid);
|
||||
public Container getContainer(ContainerId cid) {
|
||||
return containerService.getContainer(cid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContainerId> listContainersAsync() {
|
||||
return containerService.listContainersAsync();
|
||||
public List<ContainerId> listContainers() {
|
||||
return containerService.listContainers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerId createContainerAsync(Container container) {
|
||||
return containerService.createContainerAsync(container);
|
||||
public ContainerId createContainer(Container container) {
|
||||
return containerService.createContainer(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContainerAsync(ContainerId cid) {
|
||||
containerService.deleteContainerAsync(cid);
|
||||
public void deleteContainer(ContainerId cid) {
|
||||
containerService.deleteContainer(cid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHeader getObjectHeadAsync(ContainerId containerId, ObjectId objectId) {
|
||||
return objectService.getObjectHeadAsync(containerId, objectId);
|
||||
public ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId) {
|
||||
return objectService.getObjectHead(containerId, objectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectFrostFs getObjectAsync(ContainerId containerId, ObjectId objectId) {
|
||||
return objectService.getObjectAsync(containerId, objectId);
|
||||
public ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId) {
|
||||
return objectService.getObject(containerId, objectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putObjectAsync(ObjectHeader header, FileInputStream payload) {
|
||||
return objectService.putObjectAsync(header, payload);
|
||||
public ObjectId putObject(PutObjectParameters parameters) {
|
||||
return objectService.putObject(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putObjectAsync(ObjectHeader header, byte[] payload) {
|
||||
return objectService.putObjectAsync(header, payload);
|
||||
public void deleteObject(ContainerId containerId, ObjectId objectId) {
|
||||
objectService.deleteObject(containerId, objectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObjectAsync(ContainerId containerId, ObjectId objectId) {
|
||||
objectService.deleteObjectAsync(containerId, objectId);
|
||||
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter... filters) {
|
||||
return objectService.searchObjects(cid, filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ObjectId> searchObjectsAsync(ContainerId cid, ObjectFilter... filters) {
|
||||
return objectService.searchObjectsAsync(cid, filters);
|
||||
public NetmapSnapshot getNetmapSnapshot() {
|
||||
return netmapService.getNetmapSnapshot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetmapSnapshot getNetmapSnapshotAsync() {
|
||||
return netmapService.getNetmapSnapshotAsync();
|
||||
public NodeInfo getLocalNodeInfo() {
|
||||
return netmapService.getLocalNodeInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeInfo getLocalNodeInfoAsync() {
|
||||
return netmapService.getLocalNodeInfoAsync();
|
||||
public NetworkSettings getNetworkSettings() {
|
||||
return netmapService.getNetworkSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkSettings getNetworkSettingsAsync() {
|
||||
return netmapService.getNetworkSettingsAsync();
|
||||
public SessionToken createSession(long expiration) {
|
||||
return sessionService.createSession(expiration);
|
||||
}
|
||||
|
||||
public Types.SessionToken createSessionInternal(long expiration) {
|
||||
return sessionService.createSessionInternal(expiration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionToken createSessionAsync(long expiration) {
|
||||
return sessionService.createSessionAsync(expiration);
|
||||
}
|
||||
|
||||
public Types.SessionToken createSessionInternalAsync(long expiration) {
|
||||
return sessionService.createSessionInternalAsync(expiration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId CalculateObjectId(ObjectHeader header) {
|
||||
return null;
|
||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||
return objectTools.calculateObjectId(header);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package info.FrostFS.sdk.services;
|
||||
|
||||
import info.FrostFS.sdk.jdo.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.jdo.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.dto.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.dto.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.tools.NetworkSettings;
|
||||
|
||||
public interface NetmapClient {
|
||||
NetmapSnapshot getNetmapSnapshot();
|
||||
|
||||
NetmapSnapshot getNetmapSnapshotAsync();
|
||||
NodeInfo getLocalNodeInfo();
|
||||
|
||||
NodeInfo getLocalNodeInfoAsync();
|
||||
|
||||
NetworkSettings getNetworkSettingsAsync();
|
||||
NetworkSettings getNetworkSettings();
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
package info.FrostFS.sdk.services;
|
||||
|
||||
import info.FrostFS.sdk.jdo.*;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.tools.PutObjectParameters;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFilter;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFrostFS;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
|
||||
public interface ObjectClient {
|
||||
ObjectHeader getObjectHeadAsync(ContainerId containerId, ObjectId objectId);
|
||||
ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
ObjectFrostFs getObjectAsync(ContainerId containerId, ObjectId objectId);
|
||||
ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
ObjectId putObjectAsync(ObjectHeader header, FileInputStream payload);
|
||||
ObjectId putObject(PutObjectParameters parameters);
|
||||
|
||||
ObjectId putObjectAsync(ObjectHeader header, byte[] payload);
|
||||
void deleteObject(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
void deleteObjectAsync(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
Iterable<ObjectId> searchObjectsAsync(ContainerId cid, ObjectFilter... filters);
|
||||
Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter... filters);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package info.FrostFS.sdk.services;
|
||||
|
||||
import info.FrostFS.sdk.jdo.SessionToken;
|
||||
import info.FrostFS.sdk.dto.SessionToken;
|
||||
|
||||
public interface SessionClient {
|
||||
|
||||
SessionToken createSessionAsync(long expiration);
|
||||
SessionToken createSession(long expiration);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package info.FrostFS.sdk.services;
|
||||
|
||||
import info.FrostFS.sdk.jdo.ObjectHeader;
|
||||
import info.FrostFS.sdk.jdo.ObjectId;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
|
||||
public interface ToolsClient {
|
||||
ObjectId CalculateObjectId(ObjectHeader header);
|
||||
ObjectId calculateObjectId(ObjectHeader header);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ package info.FrostFS.sdk.services.impl;
|
|||
import frostFS.container.ContainerServiceGrpc;
|
||||
import frostFS.container.Service;
|
||||
import info.FrostFS.sdk.Verifier;
|
||||
import info.FrostFS.sdk.jdo.Container;
|
||||
import info.FrostFS.sdk.jdo.ContainerId;
|
||||
import info.FrostFS.sdk.mappers.ContainerIdMapper;
|
||||
import info.FrostFS.sdk.mappers.ContainerMapper;
|
||||
import info.FrostFS.sdk.dto.container.Container;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.mappers.container.ContainerIdMapper;
|
||||
import info.FrostFS.sdk.mappers.container.ContainerMapper;
|
||||
import info.FrostFS.sdk.mappers.OwnerIdMapper;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
import info.FrostFS.sdk.services.ContainerClient;
|
||||
|
@ -21,14 +21,14 @@ import static info.FrostFS.sdk.RequestSigner.sign;
|
|||
import static info.FrostFS.sdk.RequestSigner.signRFC6979;
|
||||
|
||||
public class ContainerService extends ContextAccessor implements ContainerClient {
|
||||
private final ContainerServiceGrpc.ContainerServiceBlockingStub containerServiceAsyncClient;
|
||||
private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub;
|
||||
|
||||
public ContainerService(ClientEnvironment clientEnvironment) {
|
||||
super(clientEnvironment);
|
||||
this.containerServiceAsyncClient = ContainerServiceGrpc.newBlockingStub(clientEnvironment.getChannel());
|
||||
this.serviceBlockingStub = ContainerServiceGrpc.newBlockingStub(clientEnvironment.getChannel());
|
||||
}
|
||||
|
||||
public Container getContainerAsync(ContainerId cid) {
|
||||
public Container getContainer(ContainerId cid) {
|
||||
var request = Service.GetRequest.newBuilder()
|
||||
.setBody(
|
||||
Service.GetRequest.Body.newBuilder()
|
||||
|
@ -37,26 +37,26 @@ public class ContainerService extends ContextAccessor implements ContainerClient
|
|||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = containerServiceAsyncClient.get(request.build());
|
||||
var response = serviceBlockingStub.get(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
return ContainerMapper.toModel(response.getBody().getContainer());
|
||||
}
|
||||
|
||||
public List<ContainerId> listContainersAsync() {
|
||||
public List<ContainerId> listContainers() {
|
||||
var request = Service.ListRequest.newBuilder()
|
||||
.setBody(
|
||||
Service.ListRequest.Body.newBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(context.getOwnerId()))
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.build()
|
||||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = containerServiceAsyncClient.list(request.build());
|
||||
var response = serviceBlockingStub.list(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
|
@ -65,12 +65,12 @@ public class ContainerService extends ContextAccessor implements ContainerClient
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ContainerId createContainerAsync(Container container) {
|
||||
public ContainerId createContainer(Container container) {
|
||||
var grpcContainer = ContainerMapper.toGrpcMessage(container);
|
||||
|
||||
grpcContainer = grpcContainer.toBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(context.getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(context.getVersion()))
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()))
|
||||
.build();
|
||||
|
||||
var request = Service.PutRequest.newBuilder()
|
||||
|
@ -78,21 +78,21 @@ public class ContainerService extends ContextAccessor implements ContainerClient
|
|||
Service.PutRequest.Body.newBuilder()
|
||||
.setContainer(grpcContainer)
|
||||
.setSignature(
|
||||
signRFC6979(context.getPublicKey(), context.getPrivateKey(), grpcContainer)
|
||||
signRFC6979(getContext().getKey(), grpcContainer)
|
||||
)
|
||||
.build()
|
||||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = containerServiceAsyncClient.put(request.build());
|
||||
var response = serviceBlockingStub.put(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
return ContainerId.fromHash(response.getBody().getContainerId().getValue().toByteArray());
|
||||
}
|
||||
|
||||
public void deleteContainerAsync(ContainerId cid) {
|
||||
public void deleteContainer(ContainerId cid) {
|
||||
var grpcContainerId = ContainerIdMapper.toGrpcMessage(cid);
|
||||
|
||||
var request = Service.DeleteRequest.newBuilder()
|
||||
|
@ -100,15 +100,15 @@ public class ContainerService extends ContextAccessor implements ContainerClient
|
|||
Service.DeleteRequest.Body.newBuilder()
|
||||
.setContainerId(grpcContainerId)
|
||||
.setSignature(signRFC6979(
|
||||
context.getPublicKey(), context.getPrivateKey(), grpcContainerId.getValue()
|
||||
getContext().getKey(), grpcContainerId.getValue()
|
||||
))
|
||||
.build()
|
||||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = containerServiceAsyncClient.delete(request.build());
|
||||
var response = serviceBlockingStub.delete(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import frostFS.netmap.NetmapServiceGrpc;
|
|||
import frostFS.netmap.Service;
|
||||
import frostFS.netmap.Types;
|
||||
import info.FrostFS.sdk.Verifier;
|
||||
import info.FrostFS.sdk.jdo.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.jdo.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.dto.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.dto.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.mappers.netmap.NetmapSnapshotMapper;
|
||||
import info.FrostFS.sdk.mappers.netmap.NodeInfoMapper;
|
||||
import info.FrostFS.sdk.services.ContextAccessor;
|
||||
|
@ -24,7 +24,7 @@ public class NetmapService extends ContextAccessor implements NetmapClient {
|
|||
|
||||
public NetmapService(ClientEnvironment clientEnvironment) {
|
||||
super(clientEnvironment);
|
||||
this.netmapServiceClient = NetmapServiceGrpc.newBlockingStub(context.getChannel());
|
||||
this.netmapServiceClient = NetmapServiceGrpc.newBlockingStub(getContext().getChannel());
|
||||
}
|
||||
|
||||
private static boolean getBoolValue(byte[] bytes) {
|
||||
|
@ -92,12 +92,12 @@ public class NetmapService extends ContextAccessor implements NetmapClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NetworkSettings getNetworkSettingsAsync() {
|
||||
if (nonNull(context.getNetworkSettings())) {
|
||||
return context.getNetworkSettings();
|
||||
public NetworkSettings getNetworkSettings() {
|
||||
if (nonNull(getContext().getNetworkSettings())) {
|
||||
return getContext().getNetworkSettings();
|
||||
}
|
||||
|
||||
var info = getNetworkInfoAsync();
|
||||
var info = getNetworkInfo();
|
||||
|
||||
var settings = new NetworkSettings();
|
||||
|
||||
|
@ -105,18 +105,18 @@ public class NetmapService extends ContextAccessor implements NetmapClient {
|
|||
setNetworksParam(param, settings);
|
||||
}
|
||||
|
||||
context.setNetworkSettings(settings);
|
||||
getContext().setNetworkSettings(settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeInfo getLocalNodeInfoAsync() {
|
||||
public NodeInfo getLocalNodeInfo() {
|
||||
var request = Service.LocalNodeInfoRequest.newBuilder()
|
||||
.setBody(Service.LocalNodeInfoRequest.Body.newBuilder().build());
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = netmapServiceClient.localNodeInfo(request.build());
|
||||
Verifier.checkResponse(response);
|
||||
|
@ -124,12 +124,12 @@ public class NetmapService extends ContextAccessor implements NetmapClient {
|
|||
return NodeInfoMapper.toModel(response.getBody());
|
||||
}
|
||||
|
||||
public Service.NetworkInfoResponse getNetworkInfoAsync() {
|
||||
public Service.NetworkInfoResponse getNetworkInfo() {
|
||||
var request = Service.NetworkInfoRequest.newBuilder()
|
||||
.setBody(Service.NetworkInfoRequest.Body.newBuilder().build());
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = netmapServiceClient.networkInfo(request.build());
|
||||
|
||||
|
@ -139,12 +139,12 @@ public class NetmapService extends ContextAccessor implements NetmapClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NetmapSnapshot getNetmapSnapshotAsync() {
|
||||
public NetmapSnapshot getNetmapSnapshot() {
|
||||
var request = Service.NetmapSnapshotRequest.newBuilder()
|
||||
.setBody(Service.NetmapSnapshotRequest.Body.newBuilder().build());
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = netmapServiceClient.netmapSnapshot(request.build());
|
||||
|
||||
|
|
|
@ -6,16 +6,24 @@ import frostFS.object.ObjectServiceGrpc;
|
|||
import frostFS.object.Service;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.Verifier;
|
||||
import info.FrostFS.sdk.jdo.*;
|
||||
import info.FrostFS.sdk.constants.AppConst;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
import info.FrostFS.sdk.dto.Split;
|
||||
import info.FrostFS.sdk.dto.object.*;
|
||||
import info.FrostFS.sdk.mappers.*;
|
||||
import info.FrostFS.sdk.mappers.container.ContainerIdMapper;
|
||||
import info.FrostFS.sdk.mappers.object.ObjectFilterMapper;
|
||||
import info.FrostFS.sdk.mappers.object.ObjectHeaderMapper;
|
||||
import info.FrostFS.sdk.mappers.object.ObjectIdMapper;
|
||||
import info.FrostFS.sdk.mappers.object.ObjectFrostFSMapper;
|
||||
import info.FrostFS.sdk.services.ContextAccessor;
|
||||
import info.FrostFS.sdk.services.ObjectClient;
|
||||
import info.FrostFS.sdk.tools.ClientEnvironment;
|
||||
import info.FrostFS.sdk.tools.PutObjectParameters;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -29,15 +37,17 @@ import static java.util.Objects.nonNull;
|
|||
public class ObjectService extends ContextAccessor implements ObjectClient {
|
||||
private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient;
|
||||
private final ObjectServiceGrpc.ObjectServiceStub objectServiceClient;
|
||||
private final ObjectTools objectTools;
|
||||
|
||||
public ObjectService(ClientEnvironment clientEnvironment) {
|
||||
super(clientEnvironment);
|
||||
this.objectServiceBlockingClient = ObjectServiceGrpc.newBlockingStub(context.getChannel());
|
||||
this.objectServiceClient = ObjectServiceGrpc.newStub(context.getChannel());
|
||||
this.objectServiceBlockingClient = ObjectServiceGrpc.newBlockingStub(getContext().getChannel());
|
||||
this.objectServiceClient = ObjectServiceGrpc.newStub(getContext().getChannel());
|
||||
this.objectTools = new ObjectTools(clientEnvironment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHeader getObjectHeadAsync(ContainerId cid, ObjectId oid) {
|
||||
public ObjectHeader getObjectHead(ContainerId cid, ObjectId oid) {
|
||||
var request = Service.HeadRequest.newBuilder()
|
||||
.setBody(
|
||||
Service.HeadRequest.Body.newBuilder()
|
||||
|
@ -50,7 +60,7 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = objectServiceBlockingClient.head(request.build());
|
||||
Verifier.checkResponse(response);
|
||||
|
@ -59,8 +69,8 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ObjectFrostFs getObjectAsync(ContainerId cid, ObjectId oid) {
|
||||
var sessionToken = context.getFrostFSClient().createSessionInternalAsync(-1);
|
||||
public ObjectFrostFS getObject(ContainerId cid, ObjectId oid) {
|
||||
var sessionToken = getContext().getFrostFSClient().createSessionInternal(-1);
|
||||
|
||||
var request = Service.GetRequest.newBuilder()
|
||||
.setBody(
|
||||
|
@ -71,24 +81,23 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
.setObjectId(ObjectIdMapper.toGrpcMessage(oid))
|
||||
.build()
|
||||
)
|
||||
.setRaw(false)
|
||||
.build()
|
||||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
addObjectSessionToken(
|
||||
request, sessionToken, ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid),
|
||||
frostFS.session.Types.ObjectSessionContext.Verb.GET, context.getPublicKey(), context.getPrivateKey()
|
||||
frostFS.session.Types.ObjectSessionContext.Verb.GET, getContext().getKey()
|
||||
);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var obj = getObject(request.build());
|
||||
|
||||
return ObjectMapper.toModel(obj);
|
||||
return ObjectFrostFSMapper.toModel(obj);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteObjectAsync(ContainerId cid, ObjectId oid) {
|
||||
public void deleteObject(ContainerId cid, ObjectId oid) {
|
||||
var request = Service.DeleteRequest.newBuilder()
|
||||
.setBody(
|
||||
Service.DeleteRequest.Body.newBuilder()
|
||||
|
@ -101,27 +110,17 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
.build());
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = objectServiceBlockingClient.delete(request.build());
|
||||
Verifier.checkResponse(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putObjectAsync(ObjectHeader header, FileInputStream payload) {
|
||||
return putObject(header, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putObjectAsync(ObjectHeader header, byte[] payload) {
|
||||
return putObject(header, new ByteArrayInputStream(payload));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ObjectId> searchObjectsAsync(ContainerId cid, ObjectFilter... filters) {
|
||||
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter... filters) {
|
||||
var body = Service.SearchRequest.Body.newBuilder()
|
||||
.setContainerId(ContainerIdMapper.toGrpcMessage(cid))
|
||||
.setVersion(1);
|
||||
.setVersion(1);// TODO: clarify this param
|
||||
|
||||
for (ObjectFilter filter : filters) {
|
||||
body.addFilters(ObjectFilterMapper.toGrpcMessage(filter));
|
||||
|
@ -131,13 +130,43 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
.setBody(body.build());
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var objectsIds = searchObjects(request.build());
|
||||
|
||||
return Iterables.transform(objectsIds, input -> ObjectId.fromHash(input.getValue().toByteArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putObject(PutObjectParameters parameters) {
|
||||
parameters.validate();
|
||||
|
||||
return parameters.clientCut ? putClientCutObject(parameters) : putStreamObject(parameters);
|
||||
}
|
||||
|
||||
public ObjectId putSingleObject(ObjectFrostFS modelObject) {
|
||||
var sessionToken = getContext().getFrostFSClient().createSessionInternal(-1);
|
||||
|
||||
var grpcObject = objectTools.createObject(modelObject);
|
||||
|
||||
var request = Service.PutSingleRequest.newBuilder()
|
||||
.setBody(Service.PutSingleRequest.Body.newBuilder().setObject(grpcObject).build());
|
||||
|
||||
|
||||
addMetaHeader(request);
|
||||
addObjectSessionToken(
|
||||
request, sessionToken, grpcObject.getHeader().getContainerId(), grpcObject.getObjectId(),
|
||||
frostFS.session.Types.ObjectSessionContext.Verb.PUT, getContext().getKey()
|
||||
);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var response = objectServiceBlockingClient.putSingle(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
return ObjectId.fromHash(grpcObject.getObjectId().getValue().toByteArray());
|
||||
}
|
||||
|
||||
private frostFS.object.Types.Object getObject(Service.GetRequest request) {
|
||||
var iterator = getObjectInit(request);
|
||||
var obj = iterator.readHeader();
|
||||
|
@ -162,18 +191,20 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
return new ObjectReader(objectServiceBlockingClient.get(initRequest));
|
||||
}
|
||||
|
||||
private ObjectId putObject(ObjectHeader header, InputStream payload) {
|
||||
var sessionToken = context.getFrostFSClient().createSessionInternalAsync(-1);
|
||||
var hdr = ObjectHeaderMapper.toGrpcMessage(header);
|
||||
private ObjectId putStreamObject(PutObjectParameters parameters) {
|
||||
var header = parameters.getHeader();
|
||||
|
||||
var sessionToken = getContext().getFrostFSClient().createSessionInternal(-1);
|
||||
|
||||
var hdr = ObjectHeaderMapper.toGrpcMessage(header);
|
||||
hdr = hdr.toBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(context.getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(context.getVersion()))
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()))
|
||||
.build();
|
||||
|
||||
var oid = Types.ObjectID.newBuilder().setValue(getSha256(hdr)).build();
|
||||
|
||||
var request = Service.PutRequest.newBuilder()
|
||||
var initRequest = Service.PutRequest.newBuilder()
|
||||
.setBody(
|
||||
Service.PutRequest.Body.newBuilder()
|
||||
.setInit(
|
||||
|
@ -181,34 +212,35 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
).build()
|
||||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
addMetaHeader(initRequest);
|
||||
addObjectSessionToken(
|
||||
request, sessionToken, hdr.getContainerId(), oid, frostFS.session.Types.ObjectSessionContext.Verb.PUT,
|
||||
context.getPublicKey(), context.getPrivateKey()
|
||||
initRequest, sessionToken, hdr.getContainerId(), oid,
|
||||
frostFS.session.Types.ObjectSessionContext.Verb.PUT, getContext().getKey()
|
||||
);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(initRequest, getContext().getKey());
|
||||
|
||||
|
||||
var writer = putObjectInit(request.build());
|
||||
var writer = putObjectInit(initRequest.build());
|
||||
|
||||
var buffer = new byte[Constants.OBJECT_CHUNK_SIZE];
|
||||
int bufferLength = 0;
|
||||
try {
|
||||
bufferLength = payload.readNBytes(buffer, 0, Constants.OBJECT_CHUNK_SIZE);
|
||||
while (bufferLength > 0) {
|
||||
request.setBody(
|
||||
Service.PutRequest.Body.newBuilder()
|
||||
.setChunk(ByteString.copyFrom(Arrays.copyOfRange(buffer, 0, bufferLength)))
|
||||
.build()
|
||||
)
|
||||
.clearVerifyHeader();
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
writer.write(request.build());
|
||||
bufferLength = payload.readNBytes(buffer, 0, Constants.OBJECT_CHUNK_SIZE);
|
||||
}
|
||||
} catch (
|
||||
IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
var bufferSize = parameters.getBufferMaxSize() > 0 ? parameters.getBufferMaxSize() : AppConst.OBJECT_CHUNK_SIZE;
|
||||
bufferSize = (int) Math.min(getStreamSize(parameters.getPayload()), bufferSize);
|
||||
bufferSize = header.getPayloadLength() > 0 ? (int) Math.min(header.getPayloadLength(), bufferSize) : bufferSize;
|
||||
|
||||
var buffer = new byte[bufferSize];
|
||||
while (true) {
|
||||
var bytesCount = readNBytes(parameters.getPayload(), buffer, bufferSize);
|
||||
if (bytesCount <= 0)
|
||||
break;
|
||||
|
||||
var chunkRequest = Service.PutRequest.newBuilder(initRequest.build())
|
||||
.setBody(
|
||||
Service.PutRequest.Body.newBuilder()
|
||||
.setChunk(ByteString.copyFrom(Arrays.copyOfRange(buffer, 0, bytesCount)))
|
||||
.build()
|
||||
)
|
||||
.clearVerifyHeader();
|
||||
sign(chunkRequest, getContext().getKey());
|
||||
writer.write(chunkRequest.build());
|
||||
}
|
||||
|
||||
var response = writer.complete();
|
||||
|
@ -217,6 +249,71 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
return ObjectId.fromHash(response.getBody().getObjectId().getValue().toByteArray());
|
||||
}
|
||||
|
||||
private ObjectId putClientCutObject(PutObjectParameters parameters) {
|
||||
var header = parameters.getHeader();
|
||||
|
||||
var networkSettings = getContext().getFrostFSClient().getNetworkSettings();
|
||||
var payloadSize = getStreamSize(parameters.getPayload());
|
||||
var objectSize = (int) Math.min(payloadSize, networkSettings.getMaxObjectSize());
|
||||
var fullLength = header.getPayloadLength() == 0 ? payloadSize : header.getPayloadLength();
|
||||
if (fullLength == 0) {
|
||||
throw new IllegalArgumentException("Payload stream must be able to seek or PayloadLength must be specified");
|
||||
}
|
||||
|
||||
var buffer = new byte[objectSize];
|
||||
var largeObject = new LargeObject(header.getContainerId());
|
||||
var split = new Split();
|
||||
|
||||
ObjectId objectId;
|
||||
List<ObjectId> sentObjectIds = new ArrayList<>();
|
||||
ObjectFrostFS currentObject;
|
||||
|
||||
while (true) {
|
||||
var bytesCount = readNBytes(parameters.getPayload(), buffer, objectSize);
|
||||
if (CollectionUtils.isNotEmpty(sentObjectIds)) {
|
||||
split.setPrevious(sentObjectIds.get(sentObjectIds.size() - 1));
|
||||
}
|
||||
|
||||
largeObject.appendBlock(buffer, bytesCount);
|
||||
|
||||
currentObject = new ObjectFrostFS(
|
||||
header.getContainerId(),
|
||||
bytesCount < objectSize ? Arrays.copyOfRange(buffer, 0, bytesCount) : buffer
|
||||
);
|
||||
currentObject.setSplit(split);
|
||||
|
||||
if (largeObject.getPayloadLength() == fullLength)
|
||||
break;
|
||||
|
||||
objectId = putSingleObject(currentObject);
|
||||
|
||||
sentObjectIds.add(objectId);
|
||||
}
|
||||
|
||||
if (CollectionUtils.isEmpty(sentObjectIds)) {
|
||||
currentObject.addAttributes(parameters.getHeader().getAttributes());
|
||||
return putSingleObject(currentObject);
|
||||
}
|
||||
|
||||
largeObject.addAttributes(parameters.getHeader().getAttributes());
|
||||
largeObject.calculateHash();
|
||||
|
||||
currentObject.setParent(largeObject);
|
||||
|
||||
objectId = putSingleObject(currentObject);
|
||||
|
||||
sentObjectIds.add(objectId);
|
||||
|
||||
var linkObject = new LinkObject(header.getContainerId(), split.getSplitId(), largeObject);
|
||||
linkObject.addChildren(sentObjectIds);
|
||||
|
||||
linkObject.getHeader().getAttributes().clear();
|
||||
|
||||
putSingleObject(linkObject);
|
||||
|
||||
return objectTools.calculateObjectId(largeObject.getHeader());
|
||||
}
|
||||
|
||||
private ObjectWriter putObjectInit(Service.PutRequest initRequest) {
|
||||
if (initRequest.getSerializedSize() == 0) {
|
||||
throw new IllegalArgumentException(initRequest.getClass().getName());
|
||||
|
@ -248,4 +345,19 @@ public class ObjectService extends ContextAccessor implements ObjectClient {
|
|||
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
||||
}
|
||||
|
||||
private int readNBytes(FileInputStream fileInputStream, byte[] buffer, int size) {
|
||||
try {
|
||||
return fileInputStream.readNBytes(buffer, 0, size);
|
||||
} catch (IOException exp) {
|
||||
throw new IllegalArgumentException(exp.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private long getStreamSize(FileInputStream fileInputStream) {
|
||||
try {
|
||||
return fileInputStream.getChannel().size();
|
||||
} catch (IOException exp) {
|
||||
throw new IllegalArgumentException(exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package info.FrostFS.sdk.services.impl;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.dto.object.ObjectFrostFS;
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
import info.FrostFS.sdk.dto.object.ObjectId;
|
||||
import info.FrostFS.sdk.mappers.object.ObjectHeaderMapper;
|
||||
import info.FrostFS.sdk.mappers.object.ObjectIdMapper;
|
||||
import info.FrostFS.sdk.mappers.OwnerIdMapper;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
import info.FrostFS.sdk.services.ContextAccessor;
|
||||
import info.FrostFS.sdk.services.ToolsClient;
|
||||
import info.FrostFS.sdk.tools.ClientEnvironment;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
|
||||
import static info.FrostFS.sdk.Helper.getSha256;
|
||||
import static info.FrostFS.sdk.RequestSigner.signData;
|
||||
import static java.util.Objects.nonNull;
|
||||
|
||||
public class ObjectTools extends ContextAccessor implements ToolsClient {
|
||||
public ObjectTools(ClientEnvironment context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private static frostFS.refs.Types.Checksum sha256Checksum(byte[] data) {
|
||||
return frostFS.refs.Types.Checksum.newBuilder()
|
||||
.setType(frostFS.refs.Types.ChecksumType.SHA256)
|
||||
.setSum(ByteString.copyFrom(getSha256(data)))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||
var grpcHeader = createHeader(header, new byte[]{});
|
||||
|
||||
return ObjectIdMapper.toModel(
|
||||
frostFS.refs.Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build()
|
||||
);
|
||||
}
|
||||
|
||||
public Types.Object createObject(ObjectFrostFS objectFrostFs) {
|
||||
var grpcHeaderBuilder = ObjectHeaderMapper.toGrpcMessage(objectFrostFs.getHeader()).toBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()))
|
||||
.setPayloadLength(objectFrostFs.getPayload().length)
|
||||
.setPayloadHash(sha256Checksum(objectFrostFs.getPayload()));
|
||||
|
||||
var split = objectFrostFs.getHeader().getSplit();
|
||||
if (nonNull(split)) {
|
||||
var splitGrpc = Types.Header.Split.newBuilder()
|
||||
.setSplitId(nonNull(split.getSplitId()) ? ByteString.copyFrom(split.getSplitId().toBinary()) : null);
|
||||
|
||||
ListUtils.emptyIfNull(split.getChildren()).stream()
|
||||
.map(ObjectIdMapper::toGrpcMessage)
|
||||
.forEach(splitGrpc::addChildren);
|
||||
|
||||
|
||||
if (nonNull(split.getParentHeader())) {
|
||||
var grpcParentHeader = createHeader(split.getParentHeader(), new byte[]{});
|
||||
var parent = frostFS.refs.Types.ObjectID.newBuilder().setValue(getSha256(grpcParentHeader)).build();
|
||||
|
||||
splitGrpc
|
||||
.setParent(parent)
|
||||
.setParentHeader(grpcParentHeader)
|
||||
.setParentSignature(
|
||||
frostFS.refs.Types.Signature.newBuilder()
|
||||
.setKey(ByteString.copyFrom(getContext().getKey().getPublicKeyByte()))
|
||||
.setSign(ByteString.copyFrom(signData(getContext().getKey(), parent.toByteArray())))
|
||||
);
|
||||
|
||||
split.setParent(ObjectIdMapper.toModel(parent));
|
||||
}
|
||||
if (nonNull(split.getPrevious())) {
|
||||
splitGrpc.setPrevious(ObjectIdMapper.toGrpcMessage(split.getPrevious()));
|
||||
}
|
||||
grpcHeaderBuilder.setSplit(splitGrpc);
|
||||
}
|
||||
|
||||
var grpcHeader = grpcHeaderBuilder.build();
|
||||
var objectId = frostFS.refs.Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build();
|
||||
return Types.Object.newBuilder()
|
||||
.setHeader(grpcHeader)
|
||||
.setObjectId(objectId)
|
||||
.setPayload(ByteString.copyFrom(objectFrostFs.getPayload()))
|
||||
.setSignature(
|
||||
frostFS.refs.Types.Signature.newBuilder()
|
||||
.setKey(ByteString.copyFrom(getContext().getKey().getPublicKeyByte()))
|
||||
.setSign(ByteString.copyFrom(signData(getContext().getKey(), objectId.toByteArray())))
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
private Types.Header createHeader(ObjectHeader header, byte[] payload) {
|
||||
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(header).toBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()));
|
||||
|
||||
if (header.getPayloadCheckSum() != null)
|
||||
grpcHeader.setPayloadHash(sha256Checksum(header.getPayloadCheckSum()));
|
||||
else if (payload != null)
|
||||
grpcHeader.setPayloadHash(sha256Checksum(payload));
|
||||
|
||||
return grpcHeader.build();
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package info.FrostFS.sdk.services.impl;
|
|||
import frostFS.session.Service;
|
||||
import frostFS.session.SessionServiceGrpc;
|
||||
import frostFS.session.Types;
|
||||
import info.FrostFS.sdk.jdo.SessionToken;
|
||||
import info.FrostFS.sdk.dto.SessionToken;
|
||||
import info.FrostFS.sdk.mappers.OwnerIdMapper;
|
||||
import info.FrostFS.sdk.mappers.SessionMapper;
|
||||
import info.FrostFS.sdk.services.ContextAccessor;
|
||||
|
@ -14,36 +14,36 @@ import static info.FrostFS.sdk.RequestConstructor.addMetaHeader;
|
|||
import static info.FrostFS.sdk.RequestSigner.sign;
|
||||
|
||||
public class SessionService extends ContextAccessor implements SessionClient {
|
||||
private final SessionServiceGrpc.SessionServiceBlockingStub sessionServiceAsyncClient;
|
||||
private final SessionServiceGrpc.SessionServiceBlockingStub serviceBlockingStub;
|
||||
|
||||
public SessionService(ClientEnvironment clientEnvironment) {
|
||||
super(clientEnvironment);
|
||||
this.sessionServiceAsyncClient = SessionServiceGrpc.newBlockingStub(context.getChannel());
|
||||
this.serviceBlockingStub = SessionServiceGrpc.newBlockingStub(getContext().getChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionToken createSessionAsync(long expiration) {
|
||||
var sessionToken = createSessionInternalAsync(expiration);
|
||||
public SessionToken createSession(long expiration) {
|
||||
var sessionToken = createSessionInternal(expiration);
|
||||
var token = SessionMapper.serialize(sessionToken);
|
||||
return new SessionToken(new byte[]{}, token);
|
||||
}
|
||||
|
||||
public Types.SessionToken createSessionInternalAsync(long expiration) {
|
||||
public Types.SessionToken createSessionInternal(long expiration) {
|
||||
var request = Service.CreateRequest.newBuilder()
|
||||
.setBody(
|
||||
Service.CreateRequest.Body.newBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(context.getOwnerId()))
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setExpiration(expiration).build()
|
||||
);
|
||||
|
||||
addMetaHeader(request);
|
||||
sign(request, context.getPublicKey(), context.getPrivateKey());
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return createSession(request.build());
|
||||
}
|
||||
|
||||
private Types.SessionToken createSession(Service.CreateRequest request) {
|
||||
var resp = sessionServiceAsyncClient.create(request);
|
||||
var resp = serviceBlockingStub.create(request);
|
||||
|
||||
var lifetime = Types.SessionToken.Body.TokenLifetime.newBuilder()
|
||||
.setExp(request.getBody().getExpiration())
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
package info.FrostFS.sdk.tools;
|
||||
|
||||
import info.FrostFS.sdk.jdo.OwnerId;
|
||||
import info.FrostFS.sdk.jdo.Version;
|
||||
import info.FrostFS.sdk.dto.OwnerId;
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.services.FrostFSClient;
|
||||
import io.grpc.Channel;
|
||||
|
||||
import static info.FrostFS.sdk.KeyExtension.getPrivateKeyFromWIF;
|
||||
import static info.FrostFS.sdk.KeyExtension.loadPublicKey;
|
||||
|
||||
public class ClientEnvironment {
|
||||
private final OwnerId ownerId;
|
||||
private final Version version;
|
||||
private final byte[] privateKey;
|
||||
private final byte[] publicKey;
|
||||
private final ECDsa key;
|
||||
private final Channel channel;
|
||||
private final FrostFSClient frostFSClient;
|
||||
private NetworkSettings networkSettings;
|
||||
|
||||
public ClientEnvironment(String key, Channel channel, Version version, FrostFSClient frostFSClient) {
|
||||
this.privateKey = getPrivateKeyFromWIF(key);
|
||||
this.publicKey = loadPublicKey(privateKey);
|
||||
this.ownerId = OwnerId.fromKey(publicKey);
|
||||
public ClientEnvironment(String wif, Channel channel, Version version, FrostFSClient frostFSClient) {
|
||||
this.key = new ECDsa(wif);
|
||||
this.ownerId = OwnerId.fromKey(key.getPublicKeyByte());
|
||||
this.version = version;
|
||||
this.channel = channel;
|
||||
this.frostFSClient = frostFSClient;
|
||||
|
@ -50,11 +45,7 @@ public class ClientEnvironment {
|
|||
return version;
|
||||
}
|
||||
|
||||
public byte[] getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
public ECDsa getKey() {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.FrostFS.sdk;
|
||||
package info.FrostFS.sdk.tools;
|
||||
|
||||
import io.grpc.ChannelCredentials;
|
||||
import org.apache.commons.lang3.StringUtils;
|
29
client/src/main/java/info/FrostFS/sdk/tools/ECDsa.java
Normal file
29
client/src/main/java/info/FrostFS/sdk/tools/ECDsa.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package info.FrostFS.sdk.tools;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
|
||||
import static info.FrostFS.sdk.KeyExtension.*;
|
||||
|
||||
public class ECDsa {
|
||||
private final byte[] publicKeyByte;
|
||||
private final byte[] privateKeyByte;
|
||||
private final PrivateKey privateKey;
|
||||
|
||||
public ECDsa(String wif) {
|
||||
this.privateKeyByte = getPrivateKeyFromWIF(wif);
|
||||
this.publicKeyByte = loadPublicKey(privateKeyByte);
|
||||
this.privateKey = loadPrivateKey(privateKeyByte);
|
||||
}
|
||||
|
||||
public byte[] getPublicKeyByte() {
|
||||
return publicKeyByte;
|
||||
}
|
||||
|
||||
public byte[] getPrivateKeyByte() {
|
||||
return privateKeyByte;
|
||||
}
|
||||
|
||||
public PrivateKey getPrivateKey() {
|
||||
return privateKey;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package info.FrostFS.sdk.tools;
|
||||
|
||||
import info.FrostFS.sdk.dto.object.ObjectHeader;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class PutObjectParameters {
|
||||
private static final String ERROR_TEMPLATE = "%s value cannot be null.";
|
||||
|
||||
public ObjectHeader header;
|
||||
public FileInputStream payload;
|
||||
public boolean clientCut;
|
||||
public int bufferMaxSize;
|
||||
|
||||
public PutObjectParameters(ObjectHeader header, FileInputStream payload, boolean clientCut, int bufferMaxSize) {
|
||||
this.header = header;
|
||||
this.payload = payload;
|
||||
this.clientCut = clientCut;
|
||||
this.bufferMaxSize = bufferMaxSize;
|
||||
}
|
||||
|
||||
public PutObjectParameters(ObjectHeader header, FileInputStream payload) {
|
||||
this.header = header;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public ObjectHeader getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(ObjectHeader header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public FileInputStream getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(FileInputStream payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public boolean isClientCut() {
|
||||
return clientCut;
|
||||
}
|
||||
|
||||
public void setClientCut(boolean clientCut) {
|
||||
this.clientCut = clientCut;
|
||||
}
|
||||
|
||||
public int getBufferMaxSize() {
|
||||
return bufferMaxSize;
|
||||
}
|
||||
|
||||
public void setBufferMaxSize(int bufferMaxSize) {
|
||||
this.bufferMaxSize = bufferMaxSize;
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
StringBuilder errorMessage = new StringBuilder();
|
||||
|
||||
if (isNull(header)) {
|
||||
errorMessage.append(String.format(ERROR_TEMPLATE, "Header")).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
if (isNull(payload)) {
|
||||
errorMessage.append(String.format(ERROR_TEMPLATE, "Payload")).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
if (errorMessage.length() != 0) {
|
||||
throw new IllegalArgumentException(errorMessage.toString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,11 +19,6 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
|
@ -34,11 +29,6 @@
|
|||
<artifactId>bcprov-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk18on</artifactId>
|
||||
<version>1.78.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -18,19 +18,23 @@ public class Helper {
|
|||
return hash;
|
||||
}
|
||||
|
||||
public static byte[] getSha256(byte[] value) {
|
||||
public static MessageDigest getSha256Instance() {
|
||||
try {
|
||||
return MessageDigest.getInstance("SHA-256").digest(value);
|
||||
return MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getSha256(byte[] value) {
|
||||
return getSha256Instance().digest(value);
|
||||
}
|
||||
|
||||
public static ByteString getSha256(AbstractMessage value) {
|
||||
return ByteString.copyFrom(getSha256(value.toByteArray()));
|
||||
}
|
||||
|
||||
public static String пуеHexString(byte[] array) {
|
||||
public static String getHexString(byte[] array) {
|
||||
return String.format("%0" + (array.length << 1) + "x", new BigInteger(1, array));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,9 @@ public class KeyExtension {
|
|||
|
||||
public static byte[] loadPublicKey(byte[] privateKey) {
|
||||
X9ECParameters params = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
ECDomainParameters domain = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
|
||||
ECDomainParameters domain = new ECDomainParameters(
|
||||
params.getCurve(), params.getG(), params.getN(), params.getH()
|
||||
);
|
||||
ECPoint q = domain.getG().multiply(new BigInteger(1, privateKey));
|
||||
ECPublicKeyParameters publicParams = new ECPublicKeyParameters(q, domain);
|
||||
return publicParams.getQ().getEncoded(true);
|
||||
|
@ -65,7 +67,9 @@ public class KeyExtension {
|
|||
|
||||
public static PrivateKey loadPrivateKey(byte[] privateKey) {
|
||||
X9ECParameters params = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
ECDomainParameters domain = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
|
||||
ECDomainParameters domain = new ECDomainParameters(
|
||||
params.getCurve(), params.getG(), params.getN(), params.getH()
|
||||
);
|
||||
ECPrivateKeyParameters ecParams = new ECPrivateKeyParameters(fromUnsignedByteArray(privateKey), domain);
|
||||
|
||||
ECParameterSpec ecParameterSpec = new ECNamedCurveSpec(
|
||||
|
@ -80,7 +84,7 @@ public class KeyExtension {
|
|||
}
|
||||
}
|
||||
|
||||
public static PublicKey getPublicKeyByPublic(byte[] publicKey) {
|
||||
public static PublicKey getPublicKeyFromBytes(byte[] publicKey) {
|
||||
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Decompress argument isn't compressed public key. Expected length=%s, actual=%s",
|
||||
|
@ -89,14 +93,17 @@ public class KeyExtension {
|
|||
}
|
||||
|
||||
X9ECParameters secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||
ECDomainParameters domain = new ECDomainParameters(secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH());
|
||||
ECDomainParameters domain = new ECDomainParameters(
|
||||
secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH()
|
||||
);
|
||||
var ecPoint = secp256R1.getCurve().decodePoint(publicKey);
|
||||
var publicParams = new ECPublicKeyParameters(ecPoint, domain);
|
||||
java.security.spec.ECPoint point = new java.security.spec.ECPoint(
|
||||
publicParams.getQ().getRawXCoord().toBigInteger(), publicParams.getQ().getRawYCoord().toBigInteger()
|
||||
);
|
||||
ECParameterSpec ecParameterSpec = new ECNamedCurveSpec(
|
||||
"secp256r1", secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(), secp256R1.getH(), secp256R1.getSeed()
|
||||
"secp256r1", secp256R1.getCurve(), secp256R1.getG(), secp256R1.getN(),
|
||||
secp256R1.getH(), secp256R1.getSeed()
|
||||
);
|
||||
ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(point, ecParameterSpec);
|
||||
|
||||
|
@ -108,7 +115,6 @@ public class KeyExtension {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static byte[] getScriptHash(byte[] publicKey) {
|
||||
var script = createSignatureRedeemScript(publicKey);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>modelsV2</artifactId>
|
||||
<artifactId>models</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
|
@ -30,7 +30,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.FrostFS.sdk</groupId>
|
||||
<artifactId>protosV2</artifactId>
|
||||
<artifactId>protos</artifactId>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
|
@ -1,6 +1,6 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.constants;
|
||||
|
||||
public class Constants {
|
||||
public class AppConst {
|
||||
public static final int OBJECT_CHUNK_SIZE = 3 * (1 << 20);
|
||||
public static final int SHA256_HASH_LENGTH = 32;
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto;
|
||||
|
||||
public class MetaHeader {
|
||||
public Version version;
|
||||
public int epoch;
|
||||
public int ttl;
|
||||
private Version version;
|
||||
private int epoch;
|
||||
private int ttl;
|
||||
|
||||
public MetaHeader(Version version, int epoch, int ttl) {
|
||||
this.version = version;
|
|
@ -1,4 +1,4 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import info.FrostFS.sdk.Base58;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto;
|
||||
|
||||
public class SessionToken {
|
||||
public byte[] id;
|
||||
public byte[] sessionKey;
|
||||
private final byte[] id;
|
||||
private final byte[] sessionKey;
|
||||
|
||||
public SessionToken(byte[] id, byte[] sessionKey) {
|
||||
this.id = id;
|
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);
|
||||
}
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto;
|
||||
|
||||
import info.FrostFS.sdk.enums.StatusCode;
|
||||
|
||||
import java.util.Optional;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class Status {
|
||||
public StatusCode code;
|
||||
public String message;
|
||||
private StatusCode code;
|
||||
private String message;
|
||||
|
||||
public Status(StatusCode code, String message) {
|
||||
this.code = code;
|
||||
this.message = Optional.ofNullable(message).orElse("");
|
||||
this.message = isNull(message) ? "" : message;
|
||||
}
|
||||
|
||||
public Status(StatusCode code) {
|
||||
|
@ -36,7 +36,7 @@ public class Status {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Response status: " + code + ". Message: " + message + ".";
|
||||
return String.format("Response status: %s. Message: %s.", code, message);
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
|
@ -1,8 +1,13 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto;
|
||||
|
||||
public class Version {
|
||||
public int major;
|
||||
public int minor;
|
||||
private int major;
|
||||
private int minor;
|
||||
|
||||
public Version(int major, int minor) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return major;
|
||||
|
@ -25,11 +30,6 @@ public class Version {
|
|||
return "v" + major + "." + minor;
|
||||
}
|
||||
|
||||
public Version(int major, int minor) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public boolean isSupported(Version version) {
|
||||
return major == version.getMajor();
|
||||
}
|
|
@ -1,15 +1,22 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
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 info.FrostFS.sdk.jdo.netmap.PlacementPolicy;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Container {
|
||||
public UUID nonce;
|
||||
public BasicAcl basicAcl;
|
||||
public PlacementPolicy placementPolicy;
|
||||
public Version version;
|
||||
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;
|
||||
|
@ -42,17 +49,4 @@ public class Container {
|
|||
public void setVersion(Version version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy) {
|
||||
nonce = UUID.randomUUID();
|
||||
this.basicAcl = basicAcl;
|
||||
this.placementPolicy = placementPolicy;
|
||||
}
|
||||
|
||||
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy, UUID nonce, Version version) {
|
||||
this.nonce = nonce;
|
||||
this.basicAcl = basicAcl;
|
||||
this.placementPolicy = placementPolicy;
|
||||
this.version = version;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,17 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto.container;
|
||||
|
||||
import info.FrostFS.sdk.Base58;
|
||||
import info.FrostFS.sdk.constants.AppConst;
|
||||
|
||||
public class ContainerId {
|
||||
public String value;
|
||||
private String value;
|
||||
|
||||
public ContainerId(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ContainerId fromHash(byte[] hash) {
|
||||
if (hash.length != Constants.SHA256_HASH_LENGTH) {
|
||||
if (hash.length != AppConst.SHA256_HASH_LENGTH) {
|
||||
throw new IllegalArgumentException("ContainerID must be a sha256 hash.");
|
||||
}
|
||||
return new ContainerId(Base58.encode(hash));
|
|
@ -1,10 +1,10 @@
|
|||
package info.FrostFS.sdk.jdo.netmap;
|
||||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NetmapSnapshot {
|
||||
public Long epoch;
|
||||
public List<NodeInfo> nodeInfoCollection;
|
||||
private final Long epoch;
|
||||
private final List<NodeInfo> nodeInfoCollection;
|
||||
|
||||
public NetmapSnapshot(Long epoch, List<NodeInfo> nodeInfoCollection) {
|
||||
this.epoch = epoch;
|
|
@ -1,17 +1,17 @@
|
|||
package info.FrostFS.sdk.jdo.netmap;
|
||||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
import info.FrostFS.sdk.enums.NodeState;
|
||||
import info.FrostFS.sdk.jdo.Version;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NodeInfo {
|
||||
public NodeState state;
|
||||
public Version version;
|
||||
public List<String> addresses;
|
||||
public Map<String, String> attributes;
|
||||
public byte[] publicKey;
|
||||
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) {
|
||||
|
@ -26,18 +26,10 @@ public class NodeInfo {
|
|||
return state;
|
||||
}
|
||||
|
||||
public void setState(NodeState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Version version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package info.FrostFS.sdk.jdo.netmap;
|
||||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
public class PlacementPolicy {
|
||||
public Replica[] replicas;
|
||||
public boolean unique;
|
||||
private final Replica[] replicas;
|
||||
private final boolean unique;
|
||||
|
||||
public PlacementPolicy(boolean unique, Replica[] replicas) {
|
||||
this.replicas = replicas;
|
||||
|
@ -13,15 +13,7 @@ public class PlacementPolicy {
|
|||
return replicas;
|
||||
}
|
||||
|
||||
public void setReplicas(Replica[] replicas) {
|
||||
this.replicas = replicas;
|
||||
}
|
||||
|
||||
public boolean isUnique() {
|
||||
return unique;
|
||||
}
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
package info.FrostFS.sdk.jdo.netmap;
|
||||
package info.FrostFS.sdk.dto.netmap;
|
||||
|
||||
import java.util.Optional;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class Replica {
|
||||
public int count;
|
||||
public String selector;
|
||||
private int count;
|
||||
private String selector;
|
||||
|
||||
public Replica(int count, String selector) {
|
||||
this.count = count;
|
||||
this.selector = Optional.ofNullable(selector).orElse("");
|
||||
this.selector = isNull(selector) ? "" : selector;
|
||||
}
|
||||
|
||||
public Replica(int count) {
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
public class ObjectAttribute {
|
||||
public String key;
|
||||
public String value;
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public ObjectAttribute(String key, String value) {
|
||||
this.key = key;
|
|
@ -1,13 +1,15 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
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 static final String HEADER_PREFIX = "$Object:";
|
||||
|
||||
public ObjectMatchType matchType;
|
||||
public String key;
|
||||
public String value;
|
||||
private ObjectMatchType matchType;
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
|
||||
public ObjectFilter(ObjectMatchType matchType, String key, String value) {
|
||||
|
@ -17,7 +19,7 @@ public class ObjectFilter {
|
|||
}
|
||||
|
||||
public static ObjectFilter ObjectIdFilter(ObjectMatchType matchType, ObjectId objectId) {
|
||||
return new ObjectFilter(matchType, HEADER_PREFIX + "objectID", objectId.value);
|
||||
return new ObjectFilter(matchType, HEADER_PREFIX + "objectID", objectId.getValue());
|
||||
}
|
||||
|
||||
public static ObjectFilter OwnerFilter(ObjectMatchType matchType, OwnerId ownerId) {
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,17 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
package info.FrostFS.sdk.dto.object;
|
||||
|
||||
import info.FrostFS.sdk.Base58;
|
||||
import info.FrostFS.sdk.constants.AppConst;
|
||||
|
||||
public class ObjectId {
|
||||
public String value;
|
||||
private final String value;
|
||||
|
||||
public ObjectId(String id) {
|
||||
this.value = id;
|
||||
}
|
||||
|
||||
public static ObjectId fromHash(byte[] hash) {
|
||||
if (hash.length != Constants.SHA256_HASH_LENGTH) {
|
||||
if (hash.length != AppConst.SHA256_HASH_LENGTH) {
|
||||
throw new IllegalArgumentException("ObjectId must be a sha256 hash.");
|
||||
}
|
||||
return new ObjectId(Base58.encode(hash));
|
|
@ -28,6 +28,6 @@ public enum BasicAcl {
|
|||
}
|
||||
|
||||
public static BasicAcl get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(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;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.session.Types;
|
||||
import info.FrostFS.sdk.jdo.MetaHeader;
|
||||
import info.FrostFS.sdk.dto.MetaHeader;
|
||||
|
||||
public class MetaHeaderMapper {
|
||||
|
|
@ -2,9 +2,10 @@ package info.FrostFS.sdk.mappers;
|
|||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.jdo.OwnerId;
|
||||
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()))
|
|
@ -8,24 +8,22 @@ import java.io.IOException;
|
|||
|
||||
public class SessionMapper {
|
||||
|
||||
public static byte[] serialize(Types.SessionToken token)
|
||||
{
|
||||
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 e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
} catch (IOException exp) {
|
||||
throw new IllegalArgumentException(exp.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static Types.SessionToken deserializeSessionToken(byte[] bytes)
|
||||
{
|
||||
public static Types.SessionToken deserializeSessionToken(byte[] bytes) {
|
||||
try {
|
||||
return Types.SessionToken.newBuilder().mergeFrom(bytes).build();
|
||||
} catch (InvalidProtocolBufferException exp) {
|
||||
throw new IllegalArgumentException();
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.status.Types;
|
||||
import info.FrostFS.sdk.dto.Status;
|
||||
import info.FrostFS.sdk.enums.StatusCode;
|
||||
import info.FrostFS.sdk.jdo.Status;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class StatusMapper {
|
||||
|
||||
public static Status toModel(Types.Status status) {
|
||||
if (isNull(status)) return new Status(StatusCode.SUCCESS);
|
||||
|
||||
|
@ -15,7 +16,6 @@ public class StatusMapper {
|
|||
throw new IllegalArgumentException(
|
||||
String.format("Unknown StatusCode. Value: %s.", status.getCode())
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
return new Status(statusCode, status.getMessage());
|
|
@ -1,7 +1,7 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.jdo.Version;
|
||||
import info.FrostFS.sdk.dto.Version;
|
||||
|
||||
public class VersionMapper {
|
||||
|
|
@ -1,14 +1,12 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
package info.FrostFS.sdk.mappers.container;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.jdo.ContainerId;
|
||||
import info.FrostFS.sdk.dto.container.ContainerId;
|
||||
|
||||
public class ContainerIdMapper {
|
||||
|
||||
public static Types.ContainerID toGrpcMessage(ContainerId containerId) {
|
||||
var test = containerId.toHash();
|
||||
|
||||
return Types.ContainerID.newBuilder()
|
||||
.setValue(ByteString.copyFrom(containerId.toHash()))
|
||||
.build();
|
|
@ -1,10 +1,10 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
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.jdo.Container;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
import info.FrostFS.sdk.mappers.netmap.PlacementPolicyMapper;
|
||||
|
||||
import static info.FrostFS.sdk.UUIDExtension.asBytes;
|
||||
|
@ -21,19 +21,17 @@ public class ContainerMapper {
|
|||
.build();
|
||||
}
|
||||
|
||||
public static Container toModel(Types.Container container) {
|
||||
var basicAcl = BasicAcl.get(container.getBasicAcl());
|
||||
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.", container.getBasicAcl())
|
||||
String.format("Unknown BasicACL rule. Value: %s.", containerGrpc.getBasicAcl())
|
||||
);
|
||||
}
|
||||
|
||||
return new Container(
|
||||
basicAcl,
|
||||
PlacementPolicyMapper.toModel(container.getPlacementPolicy()),
|
||||
asUuid(container.getNonce().toByteArray()),
|
||||
VersionMapper.toModel(container.getVersion())
|
||||
);
|
||||
var container = new Container(basicAcl, PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()));
|
||||
container.setNonce(asUuid(containerGrpc.getNonce().toByteArray()));
|
||||
container.setVersion(VersionMapper.toModel(containerGrpc.getVersion()));
|
||||
return container;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Service;
|
||||
import info.FrostFS.sdk.jdo.netmap.NetmapSnapshot;
|
||||
import info.FrostFS.sdk.dto.netmap.NetmapSnapshot;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class NetmapSnapshotMapper {
|
|||
return new NetmapSnapshot(
|
||||
netmap.getBody().getNetmap().getEpoch(),
|
||||
netmap.getBody().getNetmap().getNodesList().stream()
|
||||
.map(t -> NodeInfoMapper.toModel(t, netmap.getMetaHeader().getVersion()))
|
||||
.map(node -> NodeInfoMapper.toModel(node, netmap.getMetaHeader().getVersion()))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
|
@ -3,8 +3,8 @@ 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.jdo.netmap.NodeInfo;
|
||||
import info.FrostFS.sdk.mappers.VersionMapper;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -12,13 +12,13 @@ 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())
|
|
@ -1,10 +1,11 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Types;
|
||||
import info.FrostFS.sdk.jdo.netmap.PlacementPolicy;
|
||||
import info.FrostFS.sdk.jdo.netmap.Replica;
|
||||
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());
|
|
@ -1,9 +1,10 @@
|
|||
package info.FrostFS.sdk.mappers.netmap;
|
||||
|
||||
import frostFS.netmap.Types;
|
||||
import info.FrostFS.sdk.jdo.netmap.Replica;
|
||||
import info.FrostFS.sdk.dto.netmap.Replica;
|
||||
|
||||
public class ReplicaMapper {
|
||||
|
||||
public static Types.Replica toGrpcMessage(Replica replica) {
|
||||
return Types.Replica.newBuilder()
|
||||
.setCount(replica.getCount())
|
|
@ -1,9 +1,10 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.jdo.ObjectAttribute;
|
||||
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())
|
|
@ -1,13 +1,13 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import frostFS.object.Service;
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.jdo.ObjectFilter;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
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)) {
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,17 +1,21 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
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.jdo.ContainerId;
|
||||
import info.FrostFS.sdk.jdo.ObjectAttribute;
|
||||
import info.FrostFS.sdk.jdo.ObjectHeader;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
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 = EnumUtils.getEnum(Types.ObjectType.class, header.getObjectType().name());
|
||||
var objectType = Types.ObjectType.forNumber(header.getObjectType().value);
|
||||
if (isNull(objectType)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Unknown ObjectType. Value: %s.", header.getObjectType().name())
|
||||
|
@ -40,7 +44,7 @@ public class ObjectHeaderMapper {
|
|||
return new ObjectHeader(
|
||||
ContainerId.fromHash(header.getContainerId().getValue().toByteArray()),
|
||||
objectType,
|
||||
header.getAttributesList().stream().map(ObjectAttributeMapper::toModel).toArray(ObjectAttribute[]::new),
|
||||
header.getAttributesList().stream().map(ObjectAttributeMapper::toModel).collect(Collectors.toList()),
|
||||
header.getPayloadLength(),
|
||||
VersionMapper.toModel(header.getVersion())
|
||||
);
|
|
@ -1,13 +1,18 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
package info.FrostFS.sdk.mappers.object;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostFS.refs.Types;
|
||||
import info.FrostFS.sdk.jdo.ObjectId;
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
|
||||
public class ObjectFrostFs {
|
||||
public ObjectHeader header;
|
||||
public ObjectId objectId;
|
||||
public byte[] payload;
|
||||
|
||||
public ObjectFrostFs(ObjectHeader header, ObjectId objectId, byte[] payload) {
|
||||
this.header = header;
|
||||
this.objectId = objectId;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public ObjectHeader getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public void setHeader(ObjectHeader header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public ObjectId getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
public void setObjectId(ObjectId objectId) {
|
||||
this.objectId = objectId;
|
||||
}
|
||||
|
||||
public byte[] getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void setPayload(byte[] payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package info.FrostFS.sdk.jdo;
|
||||
|
||||
import info.FrostFS.sdk.enums.ObjectType;
|
||||
|
||||
public class ObjectHeader {
|
||||
public ObjectAttribute[] attributes;
|
||||
public ContainerId containerId;
|
||||
public long size;
|
||||
public ObjectType objectType;
|
||||
public Version version;
|
||||
|
||||
public ObjectHeader(ContainerId containerId, ObjectType objectType, 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, ObjectAttribute[] attributes) {
|
||||
this.attributes = attributes;
|
||||
this.containerId = containerId;
|
||||
this.objectType = type;
|
||||
}
|
||||
|
||||
public ObjectHeader(ContainerId containerId, ObjectAttribute[] attributes) {
|
||||
this.attributes = attributes;
|
||||
this.containerId = containerId;
|
||||
this.objectType = ObjectType.REGULAR;
|
||||
}
|
||||
|
||||
public ObjectAttribute[] getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(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;
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package info.FrostFS.sdk.mappers;
|
||||
|
||||
import frostFS.object.Types;
|
||||
import info.FrostFS.sdk.jdo.ObjectFrostFs;
|
||||
import info.FrostFS.sdk.jdo.ObjectId;
|
||||
|
||||
public class ObjectMapper {
|
||||
public static ObjectFrostFs toModel(Types.Object obj) {
|
||||
return new ObjectFrostFs(
|
||||
ObjectHeaderMapper.toModel(obj.getHeader()),
|
||||
ObjectId.fromHash(obj.getObjectId().getValue().toByteArray()),
|
||||
obj.getPayload().toByteArray()
|
||||
);
|
||||
}
|
||||
}
|
4
pom.xml
4
pom.xml
|
@ -9,10 +9,10 @@
|
|||
<version>0.1.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>protosV2</module>
|
||||
<module>client</module>
|
||||
<module>cryptography</module>
|
||||
<module>modelsV2</module>
|
||||
<module>models</module>
|
||||
<module>protos</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>protosV2</artifactId>
|
||||
<artifactId>protos</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<protobuf.version>3.23.0</protobuf.version>
|
||||
<grpc.version>1.62.2</grpc.version>
|
||||
<grpc.version>1.65.1</grpc.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
Loading…
Reference in a new issue