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