Compare commits
No commits in common. "master" and "feature/add-codeowners" have entirely different histories.
master
...
feature/ad
100 changed files with 575 additions and 3014 deletions
112
README.md
112
README.md
|
@ -21,40 +21,31 @@ neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>
|
|||
### Container operations
|
||||
|
||||
```java
|
||||
import info.frostfs.sdk.FrostFSClient;
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.frostfs.sdk.dto.netmap.Replica;
|
||||
import info.frostfs.sdk.enums.BasicAcl;
|
||||
import info.frostfs.sdk.jdo.ClientSettings;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
||||
import info.frostfs.sdk.FrostFSClient;
|
||||
|
||||
public class ContainerExample {
|
||||
|
||||
public void example() {
|
||||
var callContext = new CallContext();
|
||||
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
||||
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
||||
|
||||
// Create container
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
||||
var prmContainerCreate = new PrmContainerCreate(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
var containerId = frostFSClient.createContainer(prmContainerCreate, callContext);
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, Boolean.TRUE);
|
||||
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
|
||||
// Get container
|
||||
var prmContainerGet = new PrmContainerGet(containerId);
|
||||
var container = frostFSClient.getContainer(prmContainerGet, callContext);
|
||||
var container = frostFSClient.getContainer(containerId);
|
||||
|
||||
// List containers
|
||||
var containerIds = frostFSClient.listContainers(new PrmContainerGetAll(), callContext);
|
||||
var containerIds = frostFSClient.listContainers();
|
||||
|
||||
// Delete container
|
||||
var prmContainerDelete = new PrmContainerDelete(containerId);
|
||||
frostFSClient.deleteContainer(prmContainerDelete, callContext);
|
||||
frostFSClient.deleteContainer(containerId);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -62,104 +53,45 @@ public class ContainerExample {
|
|||
### Object operations
|
||||
|
||||
```java
|
||||
import info.frostfs.sdk.dto.object.*;
|
||||
import info.frostfs.sdk.enums.ObjectType;
|
||||
import info.frostfs.sdk.jdo.ClientSettings;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||
import info.frostfs.sdk.FrostFSClient;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectExample {
|
||||
|
||||
public void example() {
|
||||
CallContext callContext = new CallContext();
|
||||
ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
|
||||
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
||||
|
||||
// Put object
|
||||
ObjectId objectId;
|
||||
try (FileInputStream file = new FileInputStream("/path/to/file/cat.jpg")) {
|
||||
var attribute = new ObjectAttribute("Filename", "cat.jpg");
|
||||
var cat = new ObjectHeader(containerId, ObjectType.REGULAR, attribute);
|
||||
var prmObjectPut = PrmObjectPut.builder().objectHeader(cat).build();
|
||||
var writer = frostFSClient.putObject(prmObjectPut, callContext);
|
||||
try (FileInputStream fis = new FileInputStream("cat.jpg")) {
|
||||
var cat = new ObjectHeader(
|
||||
containerId, ObjectType.REGULAR, new ObjectAttribute[]{new ObjectAttribute("Filename", "cat.jpg")}
|
||||
);
|
||||
|
||||
writer.write(file.readAllBytes());
|
||||
objectId = writer.complete();
|
||||
var params = new PutObjectParameters(cat, fis);
|
||||
objectId = frostFSClient.putObject(params);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// Get object
|
||||
var prmObjectGet = new PrmObjectGet(containerId, oid);
|
||||
ObjectFrostFS object = frostFSClient.getObject(prmObjectGet, callContext);
|
||||
|
||||
var reader = object.getObjectReader();
|
||||
var chunk = reader.readChunk();
|
||||
var length = chunk.length;
|
||||
byte[] buffer = null;
|
||||
while (length > 0) {
|
||||
buffer = isNull(buffer) ? chunk : ArrayHelper.concat(buffer, chunk);
|
||||
|
||||
chunk = object.getObjectReader().readChunk();
|
||||
length = ArrayUtils.isEmpty(chunk) ? 0 : chunk.length;
|
||||
}
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream("/path/to/file/newCat.jpg")) {
|
||||
fos.write(buffer);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
var obj = frostFSClient.getObject(containerId, objectId);
|
||||
|
||||
// Get object header
|
||||
var prmObjectHeadGet = new PrmObjectHeadGet(containerId, objectId);
|
||||
var objectHeader = frostFSClient.getObjectHead(prmObjectHeadGet, callContext);
|
||||
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
||||
|
||||
// Search regular objects
|
||||
var prmObjectSearch = new PrmObjectSearch(containerId, new ObjectFilter.FilterByRootObject());
|
||||
var objectIds = frostFSClient.searchObjects(prmObjectSearch, callContext);
|
||||
|
||||
// Delete object
|
||||
var prmObjectDelete = new PrmObjectDelete(containerId, objectId);
|
||||
frostFSClient.deleteObject(prmObjectDelete, callContext);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Pool init
|
||||
|
||||
```java
|
||||
import info.frostfs.sdk.jdo.ECDsa;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.pool.NodeParameters;
|
||||
import info.frostfs.sdk.jdo.pool.PoolInitParameters;
|
||||
import info.frostfs.sdk.pool.Pool;
|
||||
|
||||
public class PoolExample {
|
||||
|
||||
public static void example() {
|
||||
CallContext callContext = new CallContext();
|
||||
|
||||
//Init
|
||||
var nodeParam1 = new NodeParameters(1, <your_host1>, 1);
|
||||
var nodeParam2 = new NodeParameters(1, <your_host2>, 1);
|
||||
var nodeParam3 = new NodeParameters(1, <your_host3>, 1);
|
||||
var nodeParam4 = new NodeParameters(1, <your_host4>, 1);
|
||||
|
||||
PoolInitParameters initParameters = new PoolInitParameters();
|
||||
initParameters.setKey(new ECDsa(<your_key>));
|
||||
initParameters.setNodeParams(new NodeParameters[]{nodeParam1, nodeParam2, nodeParam3, nodeParam4});
|
||||
|
||||
|
||||
Pool pool = new Pool(initParameters);
|
||||
|
||||
//Dial (Required!)
|
||||
pool.dial(callContext);
|
||||
var objectIds = frostFSClient.searchObjects(containerId, new ObjectFilter.FilterByRootObject());
|
||||
}
|
||||
}
|
||||
```
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>frostfs-sdk-java</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>client</artifactId>
|
||||
|
@ -21,17 +21,17 @@
|
|||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>cryptography</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>models</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>exceptions</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
|
@ -54,10 +54,5 @@
|
|||
<artifactId>simpleclient_common</artifactId>
|
||||
<version>0.16.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,12 +1,13 @@
|
|||
package info.frostfs.sdk;
|
||||
|
||||
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.ContainerId;
|
||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||
import info.frostfs.sdk.dto.netmap.Version;
|
||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
|
@ -15,28 +16,14 @@ import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
|||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.ClientSettings;
|
||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
||||
import info.frostfs.sdk.pool.SessionCache;
|
||||
import info.frostfs.sdk.pool.WrapperPrm;
|
||||
import info.frostfs.sdk.services.CommonClient;
|
||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||
import info.frostfs.sdk.services.*;
|
||||
import info.frostfs.sdk.services.impl.*;
|
||||
import info.frostfs.sdk.services.impl.interceptor.Configuration;
|
||||
import info.frostfs.sdk.services.impl.interceptor.MonitoringClientInterceptor;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
||||
import info.frostfs.sdk.utils.Validator;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ClientInterceptors;
|
||||
import io.grpc.ManagedChannel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -44,49 +31,26 @@ import static info.frostfs.sdk.constants.ErrorConst.VERSION_UNSUPPORTED_TEMPLATE
|
|||
import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel;
|
||||
import static java.util.Objects.nonNull;
|
||||
|
||||
public class FrostFSClient implements CommonClient {
|
||||
private static final MonitoringClientInterceptor MONITORING_CLIENT_INTERCEPTOR =
|
||||
MonitoringClientInterceptor.create(Configuration.allMetrics());
|
||||
|
||||
public class FrostFSClient
|
||||
implements ContainerClient, ObjectClient, ApeManagerClient, NetmapClient, SessionClient, ToolsClient {
|
||||
private final ContainerClientImpl containerClientImpl;
|
||||
private final ObjectClientImpl objectClientImpl;
|
||||
private final ApeManagerClientImpl apeManagerClient;
|
||||
private final NetmapClientImpl netmapClientImpl;
|
||||
private final SessionClientImpl sessionClientImpl;
|
||||
private final ObjectToolsImpl objectToolsImpl;
|
||||
private final AccountingClientImpl accountingClient;
|
||||
private final ManagedChannel channel;
|
||||
|
||||
public FrostFSClient(ClientSettings clientSettings) {
|
||||
Validator.validate(clientSettings);
|
||||
this.channel = nonNull(clientSettings.getChannel())
|
||||
Channel channel = nonNull(clientSettings.getChannel())
|
||||
? clientSettings.getChannel()
|
||||
: initGrpcChannel(clientSettings);
|
||||
|
||||
Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR);
|
||||
ClientEnvironment clientEnvironment = new ClientEnvironment(
|
||||
clientSettings.getKey(), interceptChannel, new Version(), this,
|
||||
new SessionCache(0)
|
||||
);
|
||||
|
||||
Validator.validate(clientEnvironment);
|
||||
|
||||
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
||||
this.objectClientImpl = new ObjectClientImpl(clientEnvironment);
|
||||
this.apeManagerClient = new ApeManagerClientImpl(clientEnvironment);
|
||||
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
||||
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
||||
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
||||
this.accountingClient = new AccountingClientImpl(clientEnvironment);
|
||||
checkFrostFSVersionSupport(clientEnvironment.getVersion());
|
||||
}
|
||||
|
||||
public FrostFSClient(WrapperPrm prm, SessionCache cache) {
|
||||
this.channel = initGrpcChannel(prm.getAddress());
|
||||
|
||||
Channel interceptChannel = ClientInterceptors.intercept(channel, MONITORING_CLIENT_INTERCEPTOR);
|
||||
MonitoringClientInterceptor monitoringClientInterceptor = MonitoringClientInterceptor
|
||||
.create(Configuration.allMetrics());
|
||||
channel = ClientInterceptors.intercept(channel, monitoringClientInterceptor);
|
||||
ClientEnvironment clientEnvironment =
|
||||
new ClientEnvironment(prm.getKey(), interceptChannel, new Version(), this, cache);
|
||||
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
|
||||
|
||||
Validator.validate(clientEnvironment);
|
||||
|
||||
|
@ -96,12 +60,11 @@ public class FrostFSClient implements CommonClient {
|
|||
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
||||
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
||||
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
||||
this.accountingClient = new AccountingClientImpl(clientEnvironment);
|
||||
checkFrostFSVersionSupport(clientEnvironment.getVersion());
|
||||
checkFrostFsVersionSupport(clientEnvironment.getVersion());
|
||||
}
|
||||
|
||||
private void checkFrostFSVersionSupport(Version version) {
|
||||
var localNodeInfo = netmapClientImpl.getLocalNodeInfo(new CallContext());
|
||||
private void checkFrostFsVersionSupport(Version version) {
|
||||
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
||||
if (!localNodeInfo.getVersion().isSupported(version)) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion())
|
||||
|
@ -110,115 +73,96 @@ public class FrostFSClient implements CommonClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Container getContainer(PrmContainerGet args, CallContext ctx) {
|
||||
return containerClientImpl.getContainer(args, ctx);
|
||||
public Container getContainer(ContainerId cid) {
|
||||
return containerClientImpl.getContainer(cid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx) {
|
||||
return containerClientImpl.listContainers(args, ctx);
|
||||
public List<ContainerId> listContainers() {
|
||||
return containerClientImpl.listContainers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) {
|
||||
return containerClientImpl.createContainer(args, ctx);
|
||||
public ContainerId createContainer(Container container) {
|
||||
return containerClientImpl.createContainer(container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContainer(PrmContainerDelete args, CallContext ctx) {
|
||||
containerClientImpl.deleteContainer(args, ctx);
|
||||
public void deleteContainer(ContainerId cid) {
|
||||
containerClientImpl.deleteContainer(cid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) {
|
||||
return objectClientImpl.getObjectHead(args, ctx);
|
||||
public ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId) {
|
||||
return objectClientImpl.getObjectHead(containerId, objectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) {
|
||||
return objectClientImpl.getObject(args, ctx);
|
||||
public ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId) {
|
||||
return objectClientImpl.getObject(containerId, objectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) {
|
||||
return objectClientImpl.putObject(args, ctx);
|
||||
public ObjectId putObject(PutObjectParameters parameters) {
|
||||
return objectClientImpl.putObject(parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) {
|
||||
return objectClientImpl.putClientCutObject(args, ctx);
|
||||
public ObjectId putSingleObject(ObjectFrostFS objectFrostFS) {
|
||||
return objectClientImpl.putSingleObject(objectFrostFS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) {
|
||||
return objectClientImpl.putSingleObject(args, ctx);
|
||||
public void deleteObject(ContainerId containerId, ObjectId objectId) {
|
||||
objectClientImpl.deleteObject(containerId, objectId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObject(PrmObjectDelete args, CallContext ctx) {
|
||||
objectClientImpl.deleteObject(args, ctx);
|
||||
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
||||
return objectClientImpl.searchObjects(cid, filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx) {
|
||||
return objectClientImpl.searchObjects(args, ctx);
|
||||
public byte[] addChain(Chain chain, ChainTarget chainTarget) {
|
||||
return apeManagerClient.addChain(chain, chainTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] addChain(PrmApeChainAdd args, CallContext ctx) {
|
||||
return apeManagerClient.addChain(args, ctx);
|
||||
public void removeChain(Chain chain, ChainTarget chainTarget) {
|
||||
apeManagerClient.removeChain(chain, chainTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChain(PrmApeChainRemove args, CallContext ctx) {
|
||||
apeManagerClient.removeChain(args, ctx);
|
||||
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||
return apeManagerClient.listChains(chainTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
return apeManagerClient.listChains(args, ctx);
|
||||
public NetmapSnapshot getNetmapSnapshot() {
|
||||
return netmapClientImpl.getNetmapSnapshot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetmapSnapshot getNetmapSnapshot(CallContext ctx) {
|
||||
return netmapClientImpl.getNetmapSnapshot(ctx);
|
||||
public NodeInfo getLocalNodeInfo() {
|
||||
return netmapClientImpl.getLocalNodeInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeInfo getLocalNodeInfo(CallContext ctx) {
|
||||
return netmapClientImpl.getLocalNodeInfo(ctx);
|
||||
public NetworkSettings getNetworkSettings() {
|
||||
return netmapClientImpl.getNetworkSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkSettings getNetworkSettings(CallContext ctx) {
|
||||
return netmapClientImpl.getNetworkSettings(ctx);
|
||||
public SessionToken createSession(long expiration) {
|
||||
return sessionClientImpl.createSession(expiration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionToken createSession(PrmSessionCreate args, CallContext ctx) {
|
||||
return sessionClientImpl.createSession(args, ctx);
|
||||
}
|
||||
|
||||
public frostfs.session.Types.SessionToken createSessionInternal(PrmSessionCreate args, CallContext ctx) {
|
||||
return sessionClientImpl.createSessionInternal(args, ctx);
|
||||
public frostfs.session.Types.SessionToken createSessionInternal(long expiration) {
|
||||
return sessionClientImpl.createSessionInternal(expiration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||
return objectToolsImpl.calculateObjectId(header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Types.Decimal getBalance(CallContext ctx) {
|
||||
return accountingClient.getBalance(ctx);
|
||||
}
|
||||
|
||||
public String dial(CallContext ctx) {
|
||||
accountingClient.getBalance(ctx);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
channel.shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package info.frostfs.sdk.constants;
|
||||
|
||||
public class PoolConst {
|
||||
public static final int DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION = 100; // in epochs
|
||||
public static final int DEFAULT_ERROR_THRESHOLD = 100;
|
||||
public static final int DEFAULT_GRACEFUL_CLOSE_ON_SWITCH_TIMEOUT = 10; // Seconds
|
||||
public static final int DEFAULT_REBALANCE_INTERVAL = 15; // Seconds
|
||||
public static final int DEFAULT_HEALTHCHECK_TIMEOUT = 4; // Seconds
|
||||
public static final int DEFAULT_DIAL_TIMEOUT = 5; // Seconds
|
||||
public static final int DEFAULT_STREAM_TIMEOUT = 10; // Seconds
|
||||
|
||||
private PoolConst() {
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
public enum HealthyStatus {
|
||||
// status HEALTHY is set when connection is ready to be used by the pool.
|
||||
HEALTHY(1),
|
||||
|
||||
// status UNHEALTHY_ON_REQUEST is set when communication after dialing to the
|
||||
// endpoint is failed due to immediate or accumulated errors, connection is
|
||||
// available and pool should close it before re-establishing connection once again.
|
||||
UNHEALTHY_ON_REQUEST(2),
|
||||
|
||||
// status UNHEALTHY_ON_DIAL is set when dialing to the endpoint is failed,
|
||||
// so there is no connection to the endpoint, and pool should not close it
|
||||
// before re-establishing connection once again.
|
||||
UNHEALTHY_ON_DIAL(3),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
HealthyStatus(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
public enum MethodIndex {
|
||||
METHOD_BALANCE_GET("balanceGet"),
|
||||
METHOD_CONTAINER_PUT("containerPut"),
|
||||
METHOD_CONTAINER_GET("ContainerGet"),
|
||||
METHOD_CONTAINER_LIST("ContainerList"),
|
||||
METHOD_CONTAINER_DELETE("ContainerDelete"),
|
||||
METHOD_ENDPOINT_INFO("EndpointInfo"),
|
||||
METHOD_NETWORK_INFO("NetworkInfo"),
|
||||
METHOD_NETMAP_SNAPSHOT("NetMapSnapshot"),
|
||||
METHOD_OBJECT_PUT("ObjectPut"),
|
||||
METHOD_OBJECT_DELETE("ObjectDelete"),
|
||||
METHOD_OBJECT_GET("ObjectGet"),
|
||||
METHOD_OBJECT_HEAD("ObjectHead"),
|
||||
METHOD_OBJECT_RANGE("ObjectRange"),
|
||||
METHOD_OBJECT_PATCH("ObjectPatch"),
|
||||
METHOD_SESSION_CREATE("SessionCreate"),
|
||||
METHOD_APE_MANAGER_ADD_CHAIN("APEManagerAddChain"),
|
||||
METHOD_APE_MANAGER_REMOVE_CHAIN("APEManagerRemoveChain"),
|
||||
METHOD_APE_MANAGER_LIST_CHAINS("APEManagerListChains"),
|
||||
;
|
||||
|
||||
public final String methodName;
|
||||
|
||||
MethodIndex(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import info.frostfs.sdk.dto.response.ResponseStatus;
|
|||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class ResponseFrostFSException extends FrostFSException {
|
||||
public class ResponseFrostFSException extends RuntimeException {
|
||||
private final ResponseStatus status;
|
||||
|
||||
public ResponseFrostFSException(ResponseStatus status) {
|
||||
|
|
|
@ -5,14 +5,9 @@ import info.frostfs.sdk.annotations.NotNull;
|
|||
import info.frostfs.sdk.annotations.Validate;
|
||||
import info.frostfs.sdk.dto.netmap.Version;
|
||||
import info.frostfs.sdk.dto.object.OwnerId;
|
||||
import info.frostfs.sdk.pool.SessionCache;
|
||||
import io.grpc.Channel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import static info.frostfs.sdk.Helper.getHexString;
|
||||
import static info.frostfs.sdk.pool.Pool.formCacheKey;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
@ -20,48 +15,27 @@ public class ClientEnvironment {
|
|||
|
||||
@NotNull
|
||||
private final OwnerId ownerId;
|
||||
|
||||
@NotNull
|
||||
private final Version version;
|
||||
|
||||
@NotNull
|
||||
@Validate
|
||||
private final ECDsa key;
|
||||
|
||||
@NotNull
|
||||
private final Channel channel;
|
||||
|
||||
@NotNull
|
||||
private final FrostFSClient frostFSClient;
|
||||
|
||||
private String sessionKey;
|
||||
private String address;
|
||||
private NetworkSettings networkSettings;
|
||||
|
||||
private SessionCache sessionCache;
|
||||
|
||||
public ClientEnvironment(String wif, Channel channel, Version version, FrostFSClient frostFSClient,
|
||||
SessionCache sessionCache) {
|
||||
public ClientEnvironment(String wif, Channel channel, Version version, FrostFSClient frostFSClient) {
|
||||
this.key = new ECDsa(wif);
|
||||
this.ownerId = new OwnerId(key.getPublicKeyByte());
|
||||
this.version = version;
|
||||
this.channel = channel;
|
||||
this.frostFSClient = frostFSClient;
|
||||
this.sessionCache = sessionCache;
|
||||
this.address = channel.authority();
|
||||
}
|
||||
|
||||
public ClientEnvironment(ECDsa key, Channel channel, Version version, FrostFSClient frostFSClient,
|
||||
SessionCache sessionCache) {
|
||||
this.key = key;
|
||||
this.ownerId = new OwnerId(key.getPublicKeyByte());
|
||||
this.version = version;
|
||||
this.channel = channel;
|
||||
this.frostFSClient = frostFSClient;
|
||||
this.sessionCache = sessionCache;
|
||||
}
|
||||
|
||||
public String getSessionKey() {
|
||||
if (StringUtils.isBlank(sessionKey)) {
|
||||
this.sessionKey = formCacheKey(address, getHexString(key.getPublicKeyByte()));
|
||||
}
|
||||
|
||||
return sessionKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package info.frostfs.sdk.jdo;
|
|||
|
||||
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ChannelCredentials;
|
||||
import io.grpc.ManagedChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class ClientSettings {
|
|||
|
||||
private String host;
|
||||
private ChannelCredentials credentials;
|
||||
private ManagedChannel channel;
|
||||
private Channel channel;
|
||||
|
||||
public ClientSettings(String key, String host) {
|
||||
this.key = key;
|
||||
|
@ -30,7 +30,7 @@ public class ClientSettings {
|
|||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
public ClientSettings(String key, ManagedChannel channel) {
|
||||
public ClientSettings(String key, Channel channel) {
|
||||
this.key = key;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package info.frostfs.sdk.jdo;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PutObjectParameters {
|
||||
|
||||
@NotNull
|
||||
private ObjectHeader header;
|
||||
|
||||
@NotNull
|
||||
private InputStream payload;
|
||||
|
||||
private boolean clientCut;
|
||||
private int bufferMaxSize;
|
||||
private byte[] customerBuffer;
|
||||
private SessionToken sessionToken;
|
||||
private int maxObjectSizeCache;
|
||||
private long currentStreamPosition;
|
||||
private long fullLength;
|
||||
|
||||
public PutObjectParameters(ObjectHeader header, InputStream payload, boolean clientCut, int bufferMaxSize) {
|
||||
this.header = header;
|
||||
this.payload = payload;
|
||||
this.clientCut = clientCut;
|
||||
this.bufferMaxSize = bufferMaxSize;
|
||||
}
|
||||
|
||||
public PutObjectParameters(ObjectHeader header, InputStream payload) {
|
||||
this.header = header;
|
||||
this.payload = payload;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package info.frostfs.sdk.jdo.parameters;
|
||||
package info.frostfs.sdk.jdo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -8,14 +8,14 @@ import java.time.LocalDateTime;
|
|||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class PrmWait {
|
||||
public class WaitParameters {
|
||||
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120);
|
||||
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
|
||||
|
||||
private final Duration timeout;
|
||||
private final Duration pollInterval;
|
||||
|
||||
public PrmWait() {
|
||||
public WaitParameters() {
|
||||
this.timeout = DEFAULT_TIMEOUT;
|
||||
this.pollInterval = DEFAULT_POLL_INTERVAL;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_GRPC_TIMEOUT;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class CallContext {
|
||||
private final long timeout;
|
||||
private final TimeUnit timeUnit;
|
||||
|
||||
public CallContext() {
|
||||
this.timeout = DEFAULT_GRPC_TIMEOUT;
|
||||
this.timeUnit = TimeUnit.SECONDS;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.ape;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmApeChainAdd {
|
||||
@NotNull
|
||||
private Chain chain;
|
||||
@NotNull
|
||||
private ChainTarget chainTarget;
|
||||
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmApeChainAdd(Chain chain, ChainTarget chainTarget) {
|
||||
this.chain = chain;
|
||||
this.chainTarget = chainTarget;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.ape;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmApeChainList {
|
||||
@NotNull
|
||||
private ChainTarget chainTarget;
|
||||
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmApeChainList(ChainTarget chainTarget) {
|
||||
this.chainTarget = chainTarget;
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.ape;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmApeChainRemove {
|
||||
@NotNull
|
||||
private Chain chain;
|
||||
@NotNull
|
||||
private ChainTarget chainTarget;
|
||||
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmApeChainRemove(Chain chain, ChainTarget chainTarget) {
|
||||
this.chain = chain;
|
||||
this.chainTarget = chainTarget;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.container;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.PrmWait;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmContainerCreate implements SessionContext {
|
||||
@NotNull
|
||||
private Container container;
|
||||
|
||||
private PrmWait waitParams;
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmContainerCreate(Container container, PrmWait waitParams) {
|
||||
this.container = container;
|
||||
this.waitParams = waitParams;
|
||||
}
|
||||
|
||||
public PrmContainerCreate(Container container) {
|
||||
this.container = container;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.container;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.PrmWait;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmContainerDelete implements SessionContext {
|
||||
@NotNull
|
||||
private ContainerId containerId;
|
||||
|
||||
private PrmWait waitParams;
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmContainerDelete(ContainerId containerId, PrmWait waitParams) {
|
||||
this.containerId = containerId;
|
||||
this.waitParams = waitParams;
|
||||
}
|
||||
|
||||
public PrmContainerDelete(ContainerId containerId) {
|
||||
this.containerId = containerId;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.container;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmContainerGet {
|
||||
@NotNull
|
||||
private ContainerId containerId;
|
||||
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmContainerGet(ContainerId containerId) {
|
||||
this.containerId = containerId;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.container;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PrmContainerGetAll {
|
||||
private Map<String, String> xHeaders;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectClientCutPut implements PrmObjectPutBase, SessionContext {
|
||||
@NotNull
|
||||
private final PutObjectContext putObjectContext = new PutObjectContext();
|
||||
@NotNull
|
||||
private ObjectHeader objectHeader;
|
||||
@NotNull
|
||||
private InputStream payload;
|
||||
private int bufferMaxSize;
|
||||
private byte[] customerBuffer;
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectDelete implements SessionContext {
|
||||
@NotNull
|
||||
private ContainerId containerId;
|
||||
@NotNull
|
||||
private ObjectId objectId;
|
||||
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmObjectDelete(ContainerId containerId, ObjectId objectId) {
|
||||
this.containerId = containerId;
|
||||
this.objectId = objectId;
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectGet implements SessionContext {
|
||||
@NotNull
|
||||
private ContainerId containerId;
|
||||
@NotNull
|
||||
private ObjectId objectId;
|
||||
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmObjectGet(ContainerId containerId, ObjectId objectId) {
|
||||
this.containerId = containerId;
|
||||
this.objectId = objectId;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectHeadGet implements SessionContext {
|
||||
@NotNull
|
||||
private ContainerId containerId;
|
||||
@NotNull
|
||||
private ObjectId objectId;
|
||||
|
||||
private boolean raw;
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmObjectHeadGet(ContainerId containerId, ObjectId objectId) {
|
||||
this.containerId = containerId;
|
||||
this.objectId = objectId;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectPut implements PrmObjectPutBase, SessionContext {
|
||||
@NotNull
|
||||
private final PutObjectContext putObjectContext = new PutObjectContext();
|
||||
@NotNull
|
||||
private ObjectHeader objectHeader;
|
||||
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmObjectPut(ObjectHeader objectHeader) {
|
||||
this.objectHeader = objectHeader;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PrmObjectPutBase extends SessionContext {
|
||||
ObjectHeader getObjectHeader();
|
||||
|
||||
Map<String, String> getXHeaders();
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectSearch implements SessionContext {
|
||||
@NotNull
|
||||
private ContainerId containerId;
|
||||
@NotNull
|
||||
private ObjectFilter<?>[] filters;
|
||||
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmObjectSearch(ContainerId containerId, ObjectFilter<?>... filters) {
|
||||
this.containerId = containerId;
|
||||
this.filters = filters;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmObjectSinglePut implements SessionContext {
|
||||
@NotNull
|
||||
private ObjectFrostFS objectFrostFS;
|
||||
|
||||
private SessionToken sessionToken;
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmObjectSinglePut(ObjectFrostFS objectFrostFS) {
|
||||
this.objectFrostFS = objectFrostFS;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.object;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class PutObjectContext {
|
||||
private int maxObjectSizeCache;
|
||||
private long currentStreamPosition;
|
||||
private long fullLength;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.session;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class PrmSessionCreate {
|
||||
private long expiration; //-1 is max
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmSessionCreate(long expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.parameters.session;
|
||||
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
|
||||
public interface SessionContext {
|
||||
SessionToken getSessionToken();
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.pool;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class NodeParameters {
|
||||
private final int priority;
|
||||
private final String address;
|
||||
private final double weight;
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.pool;
|
||||
|
||||
import info.frostfs.sdk.jdo.ECDsa;
|
||||
import info.frostfs.sdk.pool.ClientWrapper;
|
||||
import io.grpc.ClientInterceptors;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PoolInitParameters {
|
||||
private ECDsa key;
|
||||
|
||||
private long nodeDialTimeout;
|
||||
|
||||
private long nodeStreamTimeout;
|
||||
|
||||
private long healthCheckTimeout;
|
||||
|
||||
private long clientRebalanceInterval;
|
||||
|
||||
private long sessionExpirationDuration;
|
||||
|
||||
private int errorThreshold;
|
||||
|
||||
private NodeParameters[] nodeParams;
|
||||
|
||||
private ChannelOption<?>[] dialOptions;
|
||||
|
||||
private Function<String, ClientWrapper> clientBuilder;
|
||||
|
||||
private long gracefulCloseOnSwitchTimeout;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
private Collection<ClientInterceptors> interceptors = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package info.frostfs.sdk.jdo.result;
|
||||
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.object.SplitInfo;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
public class ObjectHeaderResult {
|
||||
private ObjectHeader headerInfo;
|
||||
private SplitInfo splitInfo;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
public interface ClientStatus {
|
||||
// isHealthy checks if the connection can handle requests.
|
||||
boolean isHealthy();
|
||||
|
||||
// isDialed checks if the connection was created.
|
||||
boolean isDialed();
|
||||
|
||||
// setUnhealthy marks client as unhealthy.
|
||||
void setUnhealthy();
|
||||
|
||||
// address return address of endpoint.
|
||||
String getAddress();
|
||||
|
||||
// currentErrorRate returns current errors rate.
|
||||
// After specific threshold connection is considered as unhealthy.
|
||||
// Pool.startRebalance routine can make this connection healthy again.
|
||||
int getCurrentErrorRate();
|
||||
|
||||
// overallErrorRate returns the number of all happened errors.
|
||||
long getOverallErrorRate();
|
||||
|
||||
// methodsStatus returns statistic for all used methods.
|
||||
StatusSnapshot[] getMethodsStatus();
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import info.frostfs.sdk.enums.HealthyStatus;
|
||||
import info.frostfs.sdk.enums.MethodIndex;
|
||||
import info.frostfs.sdk.utils.FrostFSMessages;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ClientStatusMonitor implements ClientStatus {
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final Logger logger;
|
||||
private final AtomicInteger healthy = new AtomicInteger();
|
||||
|
||||
private final String address;
|
||||
private final MethodStatus[] methods;
|
||||
|
||||
private int errorThreshold;
|
||||
private int currentErrorCount;
|
||||
private long overallErrorCount;
|
||||
|
||||
public ClientStatusMonitor(Logger logger, String address) {
|
||||
this.logger = logger;
|
||||
this.healthy.set(HealthyStatus.HEALTHY.value);
|
||||
|
||||
this.address = address;
|
||||
this.methods = Arrays.stream(MethodIndex.values())
|
||||
.map(t -> new MethodStatus(t.methodName))
|
||||
.toArray(MethodStatus[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHealthy() {
|
||||
return healthy.get() == HealthyStatus.HEALTHY.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDialed() {
|
||||
return healthy.get() != HealthyStatus.UNHEALTHY_ON_DIAL.value;
|
||||
}
|
||||
|
||||
public void setHealthy() {
|
||||
healthy.set(HealthyStatus.HEALTHY.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnhealthy() {
|
||||
healthy.set(HealthyStatus.UNHEALTHY_ON_REQUEST.value);
|
||||
}
|
||||
|
||||
public void setUnhealthyOnDial() {
|
||||
healthy.set(HealthyStatus.UNHEALTHY_ON_DIAL.value);
|
||||
}
|
||||
|
||||
public void incErrorRate() {
|
||||
boolean thresholdReached;
|
||||
lock.lock();
|
||||
try {
|
||||
currentErrorCount++;
|
||||
overallErrorCount++;
|
||||
|
||||
thresholdReached = currentErrorCount >= errorThreshold;
|
||||
|
||||
if (thresholdReached) {
|
||||
setUnhealthy();
|
||||
currentErrorCount = 0;
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
if (thresholdReached && logger != null) {
|
||||
FrostFSMessages.errorThresholdReached(logger, address, errorThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentErrorRate() {
|
||||
lock.lock();
|
||||
try {
|
||||
return currentErrorCount;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getOverallErrorRate() {
|
||||
lock.lock();
|
||||
try {
|
||||
return overallErrorCount;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusSnapshot[] getMethodsStatus() {
|
||||
StatusSnapshot[] result = new StatusSnapshot[methods.length];
|
||||
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = methods[i].getSnapshot();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import info.frostfs.sdk.FrostFSClient;
|
||||
import info.frostfs.sdk.enums.MethodIndex;
|
||||
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.utils.WaitUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.POOL_CLIENT_UNHEALTHY;
|
||||
|
||||
@Getter
|
||||
public class ClientWrapper extends ClientStatusMonitor {
|
||||
@Getter(value = AccessLevel.NONE)
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final SessionCache sessionCache;
|
||||
private final WrapperPrm wrapperPrm;
|
||||
private FrostFSClient client;
|
||||
|
||||
public ClientWrapper(WrapperPrm wrapperPrm, Pool pool) {
|
||||
super(wrapperPrm.getLogger(), wrapperPrm.getAddress());
|
||||
this.wrapperPrm = wrapperPrm;
|
||||
setErrorThreshold(wrapperPrm.getErrorThreshold());
|
||||
|
||||
this.sessionCache = pool.getSessionCache();
|
||||
this.client = new FrostFSClient(wrapperPrm, sessionCache);
|
||||
}
|
||||
|
||||
|
||||
public FrostFSClient getClient() {
|
||||
lock.lock();
|
||||
try {
|
||||
if (isHealthy()) {
|
||||
return client;
|
||||
}
|
||||
return null;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void dial(CallContext ctx) {
|
||||
FrostFSClient client = getClient();
|
||||
if (client == null) {
|
||||
throw new ValidationFrostFSException(POOL_CLIENT_UNHEALTHY);
|
||||
}
|
||||
client.dial(ctx);
|
||||
}
|
||||
|
||||
public void handleError(Exception exp) {
|
||||
if (exp instanceof ResponseFrostFSException && ((ResponseFrostFSException) exp).getStatus() != null) {
|
||||
switch (((ResponseFrostFSException) exp).getStatus().getCode()) {
|
||||
case INTERNAL:
|
||||
case WRONG_MAGIC_NUMBER:
|
||||
case SIGNATURE_VERIFICATION_FAILURE:
|
||||
case NODE_UNDER_MAINTENANCE:
|
||||
incErrorRate();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
incErrorRate();
|
||||
}
|
||||
|
||||
private void scheduleGracefulClose() {
|
||||
if (client == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WaitUtil.sleep(wrapperPrm.getGracefulCloseOnSwitchTimeout());
|
||||
client.close();
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> restartIfUnhealthy(CallContext ctx) {
|
||||
try {
|
||||
client.getLocalNodeInfo(ctx);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (isDialed()) {
|
||||
scheduleGracefulClose();
|
||||
}
|
||||
|
||||
return CompletableFuture.completedFuture(restartClient(ctx));
|
||||
}
|
||||
|
||||
private boolean restartClient(CallContext ctx) {
|
||||
FrostFSClient newClient = null;
|
||||
try {
|
||||
newClient = new FrostFSClient(wrapperPrm, sessionCache);
|
||||
|
||||
var error = newClient.dial(ctx);
|
||||
if (StringUtils.isNotBlank(error)) {
|
||||
setUnhealthyOnDial();
|
||||
newClient.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
client = newClient;
|
||||
lock.unlock();
|
||||
} catch (Exception exp) {
|
||||
if (newClient != null) {
|
||||
newClient.close();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
client.getLocalNodeInfo(ctx);
|
||||
} catch (Exception exp) {
|
||||
setUnhealthy();
|
||||
return true;
|
||||
}
|
||||
|
||||
setHealthy();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void incRequests(long elapsed, MethodIndex method) {
|
||||
var methodStat = getMethods()[method.ordinal()];
|
||||
methodStat.incRequests(elapsed);
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
class InnerPool {
|
||||
private static final int ATTEMPTS_COUNT = 3;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final ClientWrapper[] clients;
|
||||
private Sampler sampler;
|
||||
|
||||
InnerPool(Sampler sampler, ClientWrapper[] clients) {
|
||||
this.sampler = sampler;
|
||||
this.clients = clients;
|
||||
}
|
||||
|
||||
Sampler getSampler() {
|
||||
return sampler;
|
||||
}
|
||||
|
||||
void setSampler(Sampler sampler) {
|
||||
this.sampler = sampler;
|
||||
}
|
||||
|
||||
ClientWrapper[] getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
ClientWrapper connection() {
|
||||
lock.lock();
|
||||
try {
|
||||
if (clients.length == 1) {
|
||||
ClientWrapper client = clients[0];
|
||||
if (client.isHealthy()) {
|
||||
return client;
|
||||
}
|
||||
} else {
|
||||
int attempts = ATTEMPTS_COUNT * clients.length;
|
||||
|
||||
for (int i = 0; i < attempts; i++) {
|
||||
int index = sampler.next();
|
||||
|
||||
if (clients[index].isHealthy()) {
|
||||
return clients[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class MethodStatus {
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final String name;
|
||||
private StatusSnapshot snapshot;
|
||||
|
||||
public MethodStatus(String name) {
|
||||
this.name = name;
|
||||
this.snapshot = new StatusSnapshot();
|
||||
}
|
||||
|
||||
void incRequests(long elapsed) {
|
||||
lock.lock();
|
||||
try {
|
||||
snapshot.setAllTime(snapshot.getAllTime() + elapsed);
|
||||
snapshot.setAllRequests(snapshot.getAllRequests() + 1);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class NodeStatistic {
|
||||
private String address;
|
||||
private StatusSnapshot[] methods;
|
||||
private long overallErrors;
|
||||
private int currentErrors;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class NodesParam {
|
||||
private final int priority;
|
||||
private final List<String> address;
|
||||
private final List<Double> weight;
|
||||
|
||||
public NodesParam(int priority) {
|
||||
this.priority = priority;
|
||||
this.address = new ArrayList<>();
|
||||
this.weight = new ArrayList<>();
|
||||
}
|
||||
}
|
|
@ -1,535 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import frostfs.refs.Types;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.dto.object.OwnerId;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
||||
import info.frostfs.sdk.exceptions.SessionExpiredFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.SessionNotFoundFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.ECDsa;
|
||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
||||
import info.frostfs.sdk.jdo.pool.NodeParameters;
|
||||
import info.frostfs.sdk.jdo.pool.PoolInitParameters;
|
||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
||||
import info.frostfs.sdk.services.CommonClient;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
||||
import info.frostfs.sdk.utils.FrostFSMessages;
|
||||
import info.frostfs.sdk.utils.WaitUtil;
|
||||
import lombok.Getter;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static info.frostfs.sdk.Helper.getHexString;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||
import static info.frostfs.sdk.constants.PoolConst.*;
|
||||
|
||||
@Getter
|
||||
public class Pool implements CommonClient {
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final ECDsa key;
|
||||
private final SessionCache sessionCache;
|
||||
private final long sessionTokenDuration;
|
||||
private final RebalanceParameters rebalanceParams;
|
||||
private final Function<String, ClientWrapper> clientBuilder;
|
||||
private final Logger logger;
|
||||
private InnerPool[] innerPools;
|
||||
private Types.OwnerID ownerID;
|
||||
private OwnerId ownerId;
|
||||
private boolean disposedValue;
|
||||
private long maxObjectSize;
|
||||
private ClientStatus clientStatus;
|
||||
|
||||
public Pool(PoolInitParameters options) {
|
||||
if (options == null || options.getKey() == null) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(
|
||||
PARAMS_ARE_MISSING_TEMPLATE,
|
||||
String.join(
|
||||
FIELDS_DELIMITER_COMMA, PoolInitParameters.class.getName(), ECDsa.class.getName()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
List<NodesParam> nodesParams = adjustNodeParams(options.getNodeParams());
|
||||
SessionCache cache = new SessionCache(options.getSessionExpirationDuration());
|
||||
fillDefaultInitParams(options, this);
|
||||
|
||||
this.key = options.getKey();
|
||||
this.sessionCache = cache;
|
||||
this.logger = options.getLogger();
|
||||
this.sessionTokenDuration = options.getSessionExpirationDuration();
|
||||
|
||||
this.rebalanceParams = new RebalanceParameters(
|
||||
nodesParams.toArray(new NodesParam[0]),
|
||||
options.getHealthCheckTimeout(),
|
||||
options.getClientRebalanceInterval(),
|
||||
options.getSessionExpirationDuration());
|
||||
|
||||
this.clientBuilder = options.getClientBuilder();
|
||||
}
|
||||
|
||||
private static List<NodesParam> adjustNodeParams(NodeParameters[] nodeParams) {
|
||||
if (nodeParams == null || nodeParams.length == 0) {
|
||||
throw new ValidationFrostFSException(POOL_PEERS_IS_MISSING);
|
||||
}
|
||||
|
||||
Map<Integer, NodesParam> nodesParamsDict = new HashMap<>(nodeParams.length);
|
||||
for (NodeParameters nodeParam : nodeParams) {
|
||||
var nodesParam = nodesParamsDict
|
||||
.computeIfAbsent(nodeParam.getPriority(), k -> new NodesParam(nodeParam.getPriority()));
|
||||
nodesParam.getAddress().add(nodeParam.getAddress());
|
||||
nodesParam.getWeight().add(nodeParam.getWeight());
|
||||
}
|
||||
|
||||
List<NodesParam> nodesParams = new ArrayList<>(nodesParamsDict.values());
|
||||
nodesParams.sort(Comparator.comparingInt(NodesParam::getPriority));
|
||||
|
||||
for (NodesParam nodes : nodesParams) {
|
||||
double[] newWeights = adjustWeights(nodes.getWeight().stream().mapToDouble(Double::doubleValue).toArray());
|
||||
nodes.getWeight().clear();
|
||||
for (double weight : newWeights) {
|
||||
nodes.getWeight().add(weight);
|
||||
}
|
||||
}
|
||||
|
||||
return nodesParams;
|
||||
}
|
||||
|
||||
private static double[] adjustWeights(double[] weights) {
|
||||
double[] adjusted = new double[weights.length];
|
||||
double sum = Arrays.stream(weights).sum();
|
||||
|
||||
if (sum > 0) {
|
||||
for (int i = 0; i < weights.length; i++) {
|
||||
adjusted[i] = weights[i] / sum;
|
||||
}
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
private static void fillDefaultInitParams(PoolInitParameters parameters, Pool pool) {
|
||||
if (parameters.getSessionExpirationDuration() == 0) {
|
||||
parameters.setSessionExpirationDuration(DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION);
|
||||
}
|
||||
|
||||
if (parameters.getErrorThreshold() == 0) {
|
||||
parameters.setErrorThreshold(DEFAULT_ERROR_THRESHOLD);
|
||||
}
|
||||
|
||||
if (parameters.getClientRebalanceInterval() <= 0) {
|
||||
parameters.setClientRebalanceInterval(DEFAULT_REBALANCE_INTERVAL);
|
||||
}
|
||||
|
||||
if (parameters.getGracefulCloseOnSwitchTimeout() <= 0) {
|
||||
parameters.setGracefulCloseOnSwitchTimeout(DEFAULT_GRACEFUL_CLOSE_ON_SWITCH_TIMEOUT);
|
||||
}
|
||||
|
||||
if (parameters.getHealthCheckTimeout() <= 0) {
|
||||
parameters.setHealthCheckTimeout(DEFAULT_HEALTHCHECK_TIMEOUT);
|
||||
}
|
||||
|
||||
if (parameters.getNodeDialTimeout() <= 0) {
|
||||
parameters.setNodeDialTimeout(DEFAULT_DIAL_TIMEOUT);
|
||||
}
|
||||
|
||||
if (parameters.getNodeStreamTimeout() <= 0) {
|
||||
parameters.setNodeStreamTimeout(DEFAULT_STREAM_TIMEOUT);
|
||||
}
|
||||
|
||||
if (parameters.getSessionExpirationDuration() == 0) {
|
||||
parameters.setSessionExpirationDuration(DEFAULT_SESSION_TOKEN_EXPIRATION_DURATION);
|
||||
}
|
||||
|
||||
if (parameters.getClientBuilder() == null) {
|
||||
parameters.setClientBuilder(address -> {
|
||||
WrapperPrm wrapperPrm = new WrapperPrm();
|
||||
wrapperPrm.setAddress(address);
|
||||
wrapperPrm.setKey(parameters.getKey());
|
||||
wrapperPrm.setLogger(parameters.getLogger());
|
||||
wrapperPrm.setDialTimeout(parameters.getNodeDialTimeout());
|
||||
wrapperPrm.setStreamTimeout(parameters.getNodeStreamTimeout());
|
||||
wrapperPrm.setErrorThreshold(parameters.getErrorThreshold());
|
||||
wrapperPrm.setGracefulCloseOnSwitchTimeout(parameters.getGracefulCloseOnSwitchTimeout());
|
||||
wrapperPrm.setInterceptors(parameters.getInterceptors());
|
||||
return new ClientWrapper(wrapperPrm, pool);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static SessionToken initSessionForDuration(CallContext ctx, ClientWrapper cw, long duration) {
|
||||
var client = cw.getClient();
|
||||
NetworkSettings networkInfo = client.getNetworkSettings(ctx);
|
||||
|
||||
long epoch = networkInfo.getEpochDuration();
|
||||
long exp = (Long.MAX_VALUE - epoch < duration) ? Long.MAX_VALUE : (epoch + duration);
|
||||
|
||||
return client.createSession(new PrmSessionCreate(exp), ctx);
|
||||
}
|
||||
|
||||
public static String formCacheKey(String address, String key) {
|
||||
return address + key;
|
||||
}
|
||||
|
||||
public String dial(CallContext ctx) {
|
||||
InnerPool[] inner = new InnerPool[rebalanceParams.getNodesParams().length];
|
||||
boolean atLeastOneHealthy = false;
|
||||
int i = 0;
|
||||
|
||||
for (NodesParam nodeParams : rebalanceParams.getNodesParams()) {
|
||||
ClientWrapper[] clients = new ClientWrapper[nodeParams.getWeight().size()];
|
||||
|
||||
for (int j = 0; j < nodeParams.getAddress().size(); j++) {
|
||||
ClientWrapper client = clients[j] = clientBuilder.apply(nodeParams.getAddress().get(j));
|
||||
boolean dialed = false;
|
||||
|
||||
try {
|
||||
client.dial(ctx);
|
||||
dialed = true;
|
||||
|
||||
SessionToken token = initSessionForDuration(
|
||||
ctx, client, rebalanceParams.getSessionExpirationDuration()
|
||||
);
|
||||
String cacheKey = formCacheKey(
|
||||
nodeParams.getAddress().get(j),
|
||||
getHexString(key.getPublicKeyByte())
|
||||
);
|
||||
sessionCache.setValue(cacheKey, token);
|
||||
|
||||
atLeastOneHealthy = true;
|
||||
} catch (ValidationFrostFSException exp) {
|
||||
break;
|
||||
} catch (Exception exp) {
|
||||
if (!dialed) {
|
||||
client.setUnhealthyOnDial();
|
||||
} else {
|
||||
client.setUnhealthy();
|
||||
}
|
||||
|
||||
if (logger != null) {
|
||||
FrostFSMessages
|
||||
.sessionCreationError(logger, client.getWrapperPrm().getAddress(), exp.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Sampler sampler = new Sampler(nodeParams.getWeight().stream().mapToDouble(Double::doubleValue).toArray());
|
||||
inner[i] = new InnerPool(sampler, clients);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (!atLeastOneHealthy) {
|
||||
return POOL_NODES_UNHEALTHY;
|
||||
}
|
||||
|
||||
this.innerPools = inner;
|
||||
|
||||
NetworkSettings networkSettings = getNetworkSettings(ctx);
|
||||
|
||||
this.maxObjectSize = networkSettings.getMaxObjectSize();
|
||||
startRebalance(ctx);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ClientWrapper connection() {
|
||||
for (InnerPool pool : innerPools) {
|
||||
ClientWrapper client = pool.connection();
|
||||
if (client != null) {
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
throw new FrostFSException(POOL_CLIENTS_UNHEALTHY);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (innerPools != null) {
|
||||
for (InnerPool innerPool : innerPools) {
|
||||
for (ClientWrapper client : innerPool.getClients()) {
|
||||
if (client.isDialed()) {
|
||||
client.getClient().close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startRebalance(CallContext ctx) {
|
||||
double[][] buffers = new double[rebalanceParams.getNodesParams().length][];
|
||||
|
||||
for (int i = 0; i < rebalanceParams.getNodesParams().length; i++) {
|
||||
NodesParam parameters = rebalanceParams.getNodesParams()[i];
|
||||
buffers[i] = new double[parameters.getWeight().size()];
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
WaitUtil.sleep(rebalanceParams.getClientRebalanceInterval());
|
||||
updateNodesHealth(ctx, buffers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNodesHealth(CallContext ctx, double[][] buffers) {
|
||||
CompletableFuture<?>[] tasks = new CompletableFuture<?>[innerPools.length];
|
||||
|
||||
for (int i = 0; i < innerPools.length; i++) {
|
||||
double[] bufferWeights = buffers[i];
|
||||
int finalI = i;
|
||||
tasks[i] = CompletableFuture.runAsync(() -> updateInnerNodesHealth(ctx, finalI, bufferWeights));
|
||||
}
|
||||
|
||||
CompletableFuture.allOf(tasks).join();
|
||||
}
|
||||
|
||||
private void updateInnerNodesHealth(CallContext ctx, int poolIndex, double[] bufferWeights) {
|
||||
if (poolIndex > innerPools.length - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
InnerPool pool = innerPools[poolIndex];
|
||||
RebalanceParameters options = rebalanceParams;
|
||||
int[] healthyChanged = {0};
|
||||
|
||||
CompletableFuture<?>[] tasks = new CompletableFuture<?>[pool.getClients().length];
|
||||
|
||||
for (int j = 0; j < pool.getClients().length; j++) {
|
||||
ClientWrapper client = pool.getClients()[j];
|
||||
AtomicBoolean healthy = new AtomicBoolean(false);
|
||||
AtomicReference<String> error = new AtomicReference<>();
|
||||
AtomicBoolean changed = new AtomicBoolean(false);
|
||||
|
||||
int finalJ = j;
|
||||
tasks[j] = client.restartIfUnhealthy(ctx).handle((unused, throwable) -> {
|
||||
if (throwable != null) {
|
||||
error.set(throwable.getMessage());
|
||||
bufferWeights[finalJ] = 0;
|
||||
sessionCache.deleteByPrefix(client.getAddress());
|
||||
} else {
|
||||
changed.set(unused);
|
||||
healthy.set(true);
|
||||
bufferWeights[finalJ] = options.getNodesParams()[poolIndex].getWeight().get(finalJ);
|
||||
}
|
||||
return null;
|
||||
}).thenRun(() -> {
|
||||
if (changed.get()) {
|
||||
if (error.get() != null && logger != null) {
|
||||
FrostFSMessages.healthChanged(logger, client.getAddress(), healthy.get(), error.get());
|
||||
}
|
||||
healthyChanged[0] = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CompletableFuture.allOf(tasks).thenRun(() -> {
|
||||
if (healthyChanged[0] == 1) {
|
||||
double[] probabilities = adjustWeights(bufferWeights);
|
||||
lock.lock();
|
||||
try {
|
||||
pool.setSampler(new Sampler(probabilities));
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean checkSessionTokenErr(Exception error, String address) {
|
||||
if (error == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (error instanceof SessionNotFoundFrostFSException || error instanceof SessionExpiredFrostFSException) {
|
||||
sessionCache.deleteByPrefix(address);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Statistic statistic() {
|
||||
if (innerPools == null) {
|
||||
throw new ValidationFrostFSException(POOL_NOT_DIALED);
|
||||
}
|
||||
|
||||
Statistic statistics = new Statistic();
|
||||
|
||||
for (InnerPool inner : innerPools) {
|
||||
int valueIndex = 0;
|
||||
String[] nodes = new String[inner.getClients().length];
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
for (ClientWrapper client : inner.getClients()) {
|
||||
if (client.isHealthy()) {
|
||||
nodes[valueIndex] = client.getAddress();
|
||||
}
|
||||
|
||||
NodeStatistic node = new NodeStatistic();
|
||||
node.setAddress(client.getAddress());
|
||||
node.setMethods(client.getMethodsStatus());
|
||||
node.setOverallErrors(client.getOverallErrorRate());
|
||||
node.setCurrentErrors(client.getCurrentErrorRate());
|
||||
|
||||
statistics.getNodes().add(node);
|
||||
valueIndex++;
|
||||
statistics.setOverallErrors(statistics.getOverallErrors() + node.getOverallErrors());
|
||||
}
|
||||
|
||||
if (statistics.getCurrentNodes() == null || statistics.getCurrentNodes().length == 0) {
|
||||
statistics.setCurrentNodes(nodes);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return statistics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getContainer(PrmContainerGet args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getContainer(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().listContainers(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().createContainer(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContainer(PrmContainerDelete args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
client.getClient().deleteContainer(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getObjectHead(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getObject(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().putObject(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().putClientCutObject(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().putSingleObject(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObject(PrmObjectDelete args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
client.getClient().deleteObject(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().searchObjects(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] addChain(PrmApeChainAdd args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().addChain(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChain(PrmApeChainRemove args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
client.getClient().removeChain(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().listChains(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetmapSnapshot getNetmapSnapshot(CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getNetmapSnapshot(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeInfo getLocalNodeInfo(CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getLocalNodeInfo(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkSettings getNetworkSettings(CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getNetworkSettings(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionToken createSession(PrmSessionCreate args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().createSession(args, ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId calculateObjectId(ObjectHeader header) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().calculateObjectId(header);
|
||||
}
|
||||
|
||||
@Override
|
||||
public frostfs.accounting.Types.Decimal getBalance(CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().getBalance(ctx);
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class RebalanceParameters {
|
||||
private NodesParam[] nodesParams;
|
||||
private long nodeRequestTimeout;
|
||||
private long clientRebalanceInterval;
|
||||
private long sessionExpirationDuration;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import info.frostfs.sdk.enums.MethodIndex;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class RequestInfo {
|
||||
private String address;
|
||||
private MethodIndex methodIndex;
|
||||
private Duration elapsed;
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
class Sampler {
|
||||
private final Object lock = new Object();
|
||||
private final Random random = new Random();
|
||||
private final double[] probabilities;
|
||||
private final int[] alias;
|
||||
|
||||
Sampler(double[] probabilities) {
|
||||
ArrayList<Integer> small = new ArrayList<>();
|
||||
ArrayList<Integer> large = new ArrayList<>();
|
||||
|
||||
int n = probabilities.length;
|
||||
|
||||
this.probabilities = new double[n];
|
||||
this.alias = new int[n];
|
||||
|
||||
// Compute scaled probabilities.
|
||||
double[] p = new double[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
p[i] = probabilities[i] * n;
|
||||
if (p[i] < 1) {
|
||||
small.add(i);
|
||||
} else {
|
||||
large.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
while (!small.isEmpty() && !large.isEmpty()) {
|
||||
int l = small.remove(small.size() - 1);
|
||||
int g = large.remove(large.size() - 1);
|
||||
|
||||
this.probabilities[l] = p[l];
|
||||
this.alias[l] = g;
|
||||
|
||||
p[g] = p[g] + p[l] - 1;
|
||||
|
||||
if (p[g] < 1) {
|
||||
small.add(g);
|
||||
} else {
|
||||
large.add(g);
|
||||
}
|
||||
}
|
||||
|
||||
while (!large.isEmpty()) {
|
||||
int g = large.remove(large.size() - 1);
|
||||
this.probabilities[g] = 1;
|
||||
}
|
||||
|
||||
while (!small.isEmpty()) {
|
||||
int l = small.remove(small.size() - 1);
|
||||
probabilities[l] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int next() {
|
||||
int n = alias.length;
|
||||
|
||||
int i;
|
||||
double f;
|
||||
synchronized (lock) {
|
||||
i = random.nextInt(n);
|
||||
f = random.nextDouble();
|
||||
}
|
||||
|
||||
if (f < probabilities[i]) {
|
||||
return i;
|
||||
}
|
||||
|
||||
return alias[i];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class SessionCache {
|
||||
private final ConcurrentMap<String, SessionToken> cache = new ConcurrentHashMap<>();
|
||||
private final long tokenDuration;
|
||||
private long currentEpoch;
|
||||
|
||||
public SessionCache(long sessionExpirationDuration) {
|
||||
this.tokenDuration = sessionExpirationDuration;
|
||||
}
|
||||
|
||||
public boolean contains(String key) {
|
||||
return cache.containsKey(key);
|
||||
}
|
||||
|
||||
public SessionToken tryGetValue(String key) {
|
||||
return StringUtils.isBlank(key) ? null : cache.get(key);
|
||||
}
|
||||
|
||||
public void setValue(String key, SessionToken value) {
|
||||
if (key != null) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteByPrefix(String prefix) {
|
||||
cache.keySet().removeIf(key -> key.startsWith(prefix));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Statistic {
|
||||
private long overallErrors;
|
||||
private List<NodeStatistic> nodes = new ArrayList<>();
|
||||
private String[] currentNodes;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StatusSnapshot {
|
||||
private long allTime;
|
||||
private long allRequests;
|
||||
}
|
||||
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class WorkList {
|
||||
private final List<Integer> elements = new ArrayList<>();
|
||||
|
||||
private int getLength() {
|
||||
return elements.size();
|
||||
}
|
||||
|
||||
private void add(int element) {
|
||||
elements.add(element);
|
||||
}
|
||||
|
||||
private int remove() {
|
||||
int last = elements.get(elements.size() - 1);
|
||||
elements.remove(elements.size() - 1);
|
||||
return last;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import info.frostfs.sdk.jdo.ECDsa;
|
||||
import io.grpc.ClientInterceptors;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WrapperPrm {
|
||||
private Logger logger;
|
||||
private String address;
|
||||
private ECDsa key;
|
||||
private long dialTimeout;
|
||||
private long streamTimeout;
|
||||
private int errorThreshold;
|
||||
private Runnable responseInfoCallback;
|
||||
private Runnable poolRequestInfoCallback;
|
||||
private ManagedChannelBuilder<?> grpcChannelOptions;
|
||||
private long gracefulCloseOnSwitchTimeout;
|
||||
private Collection<ClientInterceptors> interceptors;
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
import frostfs.accounting.Types;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
|
||||
public interface AccountingClient {
|
||||
Types.Decimal getBalance(CallContext ctx);
|
||||
}
|
|
@ -1,17 +1,14 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApeManagerClient {
|
||||
byte[] addChain(PrmApeChainAdd args, CallContext ctx);
|
||||
byte[] addChain(Chain chain, ChainTarget chainTarget);
|
||||
|
||||
void removeChain(PrmApeChainRemove args, CallContext ctx);
|
||||
void removeChain(Chain chain, ChainTarget chainTarget);
|
||||
|
||||
List<Chain> listChains(PrmApeChainList args, CallContext ctx);
|
||||
List<Chain> listChains(ChainTarget chainTarget);
|
||||
}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
public interface CommonClient extends
|
||||
AccountingClient, ApeManagerClient, ContainerClient, NetmapClient, ObjectClient, SessionClient, ToolsClient {
|
||||
}
|
|
@ -2,20 +2,15 @@ package info.frostfs.sdk.services;
|
|||
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ContainerClient {
|
||||
Container getContainer(PrmContainerGet args, CallContext ctx);
|
||||
Container getContainer(ContainerId cid);
|
||||
|
||||
List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx);
|
||||
List<ContainerId> listContainers();
|
||||
|
||||
ContainerId createContainer(PrmContainerCreate args, CallContext ctx);
|
||||
ContainerId createContainer(Container container);
|
||||
|
||||
void deleteContainer(PrmContainerDelete args, CallContext ctx);
|
||||
void deleteContainer(ContainerId cid);
|
||||
}
|
||||
|
|
|
@ -3,12 +3,11 @@ package info.frostfs.sdk.services;
|
|||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
|
||||
public interface NetmapClient {
|
||||
NetmapSnapshot getNetmapSnapshot(CallContext ctx);
|
||||
NetmapSnapshot getNetmapSnapshot();
|
||||
|
||||
NodeInfo getLocalNodeInfo(CallContext ctx);
|
||||
NodeInfo getLocalNodeInfo();
|
||||
|
||||
NetworkSettings getNetworkSettings(CallContext ctx);
|
||||
NetworkSettings getNetworkSettings();
|
||||
}
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||
import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||
|
||||
public interface ObjectClient {
|
||||
ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx);
|
||||
ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx);
|
||||
ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
ObjectWriter putObject(PrmObjectPut args, CallContext ctx);
|
||||
ObjectId putObject(PutObjectParameters parameters);
|
||||
|
||||
ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx);
|
||||
ObjectId putSingleObject(ObjectFrostFS objectFrostFS);
|
||||
|
||||
ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx);
|
||||
void deleteObject(ContainerId containerId, ObjectId objectId);
|
||||
|
||||
void deleteObject(PrmObjectDelete args, CallContext ctx);
|
||||
|
||||
Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx);
|
||||
Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
||||
|
||||
public interface SessionClient {
|
||||
SessionToken createSession(PrmSessionCreate args, CallContext ctx);
|
||||
SessionToken createSession(long expiration);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
import frostfs.session.Types;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
|
||||
public interface SessionTools {
|
||||
SessionToken getOrCreateSession(ClientEnvironment env, CallContext ctx);
|
||||
Types.SessionToken getOrCreateSession(SessionToken token, ClientEnvironment env);
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
package info.frostfs.sdk.services.impl;
|
||||
|
||||
import frostfs.accounting.AccountingServiceGrpc;
|
||||
import frostfs.accounting.Service;
|
||||
import frostfs.accounting.Types;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
||||
import info.frostfs.sdk.services.AccountingClient;
|
||||
import info.frostfs.sdk.services.ContextAccessor;
|
||||
import info.frostfs.sdk.tools.RequestConstructor;
|
||||
import info.frostfs.sdk.tools.RequestSigner;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
|
||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
||||
|
||||
public class AccountingClientImpl extends ContextAccessor implements AccountingClient {
|
||||
private final AccountingServiceGrpc.AccountingServiceBlockingStub serviceBlockingStub;
|
||||
|
||||
public AccountingClientImpl(ClientEnvironment clientEnvironment) {
|
||||
super(clientEnvironment);
|
||||
this.serviceBlockingStub = AccountingServiceGrpc.newBlockingStub(getContext().getChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Types.Decimal getBalance(CallContext ctx) {
|
||||
var request = createGetRequest();
|
||||
|
||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.balance(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
return response.getBody().getBalance();
|
||||
}
|
||||
|
||||
private Service.BalanceRequest createGetRequest() {
|
||||
var body = Service.BalanceRequest.Body.newBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.build();
|
||||
var request = Service.BalanceRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
RequestConstructor.addMetaHeader(request);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
}
|
|
@ -5,11 +5,9 @@ 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.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
||||
import info.frostfs.sdk.mappers.chain.ChainMapper;
|
||||
import info.frostfs.sdk.mappers.chain.ChainTargetMapper;
|
||||
import info.frostfs.sdk.services.ApeManagerClient;
|
||||
|
@ -19,9 +17,10 @@ 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.utils.DeadLineUtil.deadLineAfter;
|
||||
import static info.frostfs.sdk.utils.Validator.validate;
|
||||
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;
|
||||
|
@ -32,13 +31,19 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
|||
}
|
||||
|
||||
@Override
|
||||
public byte[] addChain(PrmApeChainAdd args, CallContext ctx) {
|
||||
validate(args);
|
||||
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(args);
|
||||
var request = createAddChainRequest(chain, chainTarget, null);
|
||||
|
||||
var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.addChain(request);
|
||||
var response = apeManagerServiceClient.addChain(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
|
@ -46,70 +51,82 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
|||
}
|
||||
|
||||
@Override
|
||||
public void removeChain(PrmApeChainRemove args, CallContext ctx) {
|
||||
validate(args);
|
||||
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(args);
|
||||
var request = createRemoveChainRequest(chain, chainTarget, null);
|
||||
|
||||
var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.removeChain(request);
|
||||
var response = apeManagerServiceClient.removeChain(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
validate(args);
|
||||
public List<Chain> listChains(ChainTarget chainTarget) {
|
||||
if (isNull(chainTarget)) {
|
||||
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ChainTarget.class.getName()));
|
||||
}
|
||||
|
||||
var request = createListChainsRequest(args);
|
||||
var request = createListChainsRequest(chainTarget, null);
|
||||
|
||||
var service = deadLineAfter(apeManagerServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.listChains(request);
|
||||
var response = apeManagerServiceClient.listChains(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
return ChainMapper.toModels(response.getBody().getChainsList());
|
||||
}
|
||||
|
||||
private Service.AddChainRequest createAddChainRequest(PrmApeChainAdd args) {
|
||||
private Service.AddChainRequest createAddChainRequest(Chain chain,
|
||||
ChainTarget chainTarget,
|
||||
Map<String, String> xHeaders) {
|
||||
var chainGrpc = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(args.getChain().getRaw()))
|
||||
.setRaw(ByteString.copyFrom(chain.getRaw()))
|
||||
.build();
|
||||
var body = Service.AddChainRequest.Body.newBuilder()
|
||||
.setChain(chainGrpc)
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||
.build();
|
||||
var request = Service.AddChainRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
||||
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.RemoveChainRequest createRemoveChainRequest(PrmApeChainRemove args) {
|
||||
private Service.RemoveChainRequest createRemoveChainRequest(Chain chain,
|
||||
ChainTarget chainTarget,
|
||||
Map<String, String> xHeaders) {
|
||||
var body = Service.RemoveChainRequest.Body.newBuilder()
|
||||
.setChainId(ByteString.copyFrom(args.getChain().getRaw()))
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
||||
.setChainId(ByteString.copyFrom(chain.getRaw()))
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||
.build();
|
||||
var request = Service.RemoveChainRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
||||
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.ListChainsRequest createListChainsRequest(PrmApeChainList args) {
|
||||
private Service.ListChainsRequest createListChainsRequest(ChainTarget chainTarget,
|
||||
Map<String, String> xHeaders) {
|
||||
var body = Service.ListChainsRequest.Body.newBuilder()
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(chainTarget))
|
||||
.build();
|
||||
var request = Service.ListChainsRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
||||
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
|
|
|
@ -10,14 +10,9 @@ import info.frostfs.sdk.enums.StatusCode;
|
|||
import info.frostfs.sdk.enums.WaitExpects;
|
||||
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.TimeoutFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.PrmWait;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import info.frostfs.sdk.jdo.WaitParameters;
|
||||
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
||||
import info.frostfs.sdk.mappers.container.ContainerMapper;
|
||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||
|
@ -34,11 +29,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE;
|
||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
||||
import static info.frostfs.sdk.utils.Validator.validate;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
import static java.util.Objects.nonNull;
|
||||
|
||||
public class ContainerClientImpl extends ContextAccessor implements ContainerClient {
|
||||
private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub;
|
||||
|
@ -50,33 +42,29 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
this.sessionTools = new SessionToolsImpl(clientEnvironment);
|
||||
}
|
||||
|
||||
public SessionToken getOrCreateSession(SessionContext sessionContext, CallContext ctx) {
|
||||
return isNull(sessionContext.getSessionToken())
|
||||
? sessionTools.getOrCreateSession(getContext(), ctx)
|
||||
: sessionContext.getSessionToken();
|
||||
public frostfs.session.Types.SessionToken getOrCreateSession(SessionToken sessionToken) {
|
||||
return sessionTools.getOrCreateSession(sessionToken, getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getContainer(PrmContainerGet args, CallContext ctx) {
|
||||
validate(args);
|
||||
public Container getContainer(ContainerId cid) {
|
||||
if (isNull(cid)) {
|
||||
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()));
|
||||
}
|
||||
|
||||
var request = createGetRequest(args);
|
||||
var request = createGetRequest(ContainerIdMapper.toGrpcMessage(cid), null);
|
||||
|
||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.get(request);
|
||||
var response = serviceBlockingStub.get(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
return ContainerMapper.toModel(response.getBody().getContainer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContainerId> listContainers(PrmContainerGetAll args, CallContext ctx) {
|
||||
validate(args);
|
||||
public List<ContainerId> listContainers() {
|
||||
var request = createListRequest(null);
|
||||
|
||||
var request = createListRequest(args);
|
||||
|
||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.list(request);
|
||||
var response = serviceBlockingStub.list(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
|
@ -86,39 +74,43 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
}
|
||||
|
||||
@Override
|
||||
public ContainerId createContainer(PrmContainerCreate args, CallContext ctx) {
|
||||
validate(args);
|
||||
public ContainerId createContainer(Container container) {
|
||||
if (isNull(container)) {
|
||||
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, Container.class.getName()));
|
||||
}
|
||||
|
||||
var request = createPutRequest(args, ctx);
|
||||
var grpcContainer = ContainerMapper.toGrpcMessage(container);
|
||||
var request = createPutRequest(grpcContainer, null);
|
||||
|
||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.put(request);
|
||||
var response = serviceBlockingStub.put(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
waitForContainer(WaitExpects.EXISTS, response.getBody().getContainerId(), args.getWaitParams());
|
||||
waitForContainer(WaitExpects.EXISTS, response.getBody().getContainerId(), null);
|
||||
|
||||
return new ContainerId(response.getBody().getContainerId().getValue().toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteContainer(PrmContainerDelete args, CallContext ctx) {
|
||||
validate(args);
|
||||
public void deleteContainer(ContainerId cid) {
|
||||
if (isNull(cid)) {
|
||||
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()));
|
||||
}
|
||||
|
||||
var request = createDeleteRequest(args, ctx);
|
||||
var grpcContainerId = ContainerIdMapper.toGrpcMessage(cid);
|
||||
var request = createDeleteRequest(grpcContainerId, null);
|
||||
|
||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.delete(request);
|
||||
var response = serviceBlockingStub.delete(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
waitForContainer(WaitExpects.REMOVED, request.getBody().getContainerId(), args.getWaitParams());
|
||||
waitForContainer(WaitExpects.REMOVED, request.getBody().getContainerId(), null);
|
||||
}
|
||||
|
||||
private void waitForContainer(WaitExpects expect, Types.ContainerID cid, PrmWait waitParams) {
|
||||
var request = createGetRequest(cid, null);
|
||||
private void waitForContainer(WaitExpects expect, Types.ContainerID id, WaitParameters waitParams) {
|
||||
var request = createGetRequest(id, null);
|
||||
|
||||
waitParams = isNull(waitParams) ? new PrmWait() : waitParams;
|
||||
waitParams = isNull(waitParams) ? new WaitParameters() : waitParams;
|
||||
var deadLine = waitParams.getDeadline();
|
||||
|
||||
while (true) {
|
||||
|
@ -153,12 +145,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
}
|
||||
}
|
||||
|
||||
private Service.GetRequest createGetRequest(PrmContainerGet args) {
|
||||
var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId());
|
||||
return createGetRequest(cid, args.getXHeaders());
|
||||
}
|
||||
|
||||
private Service.GetRequest createGetRequest(Types.ContainerID cid, Map<String, String> xHeaders) {
|
||||
private Service.GetRequest createGetRequest(Types.ContainerID cid,
|
||||
Map<String, String> xHeaders) {
|
||||
var body = Service.GetRequest.Body.newBuilder()
|
||||
.setContainerId(cid)
|
||||
.build();
|
||||
|
@ -171,22 +160,22 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
return request.build();
|
||||
}
|
||||
|
||||
private Service.ListRequest createListRequest(PrmContainerGetAll args) {
|
||||
private Service.ListRequest createListRequest(Map<String, String> xHeaders) {
|
||||
var body = Service.ListRequest.Body.newBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.build();
|
||||
var request = Service.ListRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders());
|
||||
RequestConstructor.addMetaHeader(request, xHeaders);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.PutRequest createPutRequest(PrmContainerCreate args, CallContext ctx) {
|
||||
syncContainerWithNetwork(args.getContainer(), ctx);
|
||||
var container = ContainerMapper.toGrpcMessage(args.getContainer()).toBuilder()
|
||||
private Service.PutRequest createPutRequest(frostfs.container.Types.Container container,
|
||||
Map<String, String> xHeaders) {
|
||||
container = container.toBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()))
|
||||
.build();
|
||||
|
@ -198,8 +187,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
var request = Service.PutRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createContainerTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createContainerTokenContext(
|
||||
sessionToken,
|
||||
null,
|
||||
frostfs.session.Types.ContainerSessionContext.Verb.PUT,
|
||||
|
@ -207,15 +197,14 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, xHeaders, sessionToken);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.DeleteRequest createDeleteRequest(PrmContainerDelete args, CallContext ctx) {
|
||||
var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId());
|
||||
|
||||
private Service.DeleteRequest createDeleteRequest(Types.ContainerID cid,
|
||||
Map<String, String> xHeaders) {
|
||||
var body = Service.DeleteRequest.Body.newBuilder()
|
||||
.setContainerId(cid)
|
||||
.setSignature(RequestSigner.signRFC6979(getContext().getKey(), cid.getValue()))
|
||||
|
@ -223,8 +212,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
var request = Service.DeleteRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createContainerTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createContainerTokenContext(
|
||||
sessionToken,
|
||||
null,
|
||||
frostfs.session.Types.ContainerSessionContext.Verb.DELETE,
|
||||
|
@ -232,18 +222,9 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, xHeaders, sessionToken);
|
||||
RequestSigner.sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private void syncContainerWithNetwork(Container container, CallContext callContext) {
|
||||
var settings = getContext().getFrostFSClient().getNetworkSettings(callContext);
|
||||
if (nonNull(settings.getHomomorphicHashingDisabled()) && settings.getHomomorphicHashingDisabled()) {
|
||||
container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString());
|
||||
} else {
|
||||
container.getAttributes().remove(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, Boolean.TRUE.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
|||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.mappers.netmap.NetmapSnapshotMapper;
|
||||
import info.frostfs.sdk.mappers.netmap.NodeInfoMapper;
|
||||
import info.frostfs.sdk.services.ContextAccessor;
|
||||
|
@ -18,7 +17,6 @@ import info.frostfs.sdk.tools.Verifier;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
||||
import static java.util.Objects.nonNull;
|
||||
|
||||
public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
||||
|
@ -96,12 +94,12 @@ public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NetworkSettings getNetworkSettings(CallContext ctx) {
|
||||
public NetworkSettings getNetworkSettings() {
|
||||
if (nonNull(getContext().getNetworkSettings())) {
|
||||
return getContext().getNetworkSettings();
|
||||
}
|
||||
|
||||
var info = getNetworkInfo(ctx);
|
||||
var info = getNetworkInfo();
|
||||
|
||||
var settings = new NetworkSettings();
|
||||
|
||||
|
@ -115,28 +113,25 @@ public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NodeInfo getLocalNodeInfo(CallContext ctx) {
|
||||
public NodeInfo getLocalNodeInfo() {
|
||||
var request = Service.LocalNodeInfoRequest.newBuilder();
|
||||
|
||||
RequestConstructor.addMetaHeader(request);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.localNodeInfo(request.build());
|
||||
|
||||
var response = netmapServiceClient.localNodeInfo(request.build());
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
return NodeInfoMapper.toModel(response.getBody());
|
||||
}
|
||||
|
||||
public Service.NetworkInfoResponse getNetworkInfo(CallContext ctx) {
|
||||
public Service.NetworkInfoResponse getNetworkInfo() {
|
||||
var request = Service.NetworkInfoRequest.newBuilder();
|
||||
|
||||
RequestConstructor.addMetaHeader(request);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.networkInfo(request.build());
|
||||
var response = netmapServiceClient.networkInfo(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
|
@ -144,14 +139,13 @@ public class NetmapClientImpl extends ContextAccessor implements NetmapClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NetmapSnapshot getNetmapSnapshot(CallContext ctx) {
|
||||
public NetmapSnapshot getNetmapSnapshot() {
|
||||
var request = Service.NetmapSnapshotRequest.newBuilder();
|
||||
|
||||
RequestConstructor.addMetaHeader(request);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
var service = deadLineAfter(netmapServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.netmapSnapshot(request.build());
|
||||
var response = netmapServiceClient.netmapSnapshot(request.build());
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
|
|
|
@ -6,26 +6,29 @@ import frostfs.object.ObjectServiceGrpc;
|
|||
import frostfs.object.Service;
|
||||
import frostfs.refs.Types;
|
||||
import info.frostfs.sdk.constants.AppConst;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.object.*;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.enums.ObjectType;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||
import info.frostfs.sdk.jdo.PutObjectResult;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.object.*;
|
||||
import info.frostfs.sdk.jdo.parameters.session.SessionContext;
|
||||
import info.frostfs.sdk.jdo.result.ObjectHeaderResult;
|
||||
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
||||
import info.frostfs.sdk.mappers.object.*;
|
||||
import info.frostfs.sdk.mappers.object.ObjectFilterMapper;
|
||||
import info.frostfs.sdk.mappers.object.ObjectFrostFSMapper;
|
||||
import info.frostfs.sdk.mappers.object.ObjectHeaderMapper;
|
||||
import info.frostfs.sdk.mappers.object.ObjectIdMapper;
|
||||
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||
import info.frostfs.sdk.services.ContextAccessor;
|
||||
import info.frostfs.sdk.services.ObjectClient;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectReaderImpl;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectStreamer;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
||||
import info.frostfs.sdk.services.impl.rwhelper.SearchReader;
|
||||
import info.frostfs.sdk.tools.RequestConstructor;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
import info.frostfs.sdk.utils.Validator;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -34,12 +37,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import static info.frostfs.sdk.Helper.getSha256;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
||||
import static info.frostfs.sdk.utils.Validator.validate;
|
||||
import static java.util.Objects.isNull;
|
||||
import static java.util.Objects.nonNull;
|
||||
|
||||
public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||
private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient;
|
||||
|
@ -55,153 +55,87 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
this.sessionTools = new SessionToolsImpl(clientEnvironment);
|
||||
}
|
||||
|
||||
public SessionToken getOrCreateSession(SessionContext sessionContext, CallContext ctx) {
|
||||
return isNull(sessionContext.getSessionToken())
|
||||
? sessionTools.getOrCreateSession(getContext(), ctx)
|
||||
: sessionContext.getSessionToken();
|
||||
public frostfs.session.Types.SessionToken getOrCreateSession(SessionToken sessionToken) {
|
||||
return sessionTools.getOrCreateSession(sessionToken, getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectHeaderResult getObjectHead(PrmObjectHeadGet args, CallContext ctx) {
|
||||
validate(args);
|
||||
public ObjectHeader getObjectHead(ContainerId cid, ObjectId oid) {
|
||||
if (isNull(cid) || isNull(oid)) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(
|
||||
PARAMS_ARE_MISSING_TEMPLATE,
|
||||
String.join(FIELDS_DELIMITER_COMMA, ContainerId.class.getName(), ObjectId.class.getName())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
var request = createHeadRequest(args, ctx);
|
||||
var request = createHeadRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||
|
||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.head(request);
|
||||
var response = objectServiceBlockingClient.head(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
return ObjectHeaderResult.builder()
|
||||
.headerInfo(ObjectHeaderMapper.toModel(response.getBody().getHeader().getHeader()))
|
||||
.splitInfo(SplitInfoMapper.toModel(response.getBody().getSplitInfo()))
|
||||
.build();
|
||||
return ObjectHeaderMapper.toModel(response.getBody().getHeader().getHeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectFrostFS getObject(PrmObjectGet args, CallContext ctx) {
|
||||
validate(args);
|
||||
public ObjectFrostFS getObject(ContainerId cid, ObjectId oid) {
|
||||
var request = createGetRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||
|
||||
var request = createGetRequest(args, ctx);
|
||||
|
||||
return getObject(request, ctx);
|
||||
return getObject(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteObject(PrmObjectDelete args, CallContext ctx) {
|
||||
validate(args);
|
||||
public void deleteObject(ContainerId cid, ObjectId oid) {
|
||||
var request = createDeleteRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||
|
||||
var request = createDeleteRequest(args, ctx);
|
||||
|
||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.delete(request);
|
||||
var response = objectServiceBlockingClient.delete(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ObjectId> searchObjects(PrmObjectSearch args, CallContext ctx) {
|
||||
validate(args);
|
||||
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
||||
var request = createSearchRequest(ContainerIdMapper.toGrpcMessage(cid), filters);
|
||||
|
||||
var request = createSearchRequest(args, ctx);
|
||||
|
||||
var objectsIds = searchObjects(request, ctx);
|
||||
var objectsIds = searchObjects(request);
|
||||
|
||||
return Iterables.transform(objectsIds, input -> new ObjectId(input.getValue().toByteArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectWriter putObject(PrmObjectPut args, CallContext ctx) {
|
||||
validate(args);
|
||||
public ObjectId putObject(PutObjectParameters parameters) {
|
||||
Validator.validate(parameters);
|
||||
|
||||
return new ObjectWriter(getContext(), args, getUploadStream(args, ctx));
|
||||
if (parameters.isClientCut()) {
|
||||
return putClientCutObject(parameters);
|
||||
}
|
||||
|
||||
if (parameters.getHeader().getPayloadLength() > 0) {
|
||||
parameters.setFullLength(parameters.getHeader().getPayloadLength());
|
||||
} else {
|
||||
parameters.setFullLength(getStreamSize(parameters.getPayload()));
|
||||
}
|
||||
|
||||
return putStreamObject(parameters).getObjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putClientCutObject(PrmObjectClientCutPut args, CallContext ctx) {
|
||||
validate(args);
|
||||
public ObjectId putSingleObject(ObjectFrostFS modelObject) {
|
||||
var grpcObject = objectToolsImpl.createObject(modelObject);
|
||||
|
||||
var header = args.getObjectHeader();
|
||||
var fullLength = header.getPayloadLength() == 0 ? getStreamSize(args.getPayload()) : header.getPayloadLength();
|
||||
args.getPutObjectContext().setFullLength(fullLength);
|
||||
var request = createPutSingleRequest(grpcObject);
|
||||
|
||||
if (args.getPutObjectContext().getMaxObjectSizeCache() == 0) {
|
||||
var networkSettings = getContext().getFrostFSClient().getNetworkSettings(ctx);
|
||||
args.getPutObjectContext().setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue());
|
||||
}
|
||||
|
||||
var restBytes = fullLength - args.getPutObjectContext().getCurrentStreamPosition();
|
||||
var objectSize = restBytes > 0
|
||||
? Math.min(args.getPutObjectContext().getMaxObjectSizeCache(), restBytes)
|
||||
: args.getPutObjectContext().getMaxObjectSizeCache();
|
||||
|
||||
//define collection capacity
|
||||
var restPart = (restBytes % objectSize) > 0 ? 1 : 0;
|
||||
var objectsCount = fullLength > 0 ? (int) (restBytes / objectSize) + restPart : 0;
|
||||
|
||||
List<ObjectId> sentObjectIds = new ArrayList<>(objectsCount);
|
||||
|
||||
// keep attributes for the large object
|
||||
var attributes = args.getObjectHeader().getAttributes();
|
||||
|
||||
Split split = new Split();
|
||||
args.getObjectHeader().setAttributes(new ArrayList<>());
|
||||
|
||||
// send all parts except the last one as separate Objects
|
||||
while (restBytes > (long) args.getPutObjectContext().getMaxObjectSizeCache()) {
|
||||
var previous = CollectionUtils.isNotEmpty(sentObjectIds)
|
||||
? sentObjectIds.get(sentObjectIds.size() - 1)
|
||||
: null;
|
||||
split.setPrevious(previous);
|
||||
args.getObjectHeader().setSplit(split);
|
||||
|
||||
var result = putMultipartStreamObject(args, ctx);
|
||||
|
||||
sentObjectIds.add(result.getObjectId());
|
||||
|
||||
restBytes -= result.getObjectSize();
|
||||
}
|
||||
|
||||
// send the last part and create linkObject
|
||||
if (CollectionUtils.isNotEmpty(sentObjectIds)) {
|
||||
var largeObjectHeader =
|
||||
new ObjectHeader(header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, null);
|
||||
|
||||
split.setParentHeader(largeObjectHeader);
|
||||
|
||||
var result = putMultipartStreamObject(args, ctx);
|
||||
|
||||
sentObjectIds.add(result.getObjectId());
|
||||
|
||||
var linkObject = new LinkObject(header.getContainerId(), split.getSplitId(), largeObjectHeader);
|
||||
linkObject.addChildren(sentObjectIds);
|
||||
|
||||
putSingleObject(new PrmObjectSinglePut(linkObject), ctx);
|
||||
|
||||
return split.getParent();
|
||||
}
|
||||
|
||||
// We are here if the payload is placed to one Object. It means no cut action, just simple PUT.
|
||||
var singlePartResult = putMultipartStreamObject(args, ctx);
|
||||
|
||||
return singlePartResult.getObjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectId putSingleObject(PrmObjectSinglePut args, CallContext ctx) {
|
||||
var grpcObject = objectToolsImpl.createObject(args.getObjectFrostFS());
|
||||
var request = createPutSingleRequest(grpcObject, args, ctx);
|
||||
|
||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.putSingle(request);
|
||||
var response = objectServiceBlockingClient.putSingle(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
return new ObjectId(grpcObject.getObjectId().getValue().toByteArray());
|
||||
}
|
||||
|
||||
private ObjectFrostFS getObject(Service.GetRequest request, CallContext ctx) {
|
||||
var reader = getObjectInit(request, ctx);
|
||||
private ObjectFrostFS getObject(Service.GetRequest request) {
|
||||
var reader = getObjectInit(request);
|
||||
|
||||
var grpcObject = reader.readHeader();
|
||||
var modelObject = ObjectFrostFSMapper.toModel(grpcObject);
|
||||
|
@ -211,41 +145,39 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
return modelObject;
|
||||
}
|
||||
|
||||
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest, CallContext ctx) {
|
||||
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest) {
|
||||
if (initRequest.getSerializedSize() == 0) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||
);
|
||||
}
|
||||
|
||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
return new ObjectReaderImpl(service.get(initRequest));
|
||||
return new ObjectReaderImpl(objectServiceBlockingClient.get(initRequest));
|
||||
}
|
||||
|
||||
private PutObjectResult putMultipartStreamObject(PrmObjectClientCutPut args, CallContext ctx) {
|
||||
var chunkSize = args.getBufferMaxSize() > 0 ? args.getBufferMaxSize() : AppConst.OBJECT_CHUNK_SIZE;
|
||||
private PutObjectResult putStreamObject(PutObjectParameters parameters) {
|
||||
var chunkSize = parameters.getBufferMaxSize() > 0 ? parameters.getBufferMaxSize() : AppConst.OBJECT_CHUNK_SIZE;
|
||||
|
||||
var restBytes =
|
||||
args.getPutObjectContext().getFullLength() - args.getPutObjectContext().getCurrentStreamPosition();
|
||||
var restBytes = parameters.getFullLength() - parameters.getCurrentStreamPosition();
|
||||
|
||||
chunkSize = (int) Math.min(restBytes, chunkSize);
|
||||
|
||||
byte[] chunkBuffer = args.getCustomerBuffer() != null
|
||||
? args.getCustomerBuffer()
|
||||
byte[] chunkBuffer = parameters.getCustomerBuffer() != null
|
||||
? parameters.getCustomerBuffer()
|
||||
: new byte[chunkSize];//todo change to pool
|
||||
|
||||
var sentBytes = 0;
|
||||
|
||||
// 0 means no limit from client, so server side cut is performed
|
||||
var objectLimitSize = args.getPutObjectContext().getMaxObjectSizeCache();
|
||||
var objectLimitSize = parameters.isClientCut() ? parameters.getMaxObjectSizeCache() : 0;
|
||||
|
||||
var stream = getUploadStream(args, ctx);
|
||||
var stream = getUploadStream(parameters);
|
||||
|
||||
while (objectLimitSize == 0 || sentBytes < objectLimitSize) {
|
||||
// send chunks limited to default or user's settings
|
||||
var bufferSize = objectLimitSize > 0 ? Math.min(objectLimitSize - sentBytes, chunkSize) : chunkSize;
|
||||
|
||||
var bytesCount = readNBytes(args.getPayload(), chunkBuffer, bufferSize);
|
||||
var bytesCount = readNBytes(parameters.getPayload(), chunkBuffer, bufferSize);
|
||||
|
||||
if (bytesCount == 0) {
|
||||
break;
|
||||
|
@ -272,40 +204,110 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
return new PutObjectResult(objectId, sentBytes);
|
||||
}
|
||||
|
||||
private ObjectStreamer getUploadStream(PrmObjectPutBase args, CallContext ctx) {
|
||||
var header = args.getObjectHeader();
|
||||
private ObjectId putClientCutObject(PutObjectParameters parameters) {
|
||||
var header = parameters.getHeader();
|
||||
var tokenRaw = getOrCreateSession(parameters.getSessionToken());
|
||||
var token = new SessionToken(SessionMapper.serialize(tokenRaw));
|
||||
parameters.setSessionToken(token);
|
||||
|
||||
var fullLength = header.getPayloadLength() == 0
|
||||
? getStreamSize(parameters.getPayload())
|
||||
: header.getPayloadLength();
|
||||
|
||||
parameters.setFullLength(fullLength);
|
||||
|
||||
if (parameters.getMaxObjectSizeCache() == 0) {
|
||||
var networkSettings = getContext().getFrostFSClient().getNetworkSettings();
|
||||
parameters.setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue());
|
||||
}
|
||||
|
||||
var restBytes = fullLength - parameters.getCurrentStreamPosition();
|
||||
var objectSize = restBytes > 0
|
||||
? Math.min(parameters.getMaxObjectSizeCache(), restBytes)
|
||||
: parameters.getMaxObjectSizeCache();
|
||||
|
||||
//define collection capacity
|
||||
var restPart = (restBytes % objectSize) > 0 ? 1 : 0;
|
||||
var objectsCount = fullLength > 0 ? (int) (restBytes / objectSize) + restPart : 0;
|
||||
|
||||
List<ObjectId> sentObjectIds = new ArrayList<>(objectsCount);
|
||||
|
||||
// keep attributes for the large object
|
||||
var attributes = parameters.getHeader().getAttributes();
|
||||
|
||||
Split split = new Split();
|
||||
parameters.getHeader().setSplit(split);
|
||||
parameters.getHeader().setAttributes(new ArrayList<>());
|
||||
|
||||
// send all parts except the last one as separate Objects
|
||||
while (restBytes > (long) parameters.getMaxObjectSizeCache()) {
|
||||
var previous = CollectionUtils.isNotEmpty(sentObjectIds)
|
||||
? sentObjectIds.get(sentObjectIds.size() - 1)
|
||||
: null;
|
||||
split.setPrevious(previous);
|
||||
|
||||
var result = putStreamObject(parameters);
|
||||
|
||||
sentObjectIds.add(result.getObjectId());
|
||||
|
||||
restBytes -= result.getObjectSize();
|
||||
}
|
||||
|
||||
// send the last part and create linkObject
|
||||
if (CollectionUtils.isNotEmpty(sentObjectIds)) {
|
||||
var largeObjectHeader =
|
||||
new ObjectHeader(header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, null);
|
||||
|
||||
split.setParentHeader(largeObjectHeader);
|
||||
|
||||
var result = putStreamObject(parameters);
|
||||
|
||||
sentObjectIds.add(result.getObjectId());
|
||||
|
||||
var linkObject = new LinkObject(header.getContainerId(), split.getSplitId(), largeObjectHeader);
|
||||
linkObject.addChildren(sentObjectIds);
|
||||
|
||||
putSingleObject(linkObject);
|
||||
|
||||
return split.getParent();
|
||||
}
|
||||
|
||||
// We are here if the payload is placed to one Object. It means no cut action, just simple PUT.
|
||||
var singlePartResult = putStreamObject(parameters);
|
||||
|
||||
return singlePartResult.getObjectId();
|
||||
}
|
||||
|
||||
private ObjectWriter getUploadStream(PutObjectParameters parameters) {
|
||||
var header = parameters.getHeader();
|
||||
|
||||
header.setOwnerId(getContext().getOwnerId());
|
||||
header.setVersion(getContext().getVersion());
|
||||
|
||||
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(header);
|
||||
|
||||
if (nonNull(header.getSplit())) {
|
||||
grpcHeader = objectToolsImpl.updateSplitValues(grpcHeader, header.getSplit());
|
||||
}
|
||||
grpcHeader = objectToolsImpl.updateSplitValues(grpcHeader, header.getSplit());
|
||||
|
||||
var oid = Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build();
|
||||
|
||||
var initRequest = createInitPutRequest(oid, grpcHeader, args, ctx);
|
||||
var initRequest = createInitPutRequest(oid, grpcHeader);
|
||||
|
||||
return putObjectInit(initRequest, ctx);
|
||||
return putObjectInit(initRequest);
|
||||
}
|
||||
|
||||
private ObjectStreamer putObjectInit(Service.PutRequest initRequest, CallContext ctx) {
|
||||
private ObjectWriter putObjectInit(Service.PutRequest initRequest) {
|
||||
if (initRequest.getSerializedSize() == 0) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||
);
|
||||
}
|
||||
|
||||
var service = deadLineAfter(objectServiceClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
ObjectStreamer writer = new ObjectStreamer(service);
|
||||
ObjectWriter writer = new ObjectWriter(objectServiceClient);
|
||||
writer.write(initRequest);
|
||||
return writer;
|
||||
}
|
||||
|
||||
private Iterable<Types.ObjectID> searchObjects(Service.SearchRequest request, CallContext ctx) {
|
||||
var reader = getSearchReader(request, ctx);
|
||||
private Iterable<Types.ObjectID> searchObjects(Service.SearchRequest request) {
|
||||
var reader = getSearchReader(request);
|
||||
var ids = reader.read();
|
||||
List<Types.ObjectID> result = new ArrayList<>();
|
||||
|
||||
|
@ -317,15 +319,14 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
return result;//todo return yield
|
||||
}
|
||||
|
||||
private SearchReader getSearchReader(Service.SearchRequest initRequest, CallContext ctx) {
|
||||
private SearchReader getSearchReader(Service.SearchRequest initRequest) {
|
||||
if (initRequest.getSerializedSize() == 0) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||
);
|
||||
}
|
||||
|
||||
var service = deadLineAfter(objectServiceBlockingClient, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
return new SearchReader(service.search(initRequest));
|
||||
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
||||
}
|
||||
|
||||
private int readNBytes(InputStream inputStream, byte[] buffer, int size) {
|
||||
|
@ -344,37 +345,36 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
}
|
||||
}
|
||||
|
||||
private Service.HeadRequest createHeadRequest(PrmObjectHeadGet args, CallContext ctx) {
|
||||
private Service.HeadRequest createHeadRequest(Types.ContainerID cid, Types.ObjectID oid) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
||||
.setContainerId(cid)
|
||||
.setObjectId(oid)
|
||||
.build();
|
||||
var body = Service.HeadRequest.Body.newBuilder()
|
||||
.setAddress(address)
|
||||
.setRaw(args.isRaw())
|
||||
.build();
|
||||
var request = Service.HeadRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||
sessionToken,
|
||||
address,
|
||||
frostfs.session.Types.ObjectSessionContext.Verb.HEAD,
|
||||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.GetRequest createGetRequest(PrmObjectGet args, CallContext ctx) {
|
||||
|
||||
private Service.GetRequest createGetRequest(Types.ContainerID cid, Types.ObjectID oid) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
||||
.setContainerId(cid)
|
||||
.setObjectId(oid)
|
||||
.build();
|
||||
var body = Service.GetRequest.Body.newBuilder()
|
||||
.setAddress(address)
|
||||
|
@ -382,24 +382,25 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
var request = Service.GetRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||
sessionToken,
|
||||
address,
|
||||
frostfs.session.Types.ObjectSessionContext.Verb.GET,
|
||||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.DeleteRequest createDeleteRequest(PrmObjectDelete args, CallContext ctx) {
|
||||
private Service.DeleteRequest createDeleteRequest(Types.ContainerID cid, Types.ObjectID oid) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(ContainerIdMapper.toGrpcMessage(args.getContainerId()))
|
||||
.setObjectId(ObjectIdMapper.toGrpcMessage(args.getObjectId()))
|
||||
.setContainerId(cid)
|
||||
.setObjectId(oid)
|
||||
.build();
|
||||
var body = Service.DeleteRequest.Body.newBuilder()
|
||||
.setAddress(address)
|
||||
|
@ -407,23 +408,22 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
var request = Service.DeleteRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||
sessionToken,
|
||||
address,
|
||||
frostfs.session.Types.ObjectSessionContext.Verb.DELETE,
|
||||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.SearchRequest createSearchRequest(PrmObjectSearch args, CallContext ctx) {
|
||||
var cid = ContainerIdMapper.toGrpcMessage(args.getContainerId());
|
||||
|
||||
private Service.SearchRequest createSearchRequest(Types.ContainerID cid, ObjectFilter<?>... filters) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(cid)
|
||||
.build();
|
||||
|
@ -432,31 +432,29 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
.setContainerId(cid)
|
||||
.setVersion(1);// TODO: clarify this param
|
||||
|
||||
for (ObjectFilter<?> filter : args.getFilters()) {
|
||||
for (ObjectFilter<?> filter : filters) {
|
||||
body.addFilters(ObjectFilterMapper.toGrpcMessage(filter));
|
||||
}
|
||||
|
||||
var request = Service.SearchRequest.newBuilder()
|
||||
.setBody(body.build());
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||
sessionToken,
|
||||
address,
|
||||
frostfs.session.Types.ObjectSessionContext.Verb.SEARCH,
|
||||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.PutRequest createInitPutRequest(Types.ObjectID oid,
|
||||
frostfs.object.Types.Header header,
|
||||
PrmObjectPutBase args,
|
||||
CallContext ctx) {
|
||||
private Service.PutRequest createInitPutRequest(Types.ObjectID oid, frostfs.object.Types.Header header) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(header.getContainerId())
|
||||
.setObjectId(oid)
|
||||
|
@ -470,23 +468,22 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
var request = Service.PutRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||
sessionToken,
|
||||
address,
|
||||
frostfs.session.Types.ObjectSessionContext.Verb.PUT,
|
||||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
}
|
||||
|
||||
private Service.PutSingleRequest createPutSingleRequest(frostfs.object.Types.Object grpcObject,
|
||||
PrmObjectSinglePut args,
|
||||
CallContext ctx) {
|
||||
private Service.PutSingleRequest createPutSingleRequest(frostfs.object.Types.Object grpcObject) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(grpcObject.getHeader().getContainerId())
|
||||
.setObjectId(grpcObject.getObjectId())
|
||||
|
@ -497,15 +494,16 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
var request = Service.PutSingleRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
||||
var sessionToken = getOrCreateSession(args, ctx);
|
||||
var protoToken = RequestConstructor.createObjectTokenContext(
|
||||
var sessionToken = getOrCreateSession(null);
|
||||
|
||||
sessionToken = RequestConstructor.createObjectTokenContext(
|
||||
sessionToken,
|
||||
address,
|
||||
frostfs.session.Types.ObjectSessionContext.Verb.PUT,
|
||||
getContext().getKey()
|
||||
);
|
||||
|
||||
RequestConstructor.addMetaHeader(request, args.getXHeaders(), protoToken);
|
||||
RequestConstructor.addMetaHeader(request, null, sessionToken);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return request.build();
|
||||
|
|
|
@ -47,16 +47,16 @@ public class ObjectToolsImpl extends ContextAccessor implements ToolsClient {
|
|||
);
|
||||
}
|
||||
|
||||
public Types.Object createObject(ObjectFrostFS objectFrostFS) {
|
||||
objectFrostFS.getHeader().setOwnerId(getContext().getOwnerId());
|
||||
objectFrostFS.getHeader().setVersion(getContext().getVersion());
|
||||
objectFrostFS.getHeader().setPayloadLength(objectFrostFS.getPayload().length);
|
||||
public Types.Object createObject(ObjectFrostFS objectFrostFs) {
|
||||
objectFrostFs.getHeader().setOwnerId(getContext().getOwnerId());
|
||||
objectFrostFs.getHeader().setVersion(getContext().getVersion());
|
||||
objectFrostFs.getHeader().setPayloadLength(objectFrostFs.getPayload().length);
|
||||
|
||||
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(objectFrostFS.getHeader()).toBuilder()
|
||||
.setPayloadHash(sha256Checksum(objectFrostFS.getPayload()))
|
||||
var grpcHeader = ObjectHeaderMapper.toGrpcMessage(objectFrostFs.getHeader()).toBuilder()
|
||||
.setPayloadHash(sha256Checksum(objectFrostFs.getPayload()))
|
||||
.build();
|
||||
|
||||
var split = objectFrostFS.getHeader().getSplit();
|
||||
var split = objectFrostFs.getHeader().getSplit();
|
||||
if (nonNull(split)) {
|
||||
grpcHeader = updateSplitValues(grpcHeader, split);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class ObjectToolsImpl extends ContextAccessor implements ToolsClient {
|
|||
return Types.Object.newBuilder()
|
||||
.setHeader(grpcHeader)
|
||||
.setObjectId(objectId)
|
||||
.setPayload(ByteString.copyFrom(objectFrostFS.getPayload()))
|
||||
.setPayload(ByteString.copyFrom(objectFrostFs.getPayload()))
|
||||
.setSignature(sig)
|
||||
.build();
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import frostfs.session.SessionServiceGrpc;
|
|||
import frostfs.session.Types;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
||||
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
||||
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||
import info.frostfs.sdk.services.ContextAccessor;
|
||||
|
@ -15,7 +13,6 @@ import info.frostfs.sdk.tools.RequestConstructor;
|
|||
import info.frostfs.sdk.tools.Verifier;
|
||||
|
||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
||||
|
||||
public class SessionClientImpl extends ContextAccessor implements SessionClient {
|
||||
private final SessionServiceGrpc.SessionServiceBlockingStub serviceBlockingStub;
|
||||
|
@ -26,16 +23,16 @@ public class SessionClientImpl extends ContextAccessor implements SessionClient
|
|||
}
|
||||
|
||||
@Override
|
||||
public SessionToken createSession(PrmSessionCreate args, CallContext ctx) {
|
||||
var sessionToken = createSessionInternal(args, ctx);
|
||||
public SessionToken createSession(long expiration) {
|
||||
var sessionToken = createSessionInternal(expiration);
|
||||
var token = SessionMapper.serialize(sessionToken);
|
||||
return new SessionToken(token);
|
||||
}
|
||||
|
||||
public Types.SessionToken createSessionInternal(PrmSessionCreate args, CallContext ctx) {
|
||||
public Types.SessionToken createSessionInternal(long expiration) {
|
||||
var body = Service.CreateRequest.Body.newBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setExpiration(args.getExpiration())
|
||||
.setExpiration(expiration)
|
||||
.build();
|
||||
var request = Service.CreateRequest.newBuilder()
|
||||
.setBody(body);
|
||||
|
@ -43,12 +40,11 @@ public class SessionClientImpl extends ContextAccessor implements SessionClient
|
|||
RequestConstructor.addMetaHeader(request);
|
||||
sign(request, getContext().getKey());
|
||||
|
||||
return createSession(request.build(), ctx);
|
||||
return createSession(request.build());
|
||||
}
|
||||
|
||||
private Types.SessionToken createSession(Service.CreateRequest request, CallContext ctx) {
|
||||
var service = deadLineAfter(serviceBlockingStub, ctx.getTimeout(), ctx.getTimeUnit());
|
||||
var response = service.create(request);
|
||||
private Types.SessionToken createSession(Service.CreateRequest request) {
|
||||
var response = serviceBlockingStub.create(request);
|
||||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package info.frostfs.sdk.services.impl;
|
||||
|
||||
import frostfs.session.Types;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.exceptions.FrostFSException;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.session.PrmSessionCreate;
|
||||
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||
import info.frostfs.sdk.services.ContextAccessor;
|
||||
import info.frostfs.sdk.services.SessionTools;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.SESSION_CREATE_FAILED;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class SessionToolsImpl extends ContextAccessor implements SessionTools {
|
||||
|
@ -18,18 +16,11 @@ public class SessionToolsImpl extends ContextAccessor implements SessionTools {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SessionToken getOrCreateSession(ClientEnvironment env, CallContext ctx) {
|
||||
var token = env.getSessionCache().tryGetValue(env.getSessionKey());
|
||||
|
||||
if (isNull(token)) {
|
||||
token = env.getFrostFSClient().createSession(new PrmSessionCreate(-1), ctx);
|
||||
if (isNull(token)) {
|
||||
throw new FrostFSException(SESSION_CREATE_FAILED);
|
||||
}
|
||||
|
||||
env.getSessionCache().setValue(env.getSessionKey(), token);
|
||||
public Types.SessionToken getOrCreateSession(SessionToken sessionToken, ClientEnvironment env) {
|
||||
if (isNull(sessionToken)) {
|
||||
return env.getFrostFSClient().createSessionInternal(-1);
|
||||
}
|
||||
|
||||
return token;
|
||||
return SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ import static info.frostfs.sdk.services.impl.interceptor.Labels.*;
|
|||
|
||||
public class ClientMetrics {
|
||||
private static final List<String> defaultRequestLabels =
|
||||
Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method");
|
||||
Arrays.asList("grpc_type", "grpc_service", "grpc_method");
|
||||
|
||||
private static final List<String> defaultResponseLabels =
|
||||
Arrays.asList("grpc_target", "grpc_type", "grpc_service", "grpc_method", "code", "grpc_code");
|
||||
Arrays.asList("grpc_type", "grpc_service", "grpc_method", "code", "grpc_code");
|
||||
|
||||
private static final Counter.Builder rpcStartedBuilder =
|
||||
Counter.build()
|
||||
|
@ -113,9 +113,7 @@ public class ClientMetrics {
|
|||
.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 {
|
||||
private final List<Metadata.Key<String>> labelHeaderKeys;
|
||||
private final Counter rpcStarted;
|
||||
|
@ -157,9 +155,7 @@ public class ClientMetrics {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ClientMetrics} for the supplied gRPC method.
|
||||
*/
|
||||
/** Creates a {@link ClientMetrics} for the supplied gRPC method. */
|
||||
ClientMetrics createMetricsForMethod(GrpcMethod grpcMethod) {
|
||||
return new ClientMetrics(
|
||||
labelHeaderKeys,
|
||||
|
|
|
@ -2,21 +2,18 @@ package info.frostfs.sdk.services.impl.interceptor;
|
|||
|
||||
|
||||
import io.prometheus.client.CollectorRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Configuration {
|
||||
private static final double[] DEFAULT_LATENCY_BUCKETS =
|
||||
new double[]{.001, .005, .01, .05, 0.075, .1, .25, .5, 1, 2, 5, 10};
|
||||
new double[] {.001, .005, .01, .05, 0.075, .1, .25, .5, 1, 2, 5, 10};
|
||||
|
||||
private final boolean isIncludeLatencyHistograms;
|
||||
private final CollectorRegistry collectorRegistry;
|
||||
private final double[] latencyBuckets;
|
||||
private final List<String> labelHeaders;
|
||||
private final boolean isAddCodeLabelToHistograms;
|
||||
|
||||
private Configuration(
|
||||
boolean isIncludeLatencyHistograms,
|
||||
CollectorRegistry collectorRegistry,
|
||||
|
@ -31,9 +28,7 @@ public class Configuration {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a {@link Configuration} for recording all cheap metrics about the rpcs.
|
||||
*/
|
||||
/** Returns a {@link Configuration} for recording all cheap metrics about the rpcs. */
|
||||
public static Configuration cheapMetricsOnly() {
|
||||
return new Configuration(
|
||||
false /* isIncludeLatencyHistograms */,
|
||||
|
@ -124,37 +119,27 @@ public class Configuration {
|
|||
true /* isAddCodeLabelToHistograms */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not latency histograms for calls should be included.
|
||||
*/
|
||||
/** Returns whether or not latency histograms for calls should be included. */
|
||||
public boolean isIncludeLatencyHistograms() {
|
||||
return isIncludeLatencyHistograms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link CollectorRegistry} used to record stats.
|
||||
*/
|
||||
/** Returns the {@link CollectorRegistry} used to record stats. */
|
||||
public CollectorRegistry getCollectorRegistry() {
|
||||
return collectorRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the histogram buckets to use for latency metrics.
|
||||
*/
|
||||
/** Returns the histogram buckets to use for latency metrics. */
|
||||
public double[] getLatencyBuckets() {
|
||||
return latencyBuckets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured list of headers to be used as labels.
|
||||
*/
|
||||
/** Returns the configured list of headers to be used as labels. */
|
||||
public List<String> getLabelHeaders() {
|
||||
return labelHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not status code label should be added to latency histogram.
|
||||
*/
|
||||
/** Returns whether or not status code label should be added to latency histogram. */
|
||||
public boolean isAddCodeLabelToHistograms() {
|
||||
return isAddCodeLabelToHistograms;
|
||||
}
|
||||
|
|
|
@ -1,33 +1,27 @@
|
|||
package info.frostfs.sdk.services.impl.interceptor;
|
||||
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.MethodDescriptor.MethodType;
|
||||
|
||||
public class GrpcMethod {
|
||||
private final String targetName;
|
||||
private final String serviceName;
|
||||
private final String methodName;
|
||||
private final MethodType type;
|
||||
|
||||
private GrpcMethod(String targetName, String serviceName, String methodName, MethodType type) {
|
||||
this.targetName = targetName;
|
||||
private GrpcMethod(String serviceName, String methodName, MethodType type) {
|
||||
this.serviceName = serviceName;
|
||||
this.methodName = methodName;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
static GrpcMethod of(MethodDescriptor<?, ?> method, Channel channel) {
|
||||
static GrpcMethod of(MethodDescriptor<?, ?> method) {
|
||||
String serviceName = MethodDescriptor.extractFullServiceName(method.getFullMethodName());
|
||||
|
||||
// Full method names are of the form: "full.serviceName/MethodName". We extract the last part.
|
||||
String methodName = method.getFullMethodName().substring(serviceName.length() + 1);
|
||||
return new GrpcMethod(channel.authority(), serviceName, methodName, method.getType());
|
||||
return new GrpcMethod(serviceName, methodName, method.getType());
|
||||
}
|
||||
|
||||
String targetName() {
|
||||
return targetName;
|
||||
}
|
||||
|
||||
String serviceName() {
|
||||
return serviceName;
|
||||
|
|
|
@ -53,7 +53,6 @@ public class Labels {
|
|||
*/
|
||||
static <T> T addLabels(SimpleCollector<T> collector, List<String> labels, GrpcMethod method) {
|
||||
List<String> allLabels = new ArrayList<>();
|
||||
allLabels.add(method.targetName());
|
||||
allLabels.add(method.type());
|
||||
allLabels.add(method.serviceName());
|
||||
allLabels.add(method.methodName());
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package info.frostfs.sdk.services.impl.interceptor;
|
||||
|
||||
import io.grpc.*;
|
||||
|
||||
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 {
|
||||
|
@ -16,7 +19,6 @@ public class MonitoringClientInterceptor implements ClientInterceptor {
|
|||
this.configuration = configuration;
|
||||
this.clientMetricsFactory = clientMetricsFactory;
|
||||
}
|
||||
|
||||
public static MonitoringClientInterceptor create(Configuration configuration) {
|
||||
return new MonitoringClientInterceptor(
|
||||
Clock.systemDefaultZone(), configuration, new ClientMetrics.Factory(configuration));
|
||||
|
@ -25,7 +27,7 @@ public class MonitoringClientInterceptor implements ClientInterceptor {
|
|||
@Override
|
||||
public <R, S> ClientCall<R, S> interceptCall(
|
||||
MethodDescriptor<R, S> methodDescriptor, CallOptions callOptions, Channel channel) {
|
||||
GrpcMethod grpcMethod = GrpcMethod.of(methodDescriptor, channel);
|
||||
GrpcMethod grpcMethod = GrpcMethod.of(methodDescriptor);
|
||||
ClientMetrics metrics = clientMetricsFactory.createMetricsForMethod(grpcMethod);
|
||||
return new MonitoringClientCall<>(
|
||||
channel.newCall(methodDescriptor, callOptions), metrics, grpcMethod, configuration, clock);
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package info.frostfs.sdk.services.impl.rwhelper;
|
||||
|
||||
import frostfs.object.ObjectServiceGrpc;
|
||||
import frostfs.object.Service;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.utils.WaitUtil;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import lombok.Getter;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectStreamer {
|
||||
private static final long POLL_INTERVAL = 10;
|
||||
private final StreamObserver<Service.PutRequest> requestObserver;
|
||||
private final PutResponseCallback responseObserver;
|
||||
|
||||
public ObjectStreamer(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) {
|
||||
PutResponseCallback responseObserver = new PutResponseCallback();
|
||||
|
||||
this.responseObserver = responseObserver;
|
||||
this.requestObserver = objectServiceStub.put(responseObserver);
|
||||
}
|
||||
|
||||
public void write(Service.PutRequest request) {
|
||||
if (isNull(request)) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
|
||||
);
|
||||
}
|
||||
requestObserver.onNext(request);
|
||||
}
|
||||
|
||||
public Service.PutResponse complete() {
|
||||
requestObserver.onCompleted();
|
||||
|
||||
while (isNull(responseObserver.getResponse())) {
|
||||
WaitUtil.sleep(POLL_INTERVAL);
|
||||
}
|
||||
|
||||
return responseObserver.getResponse();
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
|
||||
private Service.PutResponse response;
|
||||
|
||||
@Override
|
||||
public void onNext(Service.PutResponse putResponse) {
|
||||
this.response = putResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throw new ProcessFrostFSException(throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +1,63 @@
|
|||
package info.frostfs.sdk.services.impl.rwhelper;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostfs.object.ObjectServiceGrpc;
|
||||
import frostfs.object.Service;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectPutBase;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
import lombok.AllArgsConstructor;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.utils.WaitUtil;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import lombok.Getter;
|
||||
|
||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
//todo specify a deadline for each stream request, not for the entire stream
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ObjectWriter {
|
||||
private final ClientEnvironment environment;
|
||||
private final PrmObjectPutBase args;
|
||||
private final ObjectStreamer streamer;
|
||||
private static final long POLL_INTERVAL = 10;
|
||||
private final StreamObserver<Service.PutRequest> requestObserver;
|
||||
private final PutResponseCallback responseObserver;
|
||||
|
||||
public void write(byte[] buffer) {
|
||||
var body = Service.PutRequest.Body.newBuilder()
|
||||
.setChunk(ByteString.copyFrom(buffer))
|
||||
.build();
|
||||
var chunkRequest = Service.PutRequest.newBuilder()
|
||||
.setBody(body)
|
||||
.clearVerifyHeader();
|
||||
public ObjectWriter(ObjectServiceGrpc.ObjectServiceStub objectServiceStub) {
|
||||
PutResponseCallback responseObserver = new PutResponseCallback();
|
||||
|
||||
sign(chunkRequest, environment.getKey());
|
||||
|
||||
streamer.write(chunkRequest.build());
|
||||
this.responseObserver = responseObserver;
|
||||
this.requestObserver = objectServiceStub.put(responseObserver);
|
||||
}
|
||||
|
||||
public ObjectId complete() {
|
||||
var response = streamer.complete();
|
||||
Verifier.checkResponse(response);
|
||||
public void write(Service.PutRequest request) {
|
||||
if (isNull(request)) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
return new ObjectId(response.getBody().getObjectId().getValue().toByteArray());
|
||||
requestObserver.onNext(request);
|
||||
}
|
||||
|
||||
public Service.PutResponse complete() {
|
||||
requestObserver.onCompleted();
|
||||
|
||||
while (isNull(responseObserver.getResponse())) {
|
||||
WaitUtil.sleep(POLL_INTERVAL);
|
||||
}
|
||||
|
||||
return responseObserver.getResponse();
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
|
||||
private Service.PutResponse response;
|
||||
|
||||
@Override
|
||||
public void onNext(Service.PutResponse putResponse) {
|
||||
this.response = putResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throw new ProcessFrostFSException(throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package info.frostfs.sdk.tools;
|
|||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.ClientSettings;
|
||||
import info.frostfs.sdk.utils.Validator;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.netty.NettyChannelBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -16,7 +16,7 @@ public class GrpcClient {
|
|||
private GrpcClient() {
|
||||
}
|
||||
|
||||
public static ManagedChannel initGrpcChannel(ClientSettings clientSettings) {
|
||||
public static Channel initGrpcChannel(ClientSettings clientSettings) {
|
||||
Validator.validate(clientSettings);
|
||||
|
||||
try {
|
||||
|
@ -32,15 +32,4 @@ public class GrpcClient {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static ManagedChannel initGrpcChannel(String address) {
|
||||
try {
|
||||
URI uri = new URI(address);
|
||||
return NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext().build();
|
||||
} catch (URISyntaxException exp) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(INVALID_HOST_TEMPLATE, address, exp.getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ import com.google.protobuf.ByteString;
|
|||
import com.google.protobuf.Message;
|
||||
import frostfs.session.Types;
|
||||
import info.frostfs.sdk.dto.response.MetaHeader;
|
||||
import info.frostfs.sdk.dto.session.SessionToken;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.ECDsa;
|
||||
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
||||
import info.frostfs.sdk.mappers.session.SessionMapper;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -67,11 +65,13 @@ public class RequestConstructor {
|
|||
setField(request, META_HEADER_FIELD_NAME, metaHeader.build());
|
||||
}
|
||||
|
||||
public static Types.SessionToken createObjectTokenContext(SessionToken sessionToken,
|
||||
public static Types.SessionToken createObjectTokenContext(Types.SessionToken sessionToken,
|
||||
frostfs.refs.Types.Address address,
|
||||
Types.ObjectSessionContext.Verb verb,
|
||||
ECDsa key) {
|
||||
var protoToken = SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
||||
if (isNull(sessionToken) || sessionToken.getBody().getObject().getTarget().getSerializedSize() > 0) {
|
||||
return sessionToken;
|
||||
}
|
||||
|
||||
var target = Types.ObjectSessionContext.Target.newBuilder()
|
||||
.setContainer(address.getContainerId());
|
||||
|
@ -84,23 +84,25 @@ public class RequestConstructor {
|
|||
.setTarget(target.build())
|
||||
.setVerb(verb)
|
||||
.build();
|
||||
var body = protoToken.getBody().toBuilder()
|
||||
var body = sessionToken.getBody().toBuilder()
|
||||
.setObject(ctx)
|
||||
.setSessionKey(ByteString.copyFrom(key.getPublicKeyByte()))
|
||||
.build();
|
||||
|
||||
return protoToken.toBuilder()
|
||||
return sessionToken.toBuilder()
|
||||
.setSignature(signMessagePart(key, body))
|
||||
.setBody(body)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Types.SessionToken createContainerTokenContext(SessionToken sessionToken,
|
||||
public static Types.SessionToken createContainerTokenContext(Types.SessionToken sessionToken,
|
||||
frostfs.refs.Types.ContainerID containerId,
|
||||
Types.ContainerSessionContext.Verb verb,
|
||||
frostfs.refs.Types.OwnerID ownerId,
|
||||
ECDsa key) {
|
||||
var protoToken = SessionMapper.deserializeSessionToken(sessionToken.getToken());
|
||||
if (isNull(sessionToken) || sessionToken.getBody().getContainer().getContainerId().getSerializedSize() > 0) {
|
||||
return sessionToken;
|
||||
}
|
||||
|
||||
var containerSession = Types.ContainerSessionContext.newBuilder().setVerb(verb);
|
||||
|
||||
|
@ -110,7 +112,7 @@ public class RequestConstructor {
|
|||
containerSession.setContainerId(containerId);
|
||||
}
|
||||
|
||||
var bodyBuilder = protoToken.getBody().toBuilder()
|
||||
var bodyBuilder = sessionToken.getBody().toBuilder()
|
||||
.setContainer(containerSession)
|
||||
.setSessionKey(ByteString.copyFrom(key.getPublicKeyByte()));
|
||||
|
||||
|
@ -120,7 +122,7 @@ public class RequestConstructor {
|
|||
|
||||
var body = bodyBuilder.build();
|
||||
|
||||
return protoToken.toBuilder()
|
||||
return sessionToken.toBuilder()
|
||||
.setSignature(signMessagePart(key, body))
|
||||
.setBody(body)
|
||||
.build();
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package info.frostfs.sdk.utils;
|
||||
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import io.grpc.stub.AbstractStub;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class DeadLineUtil {
|
||||
private DeadLineUtil() {
|
||||
}
|
||||
|
||||
public static <T extends AbstractStub<T>> T deadLineAfter(T stub, long deadLine, TimeUnit timeUnit) {
|
||||
if (isNull(stub)) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(PARAM_IS_MISSING_TEMPLATE, AbstractStub.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
timeUnit = isNull(timeUnit) ? TimeUnit.MILLISECONDS : timeUnit;
|
||||
return deadLine > 0 ? stub.withDeadlineAfter(deadLine, timeUnit) : stub;
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package info.frostfs.sdk.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class FrostFSMessages {
|
||||
private FrostFSMessages() {
|
||||
}
|
||||
|
||||
public static void sessionCreationError(Logger logger, String address, String error) {
|
||||
logger.warn("Failed to create frostfs session token for client. Address {}, {}", address, error);
|
||||
}
|
||||
|
||||
public static void errorThresholdReached(Logger logger, String address, long threshold) {
|
||||
logger.warn("Error threshold reached. Address {}, threshold {}", address, threshold);
|
||||
}
|
||||
|
||||
public static void healthChanged(Logger logger, String address, boolean healthy, String error) {
|
||||
logger.warn("Health has changed: {} healthy {}, reason {}", address, healthy, error);
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
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.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.services.impl.AccountingClientImpl;
|
||||
import info.frostfs.sdk.testgenerator.AccountingGenerator;
|
||||
import info.frostfs.sdk.tools.RequestConstructor;
|
||||
import info.frostfs.sdk.tools.RequestSigner;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
import io.grpc.Channel;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.platform.commons.util.ReflectionUtils;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AccountingClientTest {
|
||||
private static final String OWNER_ID = "NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S";
|
||||
|
||||
private AccountingClientImpl accountingClient;
|
||||
|
||||
@Mock
|
||||
private AccountingServiceGrpc.AccountingServiceBlockingStub AccountingServiceClient;
|
||||
@Mock
|
||||
private ClientEnvironment clientEnvironment;
|
||||
@Mock
|
||||
private Channel channel;
|
||||
|
||||
private MockedStatic<Verifier> verifierMock;
|
||||
private MockedStatic<RequestConstructor> requestConstructorMock;
|
||||
private MockedStatic<RequestSigner> requestSignerMock;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IllegalAccessException {
|
||||
when(clientEnvironment.getChannel()).thenReturn(channel);
|
||||
when(clientEnvironment.getOwnerId()).thenReturn(new OwnerId(OWNER_ID));
|
||||
|
||||
accountingClient = new AccountingClientImpl(clientEnvironment);
|
||||
|
||||
Field field = ReflectionUtils.findFields(AccountingClientImpl.class,
|
||||
f -> f.getName().equals("serviceBlockingStub"),
|
||||
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
|
||||
.get(0);
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(accountingClient, AccountingServiceClient);
|
||||
|
||||
verifierMock = Mockito.mockStatic(Verifier.class);
|
||||
requestConstructorMock = Mockito.mockStatic(RequestConstructor.class);
|
||||
requestSignerMock = Mockito.mockStatic(RequestSigner.class);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
verifierMock.close();
|
||||
requestConstructorMock.close();
|
||||
requestSignerMock.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getBalance_success() {
|
||||
//Given
|
||||
var response = AccountingGenerator.generateBalanceResponse();
|
||||
|
||||
var captor = ArgumentCaptor.forClass(Service.BalanceRequest.class);
|
||||
|
||||
when(AccountingServiceClient.balance(captor.capture())).thenReturn(response);
|
||||
|
||||
//When
|
||||
var result = accountingClient.getBalance(new CallContext(0, null));
|
||||
|
||||
//Then
|
||||
requestConstructorMock.verify(
|
||||
() -> RequestConstructor.addMetaHeader(any(Service.BalanceRequest.Builder.class)),
|
||||
times(1)
|
||||
);
|
||||
requestSignerMock.verify(
|
||||
() -> RequestSigner.sign(any(Service.BalanceRequest.Builder.class), eq(null)),
|
||||
times(1)
|
||||
);
|
||||
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||
|
||||
assertEquals(response.getBody().getBalance(), result);
|
||||
|
||||
var request = captor.getValue();
|
||||
assertEquals(OWNER_ID, Base58.encode(request.getBody().getOwnerId().getValue().toByteArray()));
|
||||
}
|
||||
}
|
|
@ -8,10 +8,6 @@ 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.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
||||
import info.frostfs.sdk.services.impl.ApeManagerClientImpl;
|
||||
import info.frostfs.sdk.testgenerator.ApeManagerGenerator;
|
||||
import info.frostfs.sdk.tools.RequestConstructor;
|
||||
|
@ -82,7 +78,6 @@ class ApeManagerClientTest {
|
|||
//Given
|
||||
Chain chain = generateChain();
|
||||
ChainTarget chainTarget = generateChainTarget();
|
||||
PrmApeChainAdd params = new PrmApeChainAdd(chain, chainTarget);
|
||||
|
||||
var response = ApeManagerGenerator.generateAddChainResponse();
|
||||
|
||||
|
@ -91,7 +86,7 @@ class ApeManagerClientTest {
|
|||
when(apeManagerServiceClient.addChain(captor.capture())).thenReturn(response);
|
||||
|
||||
//When
|
||||
var result = apeManagerClient.addChain(params, new CallContext(0, null));
|
||||
var result = apeManagerClient.addChain(chain, chainTarget);
|
||||
|
||||
//Then
|
||||
requestConstructorMock.verify(
|
||||
|
@ -117,15 +112,11 @@ class ApeManagerClientTest {
|
|||
//Given
|
||||
Chain chain = generateChain();
|
||||
ChainTarget chainTarget = generateChainTarget();
|
||||
PrmApeChainAdd params1 = new PrmApeChainAdd(null, chainTarget);
|
||||
PrmApeChainAdd params2 = new PrmApeChainAdd(chain, null);
|
||||
PrmApeChainAdd params3 = new PrmApeChainAdd(null, null);
|
||||
|
||||
|
||||
//When + Then
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params1, new CallContext()));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params2, new CallContext()));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(params3, new CallContext()));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(null, chainTarget));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(chain, null));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.addChain(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -133,7 +124,6 @@ class ApeManagerClientTest {
|
|||
//Given
|
||||
Chain chain = generateChain();
|
||||
ChainTarget chainTarget = generateChainTarget();
|
||||
PrmApeChainRemove params = new PrmApeChainRemove(chain, chainTarget);
|
||||
|
||||
var response = ApeManagerGenerator.generateRemoveChainResponse();
|
||||
|
||||
|
@ -142,7 +132,7 @@ class ApeManagerClientTest {
|
|||
when(apeManagerServiceClient.removeChain(captor.capture())).thenReturn(response);
|
||||
|
||||
//When
|
||||
apeManagerClient.removeChain(params, new CallContext(0, null));
|
||||
apeManagerClient.removeChain(chain, chainTarget);
|
||||
|
||||
//Then
|
||||
requestConstructorMock.verify(
|
||||
|
@ -166,21 +156,17 @@ class ApeManagerClientTest {
|
|||
//Given
|
||||
Chain chain = generateChain();
|
||||
ChainTarget chainTarget = generateChainTarget();
|
||||
PrmApeChainRemove params1 = new PrmApeChainRemove(null, chainTarget);
|
||||
PrmApeChainRemove params2 = new PrmApeChainRemove(chain, null);
|
||||
PrmApeChainRemove params3 = new PrmApeChainRemove(null, null);
|
||||
|
||||
//When + Then
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params1, new CallContext()));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params2, new CallContext()));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.removeChain(params3, new CallContext()));
|
||||
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();
|
||||
PrmApeChainList params = new PrmApeChainList(chainTarget);
|
||||
|
||||
var response = ApeManagerGenerator.generateListChainsResponse();
|
||||
|
||||
|
@ -189,7 +175,7 @@ class ApeManagerClientTest {
|
|||
when(apeManagerServiceClient.listChains(captor.capture())).thenReturn(response);
|
||||
|
||||
//When
|
||||
var result = apeManagerClient.listChains(params, new CallContext(0, null));
|
||||
var result = apeManagerClient.listChains(chainTarget);
|
||||
|
||||
//Then
|
||||
requestConstructorMock.verify(
|
||||
|
@ -216,8 +202,7 @@ class ApeManagerClientTest {
|
|||
@Test
|
||||
void listChain_wrongParams() {
|
||||
//When + Then
|
||||
assertThrows(ValidationFrostFSException.class,
|
||||
() -> apeManagerClient.listChains(new PrmApeChainList(null), new CallContext()));
|
||||
assertThrows(ValidationFrostFSException.class, () -> apeManagerClient.listChains(null));
|
||||
}
|
||||
|
||||
private Chain generateChain() {
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package info.frostfs.sdk.testgenerator;
|
||||
|
||||
import frostfs.accounting.Service;
|
||||
import frostfs.accounting.Types;
|
||||
|
||||
public class AccountingGenerator {
|
||||
|
||||
public static Service.BalanceRequest generateBalanceRequest() {
|
||||
return Service.BalanceRequest.newBuilder()
|
||||
.setBody(generateBalanceRequestBody())
|
||||
.setMetaHeader(SessionGenerator.generateRequestMetaHeader())
|
||||
.setVerifyHeader(SessionGenerator.generateRequestVerificationHeader())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Service.BalanceRequest.Body generateBalanceRequestBody() {
|
||||
return Service.BalanceRequest.Body.newBuilder()
|
||||
.setOwnerId(RefsGenerator.generateOwnerID())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Service.BalanceResponse generateBalanceResponse() {
|
||||
return Service.BalanceResponse.newBuilder()
|
||||
.setBody(generateBalanceResponseBody())
|
||||
.setMetaHeader(SessionGenerator.generateResponseMetaHeader())
|
||||
.setVerifyHeader(SessionGenerator.generateResponseVerificationHeader())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Service.BalanceResponse.Body generateBalanceResponseBody() {
|
||||
return Service.BalanceResponse.Body.newBuilder()
|
||||
.setBalance(generateDecimal())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Types.Decimal generateDecimal() {
|
||||
return Types.Decimal.newBuilder()
|
||||
.setValue(1)
|
||||
.setPrecision(2)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>frostfs-sdk-java</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cryptography</artifactId>
|
||||
|
@ -21,7 +21,7 @@
|
|||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>exceptions</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>frostfs-sdk-java</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>exceptions</artifactId>
|
||||
|
|
|
@ -40,13 +40,6 @@ public class ErrorConst {
|
|||
|
||||
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 SESSION_CREATE_FAILED = "cannot create session";
|
||||
|
||||
public static final String FIELDS_DELIMITER_COMMA = ", ";
|
||||
public static final String FIELDS_DELIMITER_OR = " or ";
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
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;
|
||||
|
||||
public class ProcessFrostFSException extends FrostFSException {
|
||||
public class ProcessFrostFSException extends RuntimeException {
|
||||
public ProcessFrostFSException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
package info.frostfs.sdk.exceptions;
|
||||
|
||||
public class SessionExpiredFrostFSException extends FrostFSException {
|
||||
|
||||
public SessionExpiredFrostFSException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
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;
|
||||
|
||||
public class TimeoutFrostFSException extends FrostFSException {
|
||||
public class TimeoutFrostFSException extends RuntimeException {
|
||||
public TimeoutFrostFSException() {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package info.frostfs.sdk.exceptions;
|
||||
|
||||
public class ValidationFrostFSException extends FrostFSException {
|
||||
public class ValidationFrostFSException extends RuntimeException {
|
||||
public ValidationFrostFSException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>frostfs-sdk-java</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>models</artifactId>
|
||||
|
@ -21,17 +21,17 @@
|
|||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>cryptography</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>protos</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>exceptions</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package info.frostfs.sdk.constants;
|
||||
|
||||
public class AppConst {
|
||||
public static final String RESERVED_PREFIX = "__SYSTEM__";
|
||||
|
||||
public static final int DEFAULT_MAJOR_VERSION = 2;
|
||||
public static final int DEFAULT_MINOR_VERSION = 13;
|
||||
public static final int BYTE_SHIFT = 10;
|
||||
|
@ -12,7 +10,6 @@ public class AppConst {
|
|||
public static final int OBJECT_CHUNK_SIZE = 3 * MIB;
|
||||
public static final int SHA256_HASH_LENGTH = 32;
|
||||
public static final int UUID_BYTE_ARRAY_LENGTH = 16;
|
||||
public static final int DEFAULT_GRPC_TIMEOUT = 5;
|
||||
|
||||
private AppConst() {
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
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() {
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
package info.frostfs.sdk.constants;
|
||||
|
||||
import static info.frostfs.sdk.constants.AppConst.RESERVED_PREFIX;
|
||||
|
||||
public class XHeaderConst {
|
||||
public static final String XHEADER_NETMAP_EPOCH = RESERVED_PREFIX + "NETMAP_EPOCH";
|
||||
public static final String XHEADER_NETMAP_LOOKUP_DEPTH = RESERVED_PREFIX + "NETMAP_LOOKUP_DEPTH";
|
||||
public static final String RESERVED_XHEADER_PREFIX = "__SYSTEM__";
|
||||
public static final String XHEADER_NETMAP_EPOCH = RESERVED_XHEADER_PREFIX + "NETMAP_EPOCH";
|
||||
public static final String XHEADER_NETMAP_LOOKUP_DEPTH = RESERVED_XHEADER_PREFIX + "NETMAP_LOOKUP_DEPTH";
|
||||
|
||||
private XHeaderConst() {
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import info.frostfs.sdk.enums.BasicAcl;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
|
@ -17,7 +15,6 @@ public class Container {
|
|||
private BasicAcl basicAcl;
|
||||
private PlacementPolicy placementPolicy;
|
||||
private Version version;
|
||||
private Map<String, String> attributes = new HashMap<>();
|
||||
|
||||
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy) {
|
||||
this.nonce = UUID.randomUUID();
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package info.frostfs.sdk.dto.object;
|
||||
|
||||
import frostfs.object.Types;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class SplitInfo {
|
||||
private final Types.SplitInfo splitInfo;
|
||||
|
||||
private final SplitId splitId;
|
||||
|
||||
private final ObjectId link;
|
||||
|
||||
private final ObjectId lastPart;
|
||||
}
|
|
@ -7,9 +7,6 @@ import info.frostfs.sdk.enums.BasicAcl;
|
|||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.mappers.netmap.PlacementPolicyMapper;
|
||||
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.asUuid;
|
||||
|
@ -25,22 +22,11 @@ public class ContainerMapper {
|
|||
return null;
|
||||
}
|
||||
|
||||
var containerGrpc = Types.Container.newBuilder()
|
||||
return Types.Container.newBuilder()
|
||||
.setBasicAcl(container.getBasicAcl().value)
|
||||
.setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy()))
|
||||
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())));
|
||||
|
||||
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();
|
||||
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Container toModel(Types.Container containerGrpc) {
|
||||
|
@ -55,17 +41,9 @@ public class ContainerMapper {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
var container = new Container(basicAcl, PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()));
|
||||
container.setNonce(asUuid(containerGrpc.getNonce().toByteArray()));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package info.frostfs.sdk.mappers.object;
|
||||
|
||||
import frostfs.object.Types;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.dto.object.SplitId;
|
||||
import info.frostfs.sdk.dto.object.SplitInfo;
|
||||
|
||||
import static info.frostfs.sdk.UuidExtension.asUuid;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class SplitInfoMapper {
|
||||
private SplitInfoMapper() {
|
||||
}
|
||||
|
||||
public static SplitInfo toModel(Types.SplitInfo splitInfo) {
|
||||
if (isNull(splitInfo) || splitInfo.getSerializedSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var splitId = new SplitId(asUuid(splitInfo.getSplitId().toByteArray()));
|
||||
var link = splitInfo.getLink().getSerializedSize() == 0
|
||||
? null
|
||||
: new ObjectId(splitInfo.getLink().getValue().toByteArray());
|
||||
var lastPart = splitInfo.getLastPart().getSerializedSize() == 0
|
||||
? null
|
||||
: new ObjectId(splitInfo.getLastPart().getValue().toByteArray());
|
||||
|
||||
return new SplitInfo(splitInfo, splitId, link, lastPart);
|
||||
}
|
||||
}
|
|
@ -15,7 +15,6 @@ import java.util.UUID;
|
|||
|
||||
import static info.frostfs.sdk.UuidExtension.asBytes;
|
||||
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.*;
|
||||
|
||||
public class ContainerMapperTest {
|
||||
|
@ -25,8 +24,6 @@ public class ContainerMapperTest {
|
|||
//Given
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
||||
var container = new Container(BasicAcl.PUBLIC_RW, placementPolicy);
|
||||
container.getAttributes().put("key1", "val1");
|
||||
container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, "false");
|
||||
|
||||
//When
|
||||
var result = ContainerMapper.toGrpcMessage(container);
|
||||
|
@ -45,11 +42,6 @@ public class ContainerMapperTest {
|
|||
container.getPlacementPolicy().getReplicas()[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
|
||||
|
@ -77,23 +69,11 @@ public class ContainerMapperTest {
|
|||
.addReplicas(replica)
|
||||
.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()
|
||||
.setBasicAcl(basicAcl.value)
|
||||
.setNonce(ByteString.copyFrom(asBytes(UUID.randomUUID())))
|
||||
.setVersion(version)
|
||||
.setPlacementPolicy(placementPolicy)
|
||||
.addAttributes(attribute1)
|
||||
.addAttributes(attribute2)
|
||||
.build();
|
||||
|
||||
//When
|
||||
|
@ -115,9 +95,6 @@ public class ContainerMapperTest {
|
|||
);
|
||||
assertEquals(version.getMajor(), result.getVersion().getMajor());
|
||||
assertEquals(version.getMinor(), result.getVersion().getMinor());
|
||||
|
||||
assertEquals(attribute1.getValue(), result.getAttributes().get(attribute1.getKey()));
|
||||
assertEquals(attribute2.getValue(), result.getAttributes().get(attribute2.getKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package info.frostfs.sdk.mappers.object;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostfs.object.Types;
|
||||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.dto.object.SplitId;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class SplitInfoMapperTest {
|
||||
@Test
|
||||
void toModel_successLastPart() {
|
||||
//Given
|
||||
var splitId = new SplitId();
|
||||
var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww");
|
||||
var splitInfo = Types.SplitInfo.newBuilder()
|
||||
.setSplitId(ByteString.copyFrom(splitId.toBinary()))
|
||||
.setLastPart(ObjectIdMapper.toGrpcMessage(objectId))
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = SplitInfoMapper.toModel(splitInfo);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertNull(result.getLink());
|
||||
assertThat(result.getSplitInfo()).isEqualTo(splitInfo);
|
||||
assertThat(result.getSplitId().toBinary()).containsExactly(splitId.toBinary());
|
||||
assertEquals(objectId.getValue(), result.getLastPart().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_successLink() {
|
||||
//Given
|
||||
var splitId = new SplitId();
|
||||
var objectId = new ObjectId("85orCLKSu3X1jGiTFmwmTUsBU88RBARNwuRwrEy5pyww");
|
||||
var splitInfo = Types.SplitInfo.newBuilder()
|
||||
.setSplitId(ByteString.copyFrom(splitId.toBinary()))
|
||||
.setLink(ObjectIdMapper.toGrpcMessage(objectId))
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = SplitInfoMapper.toModel(splitInfo);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertNull(result.getLastPart());
|
||||
assertThat(result.getSplitInfo()).isEqualTo(splitInfo);
|
||||
assertThat(result.getSplitId().toBinary()).containsExactly(splitId.toBinary());
|
||||
assertEquals(objectId.getValue(), result.getLink().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_null() {
|
||||
//When + Then
|
||||
assertNull(SplitInfoMapper.toModel(null));
|
||||
assertNull(SplitInfoMapper.toModel(Types.SplitInfo.getDefaultInstance()));
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>frostfs-sdk-java</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>client</module>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>frostfs-sdk-java</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>protos</artifactId>
|
||||
|
|
Loading…
Reference in a new issue