forked from TrueCloudLab/frostfs-sdk-java
149 lines
5.3 KiB
Java
149 lines
5.3 KiB
Java
package info.frostfs.sdk;
|
|
|
|
import frostfs.session.Types;
|
|
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;
|
|
import info.frostfs.sdk.dto.session.SessionToken;
|
|
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.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.utils.Validator;
|
|
import io.grpc.Channel;
|
|
import io.grpc.ClientInterceptors;
|
|
|
|
import java.util.List;
|
|
|
|
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 ContainerClient, ObjectClient, NetmapClient, SessionClient, ToolsClient {
|
|
private final ContainerClientImpl containerClientImpl;
|
|
private final NetmapClientImpl netmapClientImpl;
|
|
private final ObjectClientImpl objectClientImpl;
|
|
private final SessionClientImpl sessionClientImpl;
|
|
private final ObjectToolsImpl objectToolsImpl;
|
|
|
|
public FrostFSClient(ClientSettings clientSettings) {
|
|
Validator.validate(clientSettings);
|
|
Channel channel = nonNull(clientSettings.getChannel())
|
|
? clientSettings.getChannel()
|
|
: initGrpcChannel(clientSettings);
|
|
|
|
MonitoringClientInterceptor monitoringClientInterceptor = MonitoringClientInterceptor
|
|
.create(Configuration.allMetrics());
|
|
channel = ClientInterceptors.intercept(channel, monitoringClientInterceptor);
|
|
ClientEnvironment clientEnvironment =
|
|
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
|
|
|
|
Validator.validate(clientEnvironment);
|
|
|
|
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
|
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
|
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
|
this.objectClientImpl = new ObjectClientImpl(clientEnvironment);
|
|
this.objectToolsImpl = new ObjectToolsImpl(clientEnvironment);
|
|
checkFrostFsVersionSupport(clientEnvironment.getVersion());
|
|
}
|
|
|
|
private void checkFrostFsVersionSupport(Version version) {
|
|
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
|
if (!localNodeInfo.getVersion().isSupported(version)) {
|
|
throw new ProcessFrostFSException(
|
|
String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion())
|
|
);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Container getContainer(ContainerId cid) {
|
|
return containerClientImpl.getContainer(cid);
|
|
}
|
|
|
|
@Override
|
|
public List<ContainerId> listContainers() {
|
|
return containerClientImpl.listContainers();
|
|
}
|
|
|
|
@Override
|
|
public ContainerId createContainer(Container container) {
|
|
return containerClientImpl.createContainer(container);
|
|
}
|
|
|
|
@Override
|
|
public void deleteContainer(ContainerId cid) {
|
|
containerClientImpl.deleteContainer(cid);
|
|
}
|
|
|
|
@Override
|
|
public ObjectHeader getObjectHead(ContainerId containerId, ObjectId objectId) {
|
|
return objectClientImpl.getObjectHead(containerId, objectId);
|
|
}
|
|
|
|
@Override
|
|
public ObjectFrostFS getObject(ContainerId containerId, ObjectId objectId) {
|
|
return objectClientImpl.getObject(containerId, objectId);
|
|
}
|
|
|
|
@Override
|
|
public ObjectId putObject(PutObjectParameters parameters) {
|
|
return objectClientImpl.putObject(parameters);
|
|
}
|
|
|
|
@Override
|
|
public ObjectId putSingleObject(ObjectFrostFS objectFrostFS) {
|
|
return objectClientImpl.putSingleObject(objectFrostFS);
|
|
}
|
|
|
|
@Override
|
|
public void deleteObject(ContainerId containerId, ObjectId objectId) {
|
|
objectClientImpl.deleteObject(containerId, objectId);
|
|
}
|
|
|
|
@Override
|
|
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
|
return objectClientImpl.searchObjects(cid, filters);
|
|
}
|
|
|
|
@Override
|
|
public NetmapSnapshot getNetmapSnapshot() {
|
|
return netmapClientImpl.getNetmapSnapshot();
|
|
}
|
|
|
|
@Override
|
|
public NodeInfo getLocalNodeInfo() {
|
|
return netmapClientImpl.getLocalNodeInfo();
|
|
}
|
|
|
|
@Override
|
|
public NetworkSettings getNetworkSettings() {
|
|
return netmapClientImpl.getNetworkSettings();
|
|
}
|
|
|
|
@Override
|
|
public SessionToken createSession(long expiration) {
|
|
return sessionClientImpl.createSession(expiration);
|
|
}
|
|
|
|
public Types.SessionToken createSessionInternal(long expiration) {
|
|
return sessionClientImpl.createSessionInternal(expiration);
|
|
}
|
|
|
|
@Override
|
|
public ObjectId calculateObjectId(ObjectHeader header) {
|
|
return objectToolsImpl.calculateObjectId(header);
|
|
}
|
|
}
|