forked from TrueCloudLab/frostfs-sdk-java
Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
|
e9e9480701 | ||
3c3ed76727 | |||
|
73d5e6d72d | ||
|
aa3cff5a03 | ||
|
80c7ba58b2 | ||
694bb963e4 | |||
64e275713f | |||
3be4e87bc1 |
104 changed files with 3216 additions and 373 deletions
12
.forgejo/workflows/verify-code.yaml
Normal file
12
.forgejo/workflows/verify-code.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
name: Verify code phase
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
verify-code:
|
||||||
|
name: Verify code
|
||||||
|
runs-on: docker
|
||||||
|
container: git.frostfs.info/truecloudlab/env:openjdk-11-maven-3.8.6
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Run the Maven verify phase
|
||||||
|
run: mvn --batch-mode --update-snapshots verify
|
3
CODEOWNERS
Normal file
3
CODEOWNERS
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.* @orikik
|
||||||
|
.forgejo/.* @potyarkin
|
||||||
|
Makefile @potyarkin
|
|
@ -10,6 +10,7 @@
|
||||||
<module name="FileTabCharacter">
|
<module name="FileTabCharacter">
|
||||||
<property name="eachLine" value="true"/>
|
<property name="eachLine" value="true"/>
|
||||||
</module>
|
</module>
|
||||||
|
<module name="NewlineAtEndOfFile"/>
|
||||||
|
|
||||||
<!-- Checks for Size Violations. -->
|
<!-- Checks for Size Violations. -->
|
||||||
<!-- See http://checkstyle.sf.net/config_sizes.html -->
|
<!-- See http://checkstyle.sf.net/config_sizes.html -->
|
||||||
|
@ -20,6 +21,15 @@
|
||||||
<module name="TreeWalker">
|
<module name="TreeWalker">
|
||||||
<property name="tabWidth" value="4"/>
|
<property name="tabWidth" value="4"/>
|
||||||
|
|
||||||
|
<module name="Regexp">
|
||||||
|
<property name="message" value="Blank line at end of the block is not allowed"/>
|
||||||
|
<property name="format" value="^\s*$^\s*\}"/>
|
||||||
|
<property name="ignoreComments" value="true"/>
|
||||||
|
<property name="illegalPattern" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="HideUtilityClassConstructor" />
|
||||||
|
|
||||||
<module name="SuppressWarningsHolder" />
|
<module name="SuppressWarningsHolder" />
|
||||||
|
|
||||||
<!-- Checks for Naming Conventions. -->
|
<!-- Checks for Naming Conventions. -->
|
||||||
|
|
|
@ -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>0.1.0</version>
|
<version>0.2.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>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>models</artifactId>
|
<artifactId>models</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>exceptions</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
|
@ -54,5 +54,10 @@
|
||||||
<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,6 +1,8 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
import frostfs.session.Types;
|
import frostfs.accounting.Types;
|
||||||
|
import info.frostfs.sdk.dto.chain.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;
|
||||||
|
@ -16,13 +18,16 @@ import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.ClientSettings;
|
import info.frostfs.sdk.jdo.ClientSettings;
|
||||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
import info.frostfs.sdk.services.*;
|
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.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 java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -30,36 +35,61 @@ 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 ContainerClient, ObjectClient, NetmapClient, SessionClient, ToolsClient {
|
public class FrostFSClient implements CommonClient {
|
||||||
|
private static final MonitoringClientInterceptor MONITORING_CLIENT_INTERCEPTOR =
|
||||||
|
MonitoringClientInterceptor.create(Configuration.allMetrics());
|
||||||
|
|
||||||
private final ContainerClientImpl containerClientImpl;
|
private final ContainerClientImpl containerClientImpl;
|
||||||
private final NetmapClientImpl netmapClientImpl;
|
|
||||||
private final ObjectClientImpl objectClientImpl;
|
private final ObjectClientImpl objectClientImpl;
|
||||||
|
private final ApeManagerClientImpl apeManagerClient;
|
||||||
|
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);
|
||||||
Channel channel = nonNull(clientSettings.getChannel())
|
this.channel = nonNull(clientSettings.getChannel())
|
||||||
? clientSettings.getChannel()
|
? clientSettings.getChannel()
|
||||||
: initGrpcChannel(clientSettings);
|
: initGrpcChannel(clientSettings);
|
||||||
|
|
||||||
MonitoringClientInterceptor monitoringClientInterceptor = MonitoringClientInterceptor
|
Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR);
|
||||||
.create(Configuration.allMetrics());
|
|
||||||
channel = ClientInterceptors.intercept(channel, monitoringClientInterceptor);
|
|
||||||
ClientEnvironment clientEnvironment =
|
ClientEnvironment clientEnvironment =
|
||||||
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
|
new ClientEnvironment(clientSettings.getKey(), interceptChannel, new Version(), this);
|
||||||
|
|
||||||
Validator.validate(clientEnvironment);
|
Validator.validate(clientEnvironment);
|
||||||
|
|
||||||
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
||||||
|
this.objectClientImpl = new ObjectClientImpl(clientEnvironment);
|
||||||
|
this.apeManagerClient = new ApeManagerClientImpl(clientEnvironment);
|
||||||
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
||||||
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
||||||
this.objectClientImpl = new ObjectClientImpl(clientEnvironment);
|
|
||||||
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
||||||
checkFrostFsVersionSupport(clientEnvironment.getVersion());
|
this.accountingClient = new AccountingClientImpl(clientEnvironment);
|
||||||
|
checkFrostFSVersionSupport(clientEnvironment.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkFrostFsVersionSupport(Version version) {
|
public FrostFSClient(WrapperPrm prm, SessionCache cache) {
|
||||||
|
this.channel = initGrpcChannel(prm.getAddress());
|
||||||
|
|
||||||
|
Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR);
|
||||||
|
ClientEnvironment clientEnvironment =
|
||||||
|
new ClientEnvironment(prm.getKey(), interceptChannel, new Version(), this);
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkFrostFSVersionSupport(Version version) {
|
||||||
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
||||||
if (!localNodeInfo.getVersion().isSupported(version)) {
|
if (!localNodeInfo.getVersion().isSupported(version)) {
|
||||||
throw new ProcessFrostFSException(
|
throw new ProcessFrostFSException(
|
||||||
|
@ -118,6 +148,21 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
||||||
return objectClientImpl.searchObjects(cid, filters);
|
return objectClientImpl.searchObjects(cid, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] addChain(Chain chain, ChainTarget chainTarget) {
|
||||||
|
return apeManagerClient.addChain(chain, chainTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeChain(Chain chain, ChainTarget chainTarget) {
|
||||||
|
apeManagerClient.removeChain(chain, chainTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||||
|
return apeManagerClient.listChains(chainTarget);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetmapSnapshot getNetmapSnapshot() {
|
public NetmapSnapshot getNetmapSnapshot() {
|
||||||
return netmapClientImpl.getNetmapSnapshot();
|
return netmapClientImpl.getNetmapSnapshot();
|
||||||
|
@ -138,7 +183,7 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
||||||
return sessionClientImpl.createSession(expiration);
|
return sessionClientImpl.createSession(expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Types.SessionToken createSessionInternal(long expiration) {
|
public frostfs.session.Types.SessionToken createSessionInternal(long expiration) {
|
||||||
return sessionClientImpl.createSessionInternal(expiration);
|
return sessionClientImpl.createSessionInternal(expiration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,4 +191,18 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
||||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||||
return objectToolsImpl.calculateObjectId(header);
|
return objectToolsImpl.calculateObjectId(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Types.Decimal getBalance() {
|
||||||
|
return accountingClient.getBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dial() {
|
||||||
|
accountingClient.getBalance();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
channel.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
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() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
29
client/src/main/java/info/frostfs/sdk/enums/MethodIndex.java
Normal file
29
client/src/main/java/info/frostfs/sdk/enums/MethodIndex.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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 RuntimeException {
|
public class ResponseFrostFSException extends FrostFSException {
|
||||||
private final ResponseStatus status;
|
private final ResponseStatus status;
|
||||||
|
|
||||||
public ResponseFrostFSException(ResponseStatus status) {
|
public ResponseFrostFSException(ResponseStatus status) {
|
||||||
|
|
|
@ -38,4 +38,12 @@ public class ClientEnvironment {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.frostFSClient = frostFSClient;
|
this.frostFSClient = frostFSClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientEnvironment(ECDsa key, Channel channel, Version version, FrostFSClient frostFSClient) {
|
||||||
|
this.key = key;
|
||||||
|
this.ownerId = new OwnerId(key.getPublicKeyByte());
|
||||||
|
this.version = version;
|
||||||
|
this.channel = channel;
|
||||||
|
this.frostFSClient = frostFSClient;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||||
import info.frostfs.sdk.annotations.NotNull;
|
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;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public class ClientSettings {
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private ChannelCredentials credentials;
|
private ChannelCredentials credentials;
|
||||||
private Channel channel;
|
private ManagedChannel channel;
|
||||||
|
|
||||||
public ClientSettings(String key, String host) {
|
public ClientSettings(String key, String host) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
@ -30,7 +30,7 @@ public class ClientSettings {
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientSettings(String key, Channel channel) {
|
public ClientSettings(String key, ManagedChannel channel) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -16,7 +16,7 @@ public class PutObjectParameters {
|
||||||
private ObjectHeader header;
|
private ObjectHeader header;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private FileInputStream payload;
|
private InputStream payload;
|
||||||
|
|
||||||
private boolean clientCut;
|
private boolean clientCut;
|
||||||
private int bufferMaxSize;
|
private int bufferMaxSize;
|
||||||
|
@ -26,14 +26,14 @@ public class PutObjectParameters {
|
||||||
private long currentStreamPosition;
|
private long currentStreamPosition;
|
||||||
private long fullLength;
|
private long fullLength;
|
||||||
|
|
||||||
public PutObjectParameters(ObjectHeader header, FileInputStream payload, boolean clientCut, int bufferMaxSize) {
|
public PutObjectParameters(ObjectHeader header, InputStream payload, boolean clientCut, int bufferMaxSize) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
this.clientCut = clientCut;
|
this.clientCut = clientCut;
|
||||||
this.bufferMaxSize = bufferMaxSize;
|
this.bufferMaxSize = bufferMaxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutObjectParameters(ObjectHeader header, FileInputStream payload) {
|
public PutObjectParameters(ObjectHeader header, InputStream payload) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
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<>();
|
||||||
|
}
|
||||||
|
|
27
client/src/main/java/info/frostfs/sdk/pool/ClientStatus.java
Normal file
27
client/src/main/java/info/frostfs/sdk/pool/ClientStatus.java
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
130
client/src/main/java/info/frostfs/sdk/pool/ClientWrapper.java
Normal file
130
client/src/main/java/info/frostfs/sdk/pool/ClientWrapper.java
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
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.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() {
|
||||||
|
FrostFSClient client = getClient();
|
||||||
|
if (client == null) {
|
||||||
|
throw new ValidationFrostFSException(POOL_CLIENT_UNHEALTHY);
|
||||||
|
}
|
||||||
|
client.dial();
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
||||||
|
try {
|
||||||
|
client.getLocalNodeInfo();
|
||||||
|
return CompletableFuture.completedFuture(false);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDialed()) {
|
||||||
|
scheduleGracefulClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return CompletableFuture.completedFuture(restartClient());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean restartClient() {
|
||||||
|
FrostFSClient newClient = null;
|
||||||
|
try {
|
||||||
|
newClient = new FrostFSClient(wrapperPrm, sessionCache);
|
||||||
|
|
||||||
|
var error = newClient.dial();
|
||||||
|
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();
|
||||||
|
} catch (Exception exp) {
|
||||||
|
setUnhealthy();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
setHealthy();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incRequests(long elapsed, MethodIndex method) {
|
||||||
|
var methodStat = getMethods()[method.ordinal()];
|
||||||
|
methodStat.incRequests(elapsed);
|
||||||
|
}
|
||||||
|
}
|
54
client/src/main/java/info/frostfs/sdk/pool/InnerPool.java
Normal file
54
client/src/main/java/info/frostfs/sdk/pool/InnerPool.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
31
client/src/main/java/info/frostfs/sdk/pool/MethodStatus.java
Normal file
31
client/src/main/java/info/frostfs/sdk/pool/MethodStatus.java
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
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;
|
||||||
|
}
|
19
client/src/main/java/info/frostfs/sdk/pool/NodesParam.java
Normal file
19
client/src/main/java/info/frostfs/sdk/pool/NodesParam.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
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<>();
|
||||||
|
}
|
||||||
|
}
|
520
client/src/main/java/info/frostfs/sdk/pool/Pool.java
Normal file
520
client/src/main/java/info/frostfs/sdk/pool/Pool.java
Normal file
|
@ -0,0 +1,520 @@
|
||||||
|
package info.frostfs.sdk.pool;
|
||||||
|
|
||||||
|
import frostfs.refs.Types;
|
||||||
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
|
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.*;
|
||||||
|
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.PutObjectParameters;
|
||||||
|
import info.frostfs.sdk.jdo.pool.NodeParameters;
|
||||||
|
import info.frostfs.sdk.jdo.pool.PoolInitParameters;
|
||||||
|
import info.frostfs.sdk.services.CommonClient;
|
||||||
|
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(ClientWrapper cw, long duration) {
|
||||||
|
var client = cw.getClient();
|
||||||
|
NetworkSettings networkInfo = client.getNetworkSettings();
|
||||||
|
|
||||||
|
long epoch = networkInfo.getEpochDuration();
|
||||||
|
long exp = (Long.MAX_VALUE - epoch < duration) ? Long.MAX_VALUE : (epoch + duration);
|
||||||
|
|
||||||
|
return client.createSession(exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String formCacheKey(String address, String key) {
|
||||||
|
return address + key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String dial() {
|
||||||
|
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();
|
||||||
|
dialed = true;
|
||||||
|
|
||||||
|
SessionToken token = initSessionForDuration(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();
|
||||||
|
|
||||||
|
this.maxObjectSize = networkSettings.getMaxObjectSize();
|
||||||
|
startRebalance();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
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(buffers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNodesHealth(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(finalI, bufferWeights));
|
||||||
|
}
|
||||||
|
|
||||||
|
CompletableFuture.allOf(tasks).join();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateInnerNodesHealth(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().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(ContainerId cid) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getContainer(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ContainerId> listContainers() {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().listContainers();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContainerId createContainer(Container container) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().createContainer(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteContainer(ContainerId cid) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
client.getClient().deleteContainer(cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getObjectHead(containerId, objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getObject(containerId, objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectId putObject(PutObjectParameters parameters) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().putObject(parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectId putSingleObject(ObjectFrostFS objectFrostFS) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().putSingleObject(objectFrostFS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteObject(ContainerId containerId, ObjectId objectId) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
client.getClient().deleteObject(containerId, objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().searchObjects(cid, filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] addChain(Chain chain, ChainTarget chainTarget) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().addChain(chain, chainTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeChain(Chain chain, ChainTarget chainTarget) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
client.getClient().removeChain(chain, chainTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().listChains(chainTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetmapSnapshot getNetmapSnapshot() {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getNetmapSnapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NodeInfo getLocalNodeInfo() {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getLocalNodeInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkSettings getNetworkSettings() {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getNetworkSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SessionToken createSession(long expiration) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().createSession(expiration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public frostfs.session.Types.SessionToken createSessionInternal(long expiration) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().createSessionInternal(expiration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().calculateObjectId(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public frostfs.accounting.Types.Decimal getBalance() {
|
||||||
|
ClientWrapper client = connection();
|
||||||
|
return client.getClient().getBalance();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
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;
|
||||||
|
}
|
15
client/src/main/java/info/frostfs/sdk/pool/RequestInfo.java
Normal file
15
client/src/main/java/info/frostfs/sdk/pool/RequestInfo.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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;
|
||||||
|
}
|
77
client/src/main/java/info/frostfs/sdk/pool/Sampler.java
Normal file
77
client/src/main/java/info/frostfs/sdk/pool/Sampler.java
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
46
client/src/main/java/info/frostfs/sdk/pool/SessionCache.java
Normal file
46
client/src/main/java/info/frostfs/sdk/pool/SessionCache.java
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
package info.frostfs.sdk.pool;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
|
|
||||||
|
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 boolean tryGetValue(String key, SessionToken[] value) {
|
||||||
|
if (key == null) {
|
||||||
|
value[0] = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SessionToken token = cache.get(key);
|
||||||
|
if (token != null) {
|
||||||
|
value[0] = token;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
15
client/src/main/java/info/frostfs/sdk/pool/Statistic.java
Normal file
15
client/src/main/java/info/frostfs/sdk/pool/Statistic.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package info.frostfs.sdk.pool;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class StatusSnapshot {
|
||||||
|
private long allTime;
|
||||||
|
private long allRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
22
client/src/main/java/info/frostfs/sdk/pool/WorkList.java
Normal file
22
client/src/main/java/info/frostfs/sdk/pool/WorkList.java
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
26
client/src/main/java/info/frostfs/sdk/pool/WrapperPrm.java
Normal file
26
client/src/main/java/info/frostfs/sdk/pool/WrapperPrm.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
import frostfs.accounting.Types;
|
||||||
|
|
||||||
|
public interface AccountingClient {
|
||||||
|
Types.Decimal getBalance();
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ApeManagerClient {
|
||||||
|
byte[] addChain(Chain chain, ChainTarget chainTarget);
|
||||||
|
|
||||||
|
void removeChain(Chain chain, ChainTarget chainTarget);
|
||||||
|
|
||||||
|
List<Chain> listChains(ChainTarget chainTarget);
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
public interface CommonClient extends
|
||||||
|
AccountingClient, ApeManagerClient, ContainerClient, NetmapClient, ObjectClient, SessionClient, ToolsClient {
|
||||||
|
}
|
|
@ -10,5 +10,4 @@ public class ContextAccessor {
|
||||||
public ContextAccessor(ClientEnvironment context) {
|
public ContextAccessor(ClientEnvironment context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
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.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 java.util.Map;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
var request = createGetRequest(null);
|
||||||
|
|
||||||
|
var response = serviceBlockingStub.balance(request);
|
||||||
|
|
||||||
|
Verifier.checkResponse(response);
|
||||||
|
return response.getBody().getBalance();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Service.BalanceRequest createGetRequest(Map<String, String> xHeaders) {
|
||||||
|
var body = Service.BalanceRequest.Body.newBuilder()
|
||||||
|
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||||
|
.build();
|
||||||
|
var request = Service.BalanceRequest.newBuilder()
|
||||||
|
.setBody(body);
|
||||||
|
|
||||||
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
|
return request.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,134 @@
|
||||||
|
package info.frostfs.sdk.services.impl;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import frostfs.ape.Types;
|
||||||
|
import frostfs.apemanager.APEManagerServiceGrpc;
|
||||||
|
import frostfs.apemanager.Service;
|
||||||
|
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.mappers.chain.ChainMapper;
|
||||||
|
import info.frostfs.sdk.mappers.chain.ChainTargetMapper;
|
||||||
|
import info.frostfs.sdk.services.ApeManagerClient;
|
||||||
|
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 java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerClient {
|
||||||
|
private final APEManagerServiceGrpc.APEManagerServiceBlockingStub apeManagerServiceClient;
|
||||||
|
|
||||||
|
public ApeManagerClientImpl(ClientEnvironment clientEnvironment) {
|
||||||
|
super(clientEnvironment);
|
||||||
|
this.apeManagerServiceClient = APEManagerServiceGrpc.newBlockingStub(getContext().getChannel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] addChain(Chain chain, ChainTarget chainTarget) {
|
||||||
|
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(chain, chainTarget, null);
|
||||||
|
|
||||||
|
var response = apeManagerServiceClient.addChain(request);
|
||||||
|
|
||||||
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
return response.getBody().getChainId().toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeChain(Chain chain, ChainTarget chainTarget) {
|
||||||
|
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(chain, chainTarget, null);
|
||||||
|
|
||||||
|
var response = apeManagerServiceClient.removeChain(request);
|
||||||
|
|
||||||
|
Verifier.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||||
|
if (isNull(chainTarget)) {
|
||||||
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ChainTarget.class.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = createListChainsRequest(chainTarget, null);
|
||||||
|
|
||||||
|
var response = apeManagerServiceClient.listChains(request);
|
||||||
|
|
||||||
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
|
return ChainMapper.toModels(response.getBody().getChainsList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Service.AddChainRequest createAddChainRequest(Chain chain,
|
||||||
|
ChainTarget chainTarget,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
|
var chainGrpc = Types.Chain.newBuilder()
|
||||||
|
.setRaw(ByteString.copyFrom(chain.getRaw()))
|
||||||
|
.build();
|
||||||
|
var body = Service.AddChainRequest.Body.newBuilder()
|
||||||
|
.setChain(chainGrpc)
|
||||||
|
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||||
|
.build();
|
||||||
|
var request = Service.AddChainRequest.newBuilder()
|
||||||
|
.setBody(body);
|
||||||
|
|
||||||
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
|
return request.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Service.RemoveChainRequest createRemoveChainRequest(Chain chain,
|
||||||
|
ChainTarget chainTarget,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
|
var body = Service.RemoveChainRequest.Body.newBuilder()
|
||||||
|
.setChainId(ByteString.copyFrom(chain.getRaw()))
|
||||||
|
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||||
|
.build();
|
||||||
|
var request = Service.RemoveChainRequest.newBuilder()
|
||||||
|
.setBody(body);
|
||||||
|
|
||||||
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
|
return request.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Service.ListChainsRequest createListChainsRequest(ChainTarget chainTarget,
|
||||||
|
Map<String, String> xHeaders) {
|
||||||
|
var body = Service.ListChainsRequest.Body.newBuilder()
|
||||||
|
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||||
|
.build();
|
||||||
|
var request = Service.ListChainsRequest.newBuilder()
|
||||||
|
.setBody(body);
|
||||||
|
|
||||||
|
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||||
|
RequestSigner.sign(request, getContext().getKey());
|
||||||
|
|
||||||
|
return request.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,8 +31,8 @@ import info.frostfs.sdk.tools.Verifier;
|
||||||
import info.frostfs.sdk.utils.Validator;
|
import info.frostfs.sdk.utils.Validator;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -329,17 +329,17 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int readNBytes(FileInputStream fileInputStream, byte[] buffer, int size) {
|
private int readNBytes(InputStream inputStream, byte[] buffer, int size) {
|
||||||
try {
|
try {
|
||||||
return fileInputStream.readNBytes(buffer, 0, size);
|
return inputStream.readNBytes(buffer, 0, size);
|
||||||
} catch (IOException exp) {
|
} catch (IOException exp) {
|
||||||
throw new ProcessFrostFSException(exp.getMessage());
|
throw new ProcessFrostFSException(exp.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getStreamSize(FileInputStream fileInputStream) {
|
private long getStreamSize(InputStream inputStream) {
|
||||||
try {
|
try {
|
||||||
return fileInputStream.getChannel().size();
|
return inputStream.available();
|
||||||
} catch (IOException exp) {
|
} catch (IOException exp) {
|
||||||
throw new ProcessFrostFSException(exp.getMessage());
|
throw new ProcessFrostFSException(exp.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,4 @@ public class SessionToolsImpl extends ContextAccessor implements SessionTools {
|
||||||
|
|
||||||
return SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
return SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_type", "grpc_service", "grpc_method");
|
Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method");
|
||||||
|
|
||||||
private static final List<String> defaultResponseLabels =
|
private static final List<String> defaultResponseLabels =
|
||||||
Arrays.asList("grpc_type", "grpc_service", "grpc_method", "code", "grpc_code");
|
Arrays.asList("grpc_target", "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,7 +113,9 @@ 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;
|
||||||
|
@ -155,7 +157,9 @@ 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,
|
||||||
|
|
|
@ -1,27 +1,33 @@
|
||||||
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 serviceName, String methodName, MethodType type) {
|
private GrpcMethod(String targetName, 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) {
|
static GrpcMethod of(MethodDescriptor<?, ?> method, Channel channel) {
|
||||||
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(serviceName, methodName, method.getType());
|
return new GrpcMethod(channel.authority(), serviceName, methodName, method.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String targetName() {
|
||||||
|
return targetName;
|
||||||
|
}
|
||||||
|
|
||||||
String serviceName() {
|
String serviceName() {
|
||||||
return serviceName;
|
return serviceName;
|
||||||
|
|
|
@ -9,14 +9,21 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Labels {
|
public class Labels {
|
||||||
/** Merges two string lists into an array, maintaining order of first list then second list. */
|
private Labels() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges two string lists into an array, maintaining order of first list then second list.
|
||||||
|
*/
|
||||||
static String[] asArray(List<String> firstList, List<String> secondList) {
|
static String[] asArray(List<String> firstList, List<String> secondList) {
|
||||||
List<String> list = new ArrayList<>(firstList);
|
List<String> list = new ArrayList<>(firstList);
|
||||||
list.addAll(secondList);
|
list.addAll(secondList);
|
||||||
return list.toArray(new String[0]);
|
return list.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Converts a list of strings to a list of grpc metadata keys. */
|
/**
|
||||||
|
* Converts a list of strings to a list of grpc metadata keys.
|
||||||
|
*/
|
||||||
static List<Key<String>> metadataKeys(List<String> headerNames) {
|
static List<Key<String>> metadataKeys(List<String> headerNames) {
|
||||||
List<Key<String>> keys = new ArrayList<>();
|
List<Key<String>> keys = new ArrayList<>();
|
||||||
for (String name : headerNames) {
|
for (String name : headerNames) {
|
||||||
|
@ -41,9 +48,12 @@ public class Labels {
|
||||||
return Collections.unmodifiableList(labels);
|
return Collections.unmodifiableList(labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds standard labels, as well as custom ones, in order, to a given collector. */
|
/**
|
||||||
|
* Adds standard labels, as well as custom ones, in order, to a given collector.
|
||||||
|
*/
|
||||||
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,11 +1,8 @@
|
||||||
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 {
|
||||||
|
@ -19,6 +16,7 @@ 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));
|
||||||
|
@ -27,7 +25,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);
|
GrpcMethod grpcMethod = GrpcMethod.of(methodDescriptor, channel);
|
||||||
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);
|
||||||
|
|
|
@ -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.Channel;
|
import io.grpc.ManagedChannel;
|
||||||
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 Channel initGrpcChannel(ClientSettings clientSettings) {
|
public static ManagedChannel initGrpcChannel(ClientSettings clientSettings) {
|
||||||
Validator.validate(clientSettings);
|
Validator.validate(clientSettings);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -32,4 +32,15 @@ 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())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,5 +119,4 @@ public class RequestSigner {
|
||||||
MessageHelper.setField(verifyBuilder, ORIGIN_SIGNATURE_FIELD_NAME, signMessagePart(key, verifyOrigin));
|
MessageHelper.setField(verifyBuilder, ORIGIN_SIGNATURE_FIELD_NAME, signMessagePart(key, verifyOrigin));
|
||||||
MessageHelper.setField(request, VERIFY_HEADER_FIELD_NAME, verifyBuilder.build());
|
MessageHelper.setField(request, VERIFY_HEADER_FIELD_NAME, verifyBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,11 +15,15 @@ import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_COMMA;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class Validator {
|
public class Validator {
|
||||||
|
private Validator() {
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> void validate(T object) {
|
public static <T> void validate(T object) {
|
||||||
StringBuilder errorMessage = new StringBuilder().append(System.lineSeparator());
|
StringBuilder errorMessage = new StringBuilder();
|
||||||
process(object, errorMessage);
|
process(object, errorMessage);
|
||||||
|
|
||||||
if (errorMessage.length() != 0) {
|
if (errorMessage.length() != 0) {
|
||||||
|
errorMessage.insert(0, System.lineSeparator());
|
||||||
throw new ValidationFrostFSException(errorMessage.toString());
|
throw new ValidationFrostFSException(errorMessage.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package info.frostfs.sdk.utils;
|
package info.frostfs.sdk.utils;
|
||||||
|
|
||||||
public class WaitUtil {
|
public class WaitUtil {
|
||||||
|
private WaitUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
public static void sleep(long ms) {
|
public static void sleep(long ms) {
|
||||||
try {
|
try {
|
||||||
|
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
import frostfs.accounting.AccountingServiceGrpc;
|
||||||
|
import frostfs.accounting.Service;
|
||||||
|
import info.frostfs.sdk.Base58;
|
||||||
|
import info.frostfs.sdk.dto.object.OwnerId;
|
||||||
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
|
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 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();
|
||||||
|
|
||||||
|
//Then
|
||||||
|
requestConstructorMock.verify(
|
||||||
|
() -> RequestConstructor.addMetaHeader(any(Service.BalanceRequest.Builder.class), eq(null)),
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,216 @@
|
||||||
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
|
import frostfs.apemanager.APEManagerServiceGrpc;
|
||||||
|
import frostfs.apemanager.Service;
|
||||||
|
import info.frostfs.sdk.FileUtils;
|
||||||
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
|
import info.frostfs.sdk.enums.TargetType;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
|
import info.frostfs.sdk.services.impl.ApeManagerClientImpl;
|
||||||
|
import info.frostfs.sdk.testgenerator.ApeManagerGenerator;
|
||||||
|
import info.frostfs.sdk.tools.RequestConstructor;
|
||||||
|
import info.frostfs.sdk.tools.RequestSigner;
|
||||||
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
|
import io.grpc.Channel;
|
||||||
|
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 java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class ApeManagerClientTest {
|
||||||
|
private ApeManagerClientImpl apeManagerClient;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private APEManagerServiceGrpc.APEManagerServiceBlockingStub apeManagerServiceClient;
|
||||||
|
@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);
|
||||||
|
apeManagerClient = new ApeManagerClientImpl(clientEnvironment);
|
||||||
|
|
||||||
|
Field field = ReflectionUtils.findFields(ApeManagerClientImpl.class,
|
||||||
|
f -> f.getName().equals("apeManagerServiceClient"),
|
||||||
|
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
|
||||||
|
.get(0);
|
||||||
|
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(apeManagerClient, apeManagerServiceClient);
|
||||||
|
|
||||||
|
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 addChain_success() {
|
||||||
|
//Given
|
||||||
|
Chain chain = generateChain();
|
||||||
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
|
|
||||||
|
var response = ApeManagerGenerator.generateAddChainResponse();
|
||||||
|
|
||||||
|
var captor = ArgumentCaptor.forClass(Service.AddChainRequest.class);
|
||||||
|
|
||||||
|
when(apeManagerServiceClient.addChain(captor.capture())).thenReturn(response);
|
||||||
|
|
||||||
|
//When
|
||||||
|
var result = apeManagerClient.addChain(chain, chainTarget);
|
||||||
|
|
||||||
|
//Then
|
||||||
|
requestConstructorMock.verify(
|
||||||
|
() -> RequestConstructor.addMetaHeader(any(Service.AddChainRequest.Builder.class), eq(null)),
|
||||||
|
times(1)
|
||||||
|
);
|
||||||
|
requestSignerMock.verify(
|
||||||
|
() -> RequestSigner.sign(any(Service.AddChainRequest.Builder.class), eq(null)),
|
||||||
|
times(1)
|
||||||
|
);
|
||||||
|
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||||
|
|
||||||
|
assertThat(result).containsOnly(response.getBody().getChainId().toByteArray());
|
||||||
|
|
||||||
|
var request = captor.getValue();
|
||||||
|
assertThat(request.getBody().getChain().getRaw().toByteArray()).containsOnly(chain.getRaw());
|
||||||
|
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||||
|
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addChain_wrongParams() {
|
||||||
|
//Given
|
||||||
|
Chain chain = generateChain();
|
||||||
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
|
|
||||||
|
//When + Then
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(null, chainTarget));
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(chain, null));
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void removeChain_success() {
|
||||||
|
//Given
|
||||||
|
Chain chain = generateChain();
|
||||||
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
|
|
||||||
|
var response = ApeManagerGenerator.generateRemoveChainResponse();
|
||||||
|
|
||||||
|
var captor = ArgumentCaptor.forClass(Service.RemoveChainRequest.class);
|
||||||
|
|
||||||
|
when(apeManagerServiceClient.removeChain(captor.capture())).thenReturn(response);
|
||||||
|
|
||||||
|
//When
|
||||||
|
apeManagerClient.removeChain(chain, chainTarget);
|
||||||
|
|
||||||
|
//Then
|
||||||
|
requestConstructorMock.verify(
|
||||||
|
() -> RequestConstructor.addMetaHeader(any(Service.RemoveChainRequest.Builder.class), eq(null)),
|
||||||
|
times(1)
|
||||||
|
);
|
||||||
|
requestSignerMock.verify(
|
||||||
|
() -> RequestSigner.sign(any(Service.RemoveChainRequest.Builder.class), eq(null)),
|
||||||
|
times(1)
|
||||||
|
);
|
||||||
|
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||||
|
|
||||||
|
var request = captor.getValue();
|
||||||
|
assertThat(request.getBody().getChainId().toByteArray()).containsOnly(chain.getRaw());
|
||||||
|
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||||
|
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void removeChain_wrongParams() {
|
||||||
|
//Given
|
||||||
|
Chain chain = generateChain();
|
||||||
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
|
|
||||||
|
//When + Then
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(null, chainTarget));
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(chain, null));
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void listChain_success() {
|
||||||
|
//Given
|
||||||
|
ChainTarget chainTarget = generateChainTarget();
|
||||||
|
|
||||||
|
var response = ApeManagerGenerator.generateListChainsResponse();
|
||||||
|
|
||||||
|
var captor = ArgumentCaptor.forClass(Service.ListChainsRequest.class);
|
||||||
|
|
||||||
|
when(apeManagerServiceClient.listChains(captor.capture())).thenReturn(response);
|
||||||
|
|
||||||
|
//When
|
||||||
|
var result = apeManagerClient.listChains(chainTarget);
|
||||||
|
|
||||||
|
//Then
|
||||||
|
requestConstructorMock.verify(
|
||||||
|
() -> RequestConstructor.addMetaHeader(any(Service.ListChainsRequest.Builder.class), eq(null)),
|
||||||
|
times(1)
|
||||||
|
);
|
||||||
|
requestSignerMock.verify(
|
||||||
|
() -> RequestSigner.sign(any(Service.ListChainsRequest.Builder.class), eq(null)),
|
||||||
|
times(1)
|
||||||
|
);
|
||||||
|
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||||
|
|
||||||
|
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();
|
||||||
|
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||||
|
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void listChain_wrongParams() {
|
||||||
|
//When + Then
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.listChains(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Chain generateChain() {
|
||||||
|
byte[] chainRaw = FileUtils.resourceToBytes("test_chain_raw.json");
|
||||||
|
return new Chain(chainRaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChainTarget generateChainTarget() {
|
||||||
|
return new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", TargetType.NAMESPACE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
package info.frostfs.sdk.testgenerator;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import frostfs.ape.Types;
|
||||||
|
import frostfs.apemanager.Service;
|
||||||
|
import info.frostfs.sdk.FileUtils;
|
||||||
|
import info.frostfs.sdk.Helper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ApeManagerGenerator {
|
||||||
|
|
||||||
|
private static ByteString generateChainID() {
|
||||||
|
return ByteString.copyFrom(Helper.getByteArrayFromHex("616c6c6f774f626a476574436e72"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Types.Chain generateRawChain() {
|
||||||
|
byte[] chainRaw = FileUtils.resourceToBytes("test_chain_raw.json");
|
||||||
|
|
||||||
|
return Types.Chain.newBuilder()
|
||||||
|
.setRaw(ByteString.copyFrom(chainRaw))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Iterable<Types.Chain> generateRawChains(int size) {
|
||||||
|
var list = new ArrayList<Types.Chain>(size);
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
list.add(generateRawChain());
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Types.ChainTarget generateChainTarget() {
|
||||||
|
return Types.ChainTarget.newBuilder()
|
||||||
|
.setType(Types.TargetType.CONTAINER)
|
||||||
|
.setName("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.AddChainRequest.Body generateAddChainRequestBody() {
|
||||||
|
return Service.AddChainRequest.Body.newBuilder()
|
||||||
|
.setTarget(generateChainTarget())
|
||||||
|
.setChain(generateRawChain())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.AddChainRequest generateAddChainRequest() {
|
||||||
|
return Service.AddChainRequest.newBuilder()
|
||||||
|
.setBody(generateAddChainRequestBody())
|
||||||
|
.setMetaHeader(SessionGenerator.generateRequestMetaHeader())
|
||||||
|
.setVerifyHeader(SessionGenerator.generateRequestVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.AddChainResponse.Body generateAddChainResponseBody() {
|
||||||
|
return Service.AddChainResponse.Body.newBuilder()
|
||||||
|
.setChainId(generateChainID())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.AddChainResponse generateAddChainResponse() {
|
||||||
|
return Service.AddChainResponse.newBuilder()
|
||||||
|
.setBody(generateAddChainResponseBody())
|
||||||
|
.setMetaHeader(SessionGenerator.generateResponseMetaHeader())
|
||||||
|
.setVerifyHeader(SessionGenerator.generateResponseVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.RemoveChainRequest.Body generateRemoveChainRequestBody() {
|
||||||
|
return Service.RemoveChainRequest.Body.newBuilder()
|
||||||
|
.setChainId(generateChainID())
|
||||||
|
.setTarget(generateChainTarget())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.RemoveChainRequest generateRemoveChainRequest() {
|
||||||
|
return Service.RemoveChainRequest.newBuilder()
|
||||||
|
.setBody(generateRemoveChainRequestBody())
|
||||||
|
.setMetaHeader(SessionGenerator.generateRequestMetaHeader())
|
||||||
|
.setVerifyHeader(SessionGenerator.generateRequestVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.RemoveChainResponse.Body generateRemoveChainResponseBody() {
|
||||||
|
return Service.RemoveChainResponse.Body.getDefaultInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.RemoveChainResponse generateRemoveChainResponse() {
|
||||||
|
return Service.RemoveChainResponse.newBuilder()
|
||||||
|
.setBody(generateRemoveChainResponseBody())
|
||||||
|
.setMetaHeader(SessionGenerator.generateResponseMetaHeader())
|
||||||
|
.setVerifyHeader(SessionGenerator.generateResponseVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.ListChainsRequest.Body generateListChainsRequestBody() {
|
||||||
|
return Service.ListChainsRequest.Body.newBuilder()
|
||||||
|
.setTarget(generateChainTarget())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.ListChainsRequest generateListChainsRequest() {
|
||||||
|
return Service.ListChainsRequest.newBuilder()
|
||||||
|
.setBody(generateListChainsRequestBody())
|
||||||
|
.setMetaHeader(SessionGenerator.generateRequestMetaHeader())
|
||||||
|
.setVerifyHeader(SessionGenerator.generateRequestVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.ListChainsResponse.Body generateListChainsResponseBody() {
|
||||||
|
return Service.ListChainsResponse.Body.newBuilder()
|
||||||
|
.addAllChains(generateRawChains(10))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.ListChainsResponse generateListChainsResponse() {
|
||||||
|
return Service.ListChainsResponse.newBuilder()
|
||||||
|
.setBody(generateListChainsResponseBody())
|
||||||
|
.setMetaHeader(SessionGenerator.generateResponseMetaHeader())
|
||||||
|
.setVerifyHeader(SessionGenerator.generateResponseVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package info.frostfs.sdk.testgenerator;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import frostfs.refs.Types;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class RefsGenerator {
|
||||||
|
|
||||||
|
public static Types.Version generateVersion() {
|
||||||
|
return Types.Version.newBuilder()
|
||||||
|
.setMajor(2)
|
||||||
|
.setMinor(1)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.OwnerID generateOwnerID() {
|
||||||
|
return Types.OwnerID.newBuilder()
|
||||||
|
.setValue(ByteString.copyFrom(new byte[]{1, 2, 3}))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.Address generateAddress() {
|
||||||
|
return Types.Address.newBuilder()
|
||||||
|
.setObjectId(generateObjectID())
|
||||||
|
.setContainerId(generateContainerID())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ObjectID generateObjectID() {
|
||||||
|
return Types.ObjectID.newBuilder()
|
||||||
|
.setValue(ByteString.copyFrom(new byte[]{1, 2, 3}))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<Types.ObjectID> generateObjectIDs() {
|
||||||
|
return Arrays.asList(generateObjectID(), generateObjectID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ContainerID generateContainerID() {
|
||||||
|
return Types.ContainerID.newBuilder()
|
||||||
|
.setValue(ByteString.copyFrom(new byte[]{1, 2, 3}))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<Types.ContainerID> generateContainerIDs() {
|
||||||
|
return Arrays.asList(generateContainerID(), generateContainerID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.Signature generateSignature() {
|
||||||
|
return Types.Signature.newBuilder()
|
||||||
|
.setKey(ByteString.copyFrom(new byte[]{1}))
|
||||||
|
.setSign(ByteString.copyFrom(new byte[]{2}))
|
||||||
|
.setScheme(Types.SignatureScheme.forNumber(new Random().nextInt(3)))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.Checksum generateChecksum() {
|
||||||
|
return Types.Checksum.newBuilder()
|
||||||
|
.setType(Types.ChecksumType.SHA256)
|
||||||
|
.setSum(ByteString.copyFrom(new byte[]{1, 2, 3}))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,178 @@
|
||||||
|
package info.frostfs.sdk.testgenerator;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import frostfs.session.Service;
|
||||||
|
import frostfs.session.Types;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class SessionGenerator {
|
||||||
|
|
||||||
|
public static Service.CreateRequest.Body generateCreateRequestBody() {
|
||||||
|
return Service.CreateRequest.Body.newBuilder()
|
||||||
|
.setExpiration(555)
|
||||||
|
.setOwnerId(RefsGenerator.generateOwnerID())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.CreateRequest generateCreateRequest() {
|
||||||
|
return Service.CreateRequest.newBuilder()
|
||||||
|
.setBody(generateCreateRequestBody())
|
||||||
|
.setMetaHeader(generateRequestMetaHeader())
|
||||||
|
.setVerifyHeader(generateRequestVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.CreateResponse.Body generateCreateResponseBody() {
|
||||||
|
return Service.CreateResponse.Body.newBuilder()
|
||||||
|
.setId(ByteString.copyFrom(new byte[]{1, 2, 3}))
|
||||||
|
.setSessionKey(ByteString.copyFrom(new byte[]{4, 5, 6}))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Service.CreateResponse generateCreateResponse() {
|
||||||
|
return Service.CreateResponse.newBuilder()
|
||||||
|
.setBody(generateCreateResponseBody())
|
||||||
|
.setMetaHeader(generateResponseMetaHeader())
|
||||||
|
.setVerifyHeader(generateResponseVerificationHeader())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ResponseVerificationHeader generateResponseVerificationHeader() {
|
||||||
|
return generateResponseVerificationHeader(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ResponseVerificationHeader generateResponseVerificationHeader(boolean withOrigin) {
|
||||||
|
var builder = Types.ResponseVerificationHeader.newBuilder()
|
||||||
|
.setBodySignature(RefsGenerator.generateSignature())
|
||||||
|
.setMetaSignature(RefsGenerator.generateSignature())
|
||||||
|
.setOriginSignature(RefsGenerator.generateSignature());
|
||||||
|
|
||||||
|
if (withOrigin) {
|
||||||
|
builder.setOrigin(generateResponseVerificationHeader(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ResponseMetaHeader generateResponseMetaHeader() {
|
||||||
|
return generateResponseMetaHeader(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ResponseMetaHeader generateResponseMetaHeader(boolean withOrigin) {
|
||||||
|
var builder = Types.ResponseMetaHeader.newBuilder()
|
||||||
|
.setEpoch(13)
|
||||||
|
.setTtl(100)
|
||||||
|
.addAllXHeaders(generateXHeaders())
|
||||||
|
.setVersion(RefsGenerator.generateVersion())
|
||||||
|
.setStatus(StatusGenerator.generateStatus());
|
||||||
|
|
||||||
|
if (withOrigin) {
|
||||||
|
builder.setOrigin(generateResponseMetaHeader(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.RequestVerificationHeader generateRequestVerificationHeader() {
|
||||||
|
return generateRequestVerificationHeader(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.RequestVerificationHeader generateRequestVerificationHeader(boolean withOrigin) {
|
||||||
|
var builder = Types.RequestVerificationHeader.newBuilder()
|
||||||
|
.setBodySignature(RefsGenerator.generateSignature())
|
||||||
|
.setMetaSignature(RefsGenerator.generateSignature())
|
||||||
|
.setOriginSignature(RefsGenerator.generateSignature());
|
||||||
|
|
||||||
|
if (withOrigin) {
|
||||||
|
builder.setOrigin(generateRequestVerificationHeader(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.RequestMetaHeader generateRequestMetaHeader() {
|
||||||
|
return generateRequestMetaHeader(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.RequestMetaHeader generateRequestMetaHeader(boolean withOrigin) {
|
||||||
|
var builder = Types.RequestMetaHeader.newBuilder()
|
||||||
|
.setEpoch(13)
|
||||||
|
.setTtl(100)
|
||||||
|
.setMagicNumber(1337)
|
||||||
|
.addAllXHeaders(generateXHeaders())
|
||||||
|
.setVersion(RefsGenerator.generateVersion())
|
||||||
|
.setSessionToken(generateSessionToken());
|
||||||
|
|
||||||
|
if (withOrigin) {
|
||||||
|
builder.setOrigin(generateRequestMetaHeader(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.SessionToken.Body.TokenLifetime generateTokenLifeTime() {
|
||||||
|
return Types.SessionToken.Body.TokenLifetime.newBuilder()
|
||||||
|
.setExp(1)
|
||||||
|
.setIat(2)
|
||||||
|
.setNbf(3)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.SessionToken.Body generateSessionTokenBody() {
|
||||||
|
var builder = Types.SessionToken.Body.newBuilder()
|
||||||
|
.setId(ByteString.copyFrom(new byte[]{1}))
|
||||||
|
.setSessionKey(ByteString.copyFrom(new byte[]{2}))
|
||||||
|
.setOwnerId(RefsGenerator.generateOwnerID())
|
||||||
|
.setLifetime(generateTokenLifeTime());
|
||||||
|
|
||||||
|
if (new Random().nextBoolean()) {
|
||||||
|
builder.setContainer(generateContainerSessionContext());
|
||||||
|
} else {
|
||||||
|
builder.setObject(generateObjectSessionContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.SessionToken generateSessionToken() {
|
||||||
|
return Types.SessionToken.newBuilder()
|
||||||
|
.setBody(generateSessionTokenBody())
|
||||||
|
.setSignature(RefsGenerator.generateSignature())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ObjectSessionContext.Target generateObjectSessionContextTarget() {
|
||||||
|
return Types.ObjectSessionContext.Target.newBuilder()
|
||||||
|
.setContainer(RefsGenerator.generateContainerID())
|
||||||
|
.addObjects(RefsGenerator.generateObjectID())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ObjectSessionContext generateObjectSessionContext() {
|
||||||
|
return Types.ObjectSessionContext.newBuilder()
|
||||||
|
.setVerb(Types.ObjectSessionContext.Verb.HEAD)
|
||||||
|
.setTarget(generateObjectSessionContextTarget())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ContainerSessionContext generateContainerSessionContext() {
|
||||||
|
return Types.ContainerSessionContext.newBuilder()
|
||||||
|
.setVerb(Types.ContainerSessionContext.Verb.DELETE)
|
||||||
|
.setWildcard(true)
|
||||||
|
.setContainerId(RefsGenerator.generateContainerID())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.XHeader generateXHeader() {
|
||||||
|
return Types.XHeader.newBuilder()
|
||||||
|
.setKey("key")
|
||||||
|
.setValue("val")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<Types.XHeader> generateXHeaders() {
|
||||||
|
return Arrays.asList(generateXHeader(), generateXHeader());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package info.frostfs.sdk.testgenerator;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import frostfs.status.Types;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class StatusGenerator {
|
||||||
|
|
||||||
|
public static Types.Status.Detail generateDetail() {
|
||||||
|
return Types.Status.Detail.newBuilder()
|
||||||
|
.setId(345)
|
||||||
|
.setValue(ByteString.copyFrom("value".getBytes()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<Types.Status.Detail> generateDetails() {
|
||||||
|
return Arrays.asList(generateDetail(), generateDetail());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.Status generateStatus() {
|
||||||
|
return Types.Status.newBuilder()
|
||||||
|
.setCode(2)
|
||||||
|
.setMessage("some string")
|
||||||
|
.addAllDetails(generateDetails())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
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"
|
||||||
|
}
|
|
@ -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>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>cryptography</artifactId>
|
<artifactId>cryptography</artifactId>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>exceptions</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.protobuf</groupId>
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.frostfs.sdk;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
@ -15,6 +16,7 @@ import static java.util.Objects.isNull;
|
||||||
public class Helper {
|
public class Helper {
|
||||||
private static final String SHA256 = "SHA-256";
|
private static final String SHA256 = "SHA-256";
|
||||||
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
|
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
|
||||||
|
private static final int HEX_RADIX = 16;
|
||||||
|
|
||||||
private Helper() {
|
private Helper() {
|
||||||
}
|
}
|
||||||
|
@ -62,4 +64,12 @@ public class Helper {
|
||||||
|
|
||||||
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));
|
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] getByteArrayFromHex(String hex) {
|
||||||
|
if (StringUtils.isBlank(hex)) {
|
||||||
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BigInteger(hex, HEX_RADIX).toByteArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,4 +108,23 @@ public class HelperTest {
|
||||||
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(null));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(null));
|
||||||
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(new byte[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getByteArrayFromHex_success() {
|
||||||
|
//Given
|
||||||
|
var value = "0102030405";
|
||||||
|
|
||||||
|
//When
|
||||||
|
var result = Helper.getByteArrayFromHex(value);
|
||||||
|
|
||||||
|
//Then
|
||||||
|
assertThat(result).containsOnly(new byte[]{1, 2, 3, 4, 5});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getByteArrayFromHex_wrong() {
|
||||||
|
//When + Then
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getByteArrayFromHex(null));
|
||||||
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getByteArrayFromHex(""));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>exceptions</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
|
|
|
@ -40,6 +40,11 @@ public class ErrorConst {
|
||||||
|
|
||||||
public static final String WRONG_UUID_SIZE_TEMPLATE = "uuid byte array length must be %s";
|
public static final String WRONG_UUID_SIZE_TEMPLATE = "uuid byte array length must be %s";
|
||||||
|
|
||||||
|
public static final String POOL_CLIENT_UNHEALTHY = "pool client unhealthy";
|
||||||
|
public static final String POOL_PEERS_IS_MISSING = "no FrostFS peers configured";
|
||||||
|
public static final String POOL_NODES_UNHEALTHY = "at least one node must be healthy";
|
||||||
|
public static final String POOL_CLIENTS_UNHEALTHY = "cannot find alive client";
|
||||||
|
public static final String POOL_NOT_DIALED = "pool not dialed";
|
||||||
|
|
||||||
public static final String FIELDS_DELIMITER_COMMA = ", ";
|
public static final String FIELDS_DELIMITER_COMMA = ", ";
|
||||||
public static final String FIELDS_DELIMITER_OR = " or ";
|
public static final String FIELDS_DELIMITER_OR = " or ";
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
public class FrostFSException extends RuntimeException {
|
||||||
|
|
||||||
|
public FrostFSException() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FrostFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FrostFSException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package info.frostfs.sdk.exceptions;
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
public class ProcessFrostFSException extends RuntimeException {
|
public class ProcessFrostFSException extends FrostFSException {
|
||||||
public ProcessFrostFSException(String message) {
|
public ProcessFrostFSException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
public class SessionExpiredFrostFSException extends FrostFSException {
|
||||||
|
|
||||||
|
public SessionExpiredFrostFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
public class SessionNotFoundFrostFSException extends FrostFSException {
|
||||||
|
|
||||||
|
public SessionNotFoundFrostFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package info.frostfs.sdk.exceptions;
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
public class TimeoutFrostFSException extends RuntimeException {
|
public class TimeoutFrostFSException extends FrostFSException {
|
||||||
public TimeoutFrostFSException() {
|
public TimeoutFrostFSException() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package info.frostfs.sdk.exceptions;
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
public class ValidationFrostFSException extends RuntimeException {
|
public class ValidationFrostFSException extends FrostFSException {
|
||||||
public ValidationFrostFSException(String message) {
|
public ValidationFrostFSException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>models</artifactId>
|
<artifactId>models</artifactId>
|
||||||
|
@ -21,17 +21,17 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>cryptography</artifactId>
|
<artifactId>cryptography</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>protos</artifactId>
|
<artifactId>protos</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>exceptions</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package info.frostfs.sdk.constants;
|
package info.frostfs.sdk.constants;
|
||||||
|
|
||||||
public class AppConst {
|
public class AppConst {
|
||||||
|
public static final String RESERVED_PREFIX = "__SYSTEM__";
|
||||||
|
|
||||||
public static final int DEFAULT_MAJOR_VERSION = 2;
|
public static final int DEFAULT_MAJOR_VERSION = 2;
|
||||||
public static final int DEFAULT_MINOR_VERSION = 13;
|
public static final int DEFAULT_MINOR_VERSION = 13;
|
||||||
public static final int BYTE_SHIFT = 10;
|
public static final int BYTE_SHIFT = 10;
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package info.frostfs.sdk.constants;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.AppConst.RESERVED_PREFIX;
|
||||||
|
|
||||||
|
public class AttributeConst {
|
||||||
|
public static final String DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE = RESERVED_PREFIX + "DISABLE_HOMOMORPHIC_HASHING";
|
||||||
|
|
||||||
|
private AttributeConst() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,4 +46,7 @@ public class FilterConst {
|
||||||
|
|
||||||
// FILTER_HEADER_PHY is a filter key to check if an object physically stored on a node.
|
// FILTER_HEADER_PHY is a filter key to check if an object physically stored on a node.
|
||||||
public static final String FILTER_HEADER_PHY = HEADER_PREFIX + "PHY";
|
public static final String FILTER_HEADER_PHY = HEADER_PREFIX + "PHY";
|
||||||
|
|
||||||
|
private FilterConst() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package info.frostfs.sdk.constants;
|
package info.frostfs.sdk.constants;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.AppConst.RESERVED_PREFIX;
|
||||||
|
|
||||||
public class XHeaderConst {
|
public class XHeaderConst {
|
||||||
public static final String RESERVED_XHEADER_PREFIX = "__SYSTEM__";
|
public static final String XHEADER_NETMAP_EPOCH = RESERVED_PREFIX + "NETMAP_EPOCH";
|
||||||
public static final String XHEADER_NETMAP_EPOCH = RESERVED_XHEADER_PREFIX + "NETMAP_EPOCH";
|
public static final String XHEADER_NETMAP_LOOKUP_DEPTH = RESERVED_PREFIX + "NETMAP_LOOKUP_DEPTH";
|
||||||
public static final String XHEADER_NETMAP_LOOKUP_DEPTH = RESERVED_XHEADER_PREFIX + "NETMAP_LOOKUP_DEPTH";
|
|
||||||
|
|
||||||
private XHeaderConst() {
|
private XHeaderConst() {
|
||||||
}
|
}
|
||||||
|
|
10
models/src/main/java/info/frostfs/sdk/dto/chain/Chain.java
Normal file
10
models/src/main/java/info/frostfs/sdk/dto/chain/Chain.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package info.frostfs.sdk.dto.chain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Chain {
|
||||||
|
private final byte[] raw;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package info.frostfs.sdk.dto.chain;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.enums.TargetType;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class ChainTarget {
|
||||||
|
private final TargetType type;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public ChainTarget(String name, TargetType type) {
|
||||||
|
this.name = name;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,8 @@ import info.frostfs.sdk.enums.BasicAcl;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -15,6 +17,7 @@ public class Container {
|
||||||
private BasicAcl basicAcl;
|
private BasicAcl basicAcl;
|
||||||
private PlacementPolicy placementPolicy;
|
private PlacementPolicy placementPolicy;
|
||||||
private Version version;
|
private Version version;
|
||||||
|
private Map<String, String> attributes = new HashMap<>();
|
||||||
|
|
||||||
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy) {
|
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy) {
|
||||||
this.nonce = UUID.randomUUID();
|
this.nonce = UUID.randomUUID();
|
||||||
|
|
34
models/src/main/java/info/frostfs/sdk/enums/TargetType.java
Normal file
34
models/src/main/java/info/frostfs/sdk/enums/TargetType.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package info.frostfs.sdk.enums;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum TargetType {
|
||||||
|
UNDEFINED(0),
|
||||||
|
NAMESPACE(1),
|
||||||
|
CONTAINER(2),
|
||||||
|
USER(3),
|
||||||
|
GROUP(4),
|
||||||
|
;
|
||||||
|
|
||||||
|
private static final Map<Integer, TargetType> ENUM_MAP_BY_VALUE;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Map<Integer, TargetType> map = new HashMap<>();
|
||||||
|
for (TargetType targetType : TargetType.values()) {
|
||||||
|
map.put(targetType.value, targetType);
|
||||||
|
}
|
||||||
|
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int value;
|
||||||
|
|
||||||
|
TargetType(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TargetType get(int value) {
|
||||||
|
return ENUM_MAP_BY_VALUE.get(value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package info.frostfs.sdk.mappers.chain;
|
||||||
|
|
||||||
|
import frostfs.ape.Types;
|
||||||
|
import info.frostfs.sdk.dto.chain.Chain;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
public class ChainMapper {
|
||||||
|
private ChainMapper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Chain> toModels(List<Types.Chain> chains) {
|
||||||
|
if (CollectionUtils.isEmpty(chains)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return chains.stream().map(ChainMapper::toModel).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Chain toModel(Types.Chain chain) {
|
||||||
|
if (isNull(chain) || chain.getSerializedSize() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Chain(chain.getRaw().toByteArray());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package info.frostfs.sdk.mappers.chain;
|
||||||
|
|
||||||
|
import frostfs.ape.Types;
|
||||||
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
public class ChainTargetMapper {
|
||||||
|
private ChainTargetMapper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Types.ChainTarget toGrpcMessage(ChainTarget chainTarget) {
|
||||||
|
if (isNull(chainTarget)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var targetType = Types.TargetType.forNumber(chainTarget.getType().value);
|
||||||
|
if (isNull(targetType)) {
|
||||||
|
throw new ProcessFrostFSException(String.format(
|
||||||
|
UNKNOWN_ENUM_VALUE_TEMPLATE,
|
||||||
|
Types.ChainTarget.class.getName(),
|
||||||
|
chainTarget.getType().name()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Types.ChainTarget.newBuilder()
|
||||||
|
.setType(targetType)
|
||||||
|
.setName(chainTarget.getName())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,9 +7,13 @@ import info.frostfs.sdk.enums.BasicAcl;
|
||||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.mappers.netmap.PlacementPolicyMapper;
|
import info.frostfs.sdk.mappers.netmap.PlacementPolicyMapper;
|
||||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static info.frostfs.sdk.UuidExtension.asBytes;
|
import static info.frostfs.sdk.UuidExtension.asBytes;
|
||||||
import static info.frostfs.sdk.UuidExtension.asUuid;
|
import static info.frostfs.sdk.UuidExtension.asUuid;
|
||||||
|
import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE;
|
||||||
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@ -22,11 +26,23 @@ public class ContainerMapper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Types.Container.newBuilder()
|
var containerGrpc = Types.Container.newBuilder()
|
||||||
.setBasicAcl(container.getBasicAcl().value)
|
.setBasicAcl(container.getBasicAcl().value)
|
||||||
.setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy()))
|
.setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy()))
|
||||||
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())))
|
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())));
|
||||||
.build();
|
|
||||||
|
container.getAttributes().putIfAbsent(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString());
|
||||||
|
var attributes = container.getAttributes().entrySet().stream()
|
||||||
|
.map(entry ->
|
||||||
|
Types.Container.Attribute.newBuilder()
|
||||||
|
.setKey(entry.getKey())
|
||||||
|
.setValue(entry.getValue())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
containerGrpc.addAllAttributes(attributes);
|
||||||
|
|
||||||
|
return containerGrpc.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Container toModel(Types.Container containerGrpc) {
|
public static Container toModel(Types.Container containerGrpc) {
|
||||||
|
@ -41,9 +57,17 @@ public class ContainerMapper {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var container = new Container(basicAcl, PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()));
|
var container = new Container(basicAcl, PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()));
|
||||||
container.setNonce(asUuid(containerGrpc.getNonce().toByteArray()));
|
container.setNonce(asUuid(containerGrpc.getNonce().toByteArray()));
|
||||||
container.setVersion(VersionMapper.toModel(containerGrpc.getVersion()));
|
container.setVersion(VersionMapper.toModel(containerGrpc.getVersion()));
|
||||||
|
|
||||||
|
if (CollectionUtils.isNotEmpty(containerGrpc.getAttributesList())) {
|
||||||
|
var attributes = containerGrpc.getAttributesList().stream()
|
||||||
|
.collect(Collectors.toMap(Types.Container.Attribute::getKey, Types.Container.Attribute::getValue));
|
||||||
|
container.setAttributes(attributes);
|
||||||
|
}
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package info.frostfs.sdk.mappers.chain;
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString;
|
||||||
|
import frostfs.ape.Types;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
|
public class ChainMapperTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toModels_success() {
|
||||||
|
//Given
|
||||||
|
var chain1 = Types.Chain.newBuilder()
|
||||||
|
.setRaw(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}))
|
||||||
|
.build();
|
||||||
|
var chain2 = Types.Chain.newBuilder()
|
||||||
|
.setRaw(ByteString.copyFrom(new byte[]{6, 7, 8, 9, 10}))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
//When
|
||||||
|
var result = ChainMapper.toModels(List.of(chain1, chain2));
|
||||||
|
|
||||||
|
//Then
|
||||||
|
assertNotNull(result);
|
||||||
|
assertThat(result).hasSize(2);
|
||||||
|
assertThat(result.get(0).getRaw()).containsOnly(chain1.getRaw().toByteArray());
|
||||||
|
assertThat(result.get(1).getRaw()).containsOnly(chain2.getRaw().toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toModels_null() {
|
||||||
|
//When + Then
|
||||||
|
assertNull(ChainMapper.toModels(null));
|
||||||
|
assertNull(ChainMapper.toModels(Collections.emptyList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toModel_success() {
|
||||||
|
//Given
|
||||||
|
var chain = Types.Chain.newBuilder()
|
||||||
|
.setRaw(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
//When
|
||||||
|
var result = ChainMapper.toModel(chain);
|
||||||
|
|
||||||
|
//Then
|
||||||
|
assertNotNull(result);
|
||||||
|
assertThat(result.getRaw()).containsOnly(chain.getRaw().toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toModel_null() {
|
||||||
|
//When + Then
|
||||||
|
assertNull(ChainMapper.toModel(null));
|
||||||
|
assertNull(ChainMapper.toModel(Types.Chain.getDefaultInstance()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package info.frostfs.sdk.mappers.chain;
|
||||||
|
|
||||||
|
import frostfs.ape.Types;
|
||||||
|
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||||
|
import info.frostfs.sdk.enums.TargetType;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.mockStatic;
|
||||||
|
|
||||||
|
public class ChainTargetMapperTest {
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@EnumSource(value = TargetType.class)
|
||||||
|
void toGrpcMessage_success(TargetType targetType) {
|
||||||
|
//Given
|
||||||
|
var target = new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", targetType);
|
||||||
|
|
||||||
|
|
||||||
|
//When
|
||||||
|
var result = ChainTargetMapper.toGrpcMessage(target);
|
||||||
|
|
||||||
|
//Then
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(target.getName(), result.getName());
|
||||||
|
assertEquals(target.getType().value, result.getTypeValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toGrpcMessage_null() {
|
||||||
|
//When + Then
|
||||||
|
assertNull(ChainTargetMapper.toGrpcMessage(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void toGrpcMessage_notValidScheme() {
|
||||||
|
//Given
|
||||||
|
var target = new ChainTarget("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R", TargetType.UNDEFINED);
|
||||||
|
|
||||||
|
//When + Then
|
||||||
|
try (MockedStatic<Types.TargetType> mockStatic = mockStatic(Types.TargetType.class)) {
|
||||||
|
mockStatic.when(() -> Types.TargetType.forNumber(target.getType().value))
|
||||||
|
.thenReturn(null);
|
||||||
|
|
||||||
|
assertThrows(ProcessFrostFSException.class, () -> ChainTargetMapper.toGrpcMessage(target));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import java.util.UUID;
|
||||||
|
|
||||||
import static info.frostfs.sdk.UuidExtension.asBytes;
|
import static info.frostfs.sdk.UuidExtension.asBytes;
|
||||||
import static info.frostfs.sdk.UuidExtension.asUuid;
|
import static info.frostfs.sdk.UuidExtension.asUuid;
|
||||||
|
import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class ContainerMapperTest {
|
public class ContainerMapperTest {
|
||||||
|
@ -24,6 +25,8 @@ public class ContainerMapperTest {
|
||||||
//Given
|
//Given
|
||||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
||||||
var container = new Container(BasicAcl.PUBLIC_RW, placementPolicy);
|
var container = new Container(BasicAcl.PUBLIC_RW, placementPolicy);
|
||||||
|
container.getAttributes().put("key1", "val1");
|
||||||
|
container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, "false");
|
||||||
|
|
||||||
//When
|
//When
|
||||||
var result = ContainerMapper.toGrpcMessage(container);
|
var result = ContainerMapper.toGrpcMessage(container);
|
||||||
|
@ -42,6 +45,11 @@ public class ContainerMapperTest {
|
||||||
container.getPlacementPolicy().getReplicas()[0].getSelector(),
|
container.getPlacementPolicy().getReplicas()[0].getSelector(),
|
||||||
result.getPlacementPolicy().getReplicasList().get(0).getSelector()
|
result.getPlacementPolicy().getReplicasList().get(0).getSelector()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assertEquals("key1", result.getAttributes(0).getKey());
|
||||||
|
assertEquals("val1", result.getAttributes(0).getValue());
|
||||||
|
assertEquals(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, result.getAttributes(1).getKey());
|
||||||
|
assertEquals("false", result.getAttributes(1).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -69,11 +77,23 @@ public class ContainerMapperTest {
|
||||||
.addReplicas(replica)
|
.addReplicas(replica)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
var attribute1 = Types.Container.Attribute.newBuilder()
|
||||||
|
.setKey("key1")
|
||||||
|
.setValue("val1")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
var attribute2 = Types.Container.Attribute.newBuilder()
|
||||||
|
.setKey("key2")
|
||||||
|
.setValue("val2")
|
||||||
|
.build();
|
||||||
|
|
||||||
var container = Types.Container.newBuilder()
|
var container = Types.Container.newBuilder()
|
||||||
.setBasicAcl(basicAcl.value)
|
.setBasicAcl(basicAcl.value)
|
||||||
.setNonce(ByteString.copyFrom(asBytes(UUID.randomUUID())))
|
.setNonce(ByteString.copyFrom(asBytes(UUID.randomUUID())))
|
||||||
.setVersion(version)
|
.setVersion(version)
|
||||||
.setPlacementPolicy(placementPolicy)
|
.setPlacementPolicy(placementPolicy)
|
||||||
|
.addAttributes(attribute1)
|
||||||
|
.addAttributes(attribute2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
//When
|
//When
|
||||||
|
@ -95,6 +115,9 @@ public class ContainerMapperTest {
|
||||||
);
|
);
|
||||||
assertEquals(version.getMajor(), result.getVersion().getMajor());
|
assertEquals(version.getMajor(), result.getVersion().getMajor());
|
||||||
assertEquals(version.getMinor(), result.getVersion().getMinor());
|
assertEquals(version.getMinor(), result.getVersion().getMinor());
|
||||||
|
|
||||||
|
assertEquals(attribute1.getValue(), result.getAttributes().get(attribute1.getKey()));
|
||||||
|
assertEquals(attribute2.getValue(), result.getAttributes().get(attribute2.getKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class ObjectFilterMapperTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void toGrpcMessage_notValidScheme() {
|
void toGrpcMessage_notValidType() {
|
||||||
//Given
|
//Given
|
||||||
var objectFilter = new ObjectFilter.FilterByAttribute(UNSPECIFIED, "key", "value");
|
var objectFilter = new ObjectFilter.FilterByAttribute(UNSPECIFIED, "key", "value");
|
||||||
|
|
||||||
|
|
45
pom.xml
45
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>info.frostfs.sdk</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>frostfs-sdk-java</artifactId>
|
<artifactId>frostfs-sdk-java</artifactId>
|
||||||
<version>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>client</module>
|
<module>client</module>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
|
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
|
||||||
<mockito.version>5.12.0</mockito.version>
|
<mockito.version>5.14.2</mockito.version>
|
||||||
<junit.version>5.10.3</junit.version>
|
<junit.version>5.10.3</junit.version>
|
||||||
<assertj.version>3.26.3</assertj.version>
|
<assertj.version>3.26.3</assertj.version>
|
||||||
<lombok.version>1.18.34</lombok.version>
|
<lombok.version>1.18.34</lombok.version>
|
||||||
|
@ -64,6 +64,12 @@
|
||||||
<version>${mockito.version}</version>
|
<version>${mockito.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -85,6 +91,41 @@
|
||||||
</executions>
|
</executions>
|
||||||
<version>3.4.0</version>
|
<version>3.4.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>../target/</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${basedir}/target</directory>
|
||||||
|
<includes>
|
||||||
|
<include>/client*</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
|
@ -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>0.1.0</version>
|
<version>0.2.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>protos</artifactId>
|
<artifactId>protos</artifactId>
|
||||||
|
|
|
@ -2,20 +2,19 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.accounting;
|
package neo.fs.v2.accounting;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc;accounting";
|
|
||||||
option java_package = "frostfs.accounting";
|
option java_package = "frostfs.accounting";
|
||||||
|
|
||||||
import "accounting/types.proto";
|
import "accounting/types.proto";
|
||||||
import "refs/types.proto";
|
import "refs/types.proto";
|
||||||
import "session/types.proto";
|
import "session/types.proto";
|
||||||
|
|
||||||
// Accounting service provides methods for interaction with NeoFS sidechain via
|
// Accounting service provides methods for interaction with FrostFS sidechain
|
||||||
// other NeoFS nodes to get information about the account balance. Deposit and
|
// via other FrostFS nodes to get information about the account balance. Deposit
|
||||||
// Withdraw operations can't be implemented here, as they require Mainnet NeoFS
|
// and Withdraw operations can't be implemented here, as they require Mainnet
|
||||||
// smart contract invocation. Transfer operations between internal NeoFS
|
// FrostFS smart contract invocation. Transfer operations between internal
|
||||||
// accounts are possible if both use the same token type.
|
// FrostFS accounts are possible if both use the same token type.
|
||||||
service AccountingService {
|
service AccountingService {
|
||||||
// Returns the amount of funds in GAS token for the requested NeoFS account.
|
// Returns the amount of funds in GAS token for the requested FrostFS account.
|
||||||
//
|
//
|
||||||
// Statuses:
|
// Statuses:
|
||||||
// - **OK** (0, SECTION_SUCCESS):
|
// - **OK** (0, SECTION_SUCCESS):
|
||||||
|
@ -27,9 +26,9 @@ service AccountingService {
|
||||||
// BalanceRequest message
|
// BalanceRequest message
|
||||||
message BalanceRequest {
|
message BalanceRequest {
|
||||||
// To indicate the account for which the balance is requested, its identifier
|
// To indicate the account for which the balance is requested, its identifier
|
||||||
// is used. It can be any existing account in NeoFS sidechain `Balance` smart
|
// is used. It can be any existing account in FrostFS sidechain `Balance`
|
||||||
// contract. If omitted, client implementation MUST set it to the request's
|
// smart contract. If omitted, client implementation MUST set it to the
|
||||||
// signer `OwnerID`.
|
// request's signer `OwnerID`.
|
||||||
message Body {
|
message Body {
|
||||||
// Valid user identifier in `OwnerID` format for which the balance is
|
// Valid user identifier in `OwnerID` format for which the balance is
|
||||||
// requested. Required field.
|
// requested. Required field.
|
||||||
|
|
|
@ -2,10 +2,9 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.accounting;
|
package neo.fs.v2.accounting;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting/grpc;accounting";
|
|
||||||
option java_package = "frostfs.accounting";
|
option java_package = "frostfs.accounting";
|
||||||
|
|
||||||
// Standard floating point data type can't be used in NeoFS due to inexactness
|
// Standard floating point data type can't be used in FrostFS due to inexactness
|
||||||
// of the result when doing lots of small number operations. To solve the lost
|
// of the result when doing lots of small number operations. To solve the lost
|
||||||
// precision issue, special `Decimal` format is used for monetary computations.
|
// precision issue, special `Decimal` format is used for monetary computations.
|
||||||
//
|
//
|
||||||
|
|
|
@ -2,10 +2,10 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.acl;
|
package neo.fs.v2.acl;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/acl/grpc;acl";
|
|
||||||
option java_package = "frostfs.acl";
|
option java_package = "frostfs.acl";
|
||||||
|
|
||||||
import "refs/types.proto";
|
import "refs/types.proto";
|
||||||
|
import "ape/types.proto";
|
||||||
|
|
||||||
// Target role of the access control rule in access control list.
|
// Target role of the access control rule in access control list.
|
||||||
enum Role {
|
enum Role {
|
||||||
|
@ -88,14 +88,14 @@ enum HeaderType {
|
||||||
// Filter object headers
|
// Filter object headers
|
||||||
OBJECT = 2;
|
OBJECT = 2;
|
||||||
|
|
||||||
// Filter service headers. These are not processed by NeoFS nodes and
|
// Filter service headers. These are not processed by FrostFS nodes and
|
||||||
// exist for service use only.
|
// exist for service use only.
|
||||||
SERVICE = 3;
|
SERVICE = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Describes a single eACL rule.
|
// Describes a single eACL rule.
|
||||||
message EACLRecord {
|
message EACLRecord {
|
||||||
// NeoFS request Verb to match
|
// FrostFS request Verb to match
|
||||||
Operation operation = 1 [ json_name = "operation" ];
|
Operation operation = 1 [ json_name = "operation" ];
|
||||||
|
|
||||||
// Rule execution result. Either allows or denies access if filters match.
|
// Rule execution result. Either allows or denies access if filters match.
|
||||||
|
@ -164,7 +164,7 @@ message EACLRecord {
|
||||||
// Extended ACL rules table. A list of ACL rules defined additionally to Basic
|
// Extended ACL rules table. A list of ACL rules defined additionally to Basic
|
||||||
// ACL. Extended ACL rules can be attached to a container and can be updated
|
// ACL. Extended ACL rules can be attached to a container and can be updated
|
||||||
// or may be defined in `BearerToken` structure. Please see the corresponding
|
// or may be defined in `BearerToken` structure. Please see the corresponding
|
||||||
// NeoFS Technical Specification section for detailed description.
|
// FrostFS Technical Specification section for detailed description.
|
||||||
message EACLTable {
|
message EACLTable {
|
||||||
// eACL format version. Effectively, the version of API library used to create
|
// eACL format version. Effectively, the version of API library used to create
|
||||||
// eACL Table.
|
// eACL Table.
|
||||||
|
@ -194,6 +194,9 @@ message BearerToken {
|
||||||
// container. If it contains `container_id` field, bearer token is only
|
// container. If it contains `container_id` field, bearer token is only
|
||||||
// valid for this specific container. Otherwise, any container of the same
|
// valid for this specific container. Otherwise, any container of the same
|
||||||
// owner is allowed.
|
// owner is allowed.
|
||||||
|
//
|
||||||
|
// Deprecated: eACL tables are no longer relevant - `APEOverrides` should be
|
||||||
|
// used instead.
|
||||||
EACLTable eacl_table = 1 [ json_name = "eaclTable" ];
|
EACLTable eacl_table = 1 [ json_name = "eaclTable" ];
|
||||||
|
|
||||||
// `OwnerID` defines to whom the token was issued. It must match the request
|
// `OwnerID` defines to whom the token was issued. It must match the request
|
||||||
|
@ -218,6 +221,24 @@ message BearerToken {
|
||||||
// AllowImpersonate flag to consider token signer as request owner.
|
// AllowImpersonate flag to consider token signer as request owner.
|
||||||
// If this field is true extended ACL table in token body isn't processed.
|
// If this field is true extended ACL table in token body isn't processed.
|
||||||
bool allow_impersonate = 4 [ json_name = "allowImpersonate" ];
|
bool allow_impersonate = 4 [ json_name = "allowImpersonate" ];
|
||||||
|
|
||||||
|
// APEOverride is the list of APE chains defined for a target.
|
||||||
|
// These chains are meant to serve as overrides to the already defined (or
|
||||||
|
// even undefined) APE chains for the target (see contract `Policy`).
|
||||||
|
//
|
||||||
|
// The server-side processing of the bearer token with set APE overrides
|
||||||
|
// must verify if a client is permitted to override chains for the target,
|
||||||
|
// preventing unauthorized access through the APE mechanism.
|
||||||
|
message APEOverride {
|
||||||
|
// Target for which chains are applied.
|
||||||
|
frostfs.v2.ape.ChainTarget target = 1 [ json_name = "target" ];
|
||||||
|
|
||||||
|
// The list of APE chains.
|
||||||
|
repeated frostfs.v2.ape.Chain chains = 2 [ json_name = "chains" ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// APE override for the target.
|
||||||
|
APEOverride ape_override = 5 [ json_name = "apeOverride" ];
|
||||||
}
|
}
|
||||||
// Bearer Token body
|
// Bearer Token body
|
||||||
Body body = 1 [ json_name = "body" ];
|
Body body = 1 [ json_name = "body" ];
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
|
||||||
package frostfs.v2.apemanager;
|
package frostfs.v2.ape;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc;apemanager";
|
option java_package = "frostfs.ape";
|
||||||
option java_package = "frostfs.apemanager";
|
|
||||||
|
|
||||||
// TargetType is a type target to which a rule chain is defined.
|
// TargetType is a type target to which a rule chain is defined.
|
||||||
enum TargetType {
|
enum TargetType {
|
|
@ -2,12 +2,11 @@ syntax = "proto3";
|
||||||
|
|
||||||
package frostfs.v2.apemanager;
|
package frostfs.v2.apemanager;
|
||||||
|
|
||||||
import "apemanager/types.proto";
|
|
||||||
import "session/types.proto";
|
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc;apemanager";
|
|
||||||
option java_package = "frostfs.apemanager";
|
option java_package = "frostfs.apemanager";
|
||||||
|
|
||||||
|
import "ape/types.proto";
|
||||||
|
import "session/types.proto";
|
||||||
|
|
||||||
// `APEManagerService` provides API to manage rule chains within sidechain's
|
// `APEManagerService` provides API to manage rule chains within sidechain's
|
||||||
// `Policy` smart contract.
|
// `Policy` smart contract.
|
||||||
service APEManagerService {
|
service APEManagerService {
|
||||||
|
@ -53,10 +52,10 @@ service APEManagerService {
|
||||||
message AddChainRequest {
|
message AddChainRequest {
|
||||||
message Body {
|
message Body {
|
||||||
// A target for which a rule chain is added.
|
// A target for which a rule chain is added.
|
||||||
ChainTarget target = 1;
|
frostfs.v2.ape.ChainTarget target = 1;
|
||||||
|
|
||||||
// The chain to set for the target.
|
// The chain to set for the target.
|
||||||
Chain chain = 2;
|
frostfs.v2.ape.Chain chain = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The request's body.
|
// The request's body.
|
||||||
|
@ -96,7 +95,7 @@ message AddChainResponse {
|
||||||
message RemoveChainRequest {
|
message RemoveChainRequest {
|
||||||
message Body {
|
message Body {
|
||||||
// Target for which a rule chain is removed.
|
// Target for which a rule chain is removed.
|
||||||
ChainTarget target = 1;
|
frostfs.v2.ape.ChainTarget target = 1;
|
||||||
|
|
||||||
// Chain ID assigned for the rule chain.
|
// Chain ID assigned for the rule chain.
|
||||||
bytes chain_id = 2;
|
bytes chain_id = 2;
|
||||||
|
@ -136,7 +135,7 @@ message RemoveChainResponse {
|
||||||
message ListChainsRequest {
|
message ListChainsRequest {
|
||||||
message Body {
|
message Body {
|
||||||
// Target for which rule chains are listed.
|
// Target for which rule chains are listed.
|
||||||
ChainTarget target = 1;
|
frostfs.v2.ape.ChainTarget target = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The request's body.
|
// The request's body.
|
||||||
|
@ -155,7 +154,7 @@ message ListChainsRequest {
|
||||||
message ListChainsResponse {
|
message ListChainsResponse {
|
||||||
message Body {
|
message Body {
|
||||||
// The list of chains defined for the reqeusted target.
|
// The list of chains defined for the reqeusted target.
|
||||||
repeated Chain chains = 1;
|
repeated frostfs.v2.ape.Chain chains = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The response's body.
|
// The response's body.
|
||||||
|
|
|
@ -2,17 +2,15 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.container;
|
package neo.fs.v2.container;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc;container";
|
|
||||||
option java_package = "frostfs.container";
|
option java_package = "frostfs.container";
|
||||||
|
|
||||||
import "acl/types.proto";
|
|
||||||
import "container/types.proto";
|
import "container/types.proto";
|
||||||
import "refs/types.proto";
|
import "refs/types.proto";
|
||||||
import "session/types.proto";
|
import "session/types.proto";
|
||||||
|
|
||||||
// `ContainerService` provides API to interact with `Container` smart contract
|
// `ContainerService` provides API to interact with `Container` smart contract
|
||||||
// in NeoFS sidechain via other NeoFS nodes. All of those actions can be done
|
// in FrostFS sidechain via other FrostFS nodes. All of those actions can be
|
||||||
// equivalently by directly issuing transactions and RPC calls to sidechain
|
// done equivalently by directly issuing transactions and RPC calls to sidechain
|
||||||
// nodes.
|
// nodes.
|
||||||
service ContainerService {
|
service ContainerService {
|
||||||
// `Put` invokes `Container` smart contract's `Put` method and returns
|
// `Put` invokes `Container` smart contract's `Put` method and returns
|
||||||
|
@ -62,45 +60,9 @@ service ContainerService {
|
||||||
// - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \
|
// - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \
|
||||||
// container list access denied.
|
// container list access denied.
|
||||||
rpc List(ListRequest) returns (ListResponse);
|
rpc List(ListRequest) returns (ListResponse);
|
||||||
|
|
||||||
// Invokes 'SetEACL' method of 'Container` smart contract and returns response
|
|
||||||
// immediately. After one more block in sidechain, changes in an Extended ACL
|
|
||||||
// are added into smart contract storage.
|
|
||||||
//
|
|
||||||
// Statuses:
|
|
||||||
// - **OK** (0, SECTION_SUCCESS): \
|
|
||||||
// request to save container eACL has been sent to the sidechain;
|
|
||||||
// - Common failures (SECTION_FAILURE_COMMON);
|
|
||||||
// - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \
|
|
||||||
// set container eACL access denied.
|
|
||||||
rpc SetExtendedACL(SetExtendedACLRequest) returns (SetExtendedACLResponse);
|
|
||||||
|
|
||||||
// Returns Extended ACL table and signature from `Container` smart contract
|
|
||||||
// storage.
|
|
||||||
//
|
|
||||||
// Statuses:
|
|
||||||
// - **OK** (0, SECTION_SUCCESS): \
|
|
||||||
// container eACL has been successfully read;
|
|
||||||
// - Common failures (SECTION_FAILURE_COMMON);
|
|
||||||
// - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \
|
|
||||||
// container not found;
|
|
||||||
// - **EACL_NOT_FOUND** (3073, SECTION_CONTAINER): \
|
|
||||||
// eACL table not found;
|
|
||||||
// - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \
|
|
||||||
// access to container eACL is denied.
|
|
||||||
rpc GetExtendedACL(GetExtendedACLRequest) returns (GetExtendedACLResponse);
|
|
||||||
|
|
||||||
// Announces the space values used by the container for P2P synchronization.
|
|
||||||
//
|
|
||||||
// Statuses:
|
|
||||||
// - **OK** (0, SECTION_SUCCESS): \
|
|
||||||
// estimation of used space has been successfully announced;
|
|
||||||
// - Common failures (SECTION_FAILURE_COMMON).
|
|
||||||
rpc AnnounceUsedSpace(AnnounceUsedSpaceRequest)
|
|
||||||
returns (AnnounceUsedSpaceResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New NeoFS Container creation request
|
// New FrostFS Container creation request
|
||||||
message PutRequest {
|
message PutRequest {
|
||||||
// Container creation request has container structure's signature as a
|
// Container creation request has container structure's signature as a
|
||||||
// separate field. It's not stored in sidechain, just verified on container
|
// separate field. It's not stored in sidechain, just verified on container
|
||||||
|
@ -108,7 +70,7 @@ message PutRequest {
|
||||||
// the stable-marshalled container strucutre, hence there is no need for
|
// the stable-marshalled container strucutre, hence there is no need for
|
||||||
// additional signature checks.
|
// additional signature checks.
|
||||||
message Body {
|
message Body {
|
||||||
// Container structure to register in NeoFS
|
// Container structure to register in FrostFS
|
||||||
container.Container container = 1;
|
container.Container container = 1;
|
||||||
|
|
||||||
// Signature of a stable-marshalled container according to RFC-6979.
|
// Signature of a stable-marshalled container according to RFC-6979.
|
||||||
|
@ -127,7 +89,7 @@ message PutRequest {
|
||||||
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
|
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New NeoFS Container creation response
|
// New FrostFS Container creation response
|
||||||
message PutResponse {
|
message PutResponse {
|
||||||
// Container put response body contains information about the newly registered
|
// Container put response body contains information about the newly registered
|
||||||
// container as seen by `Container` smart contract. `ContainerID` can be
|
// container as seen by `Container` smart contract. `ContainerID` can be
|
||||||
|
@ -156,7 +118,7 @@ message DeleteRequest {
|
||||||
// the container owner's intent. The signature will be verified by `Container`
|
// the container owner's intent. The signature will be verified by `Container`
|
||||||
// smart contract, so signing algorithm must be supported by NeoVM.
|
// smart contract, so signing algorithm must be supported by NeoVM.
|
||||||
message Body {
|
message Body {
|
||||||
// Identifier of the container to delete from NeoFS
|
// Identifier of the container to delete from FrostFS
|
||||||
neo.fs.v2.refs.ContainerID container_id = 1;
|
neo.fs.v2.refs.ContainerID container_id = 1;
|
||||||
|
|
||||||
// `ContainerID` signed with the container owner's key according to
|
// `ContainerID` signed with the container owner's key according to
|
||||||
|
@ -282,150 +244,3 @@ message ListResponse {
|
||||||
// transmission.
|
// transmission.
|
||||||
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Extended ACL
|
|
||||||
message SetExtendedACLRequest {
|
|
||||||
// Set Extended ACL request body does not have separate `ContainerID`
|
|
||||||
// reference. It will be taken from `EACLTable.container_id` field.
|
|
||||||
message Body {
|
|
||||||
// Extended ACL table to set for the container
|
|
||||||
neo.fs.v2.acl.EACLTable eacl = 1;
|
|
||||||
|
|
||||||
// Signature of stable-marshalled Extended ACL table according to RFC-6979.
|
|
||||||
neo.fs.v2.refs.SignatureRFC6979 signature = 2;
|
|
||||||
}
|
|
||||||
// Body of set extended acl request message.
|
|
||||||
Body body = 1;
|
|
||||||
|
|
||||||
// Carries request meta information. Header data is used only to regulate
|
|
||||||
// message transport and does not affect request execution.
|
|
||||||
neo.fs.v2.session.RequestMetaHeader meta_header = 2;
|
|
||||||
|
|
||||||
// Carries request verification information. This header is used to
|
|
||||||
// authenticate the nodes of the message route and check the correctness of
|
|
||||||
// transmission.
|
|
||||||
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set Extended ACL
|
|
||||||
message SetExtendedACLResponse {
|
|
||||||
// `SetExtendedACLResponse` has an empty body because the operation is
|
|
||||||
// asynchronous and the update should be reflected in `Container` smart
|
|
||||||
// contract's storage after next block is issued in sidechain.
|
|
||||||
message Body {}
|
|
||||||
|
|
||||||
// Body of set extended acl response message.
|
|
||||||
Body body = 1;
|
|
||||||
|
|
||||||
// Carries response meta information. Header data is used only to regulate
|
|
||||||
// message transport and does not affect request execution.
|
|
||||||
neo.fs.v2.session.ResponseMetaHeader meta_header = 2;
|
|
||||||
|
|
||||||
// Carries response verification information. This header is used to
|
|
||||||
// authenticate the nodes of the message route and check the correctness of
|
|
||||||
// transmission.
|
|
||||||
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Extended ACL
|
|
||||||
message GetExtendedACLRequest {
|
|
||||||
// Get Extended ACL request body
|
|
||||||
message Body {
|
|
||||||
// Identifier of the container having Extended ACL
|
|
||||||
neo.fs.v2.refs.ContainerID container_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body of get extended acl request message.
|
|
||||||
Body body = 1;
|
|
||||||
|
|
||||||
// Carries request meta information. Header data is used only to regulate
|
|
||||||
// message transport and does not affect request execution.
|
|
||||||
neo.fs.v2.session.RequestMetaHeader meta_header = 2;
|
|
||||||
|
|
||||||
// Carries request verification information. This header is used to
|
|
||||||
// authenticate the nodes of the message route and check the correctness of
|
|
||||||
// transmission.
|
|
||||||
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Extended ACL
|
|
||||||
message GetExtendedACLResponse {
|
|
||||||
// Get Extended ACL Response body can be empty if the requested container does
|
|
||||||
// not have Extended ACL Table attached or Extended ACL has not been allowed
|
|
||||||
// at the time of container creation.
|
|
||||||
message Body {
|
|
||||||
// Extended ACL requested, if available
|
|
||||||
neo.fs.v2.acl.EACLTable eacl = 1;
|
|
||||||
|
|
||||||
// Signature of stable-marshalled Extended ACL according to RFC-6979.
|
|
||||||
neo.fs.v2.refs.SignatureRFC6979 signature = 2;
|
|
||||||
|
|
||||||
// Session token if Extended ACL was set within a session
|
|
||||||
neo.fs.v2.session.SessionToken session_token = 3;
|
|
||||||
}
|
|
||||||
// Body of get extended acl response message.
|
|
||||||
Body body = 1;
|
|
||||||
|
|
||||||
// Carries response meta information. Header data is used only to regulate
|
|
||||||
// message transport and does not affect request execution.
|
|
||||||
neo.fs.v2.session.ResponseMetaHeader meta_header = 2;
|
|
||||||
|
|
||||||
// Carries response verification information. This header is used to
|
|
||||||
// authenticate the nodes of the message route and check the correctness of
|
|
||||||
// transmission.
|
|
||||||
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Announce container used space
|
|
||||||
message AnnounceUsedSpaceRequest {
|
|
||||||
// Container used space announcement body.
|
|
||||||
message Body {
|
|
||||||
// Announcement contains used space information for a single container.
|
|
||||||
message Announcement {
|
|
||||||
// Epoch number for which the container size estimation was produced.
|
|
||||||
uint64 epoch = 1;
|
|
||||||
|
|
||||||
// Identifier of the container.
|
|
||||||
neo.fs.v2.refs.ContainerID container_id = 2;
|
|
||||||
|
|
||||||
// Used space is a sum of object payload sizes of a specified
|
|
||||||
// container, stored in the node. It must not include inhumed objects.
|
|
||||||
uint64 used_space = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of announcements. If nodes share several containers,
|
|
||||||
// announcements are transferred in a batch.
|
|
||||||
repeated Announcement announcements = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Body of announce used space request message.
|
|
||||||
Body body = 1;
|
|
||||||
|
|
||||||
// Carries request meta information. Header data is used only to regulate
|
|
||||||
// message transport and does not affect request execution.
|
|
||||||
neo.fs.v2.session.RequestMetaHeader meta_header = 2;
|
|
||||||
|
|
||||||
// Carries request verification information. This header is used to
|
|
||||||
// authenticate the nodes of the message route and check the correctness of
|
|
||||||
// transmission.
|
|
||||||
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Announce container used space
|
|
||||||
message AnnounceUsedSpaceResponse {
|
|
||||||
// `AnnounceUsedSpaceResponse` has an empty body because announcements are
|
|
||||||
// one way communication.
|
|
||||||
message Body {}
|
|
||||||
|
|
||||||
// Body of announce used space response message.
|
|
||||||
Body body = 1;
|
|
||||||
|
|
||||||
// Carries response meta information. Header data is used only to regulate
|
|
||||||
// message transport and does not affect request execution.
|
|
||||||
neo.fs.v2.session.ResponseMetaHeader meta_header = 2;
|
|
||||||
|
|
||||||
// Carries response verification information. This header is used to
|
|
||||||
// authenticate the nodes of the message route and check the correctness of
|
|
||||||
// transmission.
|
|
||||||
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.container;
|
package neo.fs.v2.container;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc;container";
|
|
||||||
option java_package = "frostfs.container";
|
option java_package = "frostfs.container";
|
||||||
|
|
||||||
import "netmap/types.proto";
|
import "netmap/types.proto";
|
||||||
|
@ -50,7 +49,7 @@ message Container {
|
||||||
// (`__NEOFS__DISABLE_HOMOMORPHIC_HASHING` is deprecated) \
|
// (`__NEOFS__DISABLE_HOMOMORPHIC_HASHING` is deprecated) \
|
||||||
// Disables homomorphic hashing for the container if the value equals "true"
|
// Disables homomorphic hashing for the container if the value equals "true"
|
||||||
// string. Any other values are interpreted as missing attribute. Container
|
// string. Any other values are interpreted as missing attribute. Container
|
||||||
// could be accepted in a NeoFS network only if the global network hashing
|
// could be accepted in a FrostFS network only if the global network hashing
|
||||||
// configuration value corresponds with that attribute's value. After
|
// configuration value corresponds with that attribute's value. After
|
||||||
// container inclusion, network setting is ignored.
|
// container inclusion, network setting is ignored.
|
||||||
//
|
//
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.lock;
|
package neo.fs.v2.lock;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/lock/grpc;lock";
|
|
||||||
option java_package = "frostfs.lock";
|
option java_package = "frostfs.lock";
|
||||||
|
|
||||||
import "refs/types.proto";
|
import "refs/types.proto";
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.netmap;
|
package neo.fs.v2.netmap;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc;netmap";
|
|
||||||
option java_package = "frostfs.netmap";
|
option java_package = "frostfs.netmap";
|
||||||
|
|
||||||
import "netmap/types.proto";
|
import "netmap/types.proto";
|
||||||
|
@ -12,7 +11,7 @@ import "session/types.proto";
|
||||||
// `NetmapService` provides methods to work with `Network Map` and the
|
// `NetmapService` provides methods to work with `Network Map` and the
|
||||||
// information required to build it. The resulting `Network Map` is stored in
|
// information required to build it. The resulting `Network Map` is stored in
|
||||||
// sidechain `Netmap` smart contract, while related information can be obtained
|
// sidechain `Netmap` smart contract, while related information can be obtained
|
||||||
// from other NeoFS nodes.
|
// from other FrostFS nodes.
|
||||||
service NetmapService {
|
service NetmapService {
|
||||||
// Get NodeInfo structure from the particular node directly.
|
// Get NodeInfo structure from the particular node directly.
|
||||||
// Node information can be taken from `Netmap` smart contract. In some cases,
|
// Node information can be taken from `Netmap` smart contract. In some cases,
|
||||||
|
@ -27,7 +26,7 @@ service NetmapService {
|
||||||
// - Common failures (SECTION_FAILURE_COMMON).
|
// - Common failures (SECTION_FAILURE_COMMON).
|
||||||
rpc LocalNodeInfo(LocalNodeInfoRequest) returns (LocalNodeInfoResponse);
|
rpc LocalNodeInfo(LocalNodeInfoRequest) returns (LocalNodeInfoResponse);
|
||||||
|
|
||||||
// Read recent information about the NeoFS network.
|
// Read recent information about the FrostFS network.
|
||||||
//
|
//
|
||||||
// Statuses:
|
// Statuses:
|
||||||
// - **OK** (0, SECTION_SUCCESS):
|
// - **OK** (0, SECTION_SUCCESS):
|
||||||
|
@ -35,7 +34,7 @@ service NetmapService {
|
||||||
// - Common failures (SECTION_FAILURE_COMMON).
|
// - Common failures (SECTION_FAILURE_COMMON).
|
||||||
rpc NetworkInfo(NetworkInfoRequest) returns (NetworkInfoResponse);
|
rpc NetworkInfo(NetworkInfoRequest) returns (NetworkInfoResponse);
|
||||||
|
|
||||||
// Returns network map snapshot of the current NeoFS epoch.
|
// Returns network map snapshot of the current FrostFS epoch.
|
||||||
//
|
//
|
||||||
// Statuses:
|
// Statuses:
|
||||||
// - **OK** (0, SECTION_SUCCESS):
|
// - **OK** (0, SECTION_SUCCESS):
|
||||||
|
@ -65,7 +64,7 @@ message LocalNodeInfoRequest {
|
||||||
message LocalNodeInfoResponse {
|
message LocalNodeInfoResponse {
|
||||||
// Local Node Info, including API Version in use.
|
// Local Node Info, including API Version in use.
|
||||||
message Body {
|
message Body {
|
||||||
// Latest NeoFS API version in use
|
// Latest FrostFS API version in use
|
||||||
neo.fs.v2.refs.Version version = 1;
|
neo.fs.v2.refs.Version version = 1;
|
||||||
|
|
||||||
// NodeInfo structure with recent information from node itself
|
// NodeInfo structure with recent information from node itself
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.netmap;
|
package neo.fs.v2.netmap;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap/grpc;netmap";
|
|
||||||
option java_package = "frostfs.netmap";
|
option java_package = "frostfs.netmap";
|
||||||
|
|
||||||
// Operations on filters
|
// Operations on filters
|
||||||
|
@ -36,6 +35,9 @@ enum Operation {
|
||||||
|
|
||||||
// Logical negation
|
// Logical negation
|
||||||
NOT = 9;
|
NOT = 9;
|
||||||
|
|
||||||
|
// Matches pattern
|
||||||
|
LIKE = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selector modifier shows how the node set will be formed. By default selector
|
// Selector modifier shows how the node set will be formed. By default selector
|
||||||
|
@ -119,7 +121,7 @@ message PlacementPolicy {
|
||||||
// bucket
|
// bucket
|
||||||
repeated Replica replicas = 1 [ json_name = "replicas" ];
|
repeated Replica replicas = 1 [ json_name = "replicas" ];
|
||||||
|
|
||||||
// Container backup factor controls how deep NeoFS will search for nodes
|
// Container backup factor controls how deep FrostFS will search for nodes
|
||||||
// alternatives to include into container's nodes subset
|
// alternatives to include into container's nodes subset
|
||||||
uint32 container_backup_factor = 2 [ json_name = "containerBackupFactor" ];
|
uint32 container_backup_factor = 2 [ json_name = "containerBackupFactor" ];
|
||||||
|
|
||||||
|
@ -133,25 +135,25 @@ message PlacementPolicy {
|
||||||
bool unique = 5 [ json_name = "unique" ];
|
bool unique = 5 [ json_name = "unique" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeoFS node description
|
// FrostFS node description
|
||||||
message NodeInfo {
|
message NodeInfo {
|
||||||
// Public key of the NeoFS node in a binary format
|
// Public key of the FrostFS node in a binary format
|
||||||
bytes public_key = 1 [ json_name = "publicKey" ];
|
bytes public_key = 1 [ json_name = "publicKey" ];
|
||||||
|
|
||||||
// Ways to connect to a node
|
// Ways to connect to a node
|
||||||
repeated string addresses = 2 [ json_name = "addresses" ];
|
repeated string addresses = 2 [ json_name = "addresses" ];
|
||||||
|
|
||||||
// Administrator-defined Attributes of the NeoFS Storage Node.
|
// Administrator-defined Attributes of the FrostFS Storage Node.
|
||||||
//
|
//
|
||||||
// `Attribute` is a Key-Value metadata pair. Key name must be a valid UTF-8
|
// `Attribute` is a Key-Value metadata pair. Key name must be a valid UTF-8
|
||||||
// string. Value can't be empty.
|
// string. Value can't be empty.
|
||||||
//
|
//
|
||||||
// Attributes can be constructed into a chain of attributes: any attribute can
|
// Attributes can be constructed into a chain of attributes: any attribute can
|
||||||
// have a parent attribute and a child attribute (except the first and the
|
// have a parent attribute and a child attribute (except the first and the
|
||||||
// last one). A string representation of the chain of attributes in NeoFS
|
// last one). A string representation of the chain of attributes in FrostFS
|
||||||
// Storage Node configuration uses ":" and "/" symbols, e.g.:
|
// Storage Node configuration uses ":" and "/" symbols, e.g.:
|
||||||
//
|
//
|
||||||
// `NEOFS_NODE_ATTRIBUTE_1=key1:val1/key2:val2`
|
// `FrostFS_NODE_ATTRIBUTE_1=key1:val1/key2:val2`
|
||||||
//
|
//
|
||||||
// Therefore the string attribute representation in the Node configuration
|
// Therefore the string attribute representation in the Node configuration
|
||||||
// must use "\:", "\/" and "\\" escaped symbols if any of them appears in an
|
// must use "\:", "\/" and "\\" escaped symbols if any of them appears in an
|
||||||
|
@ -198,8 +200,8 @@ message NodeInfo {
|
||||||
// [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2). Calculated
|
// [ISO 3166-2](https://en.wikipedia.org/wiki/ISO_3166-2). Calculated
|
||||||
// automatically from `UN-LOCODE` attribute.
|
// automatically from `UN-LOCODE` attribute.
|
||||||
// * Continent \
|
// * Continent \
|
||||||
// Node's continent name according to the [Seven-Continent model]
|
// Node's continent name according to the [Seven-Continent
|
||||||
// (https://en.wikipedia.org/wiki/Continent#Number). Calculated
|
// model](https://en.wikipedia.org/wiki/Continent#Number). Calculated
|
||||||
// automatically from `UN-LOCODE` attribute.
|
// automatically from `UN-LOCODE` attribute.
|
||||||
// * ExternalAddr
|
// * ExternalAddr
|
||||||
// Node's preferred way for communications with external clients.
|
// Node's preferred way for communications with external clients.
|
||||||
|
@ -207,7 +209,7 @@ message NodeInfo {
|
||||||
// Must contain a comma-separated list of multi-addresses.
|
// Must contain a comma-separated list of multi-addresses.
|
||||||
//
|
//
|
||||||
// For detailed description of each well-known attribute please see the
|
// For detailed description of each well-known attribute please see the
|
||||||
// corresponding section in NeoFS Technical Specification.
|
// corresponding section in FrostFS Technical Specification.
|
||||||
message Attribute {
|
message Attribute {
|
||||||
// Key of the node attribute
|
// Key of the node attribute
|
||||||
string key = 1 [ json_name = "key" ];
|
string key = 1 [ json_name = "key" ];
|
||||||
|
@ -219,13 +221,13 @@ message NodeInfo {
|
||||||
// `Country`.
|
// `Country`.
|
||||||
repeated string parents = 3 [ json_name = "parents" ];
|
repeated string parents = 3 [ json_name = "parents" ];
|
||||||
}
|
}
|
||||||
// Carries list of the NeoFS node attributes in a key-value form. Key name
|
// Carries list of the FrostFS node attributes in a key-value form. Key name
|
||||||
// must be a node-unique valid UTF-8 string. Value can't be empty. NodeInfo
|
// must be a node-unique valid UTF-8 string. Value can't be empty. NodeInfo
|
||||||
// structures with duplicated attribute names or attributes with empty values
|
// structures with duplicated attribute names or attributes with empty values
|
||||||
// will be considered invalid.
|
// will be considered invalid.
|
||||||
repeated Attribute attributes = 3 [ json_name = "attributes" ];
|
repeated Attribute attributes = 3 [ json_name = "attributes" ];
|
||||||
|
|
||||||
// Represents the enumeration of various states of the NeoFS node.
|
// Represents the enumeration of various states of the FrostFS node.
|
||||||
enum State {
|
enum State {
|
||||||
// Unknown state
|
// Unknown state
|
||||||
UNSPECIFIED = 0;
|
UNSPECIFIED = 0;
|
||||||
|
@ -240,7 +242,7 @@ message NodeInfo {
|
||||||
MAINTENANCE = 3;
|
MAINTENANCE = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carries state of the NeoFS node
|
// Carries state of the FrostFS node
|
||||||
State state = 4 [ json_name = "state" ];
|
State state = 4 [ json_name = "state" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +255,7 @@ message Netmap {
|
||||||
repeated NodeInfo nodes = 2 [ json_name = "nodes" ];
|
repeated NodeInfo nodes = 2 [ json_name = "nodes" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeoFS network configuration
|
// FrostFS network configuration
|
||||||
message NetworkConfig {
|
message NetworkConfig {
|
||||||
// Single configuration parameter. Key MUST be network-unique.
|
// Single configuration parameter. Key MUST be network-unique.
|
||||||
//
|
//
|
||||||
|
@ -272,7 +274,7 @@ message NetworkConfig {
|
||||||
// Fee paid for container creation by the container owner.
|
// Fee paid for container creation by the container owner.
|
||||||
// Value: little-endian integer. Default: 0.
|
// Value: little-endian integer. Default: 0.
|
||||||
// - **EpochDuration** \
|
// - **EpochDuration** \
|
||||||
// NeoFS epoch duration measured in Sidechain blocks.
|
// FrostFS epoch duration measured in Sidechain blocks.
|
||||||
// Value: little-endian integer. Default: 0.
|
// Value: little-endian integer. Default: 0.
|
||||||
// - **HomomorphicHashingDisabled** \
|
// - **HomomorphicHashingDisabled** \
|
||||||
// Flag of disabling the homomorphic hashing of objects' payload.
|
// Flag of disabling the homomorphic hashing of objects' payload.
|
||||||
|
@ -284,8 +286,39 @@ message NetworkConfig {
|
||||||
// Flag allowing setting the MAINTENANCE state to storage nodes.
|
// Flag allowing setting the MAINTENANCE state to storage nodes.
|
||||||
// Value: true if any byte != 0. Default: false.
|
// Value: true if any byte != 0. Default: false.
|
||||||
// - **MaxObjectSize** \
|
// - **MaxObjectSize** \
|
||||||
// Maximum size of physically stored NeoFS object measured in bytes.
|
// Maximum size of physically stored FrostFS object measured in bytes.
|
||||||
// Value: little-endian integer. Default: 0.
|
// Value: little-endian integer. Default: 0.
|
||||||
|
//
|
||||||
|
// This value refers to the maximum size of a **physically** stored object
|
||||||
|
// in FrostFS. However, from a user's perspective, the **logical** size of a
|
||||||
|
// stored object can be significantly larger. The relationship between the
|
||||||
|
// physical and logical object sizes is governed by the following formula
|
||||||
|
//
|
||||||
|
// ```math
|
||||||
|
// \mathrm{Stored\ Object\ Size} \le
|
||||||
|
// \frac{
|
||||||
|
// \left(\mathrm{Max\ Object\ Size}\right)^2
|
||||||
|
// }{
|
||||||
|
// \mathrm{Object\ ID\ Size}
|
||||||
|
// }
|
||||||
|
// ```
|
||||||
|
//
|
||||||
|
// This arises from the fact that a tombstone, also being an object, stores
|
||||||
|
// the IDs of inhumed objects and cannot be divided into smaller objects,
|
||||||
|
// thus having an upper limit for its size.
|
||||||
|
//
|
||||||
|
// For example, if:
|
||||||
|
// * Max Object Size Size = 64 MiB;
|
||||||
|
// * Object ID Size = 32 B;
|
||||||
|
//
|
||||||
|
// then:
|
||||||
|
// ```math
|
||||||
|
// \mathrm{Stored\ Object\ Size} \le
|
||||||
|
// \frac{\left(64\ \mathrm{MiB}\right)^2}{32\ \mathrm{B}} =
|
||||||
|
// \frac{2^{52}}{2^5}\ \mathrm{B} =
|
||||||
|
// 2^{47}\ \mathrm{B} =
|
||||||
|
// 128\ \mathrm{TiB}
|
||||||
|
// ```
|
||||||
// - **WithdrawFee** \
|
// - **WithdrawFee** \
|
||||||
// Fee paid for withdrawal of funds paid by the account owner.
|
// Fee paid for withdrawal of funds paid by the account owner.
|
||||||
// Value: little-endian integer. Default: 0.
|
// Value: little-endian integer. Default: 0.
|
||||||
|
@ -306,18 +339,18 @@ message NetworkConfig {
|
||||||
repeated Parameter parameters = 1 [ json_name = "parameters" ];
|
repeated Parameter parameters = 1 [ json_name = "parameters" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information about NeoFS network
|
// Information about FrostFS network
|
||||||
message NetworkInfo {
|
message NetworkInfo {
|
||||||
// Number of the current epoch in the NeoFS network
|
// Number of the current epoch in the FrostFS network
|
||||||
uint64 current_epoch = 1 [ json_name = "currentEpoch" ];
|
uint64 current_epoch = 1 [ json_name = "currentEpoch" ];
|
||||||
|
|
||||||
// Magic number of the sidechain of the NeoFS network
|
// Magic number of the sidechain of the FrostFS network
|
||||||
uint64 magic_number = 2 [ json_name = "magicNumber" ];
|
uint64 magic_number = 2 [ json_name = "magicNumber" ];
|
||||||
|
|
||||||
// MillisecondsPerBlock network parameter of the sidechain of the NeoFS
|
// MillisecondsPerBlock network parameter of the sidechain of the FrostFS
|
||||||
// network
|
// network
|
||||||
int64 ms_per_block = 3 [ json_name = "msPerBlock" ];
|
int64 ms_per_block = 3 [ json_name = "msPerBlock" ];
|
||||||
|
|
||||||
// NeoFS network configuration
|
// FrostFS network configuration
|
||||||
NetworkConfig network_config = 4 [ json_name = "networkConfig" ];
|
NetworkConfig network_config = 4 [ json_name = "networkConfig" ];
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.object;
|
package neo.fs.v2.object;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc;object";
|
|
||||||
option java_package = "frostfs.object";
|
option java_package = "frostfs.object";
|
||||||
|
|
||||||
import "object/types.proto";
|
import "object/types.proto";
|
||||||
|
@ -151,7 +150,7 @@ service ObjectService {
|
||||||
rpc Head(HeadRequest) returns (HeadResponse);
|
rpc Head(HeadRequest) returns (HeadResponse);
|
||||||
|
|
||||||
// Search objects in container. Search query allows to match by Object
|
// Search objects in container. Search query allows to match by Object
|
||||||
// Header's filed values. Please see the corresponding NeoFS Technical
|
// Header's filed values. Please see the corresponding FrostFS Technical
|
||||||
// Specification section for more details.
|
// Specification section for more details.
|
||||||
//
|
//
|
||||||
// Extended headers can change `Search` behaviour:
|
// Extended headers can change `Search` behaviour:
|
||||||
|
@ -283,6 +282,55 @@ service ObjectService {
|
||||||
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
|
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
|
||||||
// provided session token has expired.
|
// provided session token has expired.
|
||||||
rpc PutSingle(PutSingleRequest) returns (PutSingleResponse);
|
rpc PutSingle(PutSingleRequest) returns (PutSingleResponse);
|
||||||
|
|
||||||
|
// Patch the object. Request uses gRPC stream. First message must set
|
||||||
|
// the address of the object that is going to get patched. If the object's
|
||||||
|
// attributes are patched, then these attrubutes must be set only within the
|
||||||
|
// first stream message.
|
||||||
|
//
|
||||||
|
// If the patch request is performed by NOT the object's owner but if the
|
||||||
|
// actor has the permission to perform the patch, then `OwnerID` of the object
|
||||||
|
// is changed. In this case the object's owner loses the object's ownership
|
||||||
|
// after the patch request is successfully done.
|
||||||
|
//
|
||||||
|
// As objects are content-addressable the patching causes new object ID
|
||||||
|
// generation for the patched object. This object id is set witihn
|
||||||
|
// `PatchResponse`. But the object id may remain unchanged in such cases:
|
||||||
|
// 1. The chunk of the applying patch contains the same value as the object's
|
||||||
|
// payload within the same range;
|
||||||
|
// 2. The patch that reverts the changes applied by preceding patch;
|
||||||
|
// 3. The application of the same patches for the object a few times.
|
||||||
|
//
|
||||||
|
// Extended headers can change `Patch` behaviour:
|
||||||
|
// * [ __SYSTEM__NETMAP_EPOCH \
|
||||||
|
// (`__NEOFS__NETMAP_EPOCH` is deprecated) \
|
||||||
|
// Will use the requsted version of Network Map for object placement
|
||||||
|
// calculation.
|
||||||
|
//
|
||||||
|
// Please refer to detailed `XHeader` description.
|
||||||
|
//
|
||||||
|
// Statuses:
|
||||||
|
// - **OK** (0, SECTION_SUCCESS): \
|
||||||
|
// object has been successfully patched and saved in the container;
|
||||||
|
// - Common failures (SECTION_FAILURE_COMMON);
|
||||||
|
// - **ACCESS_DENIED** (2048, SECTION_OBJECT): \
|
||||||
|
// write access to the container is denied;
|
||||||
|
// - **OBJECT_NOT_FOUND** (2049, SECTION_OBJECT): \
|
||||||
|
// object not found in container;
|
||||||
|
// - **OBJECT_ALREADY_REMOVED** (2052, SECTION_OBJECT): \
|
||||||
|
// the requested object has been marked as deleted.
|
||||||
|
// - **OUT_OF_RANGE** (2053, SECTION_OBJECT): \
|
||||||
|
// the requested range is out of bounds;
|
||||||
|
// - **CONTAINER_NOT_FOUND** (3072, SECTION_CONTAINER): \
|
||||||
|
// object storage container not found;
|
||||||
|
// - **CONTAINER_ACCESS_DENIED** (3074, SECTION_CONTAINER): \
|
||||||
|
// access to container is denied;
|
||||||
|
// - **TOKEN_NOT_FOUND** (4096, SECTION_SESSION): \
|
||||||
|
// (for trusted object preparation) session private key does not exist or
|
||||||
|
// has been deleted;
|
||||||
|
// - **TOKEN_EXPIRED** (4097, SECTION_SESSION): \
|
||||||
|
// provided session token has expired.
|
||||||
|
rpc Patch(stream PatchRequest) returns (PatchResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET object request
|
// GET object request
|
||||||
|
@ -583,6 +631,9 @@ message SearchRequest {
|
||||||
// object_id of parent
|
// object_id of parent
|
||||||
// * $Object:split.splitID \
|
// * $Object:split.splitID \
|
||||||
// 16 byte UUIDv4 used to identify the split object hierarchy parts
|
// 16 byte UUIDv4 used to identify the split object hierarchy parts
|
||||||
|
// * $Object:ec.parent \
|
||||||
|
// If the object is stored according to EC policy, then ec_parent
|
||||||
|
// attribute is set to return an id list of all related EC chunks.
|
||||||
//
|
//
|
||||||
// There are some well-known filter aliases to match objects by certain
|
// There are some well-known filter aliases to match objects by certain
|
||||||
// properties:
|
// properties:
|
||||||
|
@ -814,3 +865,74 @@ message PutSingleResponse {
|
||||||
// transmission.
|
// transmission.
|
||||||
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Object PATCH request
|
||||||
|
message PatchRequest {
|
||||||
|
// PATCH request body
|
||||||
|
message Body {
|
||||||
|
// The address of the object that is requested to get patched.
|
||||||
|
neo.fs.v2.refs.Address address = 1;
|
||||||
|
|
||||||
|
// New attributes for the object. See `replace_attributes` flag usage to
|
||||||
|
// define how new attributes should be set.
|
||||||
|
repeated neo.fs.v2.object.Header.Attribute new_attributes = 2;
|
||||||
|
|
||||||
|
// If this flag is set, then the object's attributes will be entirely
|
||||||
|
// replaced by `new_attributes` list. The empty `new_attributes` list with
|
||||||
|
// `replace_attributes = true` just resets attributes list for the object.
|
||||||
|
//
|
||||||
|
// Default `false` value for this flag means the attributes will be just
|
||||||
|
// merged. If the incoming `new_attributes` list contains already existing
|
||||||
|
// key, then it just replaces it while merging the lists.
|
||||||
|
bool replace_attributes = 3;
|
||||||
|
|
||||||
|
// The patch for the object's payload.
|
||||||
|
message Patch {
|
||||||
|
// The range of the source object for which the payload is replaced by the
|
||||||
|
// patch's chunk. If the range's `length = 0`, then the patch's chunk is
|
||||||
|
// just appended to the original payload starting from the `offest`
|
||||||
|
// without any replace.
|
||||||
|
Range source_range = 1;
|
||||||
|
|
||||||
|
// The chunk that is being appended to or that replaces the original
|
||||||
|
// payload on the given range.
|
||||||
|
bytes chunk = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The patch that is applied for the object.
|
||||||
|
Patch patch = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Body for patch request message.
|
||||||
|
Body body = 1;
|
||||||
|
|
||||||
|
// Carries request meta information. Header data is used only to regulate
|
||||||
|
// message transport and does not affect request execution.
|
||||||
|
neo.fs.v2.session.RequestMetaHeader meta_header = 2;
|
||||||
|
|
||||||
|
// Carries request verification information. This header is used to
|
||||||
|
// authenticate the nodes of the message route and check the correctness of
|
||||||
|
// transmission.
|
||||||
|
neo.fs.v2.session.RequestVerificationHeader verify_header = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Object PATCH response
|
||||||
|
message PatchResponse {
|
||||||
|
// PATCH response body
|
||||||
|
message Body {
|
||||||
|
// The object ID of the saved patched object.
|
||||||
|
neo.fs.v2.refs.ObjectID object_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Body for patch response message.
|
||||||
|
Body body = 1;
|
||||||
|
|
||||||
|
// Carries response meta information. Header data is used only to regulate
|
||||||
|
// message transport and does not affect request execution.
|
||||||
|
neo.fs.v2.session.ResponseMetaHeader meta_header = 2;
|
||||||
|
|
||||||
|
// Carries response verification information. This header is used to
|
||||||
|
// authenticate the nodes of the message route and check the correctness of
|
||||||
|
// transmission.
|
||||||
|
neo.fs.v2.session.ResponseVerificationHeader verify_header = 3;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.object;
|
package neo.fs.v2.object;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object/grpc;object";
|
|
||||||
option java_package = "frostfs.object";
|
option java_package = "frostfs.object";
|
||||||
|
|
||||||
import "refs/types.proto";
|
import "refs/types.proto";
|
||||||
|
@ -155,7 +154,7 @@ message Header {
|
||||||
// MIME Content Type of object's payload
|
// MIME Content Type of object's payload
|
||||||
//
|
//
|
||||||
// For detailed description of each well-known attribute please see the
|
// For detailed description of each well-known attribute please see the
|
||||||
// corresponding section in NeoFS Technical Specification.
|
// corresponding section in FrostFS Technical Specification.
|
||||||
message Attribute {
|
message Attribute {
|
||||||
// string key to the object attribute
|
// string key to the object attribute
|
||||||
string key = 1 [ json_name = "key" ];
|
string key = 1 [ json_name = "key" ];
|
||||||
|
@ -208,6 +207,18 @@ message Header {
|
||||||
uint32 header_length = 4 [ json_name = "headerLength" ];
|
uint32 header_length = 4 [ json_name = "headerLength" ];
|
||||||
// Chunk of a parent header.
|
// Chunk of a parent header.
|
||||||
bytes header = 5 [ json_name = "header" ];
|
bytes header = 5 [ json_name = "header" ];
|
||||||
|
// As the origin object is EC-splitted its identifier is known to all
|
||||||
|
// chunks as parent. But parent itself can be a part of Split (does not
|
||||||
|
// relate to EC-split). In this case parent_split_id should be set.
|
||||||
|
bytes parent_split_id = 6 [ json_name = "parentSplitID" ];
|
||||||
|
// EC-parent's parent ID. parent_split_parent_id is set if EC-parent,
|
||||||
|
// itself, is a part of Split and if an object ID of its parent is
|
||||||
|
// presented. The field allows to determine how EC-chunk is placed in Split
|
||||||
|
// hierarchy.
|
||||||
|
neo.fs.v2.refs.ObjectID parent_split_parent_id = 7
|
||||||
|
[ json_name = "parentSplitParentID" ];
|
||||||
|
// EC parent's attributes.
|
||||||
|
repeated Attribute parent_attributes = 8 [ json_name = "parentAttributes" ];
|
||||||
}
|
}
|
||||||
// Erasure code chunk information.
|
// Erasure code chunk information.
|
||||||
EC ec = 12 [ json_name = "ec" ];
|
EC ec = 12 [ json_name = "ec" ];
|
||||||
|
|
|
@ -2,10 +2,9 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.refs;
|
package neo.fs.v2.refs;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/grpc;refs";
|
|
||||||
option java_package = "frostfs.refs";
|
option java_package = "frostfs.refs";
|
||||||
|
|
||||||
// Objects in NeoFS are addressed by their ContainerID and ObjectID.
|
// Objects in FrostFS are addressed by their ContainerID and ObjectID.
|
||||||
//
|
//
|
||||||
// String presentation of `Address` is a concatenation of string encoded
|
// String presentation of `Address` is a concatenation of string encoded
|
||||||
// `ContainerID` and `ObjectID` delimited by '/' character.
|
// `ContainerID` and `ObjectID` delimited by '/' character.
|
||||||
|
@ -16,8 +15,9 @@ message Address {
|
||||||
ObjectID object_id = 2 [ json_name = "objectID" ];
|
ObjectID object_id = 2 [ json_name = "objectID" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeoFS Object unique identifier. Objects are immutable and content-addressed.
|
// FrostFS Object unique identifier. Objects are immutable and
|
||||||
// It means `ObjectID` will change if the `header` or the `payload` changes.
|
// content-addressed. It means `ObjectID` will change if the `header` or the
|
||||||
|
// `payload` changes.
|
||||||
//
|
//
|
||||||
// `ObjectID` is a 32 byte long
|
// `ObjectID` is a 32 byte long
|
||||||
// [SHA256](https://csrc.nist.gov/publications/detail/fips/180/4/final) hash of
|
// [SHA256](https://csrc.nist.gov/publications/detail/fips/180/4/final) hash of
|
||||||
|
@ -37,7 +37,7 @@ message ObjectID {
|
||||||
bytes value = 1 [ json_name = "value" ];
|
bytes value = 1 [ json_name = "value" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeoFS container identifier. Container structures are immutable and
|
// FrostFS container identifier. Container structures are immutable and
|
||||||
// content-addressed.
|
// content-addressed.
|
||||||
//
|
//
|
||||||
// `ContainerID` is a 32 byte long
|
// `ContainerID` is a 32 byte long
|
||||||
|
@ -90,7 +90,7 @@ message Version {
|
||||||
uint32 minor = 2 [ json_name = "minor" ];
|
uint32 minor = 2 [ json_name = "minor" ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signature of something in NeoFS.
|
// Signature of something in FrostFS.
|
||||||
message Signature {
|
message Signature {
|
||||||
// Public key used for signing
|
// Public key used for signing
|
||||||
bytes key = 1 [ json_name = "key" ];
|
bytes key = 1 [ json_name = "key" ];
|
||||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
||||||
|
|
||||||
package neo.fs.v2.session;
|
package neo.fs.v2.session;
|
||||||
|
|
||||||
option go_package = "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc;session";
|
|
||||||
option java_package = "frostfs.session";
|
option java_package = "frostfs.session";
|
||||||
|
|
||||||
import "refs/types.proto";
|
import "refs/types.proto";
|
||||||
|
@ -11,7 +10,7 @@ import "session/types.proto";
|
||||||
// `SessionService` allows to establish a temporary trust relationship between
|
// `SessionService` allows to establish a temporary trust relationship between
|
||||||
// two peer nodes and generate a `SessionToken` as the proof of trust to be
|
// two peer nodes and generate a `SessionToken` as the proof of trust to be
|
||||||
// attached in requests for further verification. Please see corresponding
|
// attached in requests for further verification. Please see corresponding
|
||||||
// section of NeoFS Technical Specification for details.
|
// section of FrostFS Technical Specification for details.
|
||||||
service SessionService {
|
service SessionService {
|
||||||
// Open a new session between two peers.
|
// Open a new session between two peers.
|
||||||
//
|
//
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue