Compare commits
No commits in common. "master" and "feature/add-codeowners" have entirely different histories.
master
...
feature/ad
172 changed files with 1355 additions and 5679 deletions
|
@ -1,22 +0,0 @@
|
||||||
on:
|
|
||||||
push:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
image:
|
|
||||||
name: Publish Maven packages
|
|
||||||
runs-on: docker
|
|
||||||
container: git.frostfs.info/truecloudlab/env:openjdk-11-maven-3.8.6
|
|
||||||
steps:
|
|
||||||
- name: Clone git repo
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Publish release packages
|
|
||||||
run: mvn clean --batch-mode --update-snapshots deploy
|
|
||||||
if: >-
|
|
||||||
startsWith(github.ref, 'refs/tags/v') &&
|
|
||||||
(github.event_name == 'workflow_dispatch' || github.event_name == 'push')
|
|
||||||
env:
|
|
||||||
MAVEN_REGISTRY: TrueCloudLab
|
|
||||||
MAVEN_REGISTRY_USER: ${{secrets.MAVEN_REGISTRY_USER}}
|
|
||||||
MAVEN_REGISTRY_PASSWORD: ${{secrets.MAVEN_REGISTRY_PASSWORD}}
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,7 +3,6 @@ target/
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
**/.flattened-pom.xml
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea/modules.xml
|
.idea/modules.xml
|
||||||
|
|
37
CHANGELOG.md
37
CHANGELOG.md
|
@ -1,37 +0,0 @@
|
||||||
# Changelog
|
|
||||||
|
|
||||||
## [0.9.0] - 2025-03-05
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- APE rule deserializer
|
|
||||||
|
|
||||||
## [0.8.0] - 2025-03-04
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Creating client via wallet and password
|
|
||||||
|
|
||||||
## [0.7.0] - 2025-02-20
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Expanding the parameters for creating a container
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Creating a session for working with objects
|
|
||||||
|
|
||||||
## [0.6.0] - 2025-02-13
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- APE rules serializer
|
|
||||||
|
|
||||||
## [0.5.0] - 2025-02-11
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
- Loading large objects in chunks
|
|
||||||
- .gitignore
|
|
||||||
- pom revision
|
|
113
README.md
113
README.md
|
@ -21,39 +21,31 @@ neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>
|
||||||
### Container operations
|
### Container operations
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import info.frostfs.sdk.FrostFSClient;
|
|
||||||
import info.frostfs.sdk.dto.container.Container;
|
import info.frostfs.sdk.dto.container.Container;
|
||||||
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
||||||
import info.frostfs.sdk.dto.netmap.Replica;
|
import info.frostfs.sdk.dto.netmap.Replica;
|
||||||
|
import info.frostfs.sdk.enums.BasicAcl;
|
||||||
import info.frostfs.sdk.jdo.ClientSettings;
|
import info.frostfs.sdk.jdo.ClientSettings;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.FrostFSClient;
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
|
||||||
|
|
||||||
public class ContainerExample {
|
public class ContainerExample {
|
||||||
|
|
||||||
public void example() {
|
public void example() {
|
||||||
var callContext = new CallContext();
|
|
||||||
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
||||||
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
||||||
|
|
||||||
// Create container
|
// Create container
|
||||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(3)}, true, 1);
|
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, Boolean.TRUE);
|
||||||
var prmContainerCreate = new PrmContainerCreate(new Container(placementPolicy));
|
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||||
var containerId = frostFSClient.createContainer(prmContainerCreate, callContext);
|
|
||||||
|
|
||||||
// Get container
|
// Get container
|
||||||
var prmContainerGet = new PrmContainerGet(containerId);
|
var container = frostFSClient.getContainer(containerId);
|
||||||
var container = frostFSClient.getContainer(prmContainerGet, callContext);
|
|
||||||
|
|
||||||
// List containers
|
// List containers
|
||||||
var containerIds = frostFSClient.listContainers(new PrmContainerGetAll(), callContext);
|
var containerIds = frostFSClient.listContainers();
|
||||||
|
|
||||||
// Delete container
|
// Delete container
|
||||||
var prmContainerDelete = new PrmContainerDelete(containerId);
|
frostFSClient.deleteContainer(containerId);
|
||||||
frostFSClient.deleteContainer(prmContainerDelete, callContext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -61,104 +53,45 @@ public class ContainerExample {
|
||||||
### Object operations
|
### Object operations
|
||||||
|
|
||||||
```java
|
```java
|
||||||
import info.frostfs.sdk.dto.object.*;
|
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
import info.frostfs.sdk.jdo.ClientSettings;
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
|
import info.frostfs.sdk.dto.object.ObjectId;
|
||||||
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
|
import info.frostfs.sdk.FrostFSClient;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
public class ObjectExample {
|
public class ObjectExample {
|
||||||
|
|
||||||
public void example() {
|
public void example() {
|
||||||
CallContext callContext = new CallContext();
|
|
||||||
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
||||||
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
||||||
|
|
||||||
// Put object
|
// Put object
|
||||||
ObjectId objectId;
|
ObjectId objectId;
|
||||||
try (FileInputStream file = new FileInputStream("/path/to/file/cat.jpg")) {
|
try (FileInputStream fis = new FileInputStream("cat.jpg")) {
|
||||||
var attribute = new ObjectAttribute("Filename", "cat.jpg");
|
var cat = new ObjectHeader(
|
||||||
var cat = new ObjectHeader(containerId, ObjectType.REGULAR, attribute);
|
containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")}
|
||||||
var prmObjectPut = PrmObjectPut.builder().objectHeader(cat).build();
|
);
|
||||||
var writer = frostFSClient.putObject(prmObjectPut, callContext);
|
|
||||||
|
|
||||||
writer.write(file.readAllBytes());
|
var params = new PutObjectParameters(cat, fis);
|
||||||
objectId = writer.complete();
|
objectId = frostFSClient.putObject(params);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get object
|
// Get object
|
||||||
var prmObjectGet = new PrmObjectGet(containerId, oid);
|
var obj = frostFSClient.getObject(containerId, objectId);
|
||||||
ObjectFrostFS object = frostFSClient.getObject(prmObjectGet, callContext);
|
|
||||||
|
|
||||||
var reader = object.getObjectReader();
|
|
||||||
var chunk = reader.readChunk();
|
|
||||||
var length = chunk.length;
|
|
||||||
byte[] buffer = null;
|
|
||||||
while (length > 0) {
|
|
||||||
buffer = isNull(buffer) ? chunk : ArrayHelper.concat(buffer, chunk);
|
|
||||||
|
|
||||||
chunk = object.getObjectReader().readChunk();
|
|
||||||
length = ArrayUtils.isEmpty(chunk) ? 0 : chunk.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
try (FileOutputStream fos = new FileOutputStream("/path/to/file/newCat.jpg")) {
|
|
||||||
fos.write(buffer);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get object header
|
// Get object header
|
||||||
var prmObjectHeadGet = new PrmObjectHeadGet(containerId, objectId);
|
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
||||||
var objectHeader = frostFSClient.getObjectHead(prmObjectHeadGet, callContext);
|
|
||||||
|
|
||||||
// Search regular objects
|
// Search regular objects
|
||||||
var prmObjectSearch = new PrmObjectSearch(containerId, new ObjectFilter.FilterByRootObject());
|
var objectIds = frostFSClient.searchObjects(containerId, new ObjectFilter.FilterByRootObject());
|
||||||
var objectIds = frostFSClient.searchObjects(prmObjectSearch, callContext);
|
|
||||||
|
|
||||||
// Delete object
|
|
||||||
var prmObjectDelete = new PrmObjectDelete(containerId, objectId);
|
|
||||||
frostFSClient.deleteObject(prmObjectDelete, callContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pool init
|
|
||||||
|
|
||||||
```java
|
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.pool.NodeParameters;
|
|
||||||
import info.frostfs.sdk.jdo.pool.PoolInitParameters;
|
|
||||||
import info.frostfs.sdk.pool.Pool;
|
|
||||||
|
|
||||||
public class PoolExample {
|
|
||||||
|
|
||||||
public static void example() {
|
|
||||||
CallContext callContext = new CallContext();
|
|
||||||
|
|
||||||
//Init
|
|
||||||
var nodeParam1 = new NodeParameters(1, <your_host1>, 1);
|
|
||||||
var nodeParam2 = new NodeParameters(1, <your_host2>, 1);
|
|
||||||
var nodeParam3 = new NodeParameters(1, <your_host3>, 1);
|
|
||||||
var nodeParam4 = new NodeParameters(1, <your_host4>, 1);
|
|
||||||
|
|
||||||
PoolInitParameters initParameters = new PoolInitParameters();
|
|
||||||
initParameters.setKey(new ECDsa(<your_key>));
|
|
||||||
initParameters.setNodeParams(new NodeParameters[]{nodeParam1, nodeParam2, nodeParam3, nodeParam4});
|
|
||||||
|
|
||||||
|
|
||||||
Pool pool = new Pool(initParameters);
|
|
||||||
|
|
||||||
//Dial (Required!)
|
|
||||||
pool.dial(callContext);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
|
@ -6,7 +6,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>frostfs-sdk-java</artifactId>
|
<artifactId>frostfs-sdk-java</artifactId>
|
||||||
<version>${revision}</version>
|
<version>0.1.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>client</artifactId>
|
<artifactId>client</artifactId>
|
||||||
|
@ -21,17 +21,17 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>cryptography</artifactId>
|
<artifactId>cryptography</artifactId>
|
||||||
<version>${revision}</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>models</artifactId>
|
<artifactId>models</artifactId>
|
||||||
<version>${revision}</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>exceptions</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
<version>${revision}</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
|
@ -54,10 +54,5 @@
|
||||||
<artifactId>simpleclient_common</artifactId>
|
<artifactId>simpleclient_common</artifactId>
|
||||||
<version>0.16.0</version>
|
<version>0.16.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>2.0.16</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -1,12 +1,13 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
import frostfs.accounting.Types;
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
import info.frostfs.sdk.dto.ape.Chain;
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
import info.frostfs.sdk.dto.container.Container;
|
import info.frostfs.sdk.dto.container.Container;
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
|
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
import info.frostfs.sdk.dto.object.ObjectId;
|
||||||
|
@ -14,35 +15,15 @@ import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.ClientSettings;
|
import info.frostfs.sdk.jdo.ClientSettings;
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
|
||||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
import info.frostfs.sdk.services.*;
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
|
||||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
|
||||||
import info.frostfs.sdk.pool.SessionCache;
|
|
||||||
import info.frostfs.sdk.pool.WrapperPrm;
|
|
||||||
import info.frostfs.sdk.services.CommonClient;
|
|
||||||
import info.frostfs.sdk.services.impl.*;
|
import info.frostfs.sdk.services.impl.*;
|
||||||
import info.frostfs.sdk.services.impl.interceptor.Configuration;
|
import info.frostfs.sdk.services.impl.interceptor.Configuration;
|
||||||
import info.frostfs.sdk.services.impl.interceptor.MonitoringClientInterceptor;
|
import info.frostfs.sdk.services.impl.interceptor.MonitoringClientInterceptor;
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.RangeReader;
|
|
||||||
import info.frostfs.sdk.utils.Validator;
|
import info.frostfs.sdk.utils.Validator;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ClientInterceptors;
|
import io.grpc.ClientInterceptors;
|
||||||
import io.grpc.ManagedChannel;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -50,51 +31,26 @@ import static info.frostfs.sdk.constants.ErrorConst.VERSION_UNSUPPORTED_TEMPLATE
|
||||||
import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel;
|
import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel;
|
||||||
import static java.util.Objects.nonNull;
|
import static java.util.Objects.nonNull;
|
||||||
|
|
||||||
public class FrostFSClient implements CommonClient {
|
public class FrostFSClient
|
||||||
private static final MonitoringClientInterceptor MONITORING_CLIENT_INTERCEPTOR =
|
implements ContainerClient, ObjectClient, ApeManagerClient, NetmapClient, SessionClient, ToolsClient {
|
||||||
MonitoringClientInterceptor.create(Configuration.allMetrics());
|
|
||||||
|
|
||||||
private final ContainerClientImpl containerClientImpl;
|
private final ContainerClientImpl containerClientImpl;
|
||||||
private final ObjectClientImpl objectClientImpl;
|
private final ObjectClientImpl objectClientImpl;
|
||||||
private final ApeManagerClientImpl apeManagerClient;
|
private final ApeManagerClientImpl apeManagerClient;
|
||||||
private final NetmapClientImpl netmapClientImpl;
|
private final NetmapClientImpl netmapClientImpl;
|
||||||
private final SessionClientImpl sessionClientImpl;
|
private final SessionClientImpl sessionClientImpl;
|
||||||
private final ObjectToolsImpl objectToolsImpl;
|
private final ObjectToolsImpl objectToolsImpl;
|
||||||
private final AccountingClientImpl accountingClient;
|
|
||||||
private final ManagedChannel channel;
|
|
||||||
|
|
||||||
public FrostFSClient(ClientSettings clientSettings) {
|
public FrostFSClient(ClientSettings clientSettings) {
|
||||||
Validator.validate(clientSettings);
|
Validator.validate(clientSettings);
|
||||||
this.channel = nonNull(clientSettings.getChannel())
|
Channel channel = nonNull(clientSettings.getChannel())
|
||||||
? clientSettings.getChannel()
|
? clientSettings.getChannel()
|
||||||
: initGrpcChannel(clientSettings);
|
: initGrpcChannel(clientSettings);
|
||||||
|
|
||||||
var ecdsa = StringUtils.isBlank(clientSettings.getWif())
|
MonitoringClientInterceptor monitoringClientInterceptor = MonitoringClientInterceptor
|
||||||
? new ECDsa(clientSettings.getWallet(), clientSettings.getPassword())
|
.create(Configuration.allMetrics());
|
||||||
: new ECDsa(clientSettings.getWif());
|
channel = ClientInterceptors.intercept(channel, monitoringClientInterceptor);
|
||||||
Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR);
|
|
||||||
ClientEnvironment clientEnvironment = new ClientEnvironment(
|
|
||||||
ecdsa, interceptChannel, new Version(), this, new SessionCache(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
Validator.validate(clientEnvironment);
|
|
||||||
|
|
||||||
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
|
||||||
this.objectClientImpl = new ObjectClientImpl(clientEnvironment);
|
|
||||||
this.apeManagerClient = new ApeManagerClientImpl(clientEnvironment);
|
|
||||||
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
|
||||||
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
|
||||||
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
|
||||||
this.accountingClient = new AccountingClientImpl(clientEnvironment);
|
|
||||||
checkFrostFSVersionSupport(clientEnvironment.getVersion());
|
|
||||||
}
|
|
||||||
|
|
||||||
public FrostFSClient(WrapperPrm prm, SessionCache cache) {
|
|
||||||
this.channel = initGrpcChannel(prm.getAddress());
|
|
||||||
|
|
||||||
Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR);
|
|
||||||
ClientEnvironment clientEnvironment =
|
ClientEnvironment clientEnvironment =
|
||||||
new ClientEnvironment(prm.getKey(), interceptChannel, new Version(), this, cache);
|
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
|
||||||
|
|
||||||
Validator.validate(clientEnvironment);
|
Validator.validate(clientEnvironment);
|
||||||
|
|
||||||
|
@ -104,12 +60,11 @@ public class FrostFSClient implements CommonClient {
|
||||||
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
||||||
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
||||||
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
||||||
this.accountingClient = new AccountingClientImpl(clientEnvironment);
|
checkFrostFsVersionSupport(clientEnvironment.getVersion());
|
||||||
checkFrostFSVersionSupport(clientEnvironment.getVersion());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkFrostFSVersionSupport(Version version) {
|
private void checkFrostFsVersionSupport(Version version) {
|
||||||
var localNodeInfo = netmapClientImpl.getLocalNodeInfo(new CallContext());
|
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
||||||
if (!localNodeInfo.getVersion().isSupported(version)) {
|
if (!localNodeInfo.getVersion().isSupported(version)) {
|
||||||
throw new ProcessFrostFSException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion())
|
String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion())
|
||||||
|
@ -118,131 +73,96 @@ public class FrostFSClient implements CommonClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Container getContainer(PrmContainerGet args, CallContext ctx) {
|
public Container getContainer(ContainerId cid) {
|
||||||
return containerClientImpl.getContainer(args, ctx);
|
return containerClientImpl.getContainer(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx) {
|
public List<ContainerId> listContainers() {
|
||||||
return containerClientImpl.listContainers(args, ctx);
|
return containerClientImpl.listContainers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) {
|
public ContainerId createContainer(Container container) {
|
||||||
return containerClientImpl.createContainer(args, ctx);
|
return containerClientImpl.createContainer(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteContainer(PrmContainerDelete args, CallContext ctx) {
|
public void deleteContainer(ContainerId cid) {
|
||||||
containerClientImpl.deleteContainer(args, ctx);
|
containerClientImpl.deleteContainer(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) {
|
public ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId) {
|
||||||
return objectClientImpl.getObjectHead(args, ctx);
|
return objectClientImpl.getObjectHead(containerId, objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) {
|
public ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId) {
|
||||||
return objectClientImpl.getObject(args, ctx);
|
return objectClientImpl.getObject(containerId, objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) {
|
public ObjectId putObject(PutObjectParameters parameters) {
|
||||||
return objectClientImpl.putObject(args, ctx);
|
return objectClientImpl.putObject(parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) {
|
public ObjectId putSingleObject(ObjectFrostFS objectFrostFS) {
|
||||||
return objectClientImpl.putClientCutObject(args, ctx);
|
return objectClientImpl.putSingleObject(objectFrostFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) {
|
public void deleteObject(ContainerId containerId, ObjectId objectId) {
|
||||||
return objectClientImpl.putSingleObject(args, ctx);
|
objectClientImpl.deleteObject(containerId, objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteObject(PrmObjectDelete args, CallContext ctx) {
|
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
||||||
objectClientImpl.deleteObject(args, ctx);
|
return objectClientImpl.searchObjects(cid, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx) {
|
public byte[] addChain(Chain chain, ChainTarget chainTarget) {
|
||||||
return objectClientImpl.searchObjects(args, ctx);
|
return apeManagerClient.addChain(chain, chainTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RangeReader getRange(PrmRangeGet args, CallContext ctx) {
|
public void removeChain(Chain chain, ChainTarget chainTarget) {
|
||||||
return objectClientImpl.getRange(args, ctx);
|
apeManagerClient.removeChain(chain, chainTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx) {
|
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||||
return objectClientImpl.getRangeHash(args, ctx);
|
return apeManagerClient.listChains(chainTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectId patchObject(PrmObjectPatch args, CallContext ctx) {
|
public NetmapSnapshot getNetmapSnapshot() {
|
||||||
return objectClientImpl.patchObject(args, ctx);
|
return netmapClientImpl.getNetmapSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] addChain(PrmApeChainAdd args, CallContext ctx) {
|
public NodeInfo getLocalNodeInfo() {
|
||||||
return apeManagerClient.addChain(args, ctx);
|
return netmapClientImpl.getLocalNodeInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeChain(PrmApeChainRemove args, CallContext ctx) {
|
public NetworkSettings getNetworkSettings() {
|
||||||
apeManagerClient.removeChain(args, ctx);
|
return netmapClientImpl.getNetworkSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
public SessionToken createSession(long expiration) {
|
||||||
return apeManagerClient.listChains(args, ctx);
|
return sessionClientImpl.createSession(expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public frostfs.session.Types.SessionToken createSessionInternal(long expiration) {
|
||||||
public NetmapSnapshot getNetmapSnapshot(CallContext ctx) {
|
return sessionClientImpl.createSessionInternal(expiration);
|
||||||
return netmapClientImpl.getNetmapSnapshot(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeInfo getLocalNodeInfo(CallContext ctx) {
|
|
||||||
return netmapClientImpl.getLocalNodeInfo(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetworkSettings getNetworkSettings(CallContext ctx) {
|
|
||||||
return netmapClientImpl.getNetworkSettings(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SessionToken createSession(PrmSessionCreate args, CallContext ctx) {
|
|
||||||
return sessionClientImpl.createSession(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public frostfs.session.Types.SessionToken createSessionInternal(PrmSessionCreate args, CallContext ctx) {
|
|
||||||
return sessionClientImpl.createSessionInternal(args, ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||||
return objectToolsImpl.calculateObjectId(header);
|
return objectToolsImpl.calculateObjectId(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Types.Decimal getBalance(CallContext ctx) {
|
|
||||||
return accountingClient.getBalance(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String dial(CallContext ctx) {
|
|
||||||
accountingClient.getBalance(ctx);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
channel.shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package info.frostfs.sdk.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
|
||||||
public @interface ComplexAtLeastOneIsFilled {
|
|
||||||
AtLeastOneIsFilled[] value();
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package info.frostfs.sdk.constants;
|
|
||||||
|
|
||||||
public class PoolConst {
|
|
||||||
public static final int DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION = 100; // in epochs
|
|
||||||
public static final int DEFAULT_ERROR_THRESHOLD = 100;
|
|
||||||
public static final int DEFAULT_GRACEFUL_CLOSE_ON_SWITCH_TIMEOUT = 10; // Seconds
|
|
||||||
public static final int DEFAULT_REBALANCE_INTERVAL = 15; // Seconds
|
|
||||||
public static final int DEFAULT_HEALTHCHECK_TIMEOUT = 4; // Seconds
|
|
||||||
public static final int DEFAULT_DIAL_TIMEOUT = 5; // Seconds
|
|
||||||
public static final int DEFAULT_STREAM_TIMEOUT = 10; // Seconds
|
|
||||||
|
|
||||||
private PoolConst() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package info.frostfs.sdk.constants;
|
|
||||||
|
|
||||||
public class RuleConst {
|
|
||||||
public static final byte VERSION = 0;
|
|
||||||
|
|
||||||
public static final int BYTE_SIZE = 1;
|
|
||||||
public static final int U_INT_8_SIZE = BYTE_SIZE;
|
|
||||||
public static final int BOOL_SIZE = BYTE_SIZE;
|
|
||||||
|
|
||||||
public static final long NULL_SLICE = -1L;
|
|
||||||
public static final int NULL_SLICE_SIZE = 1;
|
|
||||||
|
|
||||||
public static final byte BYTE_TRUE = 1;
|
|
||||||
public static final byte BYTE_FALSE = 0;
|
|
||||||
|
|
||||||
// maxSliceLen taken from
|
|
||||||
// https://github.com/neo-project/neo/blob/38218bbee5bbe8b33cd8f9453465a19381c9a547/src/Neo/IO/Helper.cs#L77
|
|
||||||
public static final int MAX_SLICE_LENGTH = 0x1000000;
|
|
||||||
|
|
||||||
public static final int MAX_VAR_INT_LENGTH = 10;
|
|
||||||
|
|
||||||
public static final int CHAIN_MARSHAL_VERSION = 0;
|
|
||||||
|
|
||||||
public static final long OFFSET127 = 0x7f;
|
|
||||||
public static final long OFFSET128 = 0x80;
|
|
||||||
public static final int UNSIGNED_SERIALIZE_SIZE = 7;
|
|
||||||
|
|
||||||
private RuleConst() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package info.frostfs.sdk.enums;
|
|
||||||
|
|
||||||
public enum HealthyStatus {
|
|
||||||
// status HEALTHY is set when connection is ready to be used by the pool.
|
|
||||||
HEALTHY(1),
|
|
||||||
|
|
||||||
// status UNHEALTHY_ON_REQUEST is set when communication after dialing to the
|
|
||||||
// endpoint is failed due to immediate or accumulated errors, connection is
|
|
||||||
// available and pool should close it before re-establishing connection once again.
|
|
||||||
UNHEALTHY_ON_REQUEST(2),
|
|
||||||
|
|
||||||
// status UNHEALTHY_ON_DIAL is set when dialing to the endpoint is failed,
|
|
||||||
// so there is no connection to the endpoint, and pool should not close it
|
|
||||||
// before re-establishing connection once again.
|
|
||||||
UNHEALTHY_ON_DIAL(3),
|
|
||||||
;
|
|
||||||
|
|
||||||
public final int value;
|
|
||||||
|
|
||||||
HealthyStatus(int value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
package info.frostfs.sdk.enums;
|
|
||||||
|
|
||||||
public enum MethodIndex {
|
|
||||||
METHOD_BALANCE_GET("balanceGet"),
|
|
||||||
METHOD_CONTAINER_PUT("containerPut"),
|
|
||||||
METHOD_CONTAINER_GET("ContainerGet"),
|
|
||||||
METHOD_CONTAINER_LIST("ContainerList"),
|
|
||||||
METHOD_CONTAINER_DELETE("ContainerDelete"),
|
|
||||||
METHOD_ENDPOINT_INFO("EndpointInfo"),
|
|
||||||
METHOD_NETWORK_INFO("NetworkInfo"),
|
|
||||||
METHOD_NETMAP_SNAPSHOT("NetMapSnapshot"),
|
|
||||||
METHOD_OBJECT_PUT("ObjectPut"),
|
|
||||||
METHOD_OBJECT_DELETE("ObjectDelete"),
|
|
||||||
METHOD_OBJECT_GET("ObjectGet"),
|
|
||||||
METHOD_OBJECT_HEAD("ObjectHead"),
|
|
||||||
METHOD_OBJECT_RANGE("ObjectRange"),
|
|
||||||
METHOD_OBJECT_PATCH("ObjectPatch"),
|
|
||||||
METHOD_SESSION_CREATE("SessionCreate"),
|
|
||||||
METHOD_APE_MANAGER_ADD_CHAIN("APEManagerAddChain"),
|
|
||||||
METHOD_APE_MANAGER_REMOVE_CHAIN("APEManagerRemoveChain"),
|
|
||||||
METHOD_APE_MANAGER_LIST_CHAINS("APEManagerListChains"),
|
|
||||||
;
|
|
||||||
|
|
||||||
public final String methodName;
|
|
||||||
|
|
||||||
MethodIndex(String methodName) {
|
|
||||||
this.methodName = methodName;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,7 @@ import info.frostfs.sdk.dto.response.ResponseStatus;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ResponseFrostFSException extends FrostFSException {
|
public class ResponseFrostFSException extends RuntimeException {
|
||||||
private final ResponseStatus status;
|
private final ResponseStatus status;
|
||||||
|
|
||||||
public ResponseFrostFSException(ResponseStatus status) {
|
public ResponseFrostFSException(ResponseStatus status) {
|
||||||
|
|
|
@ -5,14 +5,9 @@ import info.frostfs.sdk.annotations.NotNull;
|
||||||
import info.frostfs.sdk.annotations.Validate;
|
import info.frostfs.sdk.annotations.Validate;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
import info.frostfs.sdk.dto.object.OwnerId;
|
import info.frostfs.sdk.dto.object.OwnerId;
|
||||||
import info.frostfs.sdk.pool.SessionCache;
|
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.Helper.getHexString;
|
|
||||||
import static info.frostfs.sdk.pool.Pool.formCacheKey;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -20,38 +15,27 @@ public class ClientEnvironment {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final OwnerId ownerId;
|
private final OwnerId ownerId;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Version version;
|
private final Version version;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Validate
|
@Validate
|
||||||
private final ECDsa key;
|
private final ECDsa key;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final FrostFSClient frostFSClient;
|
private final FrostFSClient frostFSClient;
|
||||||
|
|
||||||
private String sessionKey;
|
|
||||||
private String address;
|
|
||||||
private NetworkSettings networkSettings;
|
private NetworkSettings networkSettings;
|
||||||
|
|
||||||
private SessionCache sessionCache;
|
public ClientEnvironment(String wif, Channel channel, Version version, FrostFSClient frostFSClient) {
|
||||||
|
this.key = new ECDsa(wif);
|
||||||
public ClientEnvironment(ECDsa key, Channel channel, Version version, FrostFSClient frostFSClient,
|
this.ownerId = new OwnerId(key.getPublicKeyByte());
|
||||||
SessionCache sessionCache) {
|
|
||||||
this.key = key;
|
|
||||||
this.ownerId = new OwnerId(key.getAccount().getAddress());
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.frostFSClient = frostFSClient;
|
this.frostFSClient = frostFSClient;
|
||||||
this.sessionCache = sessionCache;
|
|
||||||
this.address = channel.authority();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSessionKey() {
|
|
||||||
if (StringUtils.isBlank(sessionKey)) {
|
|
||||||
this.sessionKey = formCacheKey(address, getHexString(key.getPublicKeyByte()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return sessionKey;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,61 +1,37 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||||
import info.frostfs.sdk.annotations.ComplexAtLeastOneIsFilled;
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
|
import io.grpc.Channel;
|
||||||
import io.grpc.ChannelCredentials;
|
import io.grpc.ChannelCredentials;
|
||||||
import io.grpc.ManagedChannel;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.experimental.FieldNameConstants;
|
import lombok.experimental.FieldNameConstants;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@FieldNameConstants
|
@FieldNameConstants
|
||||||
@ComplexAtLeastOneIsFilled(value = {
|
@AtLeastOneIsFilled(fields = {ClientSettings.Fields.host, ClientSettings.Fields.channel})
|
||||||
@AtLeastOneIsFilled(fields = {ClientSettings.Fields.host, ClientSettings.Fields.channel}),
|
|
||||||
@AtLeastOneIsFilled(fields = {ClientSettings.Fields.wif, ClientSettings.Fields.wallet}),
|
|
||||||
})
|
|
||||||
public class ClientSettings {
|
public class ClientSettings {
|
||||||
|
|
||||||
private String wif;
|
@NotNull
|
||||||
private File wallet;
|
private final String key;
|
||||||
private String password;
|
|
||||||
private String host;
|
private String host;
|
||||||
private ChannelCredentials credentials;
|
private ChannelCredentials credentials;
|
||||||
private ManagedChannel channel;
|
private Channel channel;
|
||||||
|
|
||||||
public ClientSettings(String wif, String host) {
|
public ClientSettings(String key, String host) {
|
||||||
this.wif = wif;
|
this.key = key;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientSettings(String wif, String host, ChannelCredentials credentials) {
|
public ClientSettings(String key, String host, ChannelCredentials credentials) {
|
||||||
this.wif = wif;
|
this.key = key;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientSettings(String wif, ManagedChannel channel) {
|
public ClientSettings(String key, Channel channel) {
|
||||||
this.wif = wif;
|
this.key = key;
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClientSettings(File wallet, String password, String host) {
|
|
||||||
this.wallet = wallet;
|
|
||||||
this.password = password;
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClientSettings(File wallet, String password, String host, ChannelCredentials credentials) {
|
|
||||||
this.wallet = wallet;
|
|
||||||
this.password = password;
|
|
||||||
this.host = host;
|
|
||||||
this.credentials = credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClientSettings(File wallet, String password, ManagedChannel channel) {
|
|
||||||
this.wallet = wallet;
|
|
||||||
this.password = password;
|
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,14 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import io.neow3j.wallet.Account;
|
|
||||||
import io.neow3j.wallet.nep6.NEP6Account;
|
|
||||||
import io.neow3j.wallet.nep6.NEP6Wallet;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.KeyExtension.loadPrivateKey;
|
import static info.frostfs.sdk.KeyExtension.*;
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.WALLET_IS_INVALID;
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.WIF_IS_INVALID;
|
import static info.frostfs.sdk.constants.ErrorConst.WIF_IS_INVALID;
|
||||||
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
|
|
||||||
import static io.neow3j.wallet.Wallet.OBJECT_MAPPER;
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ECDsa {
|
public class ECDsa {
|
||||||
|
@ -33,41 +22,13 @@ public class ECDsa {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final PrivateKey privateKey;
|
private final PrivateKey privateKey;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final Account account;
|
|
||||||
|
|
||||||
public ECDsa(String wif) {
|
public ECDsa(String wif) {
|
||||||
if (StringUtils.isEmpty(wif)) {
|
if (StringUtils.isEmpty(wif)) {
|
||||||
throw new ValidationFrostFSException(WIF_IS_INVALID);
|
throw new ValidationFrostFSException(WIF_IS_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.account = Account.fromWIF(wif);
|
this.privateKeyByte = getPrivateKeyFromWIF(wif);
|
||||||
this.privateKeyByte = account.getECKeyPair().getPrivateKey().getBytes();
|
this.publicKeyByte = loadPublicKey(privateKeyByte);
|
||||||
this.publicKeyByte = account.getECKeyPair().getPublicKey().getEncoded(true);
|
|
||||||
this.privateKey = loadPrivateKey(privateKeyByte);
|
this.privateKey = loadPrivateKey(privateKeyByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ECDsa(File walletFile, String password) {
|
|
||||||
if (isNull(walletFile)) {
|
|
||||||
throw new ValidationFrostFSException(WALLET_IS_INVALID);
|
|
||||||
}
|
|
||||||
|
|
||||||
try (var walletStream = new FileInputStream(walletFile)) {
|
|
||||||
NEP6Wallet nep6Wallet = OBJECT_MAPPER.readValue(walletStream, NEP6Wallet.class);
|
|
||||||
Optional<NEP6Account> defaultAccount = nep6Wallet.getAccounts().stream()
|
|
||||||
.filter(NEP6Account::getDefault)
|
|
||||||
.findFirst();
|
|
||||||
|
|
||||||
var account = defaultAccount.map(Account::fromNEP6Account)
|
|
||||||
.orElseGet(() -> Account.fromNEP6Account(nep6Wallet.getAccounts().get(0)));
|
|
||||||
account.decryptPrivateKey(isNull(password) ? EMPTY_STRING : password);
|
|
||||||
|
|
||||||
this.account = account;
|
|
||||||
this.privateKeyByte = account.getECKeyPair().getPrivateKey().getBytes();
|
|
||||||
this.publicKeyByte = account.getECKeyPair().getPublicKey().getEncoded(true);
|
|
||||||
this.privateKey = loadPrivateKey(privateKeyByte);
|
|
||||||
} catch (Exception exp) {
|
|
||||||
throw new FrostFSException(exp.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class PutObjectParameters {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private ObjectHeader header;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private InputStream payload;
|
||||||
|
|
||||||
|
private boolean clientCut;
|
||||||
|
private int bufferMaxSize;
|
||||||
|
private byte[] customerBuffer;
|
||||||
|
private SessionToken sessionToken;
|
||||||
|
private int maxObjectSizeCache;
|
||||||
|
private long currentStreamPosition;
|
||||||
|
private long fullLength;
|
||||||
|
|
||||||
|
public PutObjectParameters(ObjectHeader header, InputStream payload, boolean clientCut, int bufferMaxSize) {
|
||||||
|
this.header = header;
|
||||||
|
this.payload = payload;
|
||||||
|
this.clientCut = clientCut;
|
||||||
|
this.bufferMaxSize = bufferMaxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PutObjectParameters(ObjectHeader header, InputStream payload) {
|
||||||
|
this.header = header;
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package info.frostfs.sdk.jdo.parameters;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -8,14 +8,14 @@ import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PrmWait {
|
public class WaitParameters {
|
||||||
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120);
|
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120);
|
||||||
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
|
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
|
||||||
|
|
||||||
private final Duration timeout;
|
private final Duration timeout;
|
||||||
private final Duration pollInterval;
|
private final Duration pollInterval;
|
||||||
|
|
||||||
public PrmWait() {
|
public WaitParameters() {
|
||||||
this.timeout = DEFAULT_TIMEOUT;
|
this.timeout = DEFAULT_TIMEOUT;
|
||||||
this.pollInterval = DEFAULT_POLL_INTERVAL;
|
this.pollInterval = DEFAULT_POLL_INTERVAL;
|
||||||
}
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_GRPC_TIMEOUT;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class CallContext {
|
|
||||||
private final long timeout;
|
|
||||||
private final TimeUnit timeUnit;
|
|
||||||
|
|
||||||
public CallContext() {
|
|
||||||
this.timeout = DEFAULT_GRPC_TIMEOUT;
|
|
||||||
this.timeUnit = TimeUnit.SECONDS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.ape;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.ape.Chain;
|
|
||||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmApeChainAdd {
|
|
||||||
@NotNull
|
|
||||||
private Chain chain;
|
|
||||||
@NotNull
|
|
||||||
private ChainTarget chainTarget;
|
|
||||||
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmApeChainAdd(Chain chain, ChainTarget chainTarget) {
|
|
||||||
this.chain = chain;
|
|
||||||
this.chainTarget = chainTarget;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.ape;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmApeChainList {
|
|
||||||
@NotNull
|
|
||||||
private ChainTarget chainTarget;
|
|
||||||
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmApeChainList(ChainTarget chainTarget) {
|
|
||||||
this.chainTarget = chainTarget;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.ape;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmApeChainRemove {
|
|
||||||
@NotNull
|
|
||||||
private byte[] chainId;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private ChainTarget chainTarget;
|
|
||||||
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmApeChainRemove(byte[] chainId, ChainTarget chainTarget) {
|
|
||||||
this.chainId = chainId;
|
|
||||||
this.chainTarget = chainTarget;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.container;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.Container;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.PrmWait;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmContainerCreate implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private Container container;
|
|
||||||
|
|
||||||
private PrmWait waitParams;
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmContainerCreate(Container container, PrmWait waitParams) {
|
|
||||||
this.container = container;
|
|
||||||
this.waitParams = waitParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrmContainerCreate(Container container) {
|
|
||||||
this.container = container;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.container;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.PrmWait;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmContainerDelete implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
|
|
||||||
private PrmWait waitParams;
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmContainerDelete(ContainerId containerId, PrmWait waitParams) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.waitParams = waitParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrmContainerDelete(ContainerId containerId) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.container;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmContainerGet {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmContainerGet(ContainerId containerId) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.container;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class PrmContainerGetAll {
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectClientCutPut implements PrmObjectPutBase, SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private final PutObjectContext putObjectContext = new PutObjectContext();
|
|
||||||
@NotNull
|
|
||||||
private ObjectHeader objectHeader;
|
|
||||||
@NotNull
|
|
||||||
private InputStream payload;
|
|
||||||
private int bufferMaxSize;
|
|
||||||
private byte[] customerBuffer;
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectDelete implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
@NotNull
|
|
||||||
private ObjectId objectId;
|
|
||||||
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectDelete(ContainerId containerId, ObjectId objectId) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.objectId = objectId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectGet implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
@NotNull
|
|
||||||
private ObjectId objectId;
|
|
||||||
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectGet(ContainerId containerId, ObjectId objectId) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.objectId = objectId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectHeadGet implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
@NotNull
|
|
||||||
private ObjectId objectId;
|
|
||||||
|
|
||||||
private boolean raw;
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectHeadGet(ContainerId containerId, ObjectId objectId) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.objectId = objectId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectPut implements PrmObjectPutBase, SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private final PutObjectContext putObjectContext = new PutObjectContext();
|
|
||||||
@NotNull
|
|
||||||
private ObjectHeader objectHeader;
|
|
||||||
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectPut(ObjectHeader objectHeader) {
|
|
||||||
this.objectHeader = objectHeader;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface PrmObjectPutBase extends SessionContext {
|
|
||||||
ObjectHeader getObjectHeader();
|
|
||||||
|
|
||||||
Map<String, String> getXHeaders();
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectSearch implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
@NotNull
|
|
||||||
private ObjectFilter<?>[] filters;
|
|
||||||
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectSearch(ContainerId containerId, ObjectFilter<?>... filters) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.filters = filters;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectSinglePut implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ObjectFrostFS objectFrostFS;
|
|
||||||
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectSinglePut(ObjectFrostFS objectFrostFS) {
|
|
||||||
this.objectFrostFS = objectFrostFS;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class PutObjectContext {
|
|
||||||
private int maxObjectSizeCache;
|
|
||||||
private long currentStreamPosition;
|
|
||||||
private long fullLength;
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object.patch;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
|
||||||
import info.frostfs.sdk.dto.object.patch.Address;
|
|
||||||
import info.frostfs.sdk.dto.object.patch.Range;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmObjectPatch implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private Address address;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Range range;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private InputStream payload;
|
|
||||||
|
|
||||||
private List<ObjectAttribute> newAttributes;
|
|
||||||
private boolean replaceAttributes;
|
|
||||||
private int maxChunkLength;
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmObjectPatch(Address address, Range range, InputStream payload, int maxChunkLength) {
|
|
||||||
this.address = address;
|
|
||||||
this.range = range;
|
|
||||||
this.payload = payload;
|
|
||||||
this.maxChunkLength = maxChunkLength;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object.patch;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
|
||||||
import info.frostfs.sdk.dto.object.patch.Range;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmRangeGet implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
@NotNull
|
|
||||||
private ObjectId objectId;
|
|
||||||
@NotNull
|
|
||||||
private Range range;
|
|
||||||
|
|
||||||
private boolean raw;
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmRangeGet(ContainerId containerId, ObjectId objectId, Range range) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.objectId = objectId;
|
|
||||||
this.range = range;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.object.patch;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
|
||||||
import info.frostfs.sdk.dto.object.patch.Range;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmRangeHashGet implements SessionContext {
|
|
||||||
@NotNull
|
|
||||||
private ContainerId containerId;
|
|
||||||
@NotNull
|
|
||||||
private ObjectId objectId;
|
|
||||||
@NotNull
|
|
||||||
private List<Range> ranges;
|
|
||||||
@NotNull
|
|
||||||
private byte[] salt;
|
|
||||||
|
|
||||||
private SessionToken sessionToken;
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmRangeHashGet(ContainerId containerId, ObjectId objectId, List<Range> ranges, byte[] salt) {
|
|
||||||
this.containerId = containerId;
|
|
||||||
this.objectId = objectId;
|
|
||||||
this.ranges = ranges;
|
|
||||||
this.salt = salt;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.session;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class PrmSessionCreate {
|
|
||||||
private long expiration; //-1 is max
|
|
||||||
private Map<String, String> xHeaders;
|
|
||||||
|
|
||||||
public PrmSessionCreate(long expiration) {
|
|
||||||
this.expiration = expiration;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.parameters.session;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
|
|
||||||
public interface SessionContext {
|
|
||||||
SessionToken getSessionToken();
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.pool;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class NodeParameters {
|
|
||||||
private final int priority;
|
|
||||||
private final String address;
|
|
||||||
private final double weight;
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.pool;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
|
||||||
import info.frostfs.sdk.pool.ClientWrapper;
|
|
||||||
import io.grpc.ClientInterceptors;
|
|
||||||
import io.netty.channel.ChannelOption;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class PoolInitParameters {
|
|
||||||
private ECDsa key;
|
|
||||||
|
|
||||||
private long nodeDialTimeout;
|
|
||||||
|
|
||||||
private long nodeStreamTimeout;
|
|
||||||
|
|
||||||
private long healthCheckTimeout;
|
|
||||||
|
|
||||||
private long clientRebalanceInterval;
|
|
||||||
|
|
||||||
private long sessionExpirationDuration;
|
|
||||||
|
|
||||||
private int errorThreshold;
|
|
||||||
|
|
||||||
private NodeParameters[] nodeParams;
|
|
||||||
|
|
||||||
private ChannelOption<?>[] dialOptions;
|
|
||||||
|
|
||||||
private Function<String, ClientWrapper> clientBuilder;
|
|
||||||
|
|
||||||
private long gracefulCloseOnSwitchTimeout;
|
|
||||||
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
private Collection<ClientInterceptors> interceptors = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package info.frostfs.sdk.jdo.result;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
|
||||||
import info.frostfs.sdk.dto.object.SplitInfo;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Builder
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class ObjectHeaderResult {
|
|
||||||
private ObjectHeader headerInfo;
|
|
||||||
private SplitInfo splitInfo;
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
public interface ClientStatus {
|
|
||||||
// isHealthy checks if the connection can handle requests.
|
|
||||||
boolean isHealthy();
|
|
||||||
|
|
||||||
// isDialed checks if the connection was created.
|
|
||||||
boolean isDialed();
|
|
||||||
|
|
||||||
// setUnhealthy marks client as unhealthy.
|
|
||||||
void setUnhealthy();
|
|
||||||
|
|
||||||
// address return address of endpoint.
|
|
||||||
String getAddress();
|
|
||||||
|
|
||||||
// currentErrorRate returns current errors rate.
|
|
||||||
// After specific threshold connection is considered as unhealthy.
|
|
||||||
// Pool.startRebalance routine can make this connection healthy again.
|
|
||||||
int getCurrentErrorRate();
|
|
||||||
|
|
||||||
// overallErrorRate returns the number of all happened errors.
|
|
||||||
long getOverallErrorRate();
|
|
||||||
|
|
||||||
// methodsStatus returns statistic for all used methods.
|
|
||||||
StatusSnapshot[] getMethodsStatus();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.enums.HealthyStatus;
|
|
||||||
import info.frostfs.sdk.enums.MethodIndex;
|
|
||||||
import info.frostfs.sdk.utils.FrostFSMessages;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class ClientStatusMonitor implements ClientStatus {
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
|
||||||
private final Logger logger;
|
|
||||||
private final AtomicInteger healthy = new AtomicInteger();
|
|
||||||
|
|
||||||
private final String address;
|
|
||||||
private final MethodStatus[] methods;
|
|
||||||
|
|
||||||
private int errorThreshold;
|
|
||||||
private int currentErrorCount;
|
|
||||||
private long overallErrorCount;
|
|
||||||
|
|
||||||
public ClientStatusMonitor(Logger logger, String address) {
|
|
||||||
this.logger = logger;
|
|
||||||
this.healthy.set(HealthyStatus.HEALTHY.value);
|
|
||||||
|
|
||||||
this.address = address;
|
|
||||||
this.methods = Arrays.stream(MethodIndex.values())
|
|
||||||
.map(t -> new MethodStatus(t.methodName))
|
|
||||||
.toArray(MethodStatus[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isHealthy() {
|
|
||||||
return healthy.get() == HealthyStatus.HEALTHY.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDialed() {
|
|
||||||
return healthy.get() != HealthyStatus.UNHEALTHY_ON_DIAL.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHealthy() {
|
|
||||||
healthy.set(HealthyStatus.HEALTHY.ordinal());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUnhealthy() {
|
|
||||||
healthy.set(HealthyStatus.UNHEALTHY_ON_REQUEST.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUnhealthyOnDial() {
|
|
||||||
healthy.set(HealthyStatus.UNHEALTHY_ON_DIAL.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void incErrorRate() {
|
|
||||||
boolean thresholdReached;
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
currentErrorCount++;
|
|
||||||
overallErrorCount++;
|
|
||||||
|
|
||||||
thresholdReached = currentErrorCount >= errorThreshold;
|
|
||||||
|
|
||||||
if (thresholdReached) {
|
|
||||||
setUnhealthy();
|
|
||||||
currentErrorCount = 0;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thresholdReached && logger != null) {
|
|
||||||
FrostFSMessages.errorThresholdReached(logger, address, errorThreshold);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCurrentErrorRate() {
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
return currentErrorCount;
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getOverallErrorRate() {
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
return overallErrorCount;
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public StatusSnapshot[] getMethodsStatus() {
|
|
||||||
StatusSnapshot[] result = new StatusSnapshot[methods.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < result.length; i++) {
|
|
||||||
result[i] = methods[i].getSnapshot();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,131 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.FrostFSClient;
|
|
||||||
import info.frostfs.sdk.enums.MethodIndex;
|
|
||||||
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.utils.WaitUtil;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.POOL_CLIENT_UNHEALTHY;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class ClientWrapper extends ClientStatusMonitor {
|
|
||||||
@Getter(value = AccessLevel.NONE)
|
|
||||||
private final Lock lock = new ReentrantLock();
|
|
||||||
private final SessionCache sessionCache;
|
|
||||||
private final WrapperPrm wrapperPrm;
|
|
||||||
private FrostFSClient client;
|
|
||||||
|
|
||||||
public ClientWrapper(WrapperPrm wrapperPrm, Pool pool) {
|
|
||||||
super(wrapperPrm.getLogger(), wrapperPrm.getAddress());
|
|
||||||
this.wrapperPrm = wrapperPrm;
|
|
||||||
setErrorThreshold(wrapperPrm.getErrorThreshold());
|
|
||||||
|
|
||||||
this.sessionCache = pool.getSessionCache();
|
|
||||||
this.client = new FrostFSClient(wrapperPrm, sessionCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public FrostFSClient getClient() {
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
if (isHealthy()) {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dial(CallContext ctx) {
|
|
||||||
FrostFSClient client = getClient();
|
|
||||||
if (client == null) {
|
|
||||||
throw new ValidationFrostFSException(POOL_CLIENT_UNHEALTHY);
|
|
||||||
}
|
|
||||||
client.dial(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleError(Exception exp) {
|
|
||||||
if (exp instanceof ResponseFrostFSException && ((ResponseFrostFSException) exp).getStatus() != null) {
|
|
||||||
switch (((ResponseFrostFSException) exp).getStatus().getCode()) {
|
|
||||||
case INTERNAL:
|
|
||||||
case WRONG_MAGIC_NUMBER:
|
|
||||||
case SIGNATURE_VERIFICATION_FAILURE:
|
|
||||||
case NODE_UNDER_MAINTENANCE:
|
|
||||||
incErrorRate();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
incErrorRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scheduleGracefulClose() {
|
|
||||||
if (client == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitUtil.sleep(wrapperPrm.getGracefulCloseOnSwitchTimeout());
|
|
||||||
client.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<Boolean> restartIfUnhealthy(CallContext ctx) {
|
|
||||||
try {
|
|
||||||
client.getLocalNodeInfo(ctx);
|
|
||||||
return CompletableFuture.completedFuture(false);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDialed()) {
|
|
||||||
scheduleGracefulClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return CompletableFuture.completedFuture(restartClient(ctx));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean restartClient(CallContext ctx) {
|
|
||||||
FrostFSClient newClient = null;
|
|
||||||
try {
|
|
||||||
newClient = new FrostFSClient(wrapperPrm, sessionCache);
|
|
||||||
|
|
||||||
var error = newClient.dial(ctx);
|
|
||||||
if (StringUtils.isNotBlank(error)) {
|
|
||||||
setUnhealthyOnDial();
|
|
||||||
newClient.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock.lock();
|
|
||||||
client = newClient;
|
|
||||||
lock.unlock();
|
|
||||||
} catch (Exception exp) {
|
|
||||||
if (newClient != null) {
|
|
||||||
newClient.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
client.getLocalNodeInfo(ctx);
|
|
||||||
} catch (Exception exp) {
|
|
||||||
setUnhealthy();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
setHealthy();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void incRequests(long elapsed, MethodIndex method) {
|
|
||||||
var methodStat = getMethods()[method.ordinal()];
|
|
||||||
methodStat.incRequests(elapsed);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
class InnerPool {
|
|
||||||
private static final int ATTEMPTS_COUNT = 3;
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
|
||||||
private final ClientWrapper[] clients;
|
|
||||||
private Sampler sampler;
|
|
||||||
|
|
||||||
InnerPool(Sampler sampler, ClientWrapper[] clients) {
|
|
||||||
this.sampler = sampler;
|
|
||||||
this.clients = clients;
|
|
||||||
}
|
|
||||||
|
|
||||||
Sampler getSampler() {
|
|
||||||
return sampler;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSampler(Sampler sampler) {
|
|
||||||
this.sampler = sampler;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientWrapper[] getClients() {
|
|
||||||
return clients;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientWrapper connection() {
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
if (clients.length == 1) {
|
|
||||||
ClientWrapper client = clients[0];
|
|
||||||
if (client.isHealthy()) {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
int attempts = ATTEMPTS_COUNT * clients.length;
|
|
||||||
|
|
||||||
for (int i = 0; i < attempts; i++) {
|
|
||||||
int index = sampler.next();
|
|
||||||
|
|
||||||
if (clients[index].isHealthy()) {
|
|
||||||
return clients[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
@Setter
|
|
||||||
@Getter
|
|
||||||
public class MethodStatus {
|
|
||||||
@Getter(AccessLevel.NONE)
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
|
||||||
private final String name;
|
|
||||||
private StatusSnapshot snapshot;
|
|
||||||
|
|
||||||
public MethodStatus(String name) {
|
|
||||||
this.name = name;
|
|
||||||
this.snapshot = new StatusSnapshot();
|
|
||||||
}
|
|
||||||
|
|
||||||
void incRequests(long elapsed) {
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
snapshot.setAllTime(snapshot.getAllTime() + elapsed);
|
|
||||||
snapshot.setAllRequests(snapshot.getAllRequests() + 1);
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class NodeStatistic {
|
|
||||||
private String address;
|
|
||||||
private StatusSnapshot[] methods;
|
|
||||||
private long overallErrors;
|
|
||||||
private int currentErrors;
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class NodesParam {
|
|
||||||
private final int priority;
|
|
||||||
private final List<String> address;
|
|
||||||
private final List<Double> weight;
|
|
||||||
|
|
||||||
public NodesParam(int priority) {
|
|
||||||
this.priority = priority;
|
|
||||||
this.address = new ArrayList<>();
|
|
||||||
this.weight = new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,558 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import frostfs.refs.Types;
|
|
||||||
import info.frostfs.sdk.dto.ape.Chain;
|
|
||||||
import info.frostfs.sdk.dto.container.Container;
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
|
||||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
|
||||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
|
||||||
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.dto.object.OwnerId;
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.SessionExpiredFrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.SessionNotFoundFrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
|
||||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
|
||||||
import info.frostfs.sdk.jdo.pool.NodeParameters;
|
|
||||||
import info.frostfs.sdk.jdo.pool.PoolInitParameters;
|
|
||||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
|
||||||
import info.frostfs.sdk.services.CommonClient;
|
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.RangeReader;
|
|
||||||
import info.frostfs.sdk.utils.FrostFSMessages;
|
|
||||||
import info.frostfs.sdk.utils.WaitUtil;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.Helper.getHexString;
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.*;
|
|
||||||
import static info.frostfs.sdk.constants.PoolConst.*;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class Pool implements CommonClient {
|
|
||||||
|
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
|
||||||
private final ECDsa key;
|
|
||||||
private final SessionCache sessionCache;
|
|
||||||
private final long sessionTokenDuration;
|
|
||||||
private final RebalanceParameters rebalanceParams;
|
|
||||||
private final Function<String, ClientWrapper> clientBuilder;
|
|
||||||
private final Logger logger;
|
|
||||||
private InnerPool[] innerPools;
|
|
||||||
private Types.OwnerID ownerID;
|
|
||||||
private OwnerId ownerId;
|
|
||||||
private boolean disposedValue;
|
|
||||||
private long maxObjectSize;
|
|
||||||
private ClientStatus clientStatus;
|
|
||||||
|
|
||||||
public Pool(PoolInitParameters options) {
|
|
||||||
if (options == null || options.getKey() == null) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(
|
|
||||||
PARAMS_ARE_MISSING_TEMPLATE,
|
|
||||||
String.join(
|
|
||||||
FIELDS_DELIMITER_COMMA, PoolInitParameters.class.getName(), ECDsa.class.getName()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<NodesParam> nodesParams = adjustNodeParams(options.getNodeParams());
|
|
||||||
SessionCache cache = new SessionCache(options.getSessionExpirationDuration());
|
|
||||||
fillDefaultInitParams(options, this);
|
|
||||||
|
|
||||||
this.key = options.getKey();
|
|
||||||
this.sessionCache = cache;
|
|
||||||
this.logger = options.getLogger();
|
|
||||||
this.sessionTokenDuration = options.getSessionExpirationDuration();
|
|
||||||
|
|
||||||
this.rebalanceParams = new RebalanceParameters(
|
|
||||||
nodesParams.toArray(new NodesParam[0]),
|
|
||||||
options.getHealthCheckTimeout(),
|
|
||||||
options.getClientRebalanceInterval(),
|
|
||||||
options.getSessionExpirationDuration());
|
|
||||||
|
|
||||||
this.clientBuilder = options.getClientBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<NodesParam> adjustNodeParams(NodeParameters[] nodeParams) {
|
|
||||||
if (nodeParams == null || nodeParams.length == 0) {
|
|
||||||
throw new ValidationFrostFSException(POOL_PEERS_IS_MISSING);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Integer, NodesParam> nodesParamsDict = new HashMap<>(nodeParams.length);
|
|
||||||
for (NodeParameters nodeParam : nodeParams) {
|
|
||||||
var nodesParam = nodesParamsDict
|
|
||||||
.computeIfAbsent(nodeParam.getPriority(), k -> new NodesParam(nodeParam.getPriority()));
|
|
||||||
nodesParam.getAddress().add(nodeParam.getAddress());
|
|
||||||
nodesParam.getWeight().add(nodeParam.getWeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<NodesParam> nodesParams = new ArrayList<>(nodesParamsDict.values());
|
|
||||||
nodesParams.sort(Comparator.comparingInt(NodesParam::getPriority));
|
|
||||||
|
|
||||||
for (NodesParam nodes : nodesParams) {
|
|
||||||
double[] newWeights = adjustWeights(nodes.getWeight().stream().mapToDouble(Double::doubleValue).toArray());
|
|
||||||
nodes.getWeight().clear();
|
|
||||||
for (double weight : newWeights) {
|
|
||||||
nodes.getWeight().add(weight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodesParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double[] adjustWeights(double[] weights) {
|
|
||||||
double[] adjusted = new double[weights.length];
|
|
||||||
double sum = Arrays.stream(weights).sum();
|
|
||||||
|
|
||||||
if (sum > 0) {
|
|
||||||
for (int i = 0; i < weights.length; i++) {
|
|
||||||
adjusted[i] = weights[i] / sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return adjusted;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void fillDefaultInitParams(PoolInitParameters parameters, Pool pool) {
|
|
||||||
if (parameters.getSessionExpirationDuration() == 0) {
|
|
||||||
parameters.setSessionExpirationDuration(DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getErrorThreshold() == 0) {
|
|
||||||
parameters.setErrorThreshold(DEFAULT_ERROR_THRESHOLD);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getClientRebalanceInterval() <= 0) {
|
|
||||||
parameters.setClientRebalanceInterval(DEFAULT_REBALANCE_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getGracefulCloseOnSwitchTimeout() <= 0) {
|
|
||||||
parameters.setGracefulCloseOnSwitchTimeout(DEFAULT_GRACEFUL_CLOSE_ON_SWITCH_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getHealthCheckTimeout() <= 0) {
|
|
||||||
parameters.setHealthCheckTimeout(DEFAULT_HEALTHCHECK_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getNodeDialTimeout() <= 0) {
|
|
||||||
parameters.setNodeDialTimeout(DEFAULT_DIAL_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getNodeStreamTimeout() <= 0) {
|
|
||||||
parameters.setNodeStreamTimeout(DEFAULT_STREAM_TIMEOUT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getSessionExpirationDuration() == 0) {
|
|
||||||
parameters.setSessionExpirationDuration(DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameters.getClientBuilder() == null) {
|
|
||||||
parameters.setClientBuilder(address -> {
|
|
||||||
WrapperPrm wrapperPrm = new WrapperPrm();
|
|
||||||
wrapperPrm.setAddress(address);
|
|
||||||
wrapperPrm.setKey(parameters.getKey());
|
|
||||||
wrapperPrm.setLogger(parameters.getLogger());
|
|
||||||
wrapperPrm.setDialTimeout(parameters.getNodeDialTimeout());
|
|
||||||
wrapperPrm.setStreamTimeout(parameters.getNodeStreamTimeout());
|
|
||||||
wrapperPrm.setErrorThreshold(parameters.getErrorThreshold());
|
|
||||||
wrapperPrm.setGracefulCloseOnSwitchTimeout(parameters.getGracefulCloseOnSwitchTimeout());
|
|
||||||
wrapperPrm.setInterceptors(parameters.getInterceptors());
|
|
||||||
return new ClientWrapper(wrapperPrm, pool);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SessionToken initSessionForDuration(CallContext ctx, ClientWrapper cw, long duration) {
|
|
||||||
var client = cw.getClient();
|
|
||||||
NetworkSettings networkInfo = client.getNetworkSettings(ctx);
|
|
||||||
|
|
||||||
long epoch = networkInfo.getEpochDuration();
|
|
||||||
long exp = (Long.MAX_VALUE - epoch < duration) ? Long.MAX_VALUE : (epoch + duration);
|
|
||||||
|
|
||||||
return client.createSession(new PrmSessionCreate(exp), ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String formCacheKey(String address, String key) {
|
|
||||||
return address + key;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String dial(CallContext ctx) {
|
|
||||||
InnerPool[] inner = new InnerPool[rebalanceParams.getNodesParams().length];
|
|
||||||
boolean atLeastOneHealthy = false;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (NodesParam nodeParams : rebalanceParams.getNodesParams()) {
|
|
||||||
ClientWrapper[] clients = new ClientWrapper[nodeParams.getWeight().size()];
|
|
||||||
|
|
||||||
for (int j = 0; j < nodeParams.getAddress().size(); j++) {
|
|
||||||
ClientWrapper client = clients[j] = clientBuilder.apply(nodeParams.getAddress().get(j));
|
|
||||||
boolean dialed = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
client.dial(ctx);
|
|
||||||
dialed = true;
|
|
||||||
|
|
||||||
SessionToken token = initSessionForDuration(
|
|
||||||
ctx, client, rebalanceParams.getSessionExpirationDuration()
|
|
||||||
);
|
|
||||||
String cacheKey = formCacheKey(
|
|
||||||
nodeParams.getAddress().get(j),
|
|
||||||
getHexString(key.getPublicKeyByte())
|
|
||||||
);
|
|
||||||
sessionCache.setValue(cacheKey, token);
|
|
||||||
|
|
||||||
atLeastOneHealthy = true;
|
|
||||||
} catch (ValidationFrostFSException exp) {
|
|
||||||
break;
|
|
||||||
} catch (Exception exp) {
|
|
||||||
if (!dialed) {
|
|
||||||
client.setUnhealthyOnDial();
|
|
||||||
} else {
|
|
||||||
client.setUnhealthy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (logger != null) {
|
|
||||||
FrostFSMessages
|
|
||||||
.sessionCreationError(logger, client.getWrapperPrm().getAddress(), exp.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Sampler sampler = new Sampler(nodeParams.getWeight().stream().mapToDouble(Double::doubleValue).toArray());
|
|
||||||
inner[i] = new InnerPool(sampler, clients);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!atLeastOneHealthy) {
|
|
||||||
return POOL_NODES_UNHEALTHY;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.innerPools = inner;
|
|
||||||
|
|
||||||
NetworkSettings networkSettings = getNetworkSettings(ctx);
|
|
||||||
|
|
||||||
this.maxObjectSize = networkSettings.getMaxObjectSize();
|
|
||||||
startRebalance(ctx);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ClientWrapper connection() {
|
|
||||||
for (InnerPool pool : innerPools) {
|
|
||||||
ClientWrapper client = pool.connection();
|
|
||||||
if (client != null) {
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FrostFSException(POOL_CLIENTS_UNHEALTHY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
if (innerPools != null) {
|
|
||||||
for (InnerPool innerPool : innerPools) {
|
|
||||||
for (ClientWrapper client : innerPool.getClients()) {
|
|
||||||
if (client.isDialed()) {
|
|
||||||
client.getClient().close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startRebalance(CallContext ctx) {
|
|
||||||
double[][] buffers = new double[rebalanceParams.getNodesParams().length][];
|
|
||||||
|
|
||||||
for (int i = 0; i < rebalanceParams.getNodesParams().length; i++) {
|
|
||||||
NodesParam parameters = rebalanceParams.getNodesParams()[i];
|
|
||||||
buffers[i] = new double[parameters.getWeight().size()];
|
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
WaitUtil.sleep(rebalanceParams.getClientRebalanceInterval());
|
|
||||||
updateNodesHealth(ctx, buffers);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateNodesHealth(CallContext ctx, double[][] buffers) {
|
|
||||||
CompletableFuture<?>[] tasks = new CompletableFuture<?>[innerPools.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < innerPools.length; i++) {
|
|
||||||
double[] bufferWeights = buffers[i];
|
|
||||||
int finalI = i;
|
|
||||||
tasks[i] = CompletableFuture.runAsync(() -> updateInnerNodesHealth(ctx, finalI, bufferWeights));
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletableFuture.allOf(tasks).join();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateInnerNodesHealth(CallContext ctx, int poolIndex, double[] bufferWeights) {
|
|
||||||
if (poolIndex > innerPools.length - 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
InnerPool pool = innerPools[poolIndex];
|
|
||||||
RebalanceParameters options = rebalanceParams;
|
|
||||||
int[] healthyChanged = {0};
|
|
||||||
|
|
||||||
CompletableFuture<?>[] tasks = new CompletableFuture<?>[pool.getClients().length];
|
|
||||||
|
|
||||||
for (int j = 0; j < pool.getClients().length; j++) {
|
|
||||||
ClientWrapper client = pool.getClients()[j];
|
|
||||||
AtomicBoolean healthy = new AtomicBoolean(false);
|
|
||||||
AtomicReference<String> error = new AtomicReference<>();
|
|
||||||
AtomicBoolean changed = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
int finalJ = j;
|
|
||||||
tasks[j] = client.restartIfUnhealthy(ctx).handle((unused, throwable) -> {
|
|
||||||
if (throwable != null) {
|
|
||||||
error.set(throwable.getMessage());
|
|
||||||
bufferWeights[finalJ] = 0;
|
|
||||||
sessionCache.deleteByPrefix(client.getAddress());
|
|
||||||
} else {
|
|
||||||
changed.set(unused);
|
|
||||||
healthy.set(true);
|
|
||||||
bufferWeights[finalJ] = options.getNodesParams()[poolIndex].getWeight().get(finalJ);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}).thenRun(() -> {
|
|
||||||
if (changed.get()) {
|
|
||||||
if (error.get() != null && logger != null) {
|
|
||||||
FrostFSMessages.healthChanged(logger, client.getAddress(), healthy.get(), error.get());
|
|
||||||
}
|
|
||||||
healthyChanged[0] = 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
CompletableFuture.allOf(tasks).thenRun(() -> {
|
|
||||||
if (healthyChanged[0] == 1) {
|
|
||||||
double[] probabilities = adjustWeights(bufferWeights);
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
pool.setSampler(new Sampler(probabilities));
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkSessionTokenErr(Exception error, String address) {
|
|
||||||
if (error == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error instanceof SessionNotFoundFrostFSException || error instanceof SessionExpiredFrostFSException) {
|
|
||||||
sessionCache.deleteByPrefix(address);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Statistic statistic() {
|
|
||||||
if (innerPools == null) {
|
|
||||||
throw new ValidationFrostFSException(POOL_NOT_DIALED);
|
|
||||||
}
|
|
||||||
|
|
||||||
Statistic statistics = new Statistic();
|
|
||||||
|
|
||||||
for (InnerPool inner : innerPools) {
|
|
||||||
int valueIndex = 0;
|
|
||||||
String[] nodes = new String[inner.getClients().length];
|
|
||||||
|
|
||||||
lock.lock();
|
|
||||||
try {
|
|
||||||
for (ClientWrapper client : inner.getClients()) {
|
|
||||||
if (client.isHealthy()) {
|
|
||||||
nodes[valueIndex] = client.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeStatistic node = new NodeStatistic();
|
|
||||||
node.setAddress(client.getAddress());
|
|
||||||
node.setMethods(client.getMethodsStatus());
|
|
||||||
node.setOverallErrors(client.getOverallErrorRate());
|
|
||||||
node.setCurrentErrors(client.getCurrentErrorRate());
|
|
||||||
|
|
||||||
statistics.getNodes().add(node);
|
|
||||||
valueIndex++;
|
|
||||||
statistics.setOverallErrors(statistics.getOverallErrors() + node.getOverallErrors());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (statistics.getCurrentNodes() == null || statistics.getCurrentNodes().length == 0) {
|
|
||||||
statistics.setCurrentNodes(nodes);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return statistics;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Container getContainer(PrmContainerGet args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getContainer(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().listContainers(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().createContainer(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteContainer(PrmContainerDelete args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
client.getClient().deleteContainer(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getObjectHead(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getObject(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().putObject(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().putClientCutObject(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().putSingleObject(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteObject(PrmObjectDelete args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
client.getClient().deleteObject(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().searchObjects(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RangeReader getRange(PrmRangeGet args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getRange(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getRangeHash(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectId patchObject(PrmObjectPatch args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().patchObject(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] addChain(PrmApeChainAdd args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().addChain(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeChain(PrmApeChainRemove args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
client.getClient().removeChain(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().listChains(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetmapSnapshot getNetmapSnapshot(CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getNetmapSnapshot(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeInfo getLocalNodeInfo(CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getLocalNodeInfo(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetworkSettings getNetworkSettings(CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getNetworkSettings(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SessionToken createSession(PrmSessionCreate args, CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().createSession(args, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().calculateObjectId(header);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public frostfs.accounting.Types.Decimal getBalance(CallContext ctx) {
|
|
||||||
ClientWrapper client = connection();
|
|
||||||
return client.getClient().getBalance(ctx);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class RebalanceParameters {
|
|
||||||
private NodesParam[] nodesParams;
|
|
||||||
private long nodeRequestTimeout;
|
|
||||||
private long clientRebalanceInterval;
|
|
||||||
private long sessionExpirationDuration;
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.enums.MethodIndex;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class RequestInfo {
|
|
||||||
private String address;
|
|
||||||
private MethodIndex methodIndex;
|
|
||||||
private Duration elapsed;
|
|
||||||
}
|
|
|
@ -1,77 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
class Sampler {
|
|
||||||
private final Object lock = new Object();
|
|
||||||
private final Random random = new Random();
|
|
||||||
private final double[] probabilities;
|
|
||||||
private final int[] alias;
|
|
||||||
|
|
||||||
Sampler(double[] probabilities) {
|
|
||||||
ArrayList<Integer> small = new ArrayList<>();
|
|
||||||
ArrayList<Integer> large = new ArrayList<>();
|
|
||||||
|
|
||||||
int n = probabilities.length;
|
|
||||||
|
|
||||||
this.probabilities = new double[n];
|
|
||||||
this.alias = new int[n];
|
|
||||||
|
|
||||||
// Compute scaled probabilities.
|
|
||||||
double[] p = new double[n];
|
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
p[i] = probabilities[i] * n;
|
|
||||||
if (p[i] < 1) {
|
|
||||||
small.add(i);
|
|
||||||
} else {
|
|
||||||
large.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!small.isEmpty() && !large.isEmpty()) {
|
|
||||||
int l = small.remove(small.size() - 1);
|
|
||||||
int g = large.remove(large.size() - 1);
|
|
||||||
|
|
||||||
this.probabilities[l] = p[l];
|
|
||||||
this.alias[l] = g;
|
|
||||||
|
|
||||||
p[g] = p[g] + p[l] - 1;
|
|
||||||
|
|
||||||
if (p[g] < 1) {
|
|
||||||
small.add(g);
|
|
||||||
} else {
|
|
||||||
large.add(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!large.isEmpty()) {
|
|
||||||
int g = large.remove(large.size() - 1);
|
|
||||||
this.probabilities[g] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!small.isEmpty()) {
|
|
||||||
int l = small.remove(small.size() - 1);
|
|
||||||
probabilities[l] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int next() {
|
|
||||||
int n = alias.length;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
double f;
|
|
||||||
synchronized (lock) {
|
|
||||||
i = random.nextInt(n);
|
|
||||||
f = random.nextDouble();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f < probabilities[i]) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return alias[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
|
|
||||||
public class SessionCache {
|
|
||||||
private final ConcurrentMap<String, SessionToken> cache = new ConcurrentHashMap<>();
|
|
||||||
private final long tokenDuration;
|
|
||||||
private long currentEpoch;
|
|
||||||
|
|
||||||
public SessionCache(long sessionExpirationDuration) {
|
|
||||||
this.tokenDuration = sessionExpirationDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(String key) {
|
|
||||||
return cache.containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SessionToken tryGetValue(String key) {
|
|
||||||
return StringUtils.isBlank(key) ? null : cache.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String key, SessionToken value) {
|
|
||||||
if (key != null) {
|
|
||||||
cache.put(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteByPrefix(String prefix) {
|
|
||||||
cache.keySet().removeIf(key -> key.startsWith(prefix));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class Statistic {
|
|
||||||
private long overallErrors;
|
|
||||||
private List<NodeStatistic> nodes = new ArrayList<>();
|
|
||||||
private String[] currentNodes;
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class StatusSnapshot {
|
|
||||||
private long allTime;
|
|
||||||
private long allRequests;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
class WorkList {
|
|
||||||
private final List<Integer> elements = new ArrayList<>();
|
|
||||||
|
|
||||||
private int getLength() {
|
|
||||||
return elements.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void add(int element) {
|
|
||||||
elements.add(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int remove() {
|
|
||||||
int last = elements.get(elements.size() - 1);
|
|
||||||
elements.remove(elements.size() - 1);
|
|
||||||
return last;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package info.frostfs.sdk.pool;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
|
||||||
import io.grpc.ClientInterceptors;
|
|
||||||
import io.grpc.ManagedChannelBuilder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class WrapperPrm {
|
|
||||||
private Logger logger;
|
|
||||||
private String address;
|
|
||||||
private ECDsa key;
|
|
||||||
private long dialTimeout;
|
|
||||||
private long streamTimeout;
|
|
||||||
private int errorThreshold;
|
|
||||||
private Runnable responseInfoCallback;
|
|
||||||
private Runnable poolRequestInfoCallback;
|
|
||||||
private ManagedChannelBuilder<?> grpcChannelOptions;
|
|
||||||
private long gracefulCloseOnSwitchTimeout;
|
|
||||||
private Collection<ClientInterceptors> interceptors;
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package info.frostfs.sdk.services;
|
|
||||||
|
|
||||||
import frostfs.accounting.Types;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
|
|
||||||
public interface AccountingClient {
|
|
||||||
Types.Decimal getBalance(CallContext ctx);
|
|
||||||
}
|
|
|
@ -1,17 +1,14 @@
|
||||||
package info.frostfs.sdk.services;
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.ape.Chain;
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ApeManagerClient {
|
public interface ApeManagerClient {
|
||||||
byte[] addChain(PrmApeChainAdd args, CallContext ctx);
|
byte[] addChain(Chain chain, ChainTarget chainTarget);
|
||||||
|
|
||||||
void removeChain(PrmApeChainRemove args, CallContext ctx);
|
void removeChain(Chain chain, ChainTarget chainTarget);
|
||||||
|
|
||||||
List<Chain> listChains(PrmApeChainList args, CallContext ctx);
|
List<Chain> listChains(ChainTarget chainTarget);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package info.frostfs.sdk.services;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
|
|
||||||
public interface CommonClient extends
|
|
||||||
AccountingClient, ApeManagerClient, ContainerClient, NetmapClient, ObjectClient, SessionClient, ToolsClient {
|
|
||||||
|
|
||||||
String dial(CallContext ctx);
|
|
||||||
}
|
|
|
@ -2,20 +2,15 @@ package info.frostfs.sdk.services;
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.container.Container;
|
import info.frostfs.sdk.dto.container.Container;
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ContainerClient {
|
public interface ContainerClient {
|
||||||
Container getContainer(PrmContainerGet args, CallContext ctx);
|
Container getContainer(ContainerId cid);
|
||||||
|
|
||||||
List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx);
|
List<ContainerId> listContainers();
|
||||||
|
|
||||||
ContainerId createContainer(PrmContainerCreate args, CallContext ctx);
|
ContainerId createContainer(Container container);
|
||||||
|
|
||||||
void deleteContainer(PrmContainerDelete args, CallContext ctx);
|
void deleteContainer(ContainerId cid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,11 @@ package info.frostfs.sdk.services;
|
||||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
|
|
||||||
public interface NetmapClient {
|
public interface NetmapClient {
|
||||||
NetmapSnapshot getNetmapSnapshot(CallContext ctx);
|
NetmapSnapshot getNetmapSnapshot();
|
||||||
|
|
||||||
NodeInfo getLocalNodeInfo(CallContext ctx);
|
NodeInfo getLocalNodeInfo();
|
||||||
|
|
||||||
NetworkSettings getNetworkSettings(CallContext ctx);
|
NetworkSettings getNetworkSettings();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,22 @@
|
||||||
package info.frostfs.sdk.services;
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
|
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
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.dto.object.ObjectId;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet;
|
|
||||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.RangeReader;
|
|
||||||
|
|
||||||
public interface ObjectClient {
|
public interface ObjectClient {
|
||||||
ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx);
|
ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId);
|
||||||
|
|
||||||
ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx);
|
ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId);
|
||||||
|
|
||||||
ObjectWriter putObject(PrmObjectPut args, CallContext ctx);
|
ObjectId putObject(PutObjectParameters parameters);
|
||||||
|
|
||||||
ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx);
|
ObjectId putSingleObject(ObjectFrostFS objectFrostFS);
|
||||||
|
|
||||||
ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx);
|
void deleteObject(ContainerId containerId, ObjectId objectId);
|
||||||
|
|
||||||
void deleteObject(PrmObjectDelete args, CallContext ctx);
|
Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters);
|
||||||
|
|
||||||
Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx);
|
|
||||||
|
|
||||||
RangeReader getRange(PrmRangeGet args, CallContext ctx);
|
|
||||||
|
|
||||||
byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx);
|
|
||||||
|
|
||||||
ObjectId patchObject(PrmObjectPatch args, CallContext ctx);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package info.frostfs.sdk.services;
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
|
||||||
|
|
||||||
public interface SessionClient {
|
public interface SessionClient {
|
||||||
SessionToken createSession(PrmSessionCreate args, CallContext ctx);
|
SessionToken createSession(long expiration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package info.frostfs.sdk.services;
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
|
|
||||||
public interface SessionTools {
|
public interface SessionTools {
|
||||||
SessionToken getOrCreateSession(ClientEnvironment env, CallContext ctx);
|
Types.SessionToken getOrCreateSession(SessionToken token, ClientEnvironment env);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
package info.frostfs.sdk.services.impl;
|
|
||||||
|
|
||||||
import frostfs.accounting.AccountingServiceGrpc;
|
|
||||||
import frostfs.accounting.Service;
|
|
||||||
import frostfs.accounting.Types;
|
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
|
||||||
import info.frostfs.sdk.services.AccountingClient;
|
|
||||||
import info.frostfs.sdk.services.ContextAccessor;
|
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
|
||||||
import info.frostfs.sdk.tools.RequestSigner;
|
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
|
||||||
|
|
||||||
public class AccountingClientImpl extends ContextAccessor implements AccountingClient {
|
|
||||||
private final AccountingServiceGrpc.AccountingServiceBlockingStub serviceBlockingStub;
|
|
||||||
|
|
||||||
public AccountingClientImpl(ClientEnvironment clientEnvironment) {
|
|
||||||
super(clientEnvironment);
|
|
||||||
this.serviceBlockingStub = AccountingServiceGrpc.newBlockingStub(getContext().getChannel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Types.Decimal getBalance(CallContext ctx) {
|
|
||||||
var request = createGetRequest();
|
|
||||||
|
|
||||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
var response = service.balance(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
|
||||||
return response.getBody().getBalance();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Service.BalanceRequest createGetRequest() {
|
|
||||||
var body = Service.BalanceRequest.Body.newBuilder()
|
|
||||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
|
||||||
.build();
|
|
||||||
var request = Service.BalanceRequest.newBuilder()
|
|
||||||
.setBody(body);
|
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request);
|
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
|
||||||
|
|
||||||
return request.build();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,26 +4,23 @@ import com.google.protobuf.ByteString;
|
||||||
import frostfs.ape.Types;
|
import frostfs.ape.Types;
|
||||||
import frostfs.apemanager.APEManagerServiceGrpc;
|
import frostfs.apemanager.APEManagerServiceGrpc;
|
||||||
import frostfs.apemanager.Service;
|
import frostfs.apemanager.Service;
|
||||||
import info.frostfs.sdk.dto.ape.Chain;
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.mappers.chain.ChainMapper;
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
|
||||||
import info.frostfs.sdk.mappers.chain.ChainTargetMapper;
|
import info.frostfs.sdk.mappers.chain.ChainTargetMapper;
|
||||||
import info.frostfs.sdk.services.ApeManagerClient;
|
import info.frostfs.sdk.services.ApeManagerClient;
|
||||||
import info.frostfs.sdk.services.ContextAccessor;
|
import info.frostfs.sdk.services.ContextAccessor;
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
import info.frostfs.sdk.tools.RequestConstructor;
|
||||||
import info.frostfs.sdk.tools.RequestSigner;
|
import info.frostfs.sdk.tools.RequestSigner;
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
import info.frostfs.sdk.tools.ape.RuleDeserializer;
|
|
||||||
import info.frostfs.sdk.tools.ape.RuleSerializer;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.Map;
|
||||||
|
|
||||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
import static info.frostfs.sdk.utils.Validator.validate;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerClient {
|
public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerClient {
|
||||||
private final APEManagerServiceGrpc.APEManagerServiceBlockingStub apeManagerServiceClient;
|
private final APEManagerServiceGrpc.APEManagerServiceBlockingStub apeManagerServiceClient;
|
||||||
|
@ -34,13 +31,19 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] addChain(PrmApeChainAdd args, CallContext ctx) {
|
public byte[] addChain(Chain chain, ChainTarget chainTarget) {
|
||||||
validate(args);
|
if (isNull(chain) || isNull(chainTarget)) {
|
||||||
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(
|
||||||
|
PARAMS_ARE_MISSING_TEMPLATE,
|
||||||
|
String.join(FIELDS_DELIMITER_COMMA, Chain.class.getName(), ChainTarget.class.getName())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var request = createAddChainRequest(args);
|
var request = createAddChainRequest(chain, chainTarget, null);
|
||||||
|
|
||||||
var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = apeManagerServiceClient.addChain(request);
|
||||||
var response = service.addChain(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
@ -48,74 +51,82 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeChain(PrmApeChainRemove args, CallContext ctx) {
|
public void removeChain(Chain chain, ChainTarget chainTarget) {
|
||||||
validate(args);
|
if (isNull(chain) || isNull(chainTarget)) {
|
||||||
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(
|
||||||
|
PARAMS_ARE_MISSING_TEMPLATE,
|
||||||
|
String.join(FIELDS_DELIMITER_COMMA, Chain.class.getName(), ChainTarget.class.getName())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var request = createRemoveChainRequest(args);
|
var request = createRemoveChainRequest(chain, chainTarget, null);
|
||||||
|
|
||||||
var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = apeManagerServiceClient.removeChain(request);
|
||||||
var response = service.removeChain(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||||
validate(args);
|
if (isNull(chainTarget)) {
|
||||||
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ChainTarget.class.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
var request = createListChainsRequest(args);
|
var request = createListChainsRequest(chainTarget, null);
|
||||||
|
|
||||||
var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = apeManagerServiceClient.listChains(request);
|
||||||
var response = service.listChains(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
return response.getBody().getChainsList().stream()
|
return ChainMapper.toModels(response.getBody().getChainsList());
|
||||||
.map(chain -> RuleDeserializer.deserialize(chain.getRaw().toByteArray()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.AddChainRequest createAddChainRequest(PrmApeChainAdd args) {
|
private Service.AddChainRequest createAddChainRequest(Chain chain,
|
||||||
var raw = RuleSerializer.serialize(args.getChain());
|
ChainTarget chainTarget,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
var chainGrpc = Types.Chain.newBuilder()
|
var chainGrpc = Types.Chain.newBuilder()
|
||||||
.setRaw(ByteString.copyFrom(raw))
|
.setRaw(ByteString.copyFrom(chain.getRaw()))
|
||||||
.build();
|
.build();
|
||||||
var body = Service.AddChainRequest.Body.newBuilder()
|
var body = Service.AddChainRequest.Body.newBuilder()
|
||||||
.setChain(chainGrpc)
|
.setChain(chainGrpc)
|
||||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||||
.build();
|
.build();
|
||||||
var request = Service.AddChainRequest.newBuilder()
|
var request = Service.AddChainRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.RemoveChainRequest createRemoveChainRequest(PrmApeChainRemove args) {
|
private Service.RemoveChainRequest createRemoveChainRequest(Chain chain,
|
||||||
|
ChainTarget chainTarget,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
var body = Service.RemoveChainRequest.Body.newBuilder()
|
var body = Service.RemoveChainRequest.Body.newBuilder()
|
||||||
.setChainId(ByteString.copyFrom(args.getChainId()))
|
.setChainId(ByteString.copyFrom(chain.getRaw()))
|
||||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||||
.build();
|
.build();
|
||||||
var request = Service.RemoveChainRequest.newBuilder()
|
var request = Service.RemoveChainRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.ListChainsRequest createListChainsRequest(PrmApeChainList args) {
|
private Service.ListChainsRequest createListChainsRequest(ChainTarget chainTarget,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
var body = Service.ListChainsRequest.Body.newBuilder()
|
var body = Service.ListChainsRequest.Body.newBuilder()
|
||||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||||
.build();
|
.build();
|
||||||
var request = Service.ListChainsRequest.newBuilder()
|
var request = Service.ListChainsRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
|
|
|
@ -10,14 +10,9 @@ import info.frostfs.sdk.enums.StatusCode;
|
||||||
import info.frostfs.sdk.enums.WaitExpects;
|
import info.frostfs.sdk.enums.WaitExpects;
|
||||||
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
||||||
import info.frostfs.sdk.exceptions.TimeoutFrostFSException;
|
import info.frostfs.sdk.exceptions.TimeoutFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.jdo.WaitParameters;
|
||||||
import info.frostfs.sdk.jdo.parameters.PrmWait;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
||||||
import info.frostfs.sdk.mappers.container.ContainerMapper;
|
import info.frostfs.sdk.mappers.container.ContainerMapper;
|
||||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||||
|
@ -34,11 +29,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE;
|
import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
|
||||||
import static info.frostfs.sdk.utils.Validator.validate;
|
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
import static java.util.Objects.nonNull;
|
|
||||||
|
|
||||||
public class ContainerClientImpl extends ContextAccessor implements ContainerClient {
|
public class ContainerClientImpl extends ContextAccessor implements ContainerClient {
|
||||||
private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub;
|
private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub;
|
||||||
|
@ -50,33 +42,29 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
this.sessionTools = new SessionToolsImpl(clientEnvironment);
|
this.sessionTools = new SessionToolsImpl(clientEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionToken getOrCreateSession(SessionContext sessionContext, CallContext ctx) {
|
public frostfs.session.Types.SessionToken getOrCreateSession(SessionToken sessionToken) {
|
||||||
return isNull(sessionContext.getSessionToken())
|
return sessionTools.getOrCreateSession(sessionToken, getContext());
|
||||||
? sessionTools.getOrCreateSession(getContext(), ctx)
|
|
||||||
: sessionContext.getSessionToken();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Container getContainer(PrmContainerGet args, CallContext ctx) {
|
public Container getContainer(ContainerId cid) {
|
||||||
validate(args);
|
if (isNull(cid)) {
|
||||||
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
var request = createGetRequest(args);
|
var request = createGetRequest(ContainerIdMapper.toGrpcMessage(cid), null);
|
||||||
|
|
||||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = serviceBlockingStub.get(request);
|
||||||
var response = service.get(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
return ContainerMapper.toModel(response.getBody().getContainer());
|
return ContainerMapper.toModel(response.getBody().getContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx) {
|
public List<ContainerId> listContainers() {
|
||||||
validate(args);
|
var request = createListRequest(null);
|
||||||
|
|
||||||
var request = createListRequest(args);
|
var response = serviceBlockingStub.list(request);
|
||||||
|
|
||||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
var response = service.list(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
@ -86,39 +74,43 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) {
|
public ContainerId createContainer(Container container) {
|
||||||
validate(args);
|
if (isNull(container)) {
|
||||||
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, Container.class.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
var request = createPutRequest(args, ctx);
|
var grpcContainer = ContainerMapper.toGrpcMessage(container);
|
||||||
|
var request = createPutRequest(grpcContainer, null);
|
||||||
|
|
||||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = serviceBlockingStub.put(request);
|
||||||
var response = service.put(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
waitForContainer(WaitExpects.EXISTS, response.getBody().getContainerId(), args.getWaitParams());
|
waitForContainer(WaitExpects.EXISTS, response.getBody().getContainerId(), null);
|
||||||
|
|
||||||
return new ContainerId(response.getBody().getContainerId().getValue().toByteArray());
|
return new ContainerId(response.getBody().getContainerId().getValue().toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteContainer(PrmContainerDelete args, CallContext ctx) {
|
public void deleteContainer(ContainerId cid) {
|
||||||
validate(args);
|
if (isNull(cid)) {
|
||||||
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
var request = createDeleteRequest(args, ctx);
|
var grpcContainerId = ContainerIdMapper.toGrpcMessage(cid);
|
||||||
|
var request = createDeleteRequest(grpcContainerId, null);
|
||||||
|
|
||||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = serviceBlockingStub.delete(request);
|
||||||
var response = service.delete(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
waitForContainer(WaitExpects.REMOVED, request.getBody().getContainerId(), args.getWaitParams());
|
waitForContainer(WaitExpects.REMOVED, request.getBody().getContainerId(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForContainer(WaitExpects expect, Types.ContainerID cid, PrmWait waitParams) {
|
private void waitForContainer(WaitExpects expect, Types.ContainerID id, WaitParameters waitParams) {
|
||||||
var request = createGetRequest(cid, null);
|
var request = createGetRequest(id, null);
|
||||||
|
|
||||||
waitParams = isNull(waitParams) ? new PrmWait() : waitParams;
|
waitParams = isNull(waitParams) ? new WaitParameters() : waitParams;
|
||||||
var deadLine = waitParams.getDeadline();
|
var deadLine = waitParams.getDeadline();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -153,12 +145,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.GetRequest createGetRequest(PrmContainerGet args) {
|
|
||||||
var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId());
|
|
||||||
return createGetRequest(cid, args.getXHeaders());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Service.GetRequest createGetRequest(Types.ContainerID cid, Map<String, String> xHeaders) {
|
private Service.GetRequest createGetRequest(Types.ContainerID cid,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
var body = Service.GetRequest.Body.newBuilder()
|
var body = Service.GetRequest.Body.newBuilder()
|
||||||
.setContainerId(cid)
|
.setContainerId(cid)
|
||||||
.build();
|
.build();
|
||||||
|
@ -171,30 +160,26 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.ListRequest createListRequest(PrmContainerGetAll args) {
|
private Service.ListRequest createListRequest(Map<String, String> xHeaders) {
|
||||||
var body = Service.ListRequest.Body.newBuilder()
|
var body = Service.ListRequest.Body.newBuilder()
|
||||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||||
.build();
|
.build();
|
||||||
var request = Service.ListRequest.newBuilder()
|
var request = Service.ListRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.PutRequest createPutRequest(PrmContainerCreate args, CallContext ctx) {
|
private Service.PutRequest createPutRequest(frostfs.container.Types.Container container,
|
||||||
syncContainerWithNetwork(args.getContainer(), ctx);
|
Map<String, String> xHeaders) {
|
||||||
var builder = ContainerMapper.toGrpcMessage(args.getContainer());
|
container = container.toBuilder()
|
||||||
if (!builder.hasOwnerId()) {
|
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||||
builder.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()));
|
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()))
|
||||||
}
|
.build();
|
||||||
if (!builder.hasVersion()) {
|
|
||||||
builder.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()));
|
|
||||||
}
|
|
||||||
|
|
||||||
var container = builder.build();
|
|
||||||
var body = Service.PutRequest.Body.newBuilder()
|
var body = Service.PutRequest.Body.newBuilder()
|
||||||
.setContainer(container)
|
.setContainer(container)
|
||||||
.setSignature(RequestSigner.signRFC6979(getContext().getKey(), container))
|
.setSignature(RequestSigner.signRFC6979(getContext().getKey(), container))
|
||||||
|
@ -202,8 +187,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
var request = Service.PutRequest.newBuilder()
|
var request = Service.PutRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createContainerTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createContainerTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
null,
|
null,
|
||||||
frostfs.session.Types.ContainerSessionContext.Verb.PUT,
|
frostfs.session.Types.ContainerSessionContext.Verb.PUT,
|
||||||
|
@ -211,15 +197,14 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, xHeaders, sessionToken);
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.DeleteRequest createDeleteRequest(PrmContainerDelete args, CallContext ctx) {
|
private Service.DeleteRequest createDeleteRequest(Types.ContainerID cid,
|
||||||
var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId());
|
Map<String, String> xHeaders) {
|
||||||
|
|
||||||
var body = Service.DeleteRequest.Body.newBuilder()
|
var body = Service.DeleteRequest.Body.newBuilder()
|
||||||
.setContainerId(cid)
|
.setContainerId(cid)
|
||||||
.setSignature(RequestSigner.signRFC6979(getContext().getKey(), cid.getValue()))
|
.setSignature(RequestSigner.signRFC6979(getContext().getKey(), cid.getValue()))
|
||||||
|
@ -227,8 +212,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
var request = Service.DeleteRequest.newBuilder()
|
var request = Service.DeleteRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createContainerTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createContainerTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
null,
|
null,
|
||||||
frostfs.session.Types.ContainerSessionContext.Verb.DELETE,
|
frostfs.session.Types.ContainerSessionContext.Verb.DELETE,
|
||||||
|
@ -236,18 +222,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, xHeaders, sessionToken);
|
||||||
RequestSigner.sign(request, getContext().getKey());
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncContainerWithNetwork(Container container, CallContext callContext) {
|
|
||||||
var settings = getContext().getFrostFSClient().getNetworkSettings(callContext);
|
|
||||||
if (nonNull(settings.getHomomorphicHashingDisabled()) && settings.getHomomorphicHashingDisabled()) {
|
|
||||||
container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString());
|
|
||||||
} else {
|
|
||||||
container.getAttributes().remove(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
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;
|
||||||
|
@ -18,7 +17,6 @@ import info.frostfs.sdk.tools.Verifier;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
|
||||||
import static java.util.Objects.nonNull;
|
import static java.util.Objects.nonNull;
|
||||||
|
|
||||||
public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
||||||
|
@ -96,12 +94,12 @@ public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkSettings getNetworkSettings(CallContext ctx) {
|
public NetworkSettings getNetworkSettings() {
|
||||||
if (nonNull(getContext().getNetworkSettings())) {
|
if (nonNull(getContext().getNetworkSettings())) {
|
||||||
return getContext().getNetworkSettings();
|
return getContext().getNetworkSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
var info = getNetworkInfo(ctx);
|
var info = getNetworkInfo();
|
||||||
|
|
||||||
var settings = new NetworkSettings();
|
var settings = new NetworkSettings();
|
||||||
|
|
||||||
|
@ -115,28 +113,25 @@ public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeInfo getLocalNodeInfo(CallContext ctx) {
|
public NodeInfo getLocalNodeInfo() {
|
||||||
var request = Service.LocalNodeInfoRequest.newBuilder();
|
var request = Service.LocalNodeInfoRequest.newBuilder();
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request);
|
RequestConstructor.addMetaHeader(request);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = netmapServiceClient.localNodeInfo(request.build());
|
||||||
var response = service.localNodeInfo(request.build());
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
return NodeInfoMapper.toModel(response.getBody());
|
return NodeInfoMapper.toModel(response.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Service.NetworkInfoResponse getNetworkInfo(CallContext ctx) {
|
public Service.NetworkInfoResponse getNetworkInfo() {
|
||||||
var request = Service.NetworkInfoRequest.newBuilder();
|
var request = Service.NetworkInfoRequest.newBuilder();
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request);
|
RequestConstructor.addMetaHeader(request);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = netmapServiceClient.networkInfo(request.build());
|
||||||
var response = service.networkInfo(request.build());
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
@ -144,14 +139,13 @@ public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetmapSnapshot getNetmapSnapshot(CallContext ctx) {
|
public NetmapSnapshot getNetmapSnapshot() {
|
||||||
var request = Service.NetmapSnapshotRequest.newBuilder();
|
var request = Service.NetmapSnapshotRequest.newBuilder();
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request);
|
RequestConstructor.addMetaHeader(request);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = netmapServiceClient.netmapSnapshot(request.build());
|
||||||
var response = service.netmapSnapshot(request.build());
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
|
|
@ -6,28 +6,29 @@ import frostfs.object.ObjectServiceGrpc;
|
||||||
import frostfs.object.Service;
|
import frostfs.object.Service;
|
||||||
import frostfs.refs.Types;
|
import frostfs.refs.Types;
|
||||||
import info.frostfs.sdk.constants.AppConst;
|
import info.frostfs.sdk.constants.AppConst;
|
||||||
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.object.*;
|
import info.frostfs.sdk.dto.object.*;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
import info.frostfs.sdk.jdo.PutObjectResult;
|
import info.frostfs.sdk.jdo.PutObjectResult;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmObjectPatch;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.object.patch.PrmRangeHashGet;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
|
||||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
|
||||||
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
||||||
import info.frostfs.sdk.mappers.object.*;
|
import info.frostfs.sdk.mappers.object.ObjectFilterMapper;
|
||||||
import info.frostfs.sdk.mappers.object.patch.AddressMapper;
|
import info.frostfs.sdk.mappers.object.ObjectFrostFSMapper;
|
||||||
import info.frostfs.sdk.mappers.object.patch.RangeMapper;
|
import info.frostfs.sdk.mappers.object.ObjectHeaderMapper;
|
||||||
|
import info.frostfs.sdk.mappers.object.ObjectIdMapper;
|
||||||
|
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||||
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.services.impl.rwhelper.*;
|
import info.frostfs.sdk.services.impl.rwhelper.ObjectReaderImpl;
|
||||||
|
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
||||||
|
import info.frostfs.sdk.services.impl.rwhelper.SearchReader;
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
import info.frostfs.sdk.tools.RequestConstructor;
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
|
import info.frostfs.sdk.utils.Validator;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -35,12 +36,10 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
import static info.frostfs.sdk.Helper.getSha256;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
|
||||||
import static info.frostfs.sdk.utils.Validator.validate;
|
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
import static java.util.Objects.nonNull;
|
|
||||||
|
|
||||||
public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient;
|
private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient;
|
||||||
|
@ -56,226 +55,87 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
this.sessionTools = new SessionToolsImpl(clientEnvironment);
|
this.sessionTools = new SessionToolsImpl(clientEnvironment);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionToken getOrCreateSession(SessionContext sessionContext, CallContext ctx) {
|
public frostfs.session.Types.SessionToken getOrCreateSession(SessionToken sessionToken) {
|
||||||
return isNull(sessionContext.getSessionToken())
|
return sessionTools.getOrCreateSession(sessionToken, getContext());
|
||||||
? sessionTools.getOrCreateSession(getContext(), ctx)
|
|
||||||
: sessionContext.getSessionToken();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) {
|
public ObjectHeader getObjectHead(ContainerId cid, ObjectId oid) {
|
||||||
validate(args);
|
if (isNull(cid) || isNull(oid)) {
|
||||||
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(
|
||||||
|
PARAMS_ARE_MISSING_TEMPLATE,
|
||||||
|
String.join(FIELDS_DELIMITER_COMMA, ContainerId.class.getName(), ObjectId.class.getName())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var request = createHeadRequest(args, ctx);
|
var request = createHeadRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = objectServiceBlockingClient.head(request);
|
||||||
var response = service.head(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
return ObjectHeaderResult.builder()
|
return ObjectHeaderMapper.toModel(response.getBody().getHeader().getHeader());
|
||||||
.headerInfo(ObjectHeaderMapper.toModel(response.getBody().getHeader().getHeader()))
|
|
||||||
.splitInfo(SplitInfoMapper.toModel(response.getBody().getSplitInfo()))
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) {
|
public ObjectFrostFS getObject(ContainerId cid, ObjectId oid) {
|
||||||
validate(args);
|
var request = createGetRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||||
|
|
||||||
var request = createGetRequest(args, ctx);
|
return getObject(request);
|
||||||
|
|
||||||
return getObject(request, ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteObject(PrmObjectDelete args, CallContext ctx) {
|
public void deleteObject(ContainerId cid, ObjectId oid) {
|
||||||
validate(args);
|
var request = createDeleteRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||||
|
|
||||||
var request = createDeleteRequest(args, ctx);
|
var response = objectServiceBlockingClient.delete(request);
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
var response = service.delete(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx) {
|
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
||||||
validate(args);
|
var request = createSearchRequest(ContainerIdMapper.toGrpcMessage(cid), filters);
|
||||||
|
|
||||||
var request = createSearchRequest(args, ctx);
|
var objectsIds = searchObjects(request);
|
||||||
|
|
||||||
var objectsIds = searchObjects(request, ctx);
|
|
||||||
|
|
||||||
return Iterables.transform(objectsIds, input -> new ObjectId(input.getValue().toByteArray()));
|
return Iterables.transform(objectsIds, input -> new ObjectId(input.getValue().toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) {
|
public ObjectId putObject(PutObjectParameters parameters) {
|
||||||
validate(args);
|
Validator.validate(parameters);
|
||||||
|
|
||||||
return new ObjectWriter(getContext(), args, getUploadStream(args, ctx));
|
if (parameters.isClientCut()) {
|
||||||
|
return putClientCutObject(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameters.getHeader().getPayloadLength() > 0) {
|
||||||
|
parameters.setFullLength(parameters.getHeader().getPayloadLength());
|
||||||
|
} else {
|
||||||
|
parameters.setFullLength(getStreamSize(parameters.getPayload()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return putStreamObject(parameters).getObjectId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) {
|
public ObjectId putSingleObject(ObjectFrostFS modelObject) {
|
||||||
validate(args);
|
var grpcObject = objectToolsImpl.createObject(modelObject);
|
||||||
|
|
||||||
var header = args.getObjectHeader();
|
var request = createPutSingleRequest(grpcObject);
|
||||||
var fullLength = header.getPayloadLength() == 0 ? getStreamSize(args.getPayload()) : header.getPayloadLength();
|
|
||||||
args.getPutObjectContext().setFullLength(fullLength);
|
|
||||||
|
|
||||||
if (args.getPutObjectContext().getMaxObjectSizeCache() == 0) {
|
var response = objectServiceBlockingClient.putSingle(request);
|
||||||
var networkSettings = getContext().getFrostFSClient().getNetworkSettings(ctx);
|
|
||||||
args.getPutObjectContext().setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
var restBytes = fullLength - args.getPutObjectContext().getCurrentStreamPosition();
|
|
||||||
var objectSize = restBytes > 0
|
|
||||||
? Math.min(args.getPutObjectContext().getMaxObjectSizeCache(), restBytes)
|
|
||||||
: args.getPutObjectContext().getMaxObjectSizeCache();
|
|
||||||
|
|
||||||
//define collection capacity
|
|
||||||
var restPart = (restBytes % objectSize) > 0 ? 1 : 0;
|
|
||||||
var objectsCount = fullLength > 0 ? (int) (restBytes / objectSize) + restPart : 0;
|
|
||||||
|
|
||||||
List<ObjectId> sentObjectIds = new ArrayList<>(objectsCount);
|
|
||||||
|
|
||||||
// keep attributes for the large object
|
|
||||||
var attributes = args.getObjectHeader().getAttributes();
|
|
||||||
|
|
||||||
Split split = new Split();
|
|
||||||
args.getObjectHeader().setAttributes(new ArrayList<>());
|
|
||||||
|
|
||||||
// send all parts except the last one as separate Objects
|
|
||||||
while (restBytes > (long) args.getPutObjectContext().getMaxObjectSizeCache()) {
|
|
||||||
var previous = CollectionUtils.isNotEmpty(sentObjectIds)
|
|
||||||
? sentObjectIds.get(sentObjectIds.size() - 1)
|
|
||||||
: null;
|
|
||||||
split.setPrevious(previous);
|
|
||||||
args.getObjectHeader().setSplit(split);
|
|
||||||
|
|
||||||
var result = putMultipartStreamObject(args, ctx);
|
|
||||||
|
|
||||||
sentObjectIds.add(result.getObjectId());
|
|
||||||
|
|
||||||
restBytes -= result.getObjectSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// send the last part and create linkObject
|
|
||||||
if (CollectionUtils.isNotEmpty(sentObjectIds)) {
|
|
||||||
var largeObjectHeader = new ObjectHeader(
|
|
||||||
header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, header.getVersion()
|
|
||||||
);
|
|
||||||
largeObjectHeader.setOwnerId(header.getOwnerId());
|
|
||||||
|
|
||||||
split.setParentHeader(largeObjectHeader);
|
|
||||||
|
|
||||||
var result = putMultipartStreamObject(args, ctx);
|
|
||||||
|
|
||||||
sentObjectIds.add(result.getObjectId());
|
|
||||||
|
|
||||||
var linkObject = new LinkObject(header.getContainerId(), split.getSplitId(), largeObjectHeader);
|
|
||||||
linkObject.addChildren(sentObjectIds);
|
|
||||||
|
|
||||||
putSingleObject(new PrmObjectSinglePut(linkObject), ctx);
|
|
||||||
|
|
||||||
return split.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// We are here if the payload is placed to one Object. It means no cut action, just simple PUT.
|
|
||||||
var singlePartResult = putMultipartStreamObject(args, ctx);
|
|
||||||
|
|
||||||
return singlePartResult.getObjectId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) {
|
|
||||||
var grpcObject = objectToolsImpl.createObject(args.getObjectFrostFS());
|
|
||||||
var request = createPutSingleRequest(grpcObject, args, ctx);
|
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
var response = service.putSingle(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
return new ObjectId(grpcObject.getObjectId().getValue().toByteArray());
|
return new ObjectId(grpcObject.getObjectId().getValue().toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private ObjectFrostFS getObject(Service.GetRequest request) {
|
||||||
public RangeReader getRange(PrmRangeGet args, CallContext ctx) {
|
var reader = getObjectInit(request);
|
||||||
validate(args);
|
|
||||||
|
|
||||||
var request = createGetRangeRequest(args, ctx);
|
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
return new RangeReader(service.getRange(request));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[][] getRangeHash(PrmRangeHashGet args, CallContext ctx) {
|
|
||||||
validate(args);
|
|
||||||
|
|
||||||
var request = createGetRangeHashRequest(args, ctx);
|
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
var response = service.getRangeHash(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
|
||||||
|
|
||||||
return response.getBody().getHashListList().stream().map(ByteString::toByteArray).toArray(byte[][]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectId patchObject(PrmObjectPatch args, CallContext ctx) {
|
|
||||||
validate(args);
|
|
||||||
|
|
||||||
var request = createInitPatchRequest(args);
|
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
getOrCreateSession(args, ctx),
|
|
||||||
request.getBody().getAddress(),
|
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.PATCH,
|
|
||||||
getContext().getKey()
|
|
||||||
);
|
|
||||||
|
|
||||||
var currentPos = args.getRange().getOffset();
|
|
||||||
var chunkSize = args.getMaxChunkLength();
|
|
||||||
byte[] chunkBuffer = new byte[chunkSize];
|
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
|
||||||
PatchStreamer writer = new PatchStreamer(service);
|
|
||||||
|
|
||||||
var bytesCount = readNBytes(args.getPayload(), chunkBuffer, chunkSize);
|
|
||||||
while (bytesCount > 0) {
|
|
||||||
var range = Service.Range.newBuilder()
|
|
||||||
.setOffset(currentPos)
|
|
||||||
.setLength(bytesCount)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Service.PatchRequest.Body.Patch.newBuilder()
|
|
||||||
.setChunk(ByteString.copyFrom(chunkBuffer, 0, bytesCount))
|
|
||||||
.setSourceRange(range)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
currentPos += bytesCount;
|
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
|
||||||
sign(request, getContext().getKey());
|
|
||||||
|
|
||||||
writer.write(request.build());
|
|
||||||
bytesCount = readNBytes(args.getPayload(), chunkBuffer, chunkSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = writer.complete();
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
|
||||||
|
|
||||||
return ObjectIdMapper.toModel(response.getBody().getObjectId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObjectFrostFS getObject(Service.GetRequest request, CallContext ctx) {
|
|
||||||
var reader = getObjectInit(request, ctx);
|
|
||||||
|
|
||||||
var grpcObject = reader.readHeader();
|
var grpcObject = reader.readHeader();
|
||||||
var modelObject = ObjectFrostFSMapper.toModel(grpcObject);
|
var modelObject = ObjectFrostFSMapper.toModel(grpcObject);
|
||||||
|
@ -285,41 +145,39 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
return modelObject;
|
return modelObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest, CallContext ctx) {
|
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest) {
|
||||||
if (initRequest.getSerializedSize() == 0) {
|
if (initRequest.getSerializedSize() == 0) {
|
||||||
throw new ProcessFrostFSException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
return new ObjectReaderImpl(objectServiceBlockingClient.get(initRequest));
|
||||||
return new ObjectReaderImpl(service.get(initRequest));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PutObjectResult putMultipartStreamObject(PrmObjectClientCutPut args, CallContext ctx) {
|
private PutObjectResult putStreamObject(PutObjectParameters parameters) {
|
||||||
var chunkSize = args.getBufferMaxSize() > 0 ? args.getBufferMaxSize() : AppConst.OBJECT_CHUNK_SIZE;
|
var chunkSize = parameters.getBufferMaxSize() > 0 ? parameters.getBufferMaxSize() : AppConst.OBJECT_CHUNK_SIZE;
|
||||||
|
|
||||||
var restBytes =
|
var restBytes = parameters.getFullLength() - parameters.getCurrentStreamPosition();
|
||||||
args.getPutObjectContext().getFullLength() - args.getPutObjectContext().getCurrentStreamPosition();
|
|
||||||
|
|
||||||
chunkSize = (int) Math.min(restBytes, chunkSize);
|
chunkSize = (int) Math.min(restBytes, chunkSize);
|
||||||
|
|
||||||
byte[] chunkBuffer = args.getCustomerBuffer() != null
|
byte[] chunkBuffer = parameters.getCustomerBuffer() != null
|
||||||
? args.getCustomerBuffer()
|
? parameters.getCustomerBuffer()
|
||||||
: new byte[chunkSize];//todo change to pool
|
: new byte[chunkSize];//todo change to pool
|
||||||
|
|
||||||
var sentBytes = 0;
|
var sentBytes = 0;
|
||||||
|
|
||||||
// 0 means no limit from client, so server side cut is performed
|
// 0 means no limit from client, so server side cut is performed
|
||||||
var objectLimitSize = args.getPutObjectContext().getMaxObjectSizeCache();
|
var objectLimitSize = parameters.isClientCut() ? parameters.getMaxObjectSizeCache() : 0;
|
||||||
|
|
||||||
var stream = getUploadStream(args, ctx);
|
var stream = getUploadStream(parameters);
|
||||||
|
|
||||||
while (objectLimitSize == 0 || sentBytes < objectLimitSize) {
|
while (objectLimitSize == 0 || sentBytes < objectLimitSize) {
|
||||||
// send chunks limited to default or user's settings
|
// send chunks limited to default or user's settings
|
||||||
var bufferSize = objectLimitSize > 0 ? Math.min(objectLimitSize - sentBytes, chunkSize) : chunkSize;
|
var bufferSize = objectLimitSize > 0 ? Math.min(objectLimitSize - sentBytes, chunkSize) : chunkSize;
|
||||||
|
|
||||||
var bytesCount = readNBytes(args.getPayload(), chunkBuffer, bufferSize);
|
var bytesCount = readNBytes(parameters.getPayload(), chunkBuffer, bufferSize);
|
||||||
|
|
||||||
if (bytesCount == 0) {
|
if (bytesCount == 0) {
|
||||||
break;
|
break;
|
||||||
|
@ -334,7 +192,6 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
.clearVerifyHeader();
|
.clearVerifyHeader();
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(chunkRequest, args.getXHeaders());
|
|
||||||
sign(chunkRequest, getContext().getKey());
|
sign(chunkRequest, getContext().getKey());
|
||||||
|
|
||||||
stream.write(chunkRequest.build());
|
stream.write(chunkRequest.build());
|
||||||
|
@ -347,38 +204,110 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
return new PutObjectResult(objectId, sentBytes);
|
return new PutObjectResult(objectId, sentBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectStreamer getUploadStream(PrmObjectPutBase args, CallContext ctx) {
|
private ObjectId putClientCutObject(PutObjectParameters parameters) {
|
||||||
var header = args.getObjectHeader();
|
var header = parameters.getHeader();
|
||||||
|
var tokenRaw = getOrCreateSession(parameters.getSessionToken());
|
||||||
|
var token = new SessionToken(SessionMapper.serialize(tokenRaw));
|
||||||
|
parameters.setSessionToken(token);
|
||||||
|
|
||||||
|
var fullLength = header.getPayloadLength() == 0
|
||||||
|
? getStreamSize(parameters.getPayload())
|
||||||
|
: header.getPayloadLength();
|
||||||
|
|
||||||
|
parameters.setFullLength(fullLength);
|
||||||
|
|
||||||
|
if (parameters.getMaxObjectSizeCache() == 0) {
|
||||||
|
var networkSettings = getContext().getFrostFSClient().getNetworkSettings();
|
||||||
|
parameters.setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
var restBytes = fullLength - parameters.getCurrentStreamPosition();
|
||||||
|
var objectSize = restBytes > 0
|
||||||
|
? Math.min(parameters.getMaxObjectSizeCache(), restBytes)
|
||||||
|
: parameters.getMaxObjectSizeCache();
|
||||||
|
|
||||||
|
//define collection capacity
|
||||||
|
var restPart = (restBytes % objectSize) > 0 ? 1 : 0;
|
||||||
|
var objectsCount = fullLength > 0 ? (int) (restBytes / objectSize) + restPart : 0;
|
||||||
|
|
||||||
|
List<ObjectId> sentObjectIds = new ArrayList<>(objectsCount);
|
||||||
|
|
||||||
|
// keep attributes for the large object
|
||||||
|
var attributes = parameters.getHeader().getAttributes();
|
||||||
|
|
||||||
|
Split split = new Split();
|
||||||
|
parameters.getHeader().setSplit(split);
|
||||||
|
parameters.getHeader().setAttributes(new ArrayList<>());
|
||||||
|
|
||||||
|
// send all parts except the last one as separate Objects
|
||||||
|
while (restBytes > (long) parameters.getMaxObjectSizeCache()) {
|
||||||
|
var previous = CollectionUtils.isNotEmpty(sentObjectIds)
|
||||||
|
? sentObjectIds.get(sentObjectIds.size() - 1)
|
||||||
|
: null;
|
||||||
|
split.setPrevious(previous);
|
||||||
|
|
||||||
|
var result = putStreamObject(parameters);
|
||||||
|
|
||||||
|
sentObjectIds.add(result.getObjectId());
|
||||||
|
|
||||||
|
restBytes -= result.getObjectSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// send the last part and create linkObject
|
||||||
|
if (CollectionUtils.isNotEmpty(sentObjectIds)) {
|
||||||
|
var largeObjectHeader =
|
||||||
|
new ObjectHeader(header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, null);
|
||||||
|
|
||||||
|
split.setParentHeader(largeObjectHeader);
|
||||||
|
|
||||||
|
var result = putStreamObject(parameters);
|
||||||
|
|
||||||
|
sentObjectIds.add(result.getObjectId());
|
||||||
|
|
||||||
|
var linkObject = new LinkObject(header.getContainerId(), split.getSplitId(), largeObjectHeader);
|
||||||
|
linkObject.addChildren(sentObjectIds);
|
||||||
|
|
||||||
|
putSingleObject(linkObject);
|
||||||
|
|
||||||
|
return split.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are here if the payload is placed to one Object. It means no cut action, just simple PUT.
|
||||||
|
var singlePartResult = putStreamObject(parameters);
|
||||||
|
|
||||||
|
return singlePartResult.getObjectId();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectWriter getUploadStream(PutObjectParameters parameters) {
|
||||||
|
var header = parameters.getHeader();
|
||||||
|
|
||||||
header.setOwnerId(getContext().getOwnerId());
|
header.setOwnerId(getContext().getOwnerId());
|
||||||
header.setVersion(getContext().getVersion());
|
header.setVersion(getContext().getVersion());
|
||||||
|
|
||||||
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(header);
|
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(header);
|
||||||
|
|
||||||
if (nonNull(header.getSplit())) {
|
|
||||||
grpcHeader = objectToolsImpl.updateSplitValues(grpcHeader, header.getSplit());
|
grpcHeader = objectToolsImpl.updateSplitValues(grpcHeader, header.getSplit());
|
||||||
|
|
||||||
|
var oid = Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build();
|
||||||
|
|
||||||
|
var initRequest = createInitPutRequest(oid, grpcHeader);
|
||||||
|
|
||||||
|
return putObjectInit(initRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
var initRequest = createInitPutRequest(grpcHeader, args, ctx);
|
private ObjectWriter putObjectInit(Service.PutRequest initRequest) {
|
||||||
|
|
||||||
return putObjectInit(initRequest, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObjectStreamer putObjectInit(Service.PutRequest initRequest, CallContext ctx) {
|
|
||||||
if (initRequest.getSerializedSize() == 0) {
|
if (initRequest.getSerializedSize() == 0) {
|
||||||
throw new ProcessFrostFSException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
ObjectWriter writer = new ObjectWriter(objectServiceClient);
|
||||||
ObjectStreamer writer = new ObjectStreamer(service);
|
|
||||||
writer.write(initRequest);
|
writer.write(initRequest);
|
||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Iterable<Types.ObjectID> searchObjects(Service.SearchRequest request, CallContext ctx) {
|
private Iterable<Types.ObjectID> searchObjects(Service.SearchRequest request) {
|
||||||
var reader = getSearchReader(request, ctx);
|
var reader = getSearchReader(request);
|
||||||
var ids = reader.read();
|
var ids = reader.read();
|
||||||
List<Types.ObjectID> result = new ArrayList<>();
|
List<Types.ObjectID> result = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -390,15 +319,14 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
return result;//todo return yield
|
return result;//todo return yield
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchReader getSearchReader(Service.SearchRequest initRequest, CallContext ctx) {
|
private SearchReader getSearchReader(Service.SearchRequest initRequest) {
|
||||||
if (initRequest.getSerializedSize() == 0) {
|
if (initRequest.getSerializedSize() == 0) {
|
||||||
throw new ProcessFrostFSException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
||||||
return new SearchReader(service.search(initRequest));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int readNBytes(InputStream inputStream, byte[] buffer, int size) {
|
private int readNBytes(InputStream inputStream, byte[] buffer, int size) {
|
||||||
|
@ -417,36 +345,36 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.HeadRequest createHeadRequest(PrmObjectHeadGet args, CallContext ctx) {
|
private Service.HeadRequest createHeadRequest(Types.ContainerID cid, Types.ObjectID oid) {
|
||||||
var address = Types.Address.newBuilder()
|
var address = Types.Address.newBuilder()
|
||||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
.setContainerId(cid)
|
||||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
.setObjectId(oid)
|
||||||
.build();
|
.build();
|
||||||
var body = Service.HeadRequest.Body.newBuilder()
|
var body = Service.HeadRequest.Body.newBuilder()
|
||||||
.setAddress(address)
|
.setAddress(address)
|
||||||
.setRaw(args.isRaw())
|
|
||||||
.build();
|
.build();
|
||||||
var request = Service.HeadRequest.newBuilder()
|
var request = Service.HeadRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
address,
|
address,
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.HEAD,
|
frostfs.session.Types.ObjectSessionContext.Verb.HEAD,
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.GetRequest createGetRequest(PrmObjectGet args, CallContext ctx) {
|
private Service.GetRequest createGetRequest(Types.ContainerID cid, Types.ObjectID oid) {
|
||||||
var address = Types.Address.newBuilder()
|
var address = Types.Address.newBuilder()
|
||||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
.setContainerId(cid)
|
||||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
.setObjectId(oid)
|
||||||
.build();
|
.build();
|
||||||
var body = Service.GetRequest.Body.newBuilder()
|
var body = Service.GetRequest.Body.newBuilder()
|
||||||
.setAddress(address)
|
.setAddress(address)
|
||||||
|
@ -454,24 +382,25 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
var request = Service.GetRequest.newBuilder()
|
var request = Service.GetRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
address,
|
address,
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.GET,
|
frostfs.session.Types.ObjectSessionContext.Verb.GET,
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.DeleteRequest createDeleteRequest(PrmObjectDelete args, CallContext ctx) {
|
private Service.DeleteRequest createDeleteRequest(Types.ContainerID cid, Types.ObjectID oid) {
|
||||||
var address = Types.Address.newBuilder()
|
var address = Types.Address.newBuilder()
|
||||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
.setContainerId(cid)
|
||||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
.setObjectId(oid)
|
||||||
.build();
|
.build();
|
||||||
var body = Service.DeleteRequest.Body.newBuilder()
|
var body = Service.DeleteRequest.Body.newBuilder()
|
||||||
.setAddress(address)
|
.setAddress(address)
|
||||||
|
@ -479,23 +408,22 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
var request = Service.DeleteRequest.newBuilder()
|
var request = Service.DeleteRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
address,
|
address,
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.DELETE,
|
frostfs.session.Types.ObjectSessionContext.Verb.DELETE,
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.SearchRequest createSearchRequest(PrmObjectSearch args, CallContext ctx) {
|
private Service.SearchRequest createSearchRequest(Types.ContainerID cid, ObjectFilter<?>... filters) {
|
||||||
var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId());
|
|
||||||
|
|
||||||
var address = Types.Address.newBuilder()
|
var address = Types.Address.newBuilder()
|
||||||
.setContainerId(cid)
|
.setContainerId(cid)
|
||||||
.build();
|
.build();
|
||||||
|
@ -504,32 +432,32 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
.setContainerId(cid)
|
.setContainerId(cid)
|
||||||
.setVersion(1);// TODO: clarify this param
|
.setVersion(1);// TODO: clarify this param
|
||||||
|
|
||||||
for (ObjectFilter<?> filter : args.getFilters()) {
|
for (ObjectFilter<?> filter : filters) {
|
||||||
body.addFilters(ObjectFilterMapper.toGrpcMessage(filter));
|
body.addFilters(ObjectFilterMapper.toGrpcMessage(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = Service.SearchRequest.newBuilder()
|
var request = Service.SearchRequest.newBuilder()
|
||||||
.setBody(body.build());
|
.setBody(body.build());
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
address,
|
address,
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.SEARCH,
|
frostfs.session.Types.ObjectSessionContext.Verb.SEARCH,
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.PutRequest createInitPutRequest(frostfs.object.Types.Header header,
|
private Service.PutRequest createInitPutRequest(Types.ObjectID oid, frostfs.object.Types.Header header) {
|
||||||
PrmObjectPutBase args,
|
|
||||||
CallContext ctx) {
|
|
||||||
var address = Types.Address.newBuilder()
|
var address = Types.Address.newBuilder()
|
||||||
.setContainerId(header.getContainerId())
|
.setContainerId(header.getContainerId())
|
||||||
|
.setObjectId(oid)
|
||||||
.build();
|
.build();
|
||||||
var init = Service.PutRequest.Body.Init.newBuilder()
|
var init = Service.PutRequest.Body.Init.newBuilder()
|
||||||
.setHeader(header)
|
.setHeader(header)
|
||||||
|
@ -540,25 +468,25 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
var request = Service.PutRequest.newBuilder()
|
var request = Service.PutRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
address,
|
address,
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.PUT,
|
frostfs.session.Types.ObjectSessionContext.Verb.PUT,
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.PutSingleRequest createPutSingleRequest(frostfs.object.Types.Object grpcObject,
|
private Service.PutSingleRequest createPutSingleRequest(frostfs.object.Types.Object grpcObject) {
|
||||||
PrmObjectSinglePut args,
|
|
||||||
CallContext ctx) {
|
|
||||||
var address = Types.Address.newBuilder()
|
var address = Types.Address.newBuilder()
|
||||||
.setContainerId(grpcObject.getHeader().getContainerId())
|
.setContainerId(grpcObject.getHeader().getContainerId())
|
||||||
|
.setObjectId(grpcObject.getObjectId())
|
||||||
.build();
|
.build();
|
||||||
var body = Service.PutSingleRequest.Body.newBuilder()
|
var body = Service.PutSingleRequest.Body.newBuilder()
|
||||||
.setObject(grpcObject)
|
.setObject(grpcObject)
|
||||||
|
@ -566,83 +494,18 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
var request = Service.PutSingleRequest.newBuilder()
|
var request = Service.PutSingleRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
var sessionToken = getOrCreateSession(null);
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
|
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||||
sessionToken,
|
sessionToken,
|
||||||
address,
|
address,
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.PUT,
|
frostfs.session.Types.ObjectSessionContext.Verb.PUT,
|
||||||
getContext().getKey()
|
getContext().getKey()
|
||||||
);
|
);
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return request.build();
|
return request.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Service.GetRangeRequest createGetRangeRequest(PrmRangeGet args, CallContext ctx) {
|
|
||||||
var address = Types.Address.newBuilder()
|
|
||||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
|
||||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
|
||||||
.build();
|
|
||||||
var body = Service.GetRangeRequest.Body.newBuilder()
|
|
||||||
.setAddress(address)
|
|
||||||
.setRange(RangeMapper.toGrpcMessage(args.getRange()))
|
|
||||||
.setRaw(args.isRaw())
|
|
||||||
.build();
|
|
||||||
var request = Service.GetRangeRequest.newBuilder()
|
|
||||||
.setBody(body);
|
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
sessionToken,
|
|
||||||
address,
|
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.RANGE,
|
|
||||||
getContext().getKey()
|
|
||||||
);
|
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
|
||||||
sign(request, getContext().getKey());
|
|
||||||
|
|
||||||
return request.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Service.GetRangeHashRequest createGetRangeHashRequest(PrmRangeHashGet args, CallContext ctx) {
|
|
||||||
var address = Types.Address.newBuilder()
|
|
||||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
|
||||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
|
||||||
.build();
|
|
||||||
var body = Service.GetRangeHashRequest.Body.newBuilder()
|
|
||||||
.setAddress(address)
|
|
||||||
.setType(Types.ChecksumType.SHA256)
|
|
||||||
.setSalt(ByteString.copyFrom(args.getSalt()))
|
|
||||||
.addAllRanges(RangeMapper.toGrpcMessages(args.getRanges()))
|
|
||||||
.build();
|
|
||||||
var request = Service.GetRangeHashRequest.newBuilder()
|
|
||||||
.setBody(body);
|
|
||||||
|
|
||||||
var sessionToken = getOrCreateSession(args, ctx);
|
|
||||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
|
||||||
sessionToken,
|
|
||||||
address,
|
|
||||||
frostfs.session.Types.ObjectSessionContext.Verb.RANGEHASH,
|
|
||||||
getContext().getKey()
|
|
||||||
);
|
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
|
||||||
sign(request, getContext().getKey());
|
|
||||||
|
|
||||||
return request.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Service.PatchRequest.Builder createInitPatchRequest(PrmObjectPatch args) {
|
|
||||||
var address = AddressMapper.toGrpcMessage(args.getAddress());
|
|
||||||
var body = Service.PatchRequest.Body.newBuilder()
|
|
||||||
.setAddress(address)
|
|
||||||
.setReplaceAttributes(args.isReplaceAttributes())
|
|
||||||
.addAllNewAttributes(ObjectAttributeMapper.toGrpcMessages(args.getNewAttributes()))
|
|
||||||
.build();
|
|
||||||
return Service.PatchRequest.newBuilder()
|
|
||||||
.setBody(body);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,16 @@ public class ObjectToolsImpl extends ContextAccessor implements ToolsClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Types.Object createObject(ObjectFrostFS objectFrostFS) {
|
public Types.Object createObject(ObjectFrostFS objectFrostFs) {
|
||||||
objectFrostFS.getHeader().setOwnerId(getContext().getOwnerId());
|
objectFrostFs.getHeader().setOwnerId(getContext().getOwnerId());
|
||||||
objectFrostFS.getHeader().setVersion(getContext().getVersion());
|
objectFrostFs.getHeader().setVersion(getContext().getVersion());
|
||||||
objectFrostFS.getHeader().setPayloadLength(objectFrostFS.getPayload().length);
|
objectFrostFs.getHeader().setPayloadLength(objectFrostFs.getPayload().length);
|
||||||
|
|
||||||
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(objectFrostFS.getHeader()).toBuilder()
|
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(objectFrostFs.getHeader()).toBuilder()
|
||||||
.setPayloadHash(sha256Checksum(objectFrostFS.getPayload()))
|
.setPayloadHash(sha256Checksum(objectFrostFs.getPayload()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
var split = objectFrostFS.getHeader().getSplit();
|
var split = objectFrostFs.getHeader().getSplit();
|
||||||
if (nonNull(split)) {
|
if (nonNull(split)) {
|
||||||
grpcHeader = updateSplitValues(grpcHeader, split);
|
grpcHeader = updateSplitValues(grpcHeader, split);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class ObjectToolsImpl extends ContextAccessor implements ToolsClient {
|
||||||
return Types.Object.newBuilder()
|
return Types.Object.newBuilder()
|
||||||
.setHeader(grpcHeader)
|
.setHeader(grpcHeader)
|
||||||
.setObjectId(objectId)
|
.setObjectId(objectId)
|
||||||
.setPayload(ByteString.copyFrom(objectFrostFS.getPayload()))
|
.setPayload(ByteString.copyFrom(objectFrostFs.getPayload()))
|
||||||
.setSignature(sig)
|
.setSignature(sig)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -105,10 +105,7 @@ public class ObjectToolsImpl extends ContextAccessor implements ToolsClient {
|
||||||
split.setParent(ObjectIdMapper.toModel(parentObjectId));
|
split.setParent(ObjectIdMapper.toModel(parentObjectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nonNull(split.getPrevious())) {
|
|
||||||
grpcSplit.setPrevious(ObjectIdMapper.toGrpcMessage(split.getPrevious())).build();
|
grpcSplit.setPrevious(ObjectIdMapper.toGrpcMessage(split.getPrevious())).build();
|
||||||
}
|
|
||||||
|
|
||||||
return grpcHeader.toBuilder().setSplit(grpcSplit.build()).build();
|
return grpcHeader.toBuilder().setSplit(grpcSplit.build()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import frostfs.session.SessionServiceGrpc;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
|
||||||
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
||||||
import info.frostfs.sdk.mappers.session.SessionMapper;
|
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||||
import info.frostfs.sdk.services.ContextAccessor;
|
import info.frostfs.sdk.services.ContextAccessor;
|
||||||
|
@ -15,7 +13,6 @@ import info.frostfs.sdk.tools.RequestConstructor;
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
|
|
||||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
|
||||||
|
|
||||||
public class SessionClientImpl extends ContextAccessor implements SessionClient {
|
public class SessionClientImpl extends ContextAccessor implements SessionClient {
|
||||||
private final SessionServiceGrpc.SessionServiceBlockingStub serviceBlockingStub;
|
private final SessionServiceGrpc.SessionServiceBlockingStub serviceBlockingStub;
|
||||||
|
@ -26,16 +23,16 @@ public class SessionClientImpl extends ContextAccessor implements SessionClient
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionToken createSession(PrmSessionCreate args, CallContext ctx) {
|
public SessionToken createSession(long expiration) {
|
||||||
var sessionToken = createSessionInternal(args, ctx);
|
var sessionToken = createSessionInternal(expiration);
|
||||||
var token = SessionMapper.serialize(sessionToken);
|
var token = SessionMapper.serialize(sessionToken);
|
||||||
return new SessionToken(token);
|
return new SessionToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Types.SessionToken createSessionInternal(PrmSessionCreate args, CallContext ctx) {
|
public Types.SessionToken createSessionInternal(long expiration) {
|
||||||
var body = Service.CreateRequest.Body.newBuilder()
|
var body = Service.CreateRequest.Body.newBuilder()
|
||||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||||
.setExpiration(args.getExpiration())
|
.setExpiration(expiration)
|
||||||
.build();
|
.build();
|
||||||
var request = Service.CreateRequest.newBuilder()
|
var request = Service.CreateRequest.newBuilder()
|
||||||
.setBody(body);
|
.setBody(body);
|
||||||
|
@ -43,12 +40,11 @@ public class SessionClientImpl extends ContextAccessor implements SessionClient
|
||||||
RequestConstructor.addMetaHeader(request);
|
RequestConstructor.addMetaHeader(request);
|
||||||
sign(request, getContext().getKey());
|
sign(request, getContext().getKey());
|
||||||
|
|
||||||
return createSession(request.build(), ctx);
|
return createSession(request.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Types.SessionToken createSession(Service.CreateRequest request, CallContext ctx) {
|
private Types.SessionToken createSession(Service.CreateRequest request) {
|
||||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
var response = serviceBlockingStub.create(request);
|
||||||
var response = service.create(request);
|
|
||||||
|
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package info.frostfs.sdk.services.impl;
|
package info.frostfs.sdk.services.impl;
|
||||||
|
|
||||||
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
|
||||||
import info.frostfs.sdk.services.ContextAccessor;
|
import info.frostfs.sdk.services.ContextAccessor;
|
||||||
import info.frostfs.sdk.services.SessionTools;
|
import info.frostfs.sdk.services.SessionTools;
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.SESSION_CREATE_FAILED;
|
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class SessionToolsImpl extends ContextAccessor implements SessionTools {
|
public class SessionToolsImpl extends ContextAccessor implements SessionTools {
|
||||||
|
@ -18,18 +16,11 @@ public class SessionToolsImpl extends ContextAccessor implements SessionTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionToken getOrCreateSession(ClientEnvironment env, CallContext ctx) {
|
public Types.SessionToken getOrCreateSession(SessionToken sessionToken, ClientEnvironment env) {
|
||||||
var token = env.getSessionCache().tryGetValue(env.getSessionKey());
|
if (isNull(sessionToken)) {
|
||||||
|
return env.getFrostFSClient().createSessionInternal(-1);
|
||||||
if (isNull(token)) {
|
|
||||||
token = env.getFrostFSClient().createSession(new PrmSessionCreate(-1), ctx);
|
|
||||||
if (isNull(token)) {
|
|
||||||
throw new FrostFSException(SESSION_CREATE_FAILED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
env.getSessionCache().setValue(env.getSessionKey(), token);
|
return SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
||||||
}
|
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ import static info.frostfs.sdk.services.impl.interceptor.Labels.*;
|
||||||
|
|
||||||
public class ClientMetrics {
|
public class ClientMetrics {
|
||||||
private static final List<String> defaultRequestLabels =
|
private static final List<String> defaultRequestLabels =
|
||||||
Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method");
|
Arrays.asList("grpc_type", "grpc_service", "grpc_method");
|
||||||
|
|
||||||
private static final List<String> defaultResponseLabels =
|
private static final List<String> defaultResponseLabels =
|
||||||
Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method", "code", "grpc_code");
|
Arrays.asList("grpc_type", "grpc_service", "grpc_method", "code", "grpc_code");
|
||||||
|
|
||||||
private static final Counter.Builder rpcStartedBuilder =
|
private static final Counter.Builder rpcStartedBuilder =
|
||||||
Counter.build()
|
Counter.build()
|
||||||
|
@ -113,9 +113,7 @@ public class ClientMetrics {
|
||||||
.observe(latencySec);
|
.observe(latencySec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Knows how to produce {@link ClientMetrics} instances for individual methods. */
|
||||||
* Knows how to produce {@link ClientMetrics} instances for individual methods.
|
|
||||||
*/
|
|
||||||
static class Factory {
|
static class Factory {
|
||||||
private final List<Metadata.Key<String>> labelHeaderKeys;
|
private final List<Metadata.Key<String>> labelHeaderKeys;
|
||||||
private final Counter rpcStarted;
|
private final Counter rpcStarted;
|
||||||
|
@ -157,9 +155,7 @@ public class ClientMetrics {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Creates a {@link ClientMetrics} for the supplied gRPC method. */
|
||||||
* Creates a {@link ClientMetrics} for the supplied gRPC method.
|
|
||||||
*/
|
|
||||||
ClientMetrics createMetricsForMethod(GrpcMethod grpcMethod) {
|
ClientMetrics createMetricsForMethod(GrpcMethod grpcMethod) {
|
||||||
return new ClientMetrics(
|
return new ClientMetrics(
|
||||||
labelHeaderKeys,
|
labelHeaderKeys,
|
||||||
|
|
|
@ -2,21 +2,18 @@ package info.frostfs.sdk.services.impl.interceptor;
|
||||||
|
|
||||||
|
|
||||||
import io.prometheus.client.CollectorRegistry;
|
import io.prometheus.client.CollectorRegistry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
private static final double[] DEFAULT_LATENCY_BUCKETS =
|
private static final double[] DEFAULT_LATENCY_BUCKETS =
|
||||||
new double[]{.001, .005, .01, .05, 0.075, .1, .25, .5, 1, 2, 5, 10};
|
new double[] {.001, .005, .01, .05, 0.075, .1, .25, .5, 1, 2, 5, 10};
|
||||||
|
|
||||||
private final boolean isIncludeLatencyHistograms;
|
private final boolean isIncludeLatencyHistograms;
|
||||||
private final CollectorRegistry collectorRegistry;
|
private final CollectorRegistry collectorRegistry;
|
||||||
private final double[] latencyBuckets;
|
private final double[] latencyBuckets;
|
||||||
private final List<String> labelHeaders;
|
private final List<String> labelHeaders;
|
||||||
private final boolean isAddCodeLabelToHistograms;
|
private final boolean isAddCodeLabelToHistograms;
|
||||||
|
|
||||||
private Configuration(
|
private Configuration(
|
||||||
boolean isIncludeLatencyHistograms,
|
boolean isIncludeLatencyHistograms,
|
||||||
CollectorRegistry collectorRegistry,
|
CollectorRegistry collectorRegistry,
|
||||||
|
@ -31,9 +28,7 @@ public class Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/** Returns a {@link Configuration} for recording all cheap metrics about the rpcs. */
|
||||||
* Returns a {@link Configuration} for recording all cheap metrics about the rpcs.
|
|
||||||
*/
|
|
||||||
public static Configuration cheapMetricsOnly() {
|
public static Configuration cheapMetricsOnly() {
|
||||||
return new Configuration(
|
return new Configuration(
|
||||||
false /* isIncludeLatencyHistograms */,
|
false /* isIncludeLatencyHistograms */,
|
||||||
|
@ -124,37 +119,27 @@ public class Configuration {
|
||||||
true /* isAddCodeLabelToHistograms */);
|
true /* isAddCodeLabelToHistograms */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns whether or not latency histograms for calls should be included. */
|
||||||
* Returns whether or not latency histograms for calls should be included.
|
|
||||||
*/
|
|
||||||
public boolean isIncludeLatencyHistograms() {
|
public boolean isIncludeLatencyHistograms() {
|
||||||
return isIncludeLatencyHistograms;
|
return isIncludeLatencyHistograms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the {@link CollectorRegistry} used to record stats. */
|
||||||
* Returns the {@link CollectorRegistry} used to record stats.
|
|
||||||
*/
|
|
||||||
public CollectorRegistry getCollectorRegistry() {
|
public CollectorRegistry getCollectorRegistry() {
|
||||||
return collectorRegistry;
|
return collectorRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the histogram buckets to use for latency metrics. */
|
||||||
* Returns the histogram buckets to use for latency metrics.
|
|
||||||
*/
|
|
||||||
public double[] getLatencyBuckets() {
|
public double[] getLatencyBuckets() {
|
||||||
return latencyBuckets;
|
return latencyBuckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the configured list of headers to be used as labels. */
|
||||||
* Returns the configured list of headers to be used as labels.
|
|
||||||
*/
|
|
||||||
public List<String> getLabelHeaders() {
|
public List<String> getLabelHeaders() {
|
||||||
return labelHeaders;
|
return labelHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns whether or not status code label should be added to latency histogram. */
|
||||||
* Returns whether or not status code label should be added to latency histogram.
|
|
||||||
*/
|
|
||||||
public boolean isAddCodeLabelToHistograms() {
|
public boolean isAddCodeLabelToHistograms() {
|
||||||
return isAddCodeLabelToHistograms;
|
return isAddCodeLabelToHistograms;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
package info.frostfs.sdk.services.impl.interceptor;
|
package info.frostfs.sdk.services.impl.interceptor;
|
||||||
|
|
||||||
import io.grpc.Channel;
|
|
||||||
import io.grpc.MethodDescriptor;
|
import io.grpc.MethodDescriptor;
|
||||||
import io.grpc.MethodDescriptor.MethodType;
|
import io.grpc.MethodDescriptor.MethodType;
|
||||||
|
|
||||||
public class GrpcMethod {
|
public class GrpcMethod {
|
||||||
private final String targetName;
|
|
||||||
private final String serviceName;
|
private final String serviceName;
|
||||||
private final String methodName;
|
private final String methodName;
|
||||||
private final MethodType type;
|
private final MethodType type;
|
||||||
|
|
||||||
private GrpcMethod(String targetName, String serviceName, String methodName, MethodType type) {
|
private GrpcMethod(String serviceName, String methodName, MethodType type) {
|
||||||
this.targetName = targetName;
|
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GrpcMethod of(MethodDescriptor<?, ?> method, Channel channel) {
|
static GrpcMethod of(MethodDescriptor<?, ?> method) {
|
||||||
String serviceName = MethodDescriptor.extractFullServiceName(method.getFullMethodName());
|
String serviceName = MethodDescriptor.extractFullServiceName(method.getFullMethodName());
|
||||||
|
|
||||||
// Full method names are of the form: "full.serviceName/MethodName". We extract the last part.
|
// Full method names are of the form: "full.serviceName/MethodName". We extract the last part.
|
||||||
String methodName = method.getFullMethodName().substring(serviceName.length() + 1);
|
String methodName = method.getFullMethodName().substring(serviceName.length() + 1);
|
||||||
return new GrpcMethod(channel.authority(), serviceName, methodName, method.getType());
|
return new GrpcMethod(serviceName, methodName, method.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetName() {
|
|
||||||
return targetName;
|
|
||||||
}
|
|
||||||
|
|
||||||
String serviceName() {
|
String serviceName() {
|
||||||
return serviceName;
|
return serviceName;
|
||||||
|
|
|
@ -53,7 +53,6 @@ public class Labels {
|
||||||
*/
|
*/
|
||||||
static <T> T addLabels(SimpleCollector<T> collector, List<String> labels, GrpcMethod method) {
|
static <T> T addLabels(SimpleCollector<T> collector, List<String> labels, GrpcMethod method) {
|
||||||
List<String> allLabels = new ArrayList<>();
|
List<String> allLabels = new ArrayList<>();
|
||||||
allLabels.add(method.targetName());
|
|
||||||
allLabels.add(method.type());
|
allLabels.add(method.type());
|
||||||
allLabels.add(method.serviceName());
|
allLabels.add(method.serviceName());
|
||||||
allLabels.add(method.methodName());
|
allLabels.add(method.methodName());
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package info.frostfs.sdk.services.impl.interceptor;
|
package info.frostfs.sdk.services.impl.interceptor;
|
||||||
|
|
||||||
import io.grpc.*;
|
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
|
import io.grpc.CallOptions;
|
||||||
|
import io.grpc.Channel;
|
||||||
|
import io.grpc.ClientCall;
|
||||||
|
import io.grpc.ClientInterceptor;
|
||||||
|
import io.grpc.MethodDescriptor;
|
||||||
|
|
||||||
|
|
||||||
public class MonitoringClientInterceptor implements ClientInterceptor {
|
public class MonitoringClientInterceptor implements ClientInterceptor {
|
||||||
|
@ -16,7 +19,6 @@ public class MonitoringClientInterceptor implements ClientInterceptor {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.clientMetricsFactory = clientMetricsFactory;
|
this.clientMetricsFactory = clientMetricsFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MonitoringClientInterceptor create(Configuration configuration) {
|
public static MonitoringClientInterceptor create(Configuration configuration) {
|
||||||
return new MonitoringClientInterceptor(
|
return new MonitoringClientInterceptor(
|
||||||
Clock.systemDefaultZone(), configuration, new ClientMetrics.Factory(configuration));
|
Clock.systemDefaultZone(), configuration, new ClientMetrics.Factory(configuration));
|
||||||
|
@ -25,7 +27,7 @@ public class MonitoringClientInterceptor implements ClientInterceptor {
|
||||||
@Override
|
@Override
|
||||||
public <R, S> ClientCall<R, S> interceptCall(
|
public <R, S> ClientCall<R, S> interceptCall(
|
||||||
MethodDescriptor<R, S> methodDescriptor, CallOptions callOptions, Channel channel) {
|
MethodDescriptor<R, S> methodDescriptor, CallOptions callOptions, Channel channel) {
|
||||||
GrpcMethod grpcMethod = GrpcMethod.of(methodDescriptor, channel);
|
GrpcMethod grpcMethod = GrpcMethod.of(methodDescriptor);
|
||||||
ClientMetrics metrics = clientMetricsFactory.createMetricsForMethod(grpcMethod);
|
ClientMetrics metrics = clientMetricsFactory.createMetricsForMethod(grpcMethod);
|
||||||
return new MonitoringClientCall<>(
|
return new MonitoringClientCall<>(
|
||||||
channel.newCall(methodDescriptor, callOptions), metrics, grpcMethod, configuration, clock);
|
channel.newCall(methodDescriptor, callOptions), metrics, grpcMethod, configuration, clock);
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
package info.frostfs.sdk.services.impl.rwhelper;
|
|
||||||
|
|
||||||
import frostfs.object.ObjectServiceGrpc;
|
|
||||||
import frostfs.object.Service;
|
|
||||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
|
||||||
import info.frostfs.sdk.utils.WaitUtil;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_POLL_INTERVAL;
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
public class ObjectStreamer {
|
|
||||||
private final StreamObserver<Service.PutRequest> requestObserver;
|
|
||||||
private final PutResponseCallback responseObserver;
|
|
||||||
|
|
||||||
public ObjectStreamer(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) {
|
|
||||||
PutResponseCallback responseObserver = new PutResponseCallback();
|
|
||||||
|
|
||||||
this.responseObserver = responseObserver;
|
|
||||||
this.requestObserver = objectServiceStub.put(responseObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(Service.PutRequest request) {
|
|
||||||
if (isNull(request)) {
|
|
||||||
throw new ProcessFrostFSException(
|
|
||||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
requestObserver.onNext(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Service.PutResponse complete() {
|
|
||||||
requestObserver.onCompleted();
|
|
||||||
|
|
||||||
while (isNull(responseObserver.getResponse())) {
|
|
||||||
WaitUtil.sleep(DEFAULT_POLL_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseObserver.getResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
|
|
||||||
private Service.PutResponse response;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(Service.PutResponse putResponse) {
|
|
||||||
this.response = putResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable throwable) {
|
|
||||||
throw new ProcessFrostFSException(throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +1,63 @@
|
||||||
package info.frostfs.sdk.services.impl.rwhelper;
|
package info.frostfs.sdk.services.impl.rwhelper;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import frostfs.object.ObjectServiceGrpc;
|
||||||
import frostfs.object.Service;
|
import frostfs.object.Service;
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.utils.WaitUtil;
|
||||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectPutBase;
|
import io.grpc.stub.StreamObserver;
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
//todo specify a deadline for each stream request, not for the entire stream
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ObjectWriter {
|
public class ObjectWriter {
|
||||||
private final ClientEnvironment environment;
|
private static final long POLL_INTERVAL = 10;
|
||||||
private final PrmObjectPutBase args;
|
private final StreamObserver<Service.PutRequest> requestObserver;
|
||||||
private final ObjectStreamer streamer;
|
private final PutResponseCallback responseObserver;
|
||||||
|
|
||||||
public void write(byte[] buffer) {
|
public ObjectWriter(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) {
|
||||||
var body = Service.PutRequest.Body.newBuilder()
|
PutResponseCallback responseObserver = new PutResponseCallback();
|
||||||
.setChunk(ByteString.copyFrom(buffer))
|
|
||||||
.build();
|
|
||||||
var chunkRequest = Service.PutRequest.newBuilder()
|
|
||||||
.setBody(body)
|
|
||||||
.clearVerifyHeader();
|
|
||||||
|
|
||||||
RequestConstructor.addMetaHeader(chunkRequest, args.getXHeaders());
|
this.responseObserver = responseObserver;
|
||||||
sign(chunkRequest, environment.getKey());
|
this.requestObserver = objectServiceStub.put(responseObserver);
|
||||||
|
|
||||||
streamer.write(chunkRequest.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectId complete() {
|
public void write(Service.PutRequest request) {
|
||||||
var response = streamer.complete();
|
if (isNull(request)) {
|
||||||
Verifier.checkResponse(response);
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return new ObjectId(response.getBody().getObjectId().getValue().toByteArray());
|
requestObserver.onNext(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Service.PutResponse complete() {
|
||||||
|
requestObserver.onCompleted();
|
||||||
|
|
||||||
|
while (isNull(responseObserver.getResponse())) {
|
||||||
|
WaitUtil.sleep(POLL_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return responseObserver.getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
|
||||||
|
private Service.PutResponse response;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Service.PutResponse putResponse) {
|
||||||
|
this.response = putResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable throwable) {
|
||||||
|
throw new ProcessFrostFSException(throwable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCompleted() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
package info.frostfs.sdk.services.impl.rwhelper;
|
|
||||||
|
|
||||||
import frostfs.object.ObjectServiceGrpc;
|
|
||||||
import frostfs.object.Service;
|
|
||||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
|
||||||
import info.frostfs.sdk.utils.WaitUtil;
|
|
||||||
import io.grpc.stub.StreamObserver;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_POLL_INTERVAL;
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
public class PatchStreamer {
|
|
||||||
private final StreamObserver<Service.PatchRequest> requestObserver;
|
|
||||||
private final PatchResponseCallback responseObserver;
|
|
||||||
|
|
||||||
public PatchStreamer(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) {
|
|
||||||
PatchResponseCallback responseObserver = new PatchResponseCallback();
|
|
||||||
|
|
||||||
this.responseObserver = responseObserver;
|
|
||||||
this.requestObserver = objectServiceStub.patch(responseObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(Service.PatchRequest request) {
|
|
||||||
if (isNull(request)) {
|
|
||||||
throw new ProcessFrostFSException(
|
|
||||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
requestObserver.onNext(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Service.PatchResponse complete() {
|
|
||||||
requestObserver.onCompleted();
|
|
||||||
|
|
||||||
while (isNull(responseObserver.getResponse())) {
|
|
||||||
WaitUtil.sleep(DEFAULT_POLL_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseObserver.getResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private static class PatchResponseCallback implements StreamObserver<Service.PatchResponse> {
|
|
||||||
private Service.PatchResponse response;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(Service.PatchResponse patchResponse) {
|
|
||||||
this.response = patchResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable throwable) {
|
|
||||||
throw new ProcessFrostFSException(throwable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompleted() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package info.frostfs.sdk.services.impl.rwhelper;
|
|
||||||
|
|
||||||
import frostfs.object.Service;
|
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class RangeReader {
|
|
||||||
public Iterator<Service.GetRangeResponse> call;
|
|
||||||
|
|
||||||
public RangeReader(Iterator<Service.GetRangeResponse> call) {
|
|
||||||
this.call = call;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] readChunk() {
|
|
||||||
if (!call.hasNext()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = call.next();
|
|
||||||
Verifier.checkResponse(response);
|
|
||||||
|
|
||||||
return response.getBody().getChunk().toByteArray();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@ package info.frostfs.sdk.tools;
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientSettings;
|
import info.frostfs.sdk.jdo.ClientSettings;
|
||||||
import info.frostfs.sdk.utils.Validator;
|
import info.frostfs.sdk.utils.Validator;
|
||||||
import io.grpc.ManagedChannel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.netty.NettyChannelBuilder;
|
import io.grpc.netty.NettyChannelBuilder;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -16,7 +16,7 @@ public class GrpcClient {
|
||||||
private GrpcClient() {
|
private GrpcClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ManagedChannel initGrpcChannel(ClientSettings clientSettings) {
|
public static Channel initGrpcChannel(ClientSettings clientSettings) {
|
||||||
Validator.validate(clientSettings);
|
Validator.validate(clientSettings);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -32,15 +32,4 @@ public class GrpcClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ManagedChannel initGrpcChannel(String address) {
|
|
||||||
try {
|
|
||||||
URI uri = new URI(address);
|
|
||||||
return NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext().build();
|
|
||||||
} catch (URISyntaxException exp) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(INVALID_HOST_TEMPLATE, address, exp.getMessage())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,9 @@ import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.response.MetaHeader;
|
import info.frostfs.sdk.dto.response.MetaHeader;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
import info.frostfs.sdk.jdo.ECDsa;
|
||||||
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
||||||
import info.frostfs.sdk.mappers.session.SessionMapper;
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -67,11 +65,13 @@ public class RequestConstructor {
|
||||||
setField(request, META_HEADER_FIELD_NAME, metaHeader.build());
|
setField(request, META_HEADER_FIELD_NAME, metaHeader.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Types.SessionToken createObjectTokenContext(SessionToken sessionToken,
|
public static Types.SessionToken createObjectTokenContext(Types.SessionToken sessionToken,
|
||||||
frostfs.refs.Types.Address address,
|
frostfs.refs.Types.Address address,
|
||||||
Types.ObjectSessionContext.Verb verb,
|
Types.ObjectSessionContext.Verb verb,
|
||||||
ECDsa key) {
|
ECDsa key) {
|
||||||
var protoToken = SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
if (isNull(sessionToken) || sessionToken.getBody().getObject().getTarget().getSerializedSize() > 0) {
|
||||||
|
return sessionToken;
|
||||||
|
}
|
||||||
|
|
||||||
var target = Types.ObjectSessionContext.Target.newBuilder()
|
var target = Types.ObjectSessionContext.Target.newBuilder()
|
||||||
.setContainer(address.getContainerId());
|
.setContainer(address.getContainerId());
|
||||||
|
@ -84,22 +84,25 @@ public class RequestConstructor {
|
||||||
.setTarget(target.build())
|
.setTarget(target.build())
|
||||||
.setVerb(verb)
|
.setVerb(verb)
|
||||||
.build();
|
.build();
|
||||||
var body = protoToken.getBody().toBuilder()
|
var body = sessionToken.getBody().toBuilder()
|
||||||
.setObject(ctx)
|
.setObject(ctx)
|
||||||
|
.setSessionKey(ByteString.copyFrom(key.getPublicKeyByte()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return protoToken.toBuilder()
|
return sessionToken.toBuilder()
|
||||||
.setSignature(signMessagePart(key, body))
|
.setSignature(signMessagePart(key, body))
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Types.SessionToken createContainerTokenContext(SessionToken sessionToken,
|
public static Types.SessionToken createContainerTokenContext(Types.SessionToken sessionToken,
|
||||||
frostfs.refs.Types.ContainerID containerId,
|
frostfs.refs.Types.ContainerID containerId,
|
||||||
Types.ContainerSessionContext.Verb verb,
|
Types.ContainerSessionContext.Verb verb,
|
||||||
frostfs.refs.Types.OwnerID ownerId,
|
frostfs.refs.Types.OwnerID ownerId,
|
||||||
ECDsa key) {
|
ECDsa key) {
|
||||||
var protoToken = SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
if (isNull(sessionToken) || sessionToken.getBody().getContainer().getContainerId().getSerializedSize() > 0) {
|
||||||
|
return sessionToken;
|
||||||
|
}
|
||||||
|
|
||||||
var containerSession = Types.ContainerSessionContext.newBuilder().setVerb(verb);
|
var containerSession = Types.ContainerSessionContext.newBuilder().setVerb(verb);
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ public class RequestConstructor {
|
||||||
containerSession.setContainerId(containerId);
|
containerSession.setContainerId(containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var bodyBuilder = protoToken.getBody().toBuilder()
|
var bodyBuilder = sessionToken.getBody().toBuilder()
|
||||||
.setContainer(containerSession)
|
.setContainer(containerSession)
|
||||||
.setSessionKey(ByteString.copyFrom(key.getPublicKeyByte()));
|
.setSessionKey(ByteString.copyFrom(key.getPublicKeyByte()));
|
||||||
|
|
||||||
|
@ -119,7 +122,7 @@ public class RequestConstructor {
|
||||||
|
|
||||||
var body = bodyBuilder.build();
|
var body = bodyBuilder.build();
|
||||||
|
|
||||||
return protoToken.toBuilder()
|
return sessionToken.toBuilder()
|
||||||
.setSignature(signMessagePart(key, body))
|
.setSignature(signMessagePart(key, body))
|
||||||
.setBody(body)
|
.setBody(body)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -78,10 +78,6 @@ public class Verifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME);
|
var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME);
|
||||||
if (isNull(metaHeader) || metaHeader.getSerializedSize() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var status = ResponseStatusMapper.toModel(metaHeader.getStatus());
|
var status = ResponseStatusMapper.toModel(metaHeader.getStatus());
|
||||||
if (!status.isSuccess()) {
|
if (!status.isSuccess()) {
|
||||||
throw new ResponseFrostFSException(status);
|
throw new ResponseFrostFSException(status);
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package info.frostfs.sdk.tools.ape;
|
|
||||||
|
|
||||||
public interface MarshalFunction<T> {
|
|
||||||
int marshal(byte[] buf, int offset, T t);
|
|
||||||
}
|
|
|
@ -1,198 +0,0 @@
|
||||||
package info.frostfs.sdk.tools.ape;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.ape.*;
|
|
||||||
import info.frostfs.sdk.enums.ConditionKindType;
|
|
||||||
import info.frostfs.sdk.enums.ConditionType;
|
|
||||||
import info.frostfs.sdk.enums.RuleMatchType;
|
|
||||||
import info.frostfs.sdk.enums.RuleStatus;
|
|
||||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.*;
|
|
||||||
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
|
|
||||||
import static info.frostfs.sdk.constants.RuleConst.*;
|
|
||||||
|
|
||||||
public class RuleDeserializer {
|
|
||||||
private RuleDeserializer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Chain deserialize(byte[] data) {
|
|
||||||
if (ArrayUtils.isEmpty(data)) {
|
|
||||||
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
|
||||||
}
|
|
||||||
|
|
||||||
AtomicInteger offset = new AtomicInteger(0);
|
|
||||||
Chain chain = new Chain();
|
|
||||||
|
|
||||||
var version = uInt8Unmarshal(data, offset);
|
|
||||||
if (version != VERSION) {
|
|
||||||
throw new FrostFSException(String.format(UNSUPPORTED_MARSHALLER_VERSION_TEMPLATE, version));
|
|
||||||
}
|
|
||||||
|
|
||||||
var chainVersion = uInt8Unmarshal(data, offset);
|
|
||||||
if (chainVersion != CHAIN_MARSHAL_VERSION) {
|
|
||||||
throw new FrostFSException(String.format(UNSUPPORTED_CHAIN_VERSION_TEMPLATE, chainVersion));
|
|
||||||
}
|
|
||||||
|
|
||||||
chain.setId(sliceUnmarshal(data, offset, Byte.class, RuleDeserializer::uInt8Unmarshal));
|
|
||||||
chain.setRules(sliceUnmarshal(data, offset, Rule.class, RuleDeserializer::unmarshalRule));
|
|
||||||
chain.setMatchType(RuleMatchType.get(uInt8Unmarshal(data, offset)));
|
|
||||||
|
|
||||||
verifyUnmarshal(data, offset);
|
|
||||||
|
|
||||||
return chain;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Byte uInt8Unmarshal(byte[] buf, AtomicInteger offset) {
|
|
||||||
if (buf.length - offset.get() < 1) {
|
|
||||||
throw new FrostFSException(
|
|
||||||
String.format(BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE, Byte.class.getName(), offset.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf[offset.getAndAdd(1)];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long varInt(byte[] buf, AtomicInteger offset) {
|
|
||||||
long ux = uVarInt(buf, offset); // ok to continue in presence of error
|
|
||||||
long x = ux >> 1;
|
|
||||||
if ((ux & 1) != 0) {
|
|
||||||
x = ~x;
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static long uVarInt(byte[] buf, AtomicInteger offset) {
|
|
||||||
long x = 0;
|
|
||||||
int s = 0;
|
|
||||||
|
|
||||||
for (int i = offset.get(); i < buf.length; i++) {
|
|
||||||
long b = buf[i];
|
|
||||||
if (i == MAX_VAR_INT_LENGTH) {
|
|
||||||
offset.set(-(i + 1));
|
|
||||||
return 0; // overflow
|
|
||||||
}
|
|
||||||
if (b >= 0) {
|
|
||||||
if (i == MAX_VAR_INT_LENGTH - 1 && b > 1) {
|
|
||||||
offset.set(-(i + 1));
|
|
||||||
return 0; // overflow
|
|
||||||
}
|
|
||||||
offset.set(i + 1);
|
|
||||||
return x | (b << s);
|
|
||||||
}
|
|
||||||
x |= (b & OFFSET127) << s;
|
|
||||||
s += UNSIGNED_SERIALIZE_SIZE;
|
|
||||||
}
|
|
||||||
offset.set(0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> T[] sliceUnmarshal(byte[] buf,
|
|
||||||
AtomicInteger offset,
|
|
||||||
Class<T> clazz,
|
|
||||||
UnmarshalFunction<T> unmarshalT) {
|
|
||||||
var size = (int) varInt(buf, offset);
|
|
||||||
if (size == NULL_SLICE) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size > MAX_SLICE_LENGTH) {
|
|
||||||
throw new ValidationFrostFSException(String.format(SLICE_IS_TOO_BIG_TEMPLATE, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < 0) {
|
|
||||||
throw new ValidationFrostFSException(String.format(SLICE_SIZE_IS_INVALID_TEMPLATE, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
T[] result = (T[]) Array.newInstance(clazz, size);
|
|
||||||
for (int i = 0; i < result.length; i++) {
|
|
||||||
result[i] = unmarshalT.unmarshal(buf, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean boolUnmarshal(byte[] buf, AtomicInteger offset) {
|
|
||||||
return uInt8Unmarshal(buf, offset) == BYTE_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long int64Unmarshal(byte[] buf, AtomicInteger offset) {
|
|
||||||
if (buf.length - offset.get() < Long.BYTES) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE, Long.class.getName(), offset.get())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return varInt(buf, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String stringUnmarshal(byte[] buf, AtomicInteger offset) {
|
|
||||||
int size = (int) int64Unmarshal(buf, offset);
|
|
||||||
if (size == 0) {
|
|
||||||
return EMPTY_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size > MAX_SLICE_LENGTH) {
|
|
||||||
throw new ValidationFrostFSException(String.format(STRING_IS_TOO_BIG_TEMPLATE, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < 0) {
|
|
||||||
throw new ValidationFrostFSException(String.format(STRING_SIZE_IS_INVALID_TEMPLATE, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buf.length - offset.get() < size) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(BYTES_ARE_OVER_FOR_DESERIALIZE_TEMPLATE, String.class.getName(), offset.get())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new String(buf, offset.getAndAdd(size), size, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Actions unmarshalActions(byte[] buf, AtomicInteger offset) {
|
|
||||||
Actions actions = new Actions();
|
|
||||||
actions.setInverted(boolUnmarshal(buf, offset));
|
|
||||||
actions.setNames(sliceUnmarshal(buf, offset, String.class, RuleDeserializer::stringUnmarshal));
|
|
||||||
return actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Condition unmarshalCondition(byte[] buf, AtomicInteger offset) {
|
|
||||||
Condition condition = new Condition();
|
|
||||||
condition.setOp(ConditionType.get(uInt8Unmarshal(buf, offset)));
|
|
||||||
condition.setKind(ConditionKindType.get(uInt8Unmarshal(buf, offset)));
|
|
||||||
condition.setKey(stringUnmarshal(buf, offset));
|
|
||||||
condition.setValue(stringUnmarshal(buf, offset));
|
|
||||||
|
|
||||||
return condition;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Rule unmarshalRule(byte[] buf, AtomicInteger offset) {
|
|
||||||
Rule rule = new Rule();
|
|
||||||
rule.setStatus(RuleStatus.get(uInt8Unmarshal(buf, offset)));
|
|
||||||
rule.setActions(unmarshalActions(buf, offset));
|
|
||||||
rule.setResources(unmarshalResources(buf, offset));
|
|
||||||
rule.setAny(boolUnmarshal(buf, offset));
|
|
||||||
rule.setConditions(sliceUnmarshal(buf, offset, Condition.class, RuleDeserializer::unmarshalCondition));
|
|
||||||
|
|
||||||
return rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Resources unmarshalResources(byte[] buf, AtomicInteger offset) {
|
|
||||||
Resources resources = new Resources();
|
|
||||||
resources.setInverted(boolUnmarshal(buf, offset));
|
|
||||||
resources.setNames(sliceUnmarshal(buf, offset, String.class, RuleDeserializer::stringUnmarshal));
|
|
||||||
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void verifyUnmarshal(byte[] buf, AtomicInteger offset) {
|
|
||||||
if (buf.length != offset.get()) {
|
|
||||||
throw new ValidationFrostFSException(UNMARSHAL_SIZE_DIFFERS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,260 +0,0 @@
|
||||||
package info.frostfs.sdk.tools.ape;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.ape.*;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.*;
|
|
||||||
import static info.frostfs.sdk.constants.RuleConst.*;
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
import static java.util.Objects.nonNull;
|
|
||||||
|
|
||||||
public class RuleSerializer {
|
|
||||||
private RuleSerializer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] serialize(Chain chain) {
|
|
||||||
if (isNull(chain)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Chain.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
int s = U_INT_8_SIZE // Marshaller version
|
|
||||||
+ U_INT_8_SIZE // Chain version
|
|
||||||
+ sliceSize(chain.getId(), b -> BYTE_SIZE)
|
|
||||||
+ sliceSize(chain.getRules(), RuleSerializer::ruleSize)
|
|
||||||
+ U_INT_8_SIZE; // MatchType
|
|
||||||
|
|
||||||
byte[] buf = new byte[s];
|
|
||||||
|
|
||||||
int offset = uInt8Marshal(buf, 0, VERSION);
|
|
||||||
offset = uInt8Marshal(buf, offset, (byte) CHAIN_MARSHAL_VERSION);
|
|
||||||
offset = sliceMarshal(buf, offset, chain.getId(), RuleSerializer::byteMarshal);
|
|
||||||
offset = sliceMarshal(buf, offset, chain.getRules(), RuleSerializer::marshalRule);
|
|
||||||
offset = uInt8Marshal(buf, offset, (byte) chain.getMatchType().value);
|
|
||||||
|
|
||||||
verifyMarshal(buf, offset);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> int sliceSize(T[] slice, Function<T, Integer> sizeOf) {
|
|
||||||
if (isNull(slice)) {
|
|
||||||
return NULL_SLICE_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assuming int64Size is the size of the slice
|
|
||||||
int size = int64Size(slice.length);
|
|
||||||
for (T v : slice) {
|
|
||||||
size += sizeOf.apply(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* https://cs.opensource.google/go/go/+/master:src/encoding/binary/varint.go;l=92;drc=dac9b9ddbd5160c5f4552410f5f828
|
|
||||||
* 1bd5eed38c
|
|
||||||
*
|
|
||||||
* and
|
|
||||||
*
|
|
||||||
* https://cs.opensource.google/go/go/+/master:src/encoding/binary/varint.go;l=41;drc=dac9b9ddbd5160c5f4552410f5f828
|
|
||||||
* 1bd5eed38c
|
|
||||||
* */
|
|
||||||
private static int int64Size(long value) {
|
|
||||||
long ux = value << 1;
|
|
||||||
if (value < 0) {
|
|
||||||
ux = ~ux;
|
|
||||||
}
|
|
||||||
|
|
||||||
int size = 0;
|
|
||||||
while (ux >= OFFSET128) {
|
|
||||||
size++;
|
|
||||||
ux >>>= UNSIGNED_SERIALIZE_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return size + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int stringSize(String s) {
|
|
||||||
int len = nonNull(s) ? s.length() : 0;
|
|
||||||
return int64Size(len) + len;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int actionsSize(Actions action) {
|
|
||||||
return BOOL_SIZE // Inverted
|
|
||||||
+ (nonNull(action) ? sliceSize(action.getNames(), RuleSerializer::stringSize) : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int resourcesSize(Resources resource) {
|
|
||||||
return BOOL_SIZE // Inverted
|
|
||||||
+ (nonNull(resource) ? sliceSize(resource.getNames(), RuleSerializer::stringSize) : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int conditionSize(Condition condition) {
|
|
||||||
if (isNull(condition)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return BYTE_SIZE // Op
|
|
||||||
+ BYTE_SIZE // Object
|
|
||||||
+ stringSize(condition.getKey())
|
|
||||||
+ stringSize(condition.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int ruleSize(Rule rule) {
|
|
||||||
if (isNull(rule)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return BYTE_SIZE // Status
|
|
||||||
+ actionsSize(rule.getActions())
|
|
||||||
+ resourcesSize(rule.getResources())
|
|
||||||
+ BOOL_SIZE // Any
|
|
||||||
+ sliceSize(rule.getConditions(), RuleSerializer::conditionSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int uInt8Marshal(byte[] buf, int offset, byte value) {
|
|
||||||
if (buf.length - offset < 1) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, Byte.class.getName(), 1)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf[offset] = value;
|
|
||||||
|
|
||||||
return offset + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int byteMarshal(byte[] buf, int offset, byte value) {
|
|
||||||
return uInt8Marshal(buf, offset, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// putVarInt encodes an int64 into buf and returns the number of bytes written.
|
|
||||||
private static int putVarInt(byte[] buf, int offset, long x) {
|
|
||||||
long ux = x << 1;
|
|
||||||
if (x < 0) {
|
|
||||||
ux = ~ux;
|
|
||||||
}
|
|
||||||
|
|
||||||
return putUVarInt(buf, offset, ux);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int putUVarInt(byte[] buf, int offset, long x) {
|
|
||||||
while (x >= OFFSET128) {
|
|
||||||
buf[offset] = (byte) (x | OFFSET128);
|
|
||||||
x >>>= UNSIGNED_SERIALIZE_SIZE;
|
|
||||||
offset++;
|
|
||||||
}
|
|
||||||
buf[offset] = (byte) x;
|
|
||||||
return offset + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int int64Marshal(byte[] buf, int offset, long v) {
|
|
||||||
var size = int64Size(v);
|
|
||||||
if (buf.length - offset < size) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, Long.class.getName(), size)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return putVarInt(buf, offset, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> int sliceMarshal(byte[] buf, int offset, T[] slice, MarshalFunction<T> marshalT) {
|
|
||||||
if (isNull(slice)) {
|
|
||||||
return int64Marshal(buf, offset, NULL_SLICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slice.length > MAX_SLICE_LENGTH) {
|
|
||||||
throw new ValidationFrostFSException(String.format(SLICE_IS_TOO_BIG_TEMPLATE, slice.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = int64Marshal(buf, offset, slice.length);
|
|
||||||
for (T v : slice) {
|
|
||||||
offset = marshalT.marshal(buf, offset, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int boolMarshal(byte[] buf, int offset, boolean value) {
|
|
||||||
return uInt8Marshal(buf, offset, value ? BYTE_TRUE : BYTE_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int stringMarshal(byte[] buf, int offset, String value) {
|
|
||||||
if (StringUtils.isBlank(value)) {
|
|
||||||
throw new ValidationFrostFSException(STRING_IS_BLANK);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.length() > MAX_SLICE_LENGTH) {
|
|
||||||
throw new ValidationFrostFSException(String.format(STRING_IS_TOO_BIG_TEMPLATE, value.length()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buf.length - offset < int64Size(value.length()) + value.length()) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, String.class.getName(), value.length())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = int64Marshal(buf, offset, value.length());
|
|
||||||
if (value.isEmpty()) {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] stringBytes = value.getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
// Copy exactly value.length() bytes as in the original code
|
|
||||||
System.arraycopy(stringBytes, 0, buf, offset, value.length());
|
|
||||||
return offset + value.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int marshalActions(byte[] buf, int offset, Actions action) {
|
|
||||||
if (isNull(action)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Actions.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = boolMarshal(buf, offset, action.isInverted());
|
|
||||||
return sliceMarshal(buf, offset, action.getNames(), RuleSerializer::stringMarshal);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int marshalCondition(byte[] buf, int offset, Condition condition) {
|
|
||||||
if (isNull(condition)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Condition.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = byteMarshal(buf, offset, (byte) condition.getOp().value);
|
|
||||||
offset = byteMarshal(buf, offset, (byte) condition.getKind().value);
|
|
||||||
offset = stringMarshal(buf, offset, condition.getKey());
|
|
||||||
return stringMarshal(buf, offset, condition.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int marshalRule(byte[] buf, int offset, Rule rule) {
|
|
||||||
if (isNull(rule)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = byteMarshal(buf, offset, (byte) rule.getStatus().value);
|
|
||||||
offset = marshalActions(buf, offset, rule.getActions());
|
|
||||||
offset = marshalResources(buf, offset, rule.getResources());
|
|
||||||
offset = boolMarshal(buf, offset, rule.isAny());
|
|
||||||
return sliceMarshal(buf, offset, rule.getConditions(), RuleSerializer::marshalCondition);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int marshalResources(byte[] buf, int offset, Resources resources) {
|
|
||||||
if (isNull(resources)) {
|
|
||||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Resources.class.getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
offset = boolMarshal(buf, offset, resources.isInverted());
|
|
||||||
return sliceMarshal(buf, offset, resources.getNames(), RuleSerializer::stringMarshal);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void verifyMarshal(byte[] buf, int lastOffset) {
|
|
||||||
if (buf.length != lastOffset) {
|
|
||||||
throw new ValidationFrostFSException(MARSHAL_SIZE_DIFFERS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
package info.frostfs.sdk.tools.ape;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public interface UnmarshalFunction<T> {
|
|
||||||
T unmarshal(byte[] buf, AtomicInteger offset);
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
package info.frostfs.sdk.utils;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
|
||||||
import io.grpc.stub.AbstractStub;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE;
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
public class DeadLineUtil {
|
|
||||||
private DeadLineUtil() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T extends AbstractStub<T>> T deadLineAfter(T stub, long deadLine, TimeUnit timeUnit) {
|
|
||||||
if (isNull(stub)) {
|
|
||||||
throw new ValidationFrostFSException(
|
|
||||||
String.format(PARAM_IS_MISSING_TEMPLATE, AbstractStub.class.getName())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
timeUnit = isNull(timeUnit) ? TimeUnit.MILLISECONDS : timeUnit;
|
|
||||||
return deadLine > 0 ? stub.withDeadlineAfter(deadLine, timeUnit) : stub;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package info.frostfs.sdk.utils;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
public class FrostFSMessages {
|
|
||||||
private FrostFSMessages() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sessionCreationError(Logger logger, String address, String error) {
|
|
||||||
logger.warn("Failed to create frostfs session token for client. Address {}, {}", address, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void errorThresholdReached(Logger logger, String address, long threshold) {
|
|
||||||
logger.warn("Error threshold reached. Address {}, threshold {}", address, threshold);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void healthChanged(Logger logger, String address, boolean healthy, String error) {
|
|
||||||
logger.warn("Health has changed: {} healthy {}, reason {}", address, healthy, error);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,9 @@
|
||||||
package info.frostfs.sdk.utils;
|
package info.frostfs.sdk.utils;
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.*;
|
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||||
|
import info.frostfs.sdk.annotations.NotBlank;
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
|
import info.frostfs.sdk.annotations.Validate;
|
||||||
import info.frostfs.sdk.constants.ErrorConst;
|
import info.frostfs.sdk.constants.ErrorConst;
|
||||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
@ -34,10 +37,6 @@ public class Validator {
|
||||||
|
|
||||||
Class<?> clazz = object.getClass();
|
Class<?> clazz = object.getClass();
|
||||||
|
|
||||||
if (clazz.isAnnotationPresent(ComplexAtLeastOneIsFilled.class)) {
|
|
||||||
processComplexAtLeastOneIsFilled(object, clazz, errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clazz.isAnnotationPresent(AtLeastOneIsFilled.class)) {
|
if (clazz.isAnnotationPresent(AtLeastOneIsFilled.class)) {
|
||||||
processAtLeastOneIsFilled(object, clazz, errorMessage);
|
processAtLeastOneIsFilled(object, clazz, errorMessage);
|
||||||
}
|
}
|
||||||
|
@ -84,22 +83,8 @@ public class Validator {
|
||||||
process(getFieldValue(object, field), errorMessage);
|
process(getFieldValue(object, field), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> void processComplexAtLeastOneIsFilled(T object, Class<?> clazz, StringBuilder errorMessage) {
|
|
||||||
var annotation = clazz.getAnnotation(ComplexAtLeastOneIsFilled.class);
|
|
||||||
for (AtLeastOneIsFilled value : annotation.value()) {
|
|
||||||
processAtLeastOneIsFilled(object, clazz, errorMessage, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> void processAtLeastOneIsFilled(T object, Class<?> clazz, StringBuilder errorMessage) {
|
private static <T> void processAtLeastOneIsFilled(T object, Class<?> clazz, StringBuilder errorMessage) {
|
||||||
var annotation = clazz.getAnnotation(AtLeastOneIsFilled.class);
|
var annotation = clazz.getAnnotation(AtLeastOneIsFilled.class);
|
||||||
processAtLeastOneIsFilled(object, clazz, errorMessage, annotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> void processAtLeastOneIsFilled(T object,
|
|
||||||
Class<?> clazz,
|
|
||||||
StringBuilder errorMessage,
|
|
||||||
AtLeastOneIsFilled annotation) {
|
|
||||||
var emptyFieldsCount = 0;
|
var emptyFieldsCount = 0;
|
||||||
for (String fieldName : annotation.fields()) {
|
for (String fieldName : annotation.fields()) {
|
||||||
var field = getField(clazz, fieldName);
|
var field = getField(clazz, fieldName);
|
||||||
|
@ -121,7 +106,6 @@ public class Validator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static <T> Object getFieldValue(T object, Field field) {
|
private static <T> Object getFieldValue(T object, Field field) {
|
||||||
try {
|
try {
|
||||||
return field.get(object);
|
return field.get(object);
|
||||||
|
|
31
client/src/test/java/info/frostfs/sdk/FileUtils.java
Normal file
31
client/src/test/java/info/frostfs/sdk/FileUtils.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
public class FileUtils {
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public static byte[] resourceToBytes(String resourcePath) {
|
||||||
|
if (StringUtils.isBlank(resourcePath)) {
|
||||||
|
throw new IllegalArgumentException("Blank filename!");
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassLoader loader = FileUtils.class.getClassLoader();
|
||||||
|
if (isNull(loader)) {
|
||||||
|
throw new RuntimeException("Class loader is null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream certStream = loader.getResourceAsStream(resourcePath);
|
||||||
|
if (isNull(certStream)) {
|
||||||
|
throw new RuntimeException("Resource could not be found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ByteStreams.toByteArray(certStream);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,103 +0,0 @@
|
||||||
package info.frostfs.sdk.services;
|
|
||||||
|
|
||||||
import frostfs.accounting.AccountingServiceGrpc;
|
|
||||||
import frostfs.accounting.Service;
|
|
||||||
import info.frostfs.sdk.dto.object.OwnerId;
|
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.services.impl.AccountingClientImpl;
|
|
||||||
import info.frostfs.sdk.testgenerator.AccountingGenerator;
|
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
|
||||||
import info.frostfs.sdk.tools.RequestSigner;
|
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
|
||||||
import io.grpc.Channel;
|
|
||||||
import io.neow3j.crypto.Base58;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.junit.platform.commons.util.ReflectionUtils;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockedStatic;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class AccountingClientTest {
|
|
||||||
private static final String OWNER_ID = "NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S";
|
|
||||||
|
|
||||||
private AccountingClientImpl accountingClient;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private AccountingServiceGrpc.AccountingServiceBlockingStub AccountingServiceClient;
|
|
||||||
@Mock
|
|
||||||
private ClientEnvironment clientEnvironment;
|
|
||||||
@Mock
|
|
||||||
private Channel channel;
|
|
||||||
|
|
||||||
private MockedStatic<Verifier> verifierMock;
|
|
||||||
private MockedStatic<RequestConstructor> requestConstructorMock;
|
|
||||||
private MockedStatic<RequestSigner> requestSignerMock;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() throws IllegalAccessException {
|
|
||||||
when(clientEnvironment.getChannel()).thenReturn(channel);
|
|
||||||
when(clientEnvironment.getOwnerId()).thenReturn(new OwnerId(OWNER_ID));
|
|
||||||
|
|
||||||
accountingClient = new AccountingClientImpl(clientEnvironment);
|
|
||||||
|
|
||||||
Field field = ReflectionUtils.findFields(AccountingClientImpl.class,
|
|
||||||
f -> f.getName().equals("serviceBlockingStub"),
|
|
||||||
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
|
|
||||||
.get(0);
|
|
||||||
|
|
||||||
field.setAccessible(true);
|
|
||||||
field.set(accountingClient, AccountingServiceClient);
|
|
||||||
|
|
||||||
verifierMock = Mockito.mockStatic(Verifier.class);
|
|
||||||
requestConstructorMock = Mockito.mockStatic(RequestConstructor.class);
|
|
||||||
requestSignerMock = Mockito.mockStatic(RequestSigner.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void cleanUp() {
|
|
||||||
verifierMock.close();
|
|
||||||
requestConstructorMock.close();
|
|
||||||
requestSignerMock.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getBalance_success() {
|
|
||||||
//Given
|
|
||||||
var response = AccountingGenerator.generateBalanceResponse();
|
|
||||||
|
|
||||||
var captor = ArgumentCaptor.forClass(Service.BalanceRequest.class);
|
|
||||||
|
|
||||||
when(AccountingServiceClient.balance(captor.capture())).thenReturn(response);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var result = accountingClient.getBalance(new CallContext(0, null));
|
|
||||||
|
|
||||||
//Then
|
|
||||||
requestConstructorMock.verify(
|
|
||||||
() -> RequestConstructor.addMetaHeader(any(Service.BalanceRequest.Builder.class)),
|
|
||||||
times(1)
|
|
||||||
);
|
|
||||||
requestSignerMock.verify(
|
|
||||||
() -> RequestSigner.sign(any(Service.BalanceRequest.Builder.class), eq(null)),
|
|
||||||
times(1)
|
|
||||||
);
|
|
||||||
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
|
||||||
|
|
||||||
assertEquals(response.getBody().getBalance(), result);
|
|
||||||
|
|
||||||
var request = captor.getValue();
|
|
||||||
assertEquals(OWNER_ID, Base58.encode(request.getBody().getOwnerId().getValue().toByteArray()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,22 +2,18 @@ package info.frostfs.sdk.services;
|
||||||
|
|
||||||
import frostfs.apemanager.APEManagerServiceGrpc;
|
import frostfs.apemanager.APEManagerServiceGrpc;
|
||||||
import frostfs.apemanager.Service;
|
import frostfs.apemanager.Service;
|
||||||
import info.frostfs.sdk.dto.ape.*;
|
import info.frostfs.sdk.FileUtils;
|
||||||
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
import info.frostfs.sdk.enums.*;
|
import info.frostfs.sdk.enums.TargetType;
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
|
||||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
|
||||||
import info.frostfs.sdk.services.impl.ApeManagerClientImpl;
|
import info.frostfs.sdk.services.impl.ApeManagerClientImpl;
|
||||||
import info.frostfs.sdk.testgenerator.ApeManagerGenerator;
|
import info.frostfs.sdk.testgenerator.ApeManagerGenerator;
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
import info.frostfs.sdk.tools.RequestConstructor;
|
||||||
import info.frostfs.sdk.tools.RequestSigner;
|
import info.frostfs.sdk.tools.RequestSigner;
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -30,8 +26,7 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Base64;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
@ -40,9 +35,6 @@ import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class ApeManagerClientTest {
|
class ApeManagerClientTest {
|
||||||
private static final String CHAIN_BASE64 =
|
|
||||||
"AAAaY2hhaW4taWQtdGVzdAIAAAISR2V0T2JqZWN0AAIebmF0aXZlOm9iamVjdC8qAAIAABREZXBhcnRtZW50BEhSAA==";
|
|
||||||
|
|
||||||
private ApeManagerClientImpl apeManagerClient;
|
private ApeManagerClientImpl apeManagerClient;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -86,7 +78,6 @@ class ApeManagerClientTest {
|
||||||
//Given
|
//Given
|
||||||
Chain chain = generateChain();
|
Chain chain = generateChain();
|
||||||
ChainTarget chainTarget = generateChainTarget();
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
PrmApeChainAdd params = new PrmApeChainAdd(chain, chainTarget);
|
|
||||||
|
|
||||||
var response = ApeManagerGenerator.generateAddChainResponse();
|
var response = ApeManagerGenerator.generateAddChainResponse();
|
||||||
|
|
||||||
|
@ -95,7 +86,7 @@ class ApeManagerClientTest {
|
||||||
when(apeManagerServiceClient.addChain(captor.capture())).thenReturn(response);
|
when(apeManagerServiceClient.addChain(captor.capture())).thenReturn(response);
|
||||||
|
|
||||||
//When
|
//When
|
||||||
var result = apeManagerClient.addChain(params, new CallContext(0, null));
|
var result = apeManagerClient.addChain(chain, chainTarget);
|
||||||
|
|
||||||
//Then
|
//Then
|
||||||
requestConstructorMock.verify(
|
requestConstructorMock.verify(
|
||||||
|
@ -111,9 +102,7 @@ class ApeManagerClientTest {
|
||||||
assertThat(result).containsOnly(response.getBody().getChainId().toByteArray());
|
assertThat(result).containsOnly(response.getBody().getChainId().toByteArray());
|
||||||
|
|
||||||
var request = captor.getValue();
|
var request = captor.getValue();
|
||||||
assertEquals(
|
assertThat(request.getBody().getChain().getRaw().toByteArray()).containsOnly(chain.getRaw());
|
||||||
Base64.getEncoder().encodeToString(request.getBody().getChain().getRaw().toByteArray()), CHAIN_BASE64)
|
|
||||||
;
|
|
||||||
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||||
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||||
}
|
}
|
||||||
|
@ -123,15 +112,11 @@ class ApeManagerClientTest {
|
||||||
//Given
|
//Given
|
||||||
Chain chain = generateChain();
|
Chain chain = generateChain();
|
||||||
ChainTarget chainTarget = generateChainTarget();
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
PrmApeChainAdd params1 = new PrmApeChainAdd(null, chainTarget);
|
|
||||||
PrmApeChainAdd params2 = new PrmApeChainAdd(chain, null);
|
|
||||||
PrmApeChainAdd params3 = new PrmApeChainAdd(null, null);
|
|
||||||
|
|
||||||
|
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params1, new CallContext()));
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(null, chainTarget));
|
||||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params2, new CallContext()));
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(chain, null));
|
||||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params3, new CallContext()));
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -139,7 +124,6 @@ class ApeManagerClientTest {
|
||||||
//Given
|
//Given
|
||||||
Chain chain = generateChain();
|
Chain chain = generateChain();
|
||||||
ChainTarget chainTarget = generateChainTarget();
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
PrmApeChainRemove params = new PrmApeChainRemove(Base64.getDecoder().decode(CHAIN_BASE64), chainTarget);
|
|
||||||
|
|
||||||
var response = ApeManagerGenerator.generateRemoveChainResponse();
|
var response = ApeManagerGenerator.generateRemoveChainResponse();
|
||||||
|
|
||||||
|
@ -148,7 +132,7 @@ class ApeManagerClientTest {
|
||||||
when(apeManagerServiceClient.removeChain(captor.capture())).thenReturn(response);
|
when(apeManagerServiceClient.removeChain(captor.capture())).thenReturn(response);
|
||||||
|
|
||||||
//When
|
//When
|
||||||
apeManagerClient.removeChain(params, new CallContext(0, null));
|
apeManagerClient.removeChain(chain, chainTarget);
|
||||||
|
|
||||||
//Then
|
//Then
|
||||||
requestConstructorMock.verify(
|
requestConstructorMock.verify(
|
||||||
|
@ -162,7 +146,7 @@ class ApeManagerClientTest {
|
||||||
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||||
|
|
||||||
var request = captor.getValue();
|
var request = captor.getValue();
|
||||||
assertThat(request.getBody().getChainId().toByteArray()).containsOnly(Base64.getDecoder().decode(CHAIN_BASE64));
|
assertThat(request.getBody().getChainId().toByteArray()).containsOnly(chain.getRaw());
|
||||||
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||||
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||||
}
|
}
|
||||||
|
@ -172,21 +156,17 @@ class ApeManagerClientTest {
|
||||||
//Given
|
//Given
|
||||||
Chain chain = generateChain();
|
Chain chain = generateChain();
|
||||||
ChainTarget chainTarget = generateChainTarget();
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
PrmApeChainRemove params1 = new PrmApeChainRemove(null, chainTarget);
|
|
||||||
PrmApeChainRemove params2 = new PrmApeChainRemove(Base64.getDecoder().decode(CHAIN_BASE64), null);
|
|
||||||
PrmApeChainRemove params3 = new PrmApeChainRemove(null, null);
|
|
||||||
|
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params1, new CallContext()));
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(null, chainTarget));
|
||||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params2, new CallContext()));
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(chain, null));
|
||||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params3, new CallContext()));
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void listChain_success() {
|
void listChain_success() {
|
||||||
//Given
|
//Given
|
||||||
ChainTarget chainTarget = generateChainTarget();
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
PrmApeChainList params = new PrmApeChainList(chainTarget);
|
|
||||||
|
|
||||||
var response = ApeManagerGenerator.generateListChainsResponse();
|
var response = ApeManagerGenerator.generateListChainsResponse();
|
||||||
|
|
||||||
|
@ -195,7 +175,7 @@ class ApeManagerClientTest {
|
||||||
when(apeManagerServiceClient.listChains(captor.capture())).thenReturn(response);
|
when(apeManagerServiceClient.listChains(captor.capture())).thenReturn(response);
|
||||||
|
|
||||||
//When
|
//When
|
||||||
var result = apeManagerClient.listChains(params, new CallContext(0, null));
|
var result = apeManagerClient.listChains(chainTarget);
|
||||||
|
|
||||||
//Then
|
//Then
|
||||||
requestConstructorMock.verify(
|
requestConstructorMock.verify(
|
||||||
|
@ -208,7 +188,11 @@ class ApeManagerClientTest {
|
||||||
);
|
);
|
||||||
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||||
|
|
||||||
assertThat(result).hasSize(10);
|
var actual = result.stream().map(Chain::getRaw).collect(Collectors.toList());
|
||||||
|
var expected = response.getBody().getChainsList().stream()
|
||||||
|
.map(chain -> chain.getRaw().toByteArray())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
assertThat(actual).hasSize(10).containsAll(expected);
|
||||||
|
|
||||||
var request = captor.getValue();
|
var request = captor.getValue();
|
||||||
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||||
|
@ -218,29 +202,12 @@ class ApeManagerClientTest {
|
||||||
@Test
|
@Test
|
||||||
void listChain_wrongParams() {
|
void listChain_wrongParams() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(ValidationFrostFSException.class,
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.listChains(null));
|
||||||
() -> apeManagerClient.listChains(new PrmApeChainList(null), new CallContext()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chain generateChain() {
|
private Chain generateChain() {
|
||||||
var resources = new Resources(false, new String[]{"native:object/*"});
|
byte[] chainRaw = FileUtils.resourceToBytes("test_chain_raw.json");
|
||||||
var actions = new Actions(false, new String[]{"GetObject"});
|
return new Chain(chainRaw);
|
||||||
var condition = new Condition(
|
|
||||||
ConditionType.COND_STRING_EQUALS, ConditionKindType.RESOURCE, "Department", "HR"
|
|
||||||
);
|
|
||||||
|
|
||||||
var rule = new Rule();
|
|
||||||
rule.setStatus(RuleStatus.ALLOW);
|
|
||||||
rule.setResources(resources);
|
|
||||||
rule.setActions(actions);
|
|
||||||
rule.setAny(false);
|
|
||||||
rule.setConditions(new Condition[]{condition});
|
|
||||||
|
|
||||||
var chain = new Chain();
|
|
||||||
chain.setId(ArrayUtils.toObject("chain-id-test".getBytes(StandardCharsets.UTF_8)));
|
|
||||||
chain.setRules(new Rule[]{rule});
|
|
||||||
chain.setMatchType(RuleMatchType.DENY_PRIORITY);
|
|
||||||
return chain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChainTarget generateChainTarget() {
|
private ChainTarget generateChainTarget() {
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
package info.frostfs.sdk.testgenerator;
|
|
||||||
|
|
||||||
import frostfs.accounting.Service;
|
|
||||||
import frostfs.accounting.Types;
|
|
||||||
|
|
||||||
public class AccountingGenerator {
|
|
||||||
|
|
||||||
public static Service.BalanceRequest generateBalanceRequest() {
|
|
||||||
return Service.BalanceRequest.newBuilder()
|
|
||||||
.setBody(generateBalanceRequestBody())
|
|
||||||
.setMetaHeader(SessionGenerator.generateRequestMetaHeader())
|
|
||||||
.setVerifyHeader(SessionGenerator.generateRequestVerificationHeader())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Service.BalanceRequest.Body generateBalanceRequestBody() {
|
|
||||||
return Service.BalanceRequest.Body.newBuilder()
|
|
||||||
.setOwnerId(RefsGenerator.generateOwnerID())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Service.BalanceResponse generateBalanceResponse() {
|
|
||||||
return Service.BalanceResponse.newBuilder()
|
|
||||||
.setBody(generateBalanceResponseBody())
|
|
||||||
.setMetaHeader(SessionGenerator.generateResponseMetaHeader())
|
|
||||||
.setVerifyHeader(SessionGenerator.generateResponseVerificationHeader())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Service.BalanceResponse.Body generateBalanceResponseBody() {
|
|
||||||
return Service.BalanceResponse.Body.newBuilder()
|
|
||||||
.setBalance(generateDecimal())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Types.Decimal generateDecimal() {
|
|
||||||
return Types.Decimal.newBuilder()
|
|
||||||
.setValue(1)
|
|
||||||
.setPrecision(2)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,21 +3,22 @@ package info.frostfs.sdk.testgenerator;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import frostfs.ape.Types;
|
import frostfs.ape.Types;
|
||||||
import frostfs.apemanager.Service;
|
import frostfs.apemanager.Service;
|
||||||
|
import info.frostfs.sdk.FileUtils;
|
||||||
import info.frostfs.sdk.Helper;
|
import info.frostfs.sdk.Helper;
|
||||||
import org.bouncycastle.util.encoders.Base64;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ApeManagerGenerator {
|
public class ApeManagerGenerator {
|
||||||
private static final String BASE64_CHAIN = "AAAaY2hhaW4taWQtdGVzdAIAAAICKgACHm5hdGl2ZTpvYmplY3QvKgAAAA==";
|
|
||||||
|
|
||||||
private static ByteString generateChainID() {
|
private static ByteString generateChainID() {
|
||||||
return ByteString.copyFrom(Helper.getByteArrayFromHex("616c6c6f774f626a476574436e72"));
|
return ByteString.copyFrom(Helper.getByteArrayFromHex("616c6c6f774f626a476574436e72"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Types.Chain generateRawChain() {
|
private static Types.Chain generateRawChain() {
|
||||||
|
byte[] chainRaw = FileUtils.resourceToBytes("test_chain_raw.json");
|
||||||
|
|
||||||
return Types.Chain.newBuilder()
|
return Types.Chain.newBuilder()
|
||||||
.setRaw(ByteString.copyFrom(Base64.decode(BASE64_CHAIN)))
|
.setRaw(ByteString.copyFrom(chainRaw))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,179 +0,0 @@
|
||||||
package info.frostfs.sdk.tools.ape;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.ape.*;
|
|
||||||
import info.frostfs.sdk.enums.ConditionKindType;
|
|
||||||
import info.frostfs.sdk.enums.ConditionType;
|
|
||||||
import info.frostfs.sdk.enums.RuleMatchType;
|
|
||||||
import info.frostfs.sdk.enums.RuleStatus;
|
|
||||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.bouncycastle.util.encoders.Base64;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
public class ApeRuleTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void apeRuleTest() {
|
|
||||||
//Given
|
|
||||||
var resources = new Resources(false, new String[]{"native:object/*"});
|
|
||||||
var actions = new Actions(false, new String[]{"*"});
|
|
||||||
var rule = new Rule();
|
|
||||||
rule.setStatus(RuleStatus.ALLOW);
|
|
||||||
rule.setResources(resources);
|
|
||||||
rule.setActions(actions);
|
|
||||||
rule.setAny(false);
|
|
||||||
rule.setConditions(new Condition[]{});
|
|
||||||
|
|
||||||
|
|
||||||
var chain = new Chain();
|
|
||||||
chain.setId(ArrayUtils.toObject("chain-id-test".getBytes(StandardCharsets.UTF_8)));
|
|
||||||
chain.setRules(new Rule[]{rule});
|
|
||||||
chain.setMatchType(RuleMatchType.DENY_PRIORITY);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var serialized = RuleSerializer.serialize(chain);
|
|
||||||
var t = Base64.encode(serialized);
|
|
||||||
var restoredChain = RuleDeserializer.deserialize(serialized);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
assertThat(restoredChain.getId()).isNotEmpty().containsOnly(chain.getId());
|
|
||||||
assertEquals(chain.getMatchType(), restoredChain.getMatchType());
|
|
||||||
compareRules(chain.getRules(), restoredChain.getRules());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void apeRuleTest2() {
|
|
||||||
//Given
|
|
||||||
var resources = new Resources(true, new String[]{"native:object/*", "U.S.S. ENTERPRISE"});
|
|
||||||
var actions = new Actions(true, new String[]{"put", "get"});
|
|
||||||
var cond1 = new Condition(
|
|
||||||
ConditionType.COND_STRING_EQUALS, ConditionKindType.RESOURCE, "key1", "value1"
|
|
||||||
);
|
|
||||||
var cond2 = new Condition(
|
|
||||||
ConditionType.COND_NUMERIC_GREATER_THAN, ConditionKindType.REQUEST, "key2", "value2"
|
|
||||||
);
|
|
||||||
var rule = new Rule();
|
|
||||||
rule.setStatus(RuleStatus.ACCESS_DENIED);
|
|
||||||
rule.setResources(resources);
|
|
||||||
rule.setActions(actions);
|
|
||||||
rule.setAny(true);
|
|
||||||
rule.setConditions(new Condition[]{cond1, cond2});
|
|
||||||
|
|
||||||
|
|
||||||
var chain = new Chain();
|
|
||||||
chain.setId(ArrayUtils.toObject("dumptext".getBytes(StandardCharsets.UTF_8)));
|
|
||||||
chain.setRules(new Rule[]{rule});
|
|
||||||
chain.setMatchType(RuleMatchType.FIRST_MATCH);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var serialized = RuleSerializer.serialize(chain);
|
|
||||||
var restoredChain = RuleDeserializer.deserialize(serialized);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
assertThat(restoredChain.getId()).isNotEmpty().containsOnly(chain.getId());
|
|
||||||
assertEquals(chain.getMatchType(), restoredChain.getMatchType());
|
|
||||||
compareRules(chain.getRules(), restoredChain.getRules());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void apeRuleTest3() {
|
|
||||||
//Given
|
|
||||||
var chain = new Chain();
|
|
||||||
chain.setMatchType(RuleMatchType.DENY_PRIORITY);
|
|
||||||
|
|
||||||
//When
|
|
||||||
var serialized = RuleSerializer.serialize(chain);
|
|
||||||
var restoredChain = RuleDeserializer.deserialize(serialized);
|
|
||||||
|
|
||||||
//Then
|
|
||||||
assertNull(restoredChain.getId());
|
|
||||||
assertEquals(chain.getMatchType(), restoredChain.getMatchType());
|
|
||||||
assertNull(restoredChain.getRules());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void apeRule_deserialize_wrong() {
|
|
||||||
//When + Then
|
|
||||||
assertThrows(ValidationFrostFSException.class, () -> RuleDeserializer.deserialize(null));
|
|
||||||
assertThrows(ValidationFrostFSException.class, () -> RuleDeserializer.deserialize(new byte[]{}));
|
|
||||||
assertThrows(FrostFSException.class, () -> RuleDeserializer.deserialize(new byte[]{1, 2, 3}));
|
|
||||||
assertThrows(ValidationFrostFSException.class, () -> RuleDeserializer.deserialize(new byte[]{
|
|
||||||
0x00, 0x00, 0x3A, 0x77, 0x73, 0x3A, 0x69, 0x61, 0x6D, 0x3A, 0x3A, 0x6E, 0x61, 0x6D, 0x65, 0x73,
|
|
||||||
0x70, 0x61, 0x63, 0x65, 0x3A, 0x67, 0x72, 0x6F, 0x75, 0x70, 0x2F, 0x73, 0x6F, (byte) 0x82, (byte) 0x82,
|
|
||||||
(byte) 0x82, (byte) 0x82, (byte) 0x82, (byte) 0x82, 0x75, (byte) 0x82
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void apeRule_serialize_wrong() {
|
|
||||||
//When + Then
|
|
||||||
assertThrows(ValidationFrostFSException.class, () -> RuleSerializer.serialize(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void compareRules(Rule[] rules1, Rule[] rules2) {
|
|
||||||
assertThat(rules1).isNotEmpty();
|
|
||||||
assertThat(rules2).isNotEmpty();
|
|
||||||
|
|
||||||
assertEquals(rules1.length, rules2.length);
|
|
||||||
|
|
||||||
for (int ri = 0; ri < rules1.length; ri++) {
|
|
||||||
var rule1 = rules1[ri];
|
|
||||||
var rule2 = rules2[ri];
|
|
||||||
|
|
||||||
assertEquals(rule1.getStatus(), rule2.getStatus());
|
|
||||||
assertEquals(rule1.isAny(), rule2.isAny());
|
|
||||||
|
|
||||||
compareActions(rule1.getActions(), rule2.getActions());
|
|
||||||
compareResources(rule1.getResources(), rule2.getResources());
|
|
||||||
compareConditions(rule1.getConditions(), rule2.getConditions());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void compareActions(Actions actions1, Actions actions2) {
|
|
||||||
if (isNull(actions1) && isNull(actions2)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(actions1.isInverted(), actions2.isInverted());
|
|
||||||
if (ArrayUtils.isEmpty(actions1.getNames()) && ArrayUtils.isEmpty(actions2.getNames())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThat(actions2.getNames()).hasSize(actions1.getNames().length).containsOnly(actions1.getNames());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void compareResources(Resources resources1, Resources resources2) {
|
|
||||||
if (isNull(resources1) && isNull(resources2)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(resources1.isInverted(), resources2.isInverted());
|
|
||||||
if (ArrayUtils.isEmpty(resources1.getNames()) && ArrayUtils.isEmpty(resources2.getNames())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThat(resources2.getNames()).hasSize(resources1.getNames().length).containsOnly(resources1.getNames());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void compareConditions(Condition[] conditions1, Condition[] conditions2) {
|
|
||||||
if (ArrayUtils.isEmpty(conditions1) && ArrayUtils.isEmpty(conditions2)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals(conditions1.length, conditions2.length);
|
|
||||||
for (int i = 0; i < conditions1.length; i++) {
|
|
||||||
assertEquals(conditions1[i].getOp(), conditions2[i].getOp());
|
|
||||||
assertEquals(conditions1[i].getKind(), conditions2[i].getKind());
|
|
||||||
assertEquals(conditions1[i].getKey(), conditions2[i].getKey());
|
|
||||||
assertEquals(conditions1[i].getValue(), conditions2[i].getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
30
client/src/test/resources/test_chain_raw.json
Normal file
30
client/src/test/resources/test_chain_raw.json
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"ID": "",
|
||||||
|
"Rules": [
|
||||||
|
{
|
||||||
|
"Status": "Allow",
|
||||||
|
"Actions": {
|
||||||
|
"Inverted": false,
|
||||||
|
"Names": [
|
||||||
|
"GetObject"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Resources": {
|
||||||
|
"Inverted": false,
|
||||||
|
"Names": [
|
||||||
|
"native:object/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Any": false,
|
||||||
|
"Condition": [
|
||||||
|
{
|
||||||
|
"Op": "StringEquals",
|
||||||
|
"Object": "Resource",
|
||||||
|
"Key": "Department",
|
||||||
|
"Value": "HR"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"MatchType": "DenyPriority"
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue