[#14] add lombok and refactor exceptions. #15
87 changed files with 819 additions and 970 deletions
|
@ -35,7 +35,7 @@ public class ContainerExample {
|
||||||
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
||||||
|
|
||||||
// Create container
|
// Create container
|
||||||
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, Boolean.TRUE);
|
||||||
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||||
|
|
||||||
// Get container
|
// Get container
|
||||||
|
@ -91,7 +91,7 @@ public class ObjectExample {
|
||||||
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
|
||||||
|
|
||||||
// Search regular objects
|
// Search regular objects
|
||||||
var objectIds = frostFSClient.searchObjects(containerId, ObjectFilter.RootFilter());
|
var objectIds = frostFSClient.searchObjects(containerId, new ObjectFilter.FilterByRootObject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
|
@ -29,9 +29,9 @@
|
||||||
<version>0.1.0</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>commons-collections4</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
<version>4.4</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
|
|
|
@ -11,24 +11,23 @@ import info.frostfs.sdk.dto.object.ObjectFrostFS;
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
import info.frostfs.sdk.dto.object.ObjectId;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.ClientSettings;
|
import info.frostfs.sdk.jdo.ClientSettings;
|
||||||
import info.frostfs.sdk.jdo.NetworkSettings;
|
import info.frostfs.sdk.jdo.NetworkSettings;
|
||||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
import info.frostfs.sdk.services.*;
|
import info.frostfs.sdk.services.*;
|
||||||
import info.frostfs.sdk.services.impl.*;
|
import info.frostfs.sdk.services.impl.*;
|
||||||
|
import info.frostfs.sdk.utils.Validator;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.VERSION_UNSUPPORTED_TEMPLATE;
|
||||||
import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel;
|
import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel;
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
import static java.util.Objects.nonNull;
|
import static java.util.Objects.nonNull;
|
||||||
|
|
||||||
public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClient, SessionClient, ToolsClient {
|
public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClient, SessionClient, ToolsClient {
|
||||||
private static final String ERROR_CLIENT_OPTIONS_INIT = "Options must be initialized.";
|
|
||||||
private static final String ERROR_VERSION_SUPPORT_TEMPLATE = "FrostFS %s is not supported.";
|
|
||||||
|
|
||||||
private final ContainerClientImpl containerClientImpl;
|
private final ContainerClientImpl containerClientImpl;
|
||||||
private final NetmapClientImpl netmapClientImpl;
|
private final NetmapClientImpl netmapClientImpl;
|
||||||
private final ObjectClientImpl objectClientImpl;
|
private final ObjectClientImpl objectClientImpl;
|
||||||
|
@ -36,16 +35,16 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
||||||
private final ObjectToolsImpl objectToolsImpl;
|
private final ObjectToolsImpl objectToolsImpl;
|
||||||
|
|
||||||
public FrostFSClient(ClientSettings clientSettings) {
|
public FrostFSClient(ClientSettings clientSettings) {
|
||||||
if (isNull(clientSettings)) {
|
Validator.validate(clientSettings);
|
||||||
throw new IllegalArgumentException(ERROR_CLIENT_OPTIONS_INIT);
|
Channel channel = nonNull(clientSettings.getChannel())
|
||||||
}
|
? clientSettings.getChannel()
|
||||||
|
: initGrpcChannel(clientSettings);
|
||||||
Channel channel = nonNull(clientSettings.getChannel()) ? clientSettings.getChannel()
|
|
||||||
: initGrpcChannel(clientSettings.getHost(), clientSettings.getCredentials());
|
|
||||||
|
|
||||||
ClientEnvironment clientEnvironment =
|
ClientEnvironment clientEnvironment =
|
||||||
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
|
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
|
||||||
|
|
||||||
|
Validator.validate(clientEnvironment);
|
||||||
|
|
||||||
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
|
||||||
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
|
||||||
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
|
||||||
|
@ -57,8 +56,8 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
|
||||||
private void checkFrostFsVersionSupport(Version version) {
|
private void checkFrostFsVersionSupport(Version version) {
|
||||||
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
|
||||||
if (!localNodeInfo.getVersion().isSupported(version)) {
|
if (!localNodeInfo.getVersion().isSupported(version)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(ERROR_VERSION_SUPPORT_TEMPLATE, localNodeInfo.getVersion())
|
String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package info.frostfs.sdk.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
|
||||||
|
public @interface AtLeastOneIsFilled {
|
||||||
|
String message() default "At least one of the fields (%s) must be filled in";
|
||||||
|
|
||||||
|
String[] fields();
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.frostfs.sdk.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface NotBlank {
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.frostfs.sdk.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface NotNull {
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.frostfs.sdk.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface Validate {
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ package info.frostfs.sdk.constants;
|
||||||
|
|
||||||
public class CryptoConst {
|
public class CryptoConst {
|
||||||
public static final String SIGNATURE_ALGORITHM = "NONEwithECDSAinP1363Format";
|
public static final String SIGNATURE_ALGORITHM = "NONEwithECDSAinP1363Format";
|
||||||
|
public static final int RFC6979_SIGNATURE_SIZE = 64;
|
||||||
|
public static final int HASH_SIGNATURE_SIZE = 65;
|
||||||
|
|
||||||
private CryptoConst() {
|
private CryptoConst() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package info.frostfs.sdk.exceptions;
|
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.response.ResponseStatus;
|
|
||||||
|
|
||||||
public class ResponseException extends RuntimeException {
|
|
||||||
private final ResponseStatus status;
|
|
||||||
|
|
||||||
public ResponseException(ResponseStatus status) {
|
|
||||||
super(status.toString());
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResponseStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.dto.response.ResponseStatus;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class ResponseFrostFSException extends RuntimeException {
|
||||||
|
private final ResponseStatus status;
|
||||||
|
|
||||||
|
public ResponseFrostFSException(ResponseStatus status) {
|
||||||
|
super(status.toString());
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResponseFrostFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
this.status = null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
package info.frostfs.sdk.exceptions;
|
|
||||||
|
|
||||||
public class TimeoutException extends RuntimeException {
|
|
||||||
public TimeoutException() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +1,41 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
import info.frostfs.sdk.FrostFSClient;
|
import info.frostfs.sdk.FrostFSClient;
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
|
import info.frostfs.sdk.annotations.Validate;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
import info.frostfs.sdk.dto.object.OwnerId;
|
import info.frostfs.sdk.dto.object.OwnerId;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class ClientEnvironment {
|
public class ClientEnvironment {
|
||||||
private static final String ERROR_MESSAGE = "One of the input attributes is missing";
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final OwnerId ownerId;
|
private final OwnerId ownerId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final Version version;
|
private final Version version;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Validate
|
||||||
private final ECDsa key;
|
private final ECDsa key;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final FrostFSClient frostFSClient;
|
private final FrostFSClient frostFSClient;
|
||||||
|
|
||||||
private NetworkSettings networkSettings;
|
private NetworkSettings networkSettings;
|
||||||
|
|
||||||
public ClientEnvironment(String wif, Channel channel, Version version, FrostFSClient frostFSClient) {
|
public ClientEnvironment(String wif, Channel channel, Version version, FrostFSClient frostFSClient) {
|
||||||
if (StringUtils.isEmpty(wif) || isNull(channel) || isNull(version) || isNull(frostFSClient)) {
|
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.key = new ECDsa(wif);
|
this.key = new ECDsa(wif);
|
||||||
this.ownerId = new OwnerId(key.getPublicKeyByte());
|
this.ownerId = new OwnerId(key.getPublicKeyByte());
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.frostFSClient = frostFSClient;
|
this.frostFSClient = frostFSClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Channel getChannel() {
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NetworkSettings getNetworkSettings() {
|
|
||||||
return networkSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNetworkSettings(NetworkSettings networkSettings) {
|
|
||||||
this.networkSettings = networkSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FrostFSClient getFrostFSClient() {
|
|
||||||
return frostFSClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OwnerId getOwnerId() {
|
|
||||||
return ownerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ECDsa getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ChannelCredentials;
|
import io.grpc.ChannelCredentials;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.FieldNameConstants;
|
||||||
import static java.util.Objects.isNull;
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@FieldNameConstants
|
||||||
|
@AtLeastOneIsFilled(fields = {ClientSettings.Fields.host, ClientSettings.Fields.channel})
|
||||||
public class ClientSettings {
|
public class ClientSettings {
|
||||||
private static final String ERROR_TEMPLATE = "%s required parameter.";
|
|
||||||
private static final String KEY_NAME = "Key";
|
|
||||||
private static final String HOST_AND_CHANNEL_NAME = "Host or Channel";
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final String key;
|
private final String key;
|
||||||
|
|
||||||
private String host;
|
private String host;
|
||||||
private ChannelCredentials credentials;
|
private ChannelCredentials credentials;
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
|
@ -19,51 +22,16 @@ public class ClientSettings {
|
||||||
public ClientSettings(String key, String host) {
|
public ClientSettings(String key, String host) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientSettings(String key, String host, ChannelCredentials credentials) {
|
public ClientSettings(String key, String host, ChannelCredentials credentials) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientSettings(String key, Channel channel) {
|
public ClientSettings(String key, Channel channel) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Channel getChannel() {
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChannelCredentials getCredentials() {
|
|
||||||
return credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getHost() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate() {
|
|
||||||
StringBuilder errorMessage = new StringBuilder();
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(key)) {
|
|
||||||
errorMessage.append(String.format(ERROR_TEMPLATE, KEY_NAME)).append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(host) && isNull(channel)) {
|
|
||||||
errorMessage.append(String.format(ERROR_TEMPLATE, HOST_AND_CHANNEL_NAME)).append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errorMessage.length() != 0) {
|
|
||||||
throw new IllegalArgumentException(errorMessage.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,34 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
|
|
||||||
import static info.frostfs.sdk.KeyExtension.*;
|
import static info.frostfs.sdk.KeyExtension.*;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.WIF_IS_INVALID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class ECDsa {
|
public class ECDsa {
|
||||||
private static final String ERROR_MESSAGE = "WIF is invalid";
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final byte[] publicKeyByte;
|
private final byte[] publicKeyByte;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final byte[] privateKeyByte;
|
private final byte[] privateKeyByte;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final PrivateKey privateKey;
|
private final PrivateKey privateKey;
|
||||||
|
|
||||||
public ECDsa(String wif) {
|
public ECDsa(String wif) {
|
||||||
if (StringUtils.isEmpty(wif)) {
|
if (StringUtils.isEmpty(wif)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(WIF_IS_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.privateKeyByte = getPrivateKeyFromWIF(wif);
|
this.privateKeyByte = getPrivateKeyFromWIF(wif);
|
||||||
this.publicKeyByte = loadPublicKey(privateKeyByte);
|
this.publicKeyByte = loadPublicKey(privateKeyByte);
|
||||||
this.privateKey = loadPrivateKey(privateKeyByte);
|
this.privateKey = loadPrivateKey(privateKeyByte);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getPublicKeyByte() {
|
|
||||||
return publicKeyByte;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPrivateKeyByte() {
|
|
||||||
return privateKeyByte;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PrivateKey getPrivateKey() {
|
|
||||||
return privateKey;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class NetworkSettings {
|
public class NetworkSettings {
|
||||||
|
|
||||||
private Long auditFee;
|
private Long auditFee;
|
||||||
|
@ -20,124 +25,4 @@ public class NetworkSettings {
|
||||||
private Boolean homomorphicHashingDisabled;
|
private Boolean homomorphicHashingDisabled;
|
||||||
private Boolean maintenanceModeAllowed;
|
private Boolean maintenanceModeAllowed;
|
||||||
private Map<String, Object> unnamedSettings = new HashMap<>();
|
private Map<String, Object> unnamedSettings = new HashMap<>();
|
||||||
|
|
||||||
public Long getAuditFee() {
|
|
||||||
return auditFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuditFee(Long auditFee) {
|
|
||||||
this.auditFee = auditFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getBasicIncomeRate() {
|
|
||||||
return basicIncomeRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicIncomeRate(Long basicIncomeRate) {
|
|
||||||
this.basicIncomeRate = basicIncomeRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getContainerFee() {
|
|
||||||
return containerFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContainerFee(long containerFee) {
|
|
||||||
this.containerFee = containerFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getContainerAliasFee() {
|
|
||||||
return containerAliasFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContainerAliasFee(long containerAliasFee) {
|
|
||||||
this.containerAliasFee = containerAliasFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getInnerRingCandidateFee() {
|
|
||||||
return innerRingCandidateFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInnerRingCandidateFee(long innerRingCandidateFee) {
|
|
||||||
this.innerRingCandidateFee = innerRingCandidateFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getWithdrawFee() {
|
|
||||||
return withdrawFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWithdrawFee(long withdrawFee) {
|
|
||||||
this.withdrawFee = withdrawFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getEpochDuration() {
|
|
||||||
return epochDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEpochDuration(long epochDuration) {
|
|
||||||
this.epochDuration = epochDuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getIRCandidateFee() {
|
|
||||||
return iRCandidateFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIRCandidateFee(long iRCandidateFee) {
|
|
||||||
this.iRCandidateFee = iRCandidateFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMaxObjectSize() {
|
|
||||||
return maxObjectSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxObjectSize(long maxObjectSize) {
|
|
||||||
this.maxObjectSize = maxObjectSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMaxECDataCount() {
|
|
||||||
return maxECDataCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxECDataCount(long maxECDataCount) {
|
|
||||||
this.maxECDataCount = maxECDataCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMaxECParityCount() {
|
|
||||||
return maxECParityCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxECParityCount(long maxECParityCount) {
|
|
||||||
this.maxECParityCount = maxECParityCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getWithdrawalFee() {
|
|
||||||
return withdrawalFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWithdrawalFee(long withdrawalFee) {
|
|
||||||
this.withdrawalFee = withdrawalFee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHomomorphicHashingDisabled() {
|
|
||||||
return homomorphicHashingDisabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHomomorphicHashingDisabled(boolean homomorphicHashingDisabled) {
|
|
||||||
this.homomorphicHashingDisabled = homomorphicHashingDisabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMaintenanceModeAllowed() {
|
|
||||||
return maintenanceModeAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaintenanceModeAllowed(boolean maintenanceModeAllowed) {
|
|
||||||
this.maintenanceModeAllowed = maintenanceModeAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getUnnamedSettings() {
|
|
||||||
return unnamedSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUnnamedSettings(Map<String, Object> unnamedSettings) {
|
|
||||||
this.unnamedSettings = unnamedSettings;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
|
||||||
import static java.util.Objects.isNull;
|
@Getter
|
||||||
|
@Setter
|
||||||
public class PutObjectParameters {
|
public class PutObjectParameters {
|
||||||
private static final String ERROR_TEMPLATE = "%s value cannot be null.";
|
|
||||||
private static final String HEADER_NAME = "Header";
|
|
||||||
private static final String PAYLOAD_NAME = "Payload";
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private ObjectHeader header;
|
private ObjectHeader header;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private FileInputStream payload;
|
private FileInputStream payload;
|
||||||
|
|
||||||
private boolean clientCut;
|
private boolean clientCut;
|
||||||
private int bufferMaxSize;
|
private int bufferMaxSize;
|
||||||
private byte[] customerBuffer;
|
private byte[] customerBuffer;
|
||||||
|
@ -27,102 +31,10 @@ public class PutObjectParameters {
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
this.clientCut = clientCut;
|
this.clientCut = clientCut;
|
||||||
this.bufferMaxSize = bufferMaxSize;
|
this.bufferMaxSize = bufferMaxSize;
|
||||||
|
|
||||||
validate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutObjectParameters(ObjectHeader header, FileInputStream payload) {
|
public PutObjectParameters(ObjectHeader header, FileInputStream payload) {
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
|
|
||||||
validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getCustomerBuffer() {
|
|
||||||
return customerBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCustomerBuffer(byte[] customerBuffer) {
|
|
||||||
this.customerBuffer = customerBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SessionToken getSessionToken() {
|
|
||||||
return sessionToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSessionToken(SessionToken sessionToken) {
|
|
||||||
this.sessionToken = sessionToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMaxObjectSizeCache() {
|
|
||||||
return maxObjectSizeCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxObjectSizeCache(int maxObjectSizeCache) {
|
|
||||||
this.maxObjectSizeCache = maxObjectSizeCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCurrentStreamPosition() {
|
|
||||||
return currentStreamPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentStreamPosition(long currentStreamPosition) {
|
|
||||||
this.currentStreamPosition = currentStreamPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getFullLength() {
|
|
||||||
return fullLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFullLength(long fullLength) {
|
|
||||||
this.fullLength = fullLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectHeader getHeader() {
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHeader(ObjectHeader header) {
|
|
||||||
this.header = header;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileInputStream getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayload(FileInputStream payload) {
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isClientCut() {
|
|
||||||
return clientCut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientCut(boolean clientCut) {
|
|
||||||
this.clientCut = clientCut;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBufferMaxSize() {
|
|
||||||
return bufferMaxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBufferMaxSize(int bufferMaxSize) {
|
|
||||||
this.bufferMaxSize = bufferMaxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void validate() {
|
|
||||||
StringBuilder errorMessage = new StringBuilder();
|
|
||||||
|
|
||||||
if (isNull(header)) {
|
|
||||||
errorMessage.append(String.format(ERROR_TEMPLATE, HEADER_NAME)).append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNull(payload)) {
|
|
||||||
errorMessage.append(String.format(ERROR_TEMPLATE, PAYLOAD_NAME)).append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errorMessage.length() != 0) {
|
|
||||||
throw new IllegalArgumentException(errorMessage.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.object.ObjectId;
|
import info.frostfs.sdk.dto.object.ObjectId;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class PutObjectResult {
|
public class PutObjectResult {
|
||||||
|
|
||||||
private final ObjectId objectId;
|
private final ObjectId objectId;
|
||||||
private final int objectSize;
|
private final int objectSize;
|
||||||
|
|
||||||
public PutObjectResult(ObjectId objectId, int objectSize) {
|
|
||||||
this.objectId = objectId;
|
|
||||||
this.objectSize = objectSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectId getObjectId() {
|
|
||||||
return objectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getObjectSize() {
|
|
||||||
return objectSize;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
package info.frostfs.sdk.jdo;
|
package info.frostfs.sdk.jdo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class WaitParameters {
|
public class WaitParameters {
|
||||||
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120);
|
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120);
|
||||||
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
|
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
|
||||||
|
@ -15,19 +20,6 @@ public class WaitParameters {
|
||||||
this.pollInterval = DEFAULT_POLL_INTERVAL;
|
this.pollInterval = DEFAULT_POLL_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaitParameters(Duration timeout, Duration pollInterval) {
|
|
||||||
this.timeout = timeout;
|
|
||||||
this.pollInterval = pollInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getTimeout() {
|
|
||||||
return timeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Duration getPollInterval() {
|
|
||||||
return pollInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getDeadline() {
|
public LocalDateTime getDeadline() {
|
||||||
return LocalDateTime.now().plus(timeout);
|
return LocalDateTime.now().plus(timeout);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package info.frostfs.sdk.services;
|
package info.frostfs.sdk.services;
|
||||||
|
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class ContextAccessor {
|
public class ContextAccessor {
|
||||||
private final ClientEnvironment context;
|
private final ClientEnvironment context;
|
||||||
|
|
||||||
|
@ -9,7 +11,4 @@ public class ContextAccessor {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientEnvironment getContext() {
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,9 @@ import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.enums.StatusCode;
|
import info.frostfs.sdk.enums.StatusCode;
|
||||||
import info.frostfs.sdk.enums.WaitExpects;
|
import info.frostfs.sdk.enums.WaitExpects;
|
||||||
import info.frostfs.sdk.exceptions.ResponseException;
|
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
||||||
import info.frostfs.sdk.exceptions.TimeoutException;
|
import info.frostfs.sdk.exceptions.TimeoutFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.WaitParameters;
|
import info.frostfs.sdk.jdo.WaitParameters;
|
||||||
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
||||||
|
@ -28,12 +29,10 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ContainerClientImpl extends ContextAccessor implements ContainerClient {
|
public class ContainerClientImpl extends ContextAccessor implements ContainerClient {
|
||||||
private static final String ERROR_CONTAINER_ID_MISSING = "ContainerId is not present";
|
|
||||||
private static final String ERROR_CONTAINER_MISSING = "Container is not present";
|
|
||||||
|
|
||||||
private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub;
|
private final ContainerServiceGrpc.ContainerServiceBlockingStub serviceBlockingStub;
|
||||||
private final SessionToolsImpl sessionTools;
|
private final SessionToolsImpl sessionTools;
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
@Override
|
@Override
|
||||||
public Container getContainer(ContainerId cid) {
|
public Container getContainer(ContainerId cid) {
|
||||||
if (isNull(cid)) {
|
if (isNull(cid)) {
|
||||||
throw new IllegalArgumentException(ERROR_CONTAINER_ID_MISSING);
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = createGetRequest(ContainerIdMapper.toGrpcMessage(cid), null);
|
var request = createGetRequest(ContainerIdMapper.toGrpcMessage(cid), null);
|
||||||
|
@ -77,7 +76,7 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
@Override
|
@Override
|
||||||
public ContainerId createContainer(Container container) {
|
public ContainerId createContainer(Container container) {
|
||||||
if (isNull(container)) {
|
if (isNull(container)) {
|
||||||
throw new IllegalArgumentException(ERROR_CONTAINER_MISSING);
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, Container.class.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
var grpcContainer = ContainerMapper.toGrpcMessage(container);
|
var grpcContainer = ContainerMapper.toGrpcMessage(container);
|
||||||
|
@ -95,7 +94,7 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
@Override
|
@Override
|
||||||
public void deleteContainer(ContainerId cid) {
|
public void deleteContainer(ContainerId cid) {
|
||||||
if (isNull(cid)) {
|
if (isNull(cid)) {
|
||||||
throw new IllegalArgumentException(ERROR_CONTAINER_ID_MISSING);
|
throw new ValidationFrostFSException(String.format(PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
var grpcContainerId = ContainerIdMapper.toGrpcMessage(cid);
|
var grpcContainerId = ContainerIdMapper.toGrpcMessage(cid);
|
||||||
|
@ -124,13 +123,13 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LocalDateTime.now().isAfter(deadLine)) {
|
if (LocalDateTime.now().isAfter(deadLine)) {
|
||||||
throw new TimeoutException();
|
throw new TimeoutFrostFSException();
|
||||||
}
|
}
|
||||||
|
|
||||||
WaitUtil.sleep(waitParams.getPollInterval().toMillis());
|
WaitUtil.sleep(waitParams.getPollInterval().toMillis());
|
||||||
} catch (ResponseException exp) {
|
} catch (ResponseFrostFSException exp) {
|
||||||
if (LocalDateTime.now().isAfter(deadLine)) {
|
if (LocalDateTime.now().isAfter(deadLine)) {
|
||||||
throw new TimeoutException();
|
throw new TimeoutFrostFSException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp.getStatus().getCode() != StatusCode.CONTAINER_NOT_FOUND) {
|
if (exp.getStatus().getCode() != StatusCode.CONTAINER_NOT_FOUND) {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.object.*;
|
import info.frostfs.sdk.dto.object.*;
|
||||||
import info.frostfs.sdk.dto.session.SessionToken;
|
import info.frostfs.sdk.dto.session.SessionToken;
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||||
import info.frostfs.sdk.jdo.PutObjectParameters;
|
import info.frostfs.sdk.jdo.PutObjectParameters;
|
||||||
import info.frostfs.sdk.jdo.PutObjectResult;
|
import info.frostfs.sdk.jdo.PutObjectResult;
|
||||||
|
@ -26,6 +28,7 @@ import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
|
||||||
import info.frostfs.sdk.services.impl.rwhelper.SearchReader;
|
import info.frostfs.sdk.services.impl.rwhelper.SearchReader;
|
||||||
import info.frostfs.sdk.tools.RequestConstructor;
|
import info.frostfs.sdk.tools.RequestConstructor;
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
|
import info.frostfs.sdk.utils.Validator;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -34,12 +37,11 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static info.frostfs.sdk.Helper.getSha256;
|
import static info.frostfs.sdk.Helper.getSha256;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
private static final String ERROR_PARAMS_MISSING = "Params is not present";
|
|
||||||
|
|
||||||
private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient;
|
private final ObjectServiceGrpc.ObjectServiceBlockingStub objectServiceBlockingClient;
|
||||||
private final ObjectServiceGrpc.ObjectServiceStub objectServiceClient;
|
private final ObjectServiceGrpc.ObjectServiceStub objectServiceClient;
|
||||||
private final ObjectToolsImpl objectToolsImpl;
|
private final ObjectToolsImpl objectToolsImpl;
|
||||||
|
@ -60,7 +62,12 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
@Override
|
@Override
|
||||||
public ObjectHeader getObjectHead(ContainerId cid, ObjectId oid) {
|
public ObjectHeader getObjectHead(ContainerId cid, ObjectId oid) {
|
||||||
if (isNull(cid) || isNull(oid)) {
|
if (isNull(cid) || isNull(oid)) {
|
||||||
throw new IllegalArgumentException(ERROR_PARAMS_MISSING);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(
|
||||||
|
PARAMS_ARE_MISSING_TEMPLATE,
|
||||||
|
String.join(FIELDS_DELIMITER_COMMA, ContainerId.class.getName(), ObjectId.class.getName())
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var request = createHeadRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
var request = createHeadRequest(ContainerIdMapper.toGrpcMessage(cid), ObjectIdMapper.toGrpcMessage(oid));
|
||||||
|
@ -89,7 +96,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter... filters) {
|
public Iterable<ObjectId> searchObjects(ContainerId cid, ObjectFilter<?>... filters) {
|
||||||
var request = createSearchRequest(ContainerIdMapper.toGrpcMessage(cid), filters);
|
var request = createSearchRequest(ContainerIdMapper.toGrpcMessage(cid), filters);
|
||||||
|
|
||||||
var objectsIds = searchObjects(request);
|
var objectsIds = searchObjects(request);
|
||||||
|
@ -99,7 +106,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ObjectId putObject(PutObjectParameters parameters) {
|
public ObjectId putObject(PutObjectParameters parameters) {
|
||||||
parameters.validate();
|
Validator.validate(parameters);
|
||||||
|
|
||||||
if (parameters.isClientCut()) {
|
if (parameters.isClientCut()) {
|
||||||
return putClientCutObject(parameters);
|
return putClientCutObject(parameters);
|
||||||
|
@ -140,7 +147,9 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
|
|
||||||
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest) {
|
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest) {
|
||||||
if (initRequest.getSerializedSize() == 0) {
|
if (initRequest.getSerializedSize() == 0) {
|
||||||
throw new IllegalArgumentException(initRequest.getClass().getName());
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ObjectReaderImpl(objectServiceBlockingClient.get(initRequest));
|
return new ObjectReaderImpl(objectServiceBlockingClient.get(initRequest));
|
||||||
|
@ -209,7 +218,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
|
|
||||||
if (parameters.getMaxObjectSizeCache() == 0) {
|
if (parameters.getMaxObjectSizeCache() == 0) {
|
||||||
var networkSettings = getContext().getFrostFSClient().getNetworkSettings();
|
var networkSettings = getContext().getFrostFSClient().getNetworkSettings();
|
||||||
parameters.setMaxObjectSizeCache((int) networkSettings.getMaxObjectSize());
|
parameters.setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
var restBytes = fullLength - parameters.getCurrentStreamPosition();
|
var restBytes = fullLength - parameters.getCurrentStreamPosition();
|
||||||
|
@ -287,7 +296,9 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
|
|
||||||
private ObjectWriter putObjectInit(Service.PutRequest initRequest) {
|
private ObjectWriter putObjectInit(Service.PutRequest initRequest) {
|
||||||
if (initRequest.getSerializedSize() == 0) {
|
if (initRequest.getSerializedSize() == 0) {
|
||||||
throw new IllegalArgumentException(initRequest.getClass().getName());
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectWriter writer = new ObjectWriter(objectServiceClient);
|
ObjectWriter writer = new ObjectWriter(objectServiceClient);
|
||||||
|
@ -310,7 +321,9 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
|
|
||||||
private SearchReader getSearchReader(Service.SearchRequest initRequest) {
|
private SearchReader getSearchReader(Service.SearchRequest initRequest) {
|
||||||
if (initRequest.getSerializedSize() == 0) {
|
if (initRequest.getSerializedSize() == 0) {
|
||||||
throw new IllegalArgumentException(initRequest.getClass().getName());
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, initRequest.getClass().getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
return new SearchReader(objectServiceBlockingClient.search(initRequest));
|
||||||
|
@ -320,7 +333,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
try {
|
try {
|
||||||
return fileInputStream.readNBytes(buffer, 0, size);
|
return fileInputStream.readNBytes(buffer, 0, size);
|
||||||
} catch (IOException exp) {
|
} catch (IOException exp) {
|
||||||
throw new IllegalArgumentException(exp.getMessage());
|
throw new ProcessFrostFSException(exp.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +341,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
||||||
try {
|
try {
|
||||||
return fileInputStream.getChannel().size();
|
return fileInputStream.getChannel().size();
|
||||||
} catch (IOException exp) {
|
} catch (IOException exp) {
|
||||||
throw new IllegalArgumentException(exp.getMessage());
|
throw new ProcessFrostFSException(exp.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,15 @@ package info.frostfs.sdk.services.impl.rwhelper;
|
||||||
import frostfs.object.Service;
|
import frostfs.object.Service;
|
||||||
import frostfs.object.Types;
|
import frostfs.object.Types;
|
||||||
import info.frostfs.sdk.dto.object.ObjectReader;
|
import info.frostfs.sdk.dto.object.ObjectReader;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.tools.Verifier;
|
import info.frostfs.sdk.tools.Verifier;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class ObjectReaderImpl implements ObjectReader {
|
import static info.frostfs.sdk.constants.ErrorConst.UNEXPECTED_MESSAGE_TYPE_TEMPLATE;
|
||||||
public static final String ERROR_UNEXPECTED_STREAM = "unexpected end of stream";
|
import static info.frostfs.sdk.constants.ErrorConst.UNEXPECTED_STREAM;
|
||||||
public static final String ERROR_UNEXPECTED_MESSAGE_TYPE = "unexpected message type";
|
|
||||||
|
|
||||||
|
public class ObjectReaderImpl implements ObjectReader {
|
||||||
public Iterator<Service.GetResponse> call;
|
public Iterator<Service.GetResponse> call;
|
||||||
|
|
||||||
public ObjectReaderImpl(Iterator<Service.GetResponse> call) {
|
public ObjectReaderImpl(Iterator<Service.GetResponse> call) {
|
||||||
|
@ -19,14 +20,20 @@ public class ObjectReaderImpl implements ObjectReader {
|
||||||
|
|
||||||
public Types.Object readHeader() {
|
public Types.Object readHeader() {
|
||||||
if (!call.hasNext()) {
|
if (!call.hasNext()) {
|
||||||
throw new IllegalArgumentException(ERROR_UNEXPECTED_STREAM);
|
throw new ProcessFrostFSException(UNEXPECTED_STREAM);
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = call.next();
|
var response = call.next();
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.INIT_FIELD_NUMBER) {
|
if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.INIT_FIELD_NUMBER) {
|
||||||
throw new IllegalArgumentException(ERROR_UNEXPECTED_MESSAGE_TYPE);
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(
|
||||||
|
UNEXPECTED_MESSAGE_TYPE_TEMPLATE,
|
||||||
|
Service.GetResponse.Body.INIT_FIELD_NUMBER,
|
||||||
|
response.getBody().getObjectPartCase().getNumber()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Types.Object.newBuilder()
|
return Types.Object.newBuilder()
|
||||||
|
@ -44,7 +51,13 @@ public class ObjectReaderImpl implements ObjectReader {
|
||||||
Verifier.checkResponse(response);
|
Verifier.checkResponse(response);
|
||||||
|
|
||||||
if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.CHUNK_FIELD_NUMBER) {
|
if (response.getBody().getObjectPartCase().getNumber() != Service.GetResponse.Body.CHUNK_FIELD_NUMBER) {
|
||||||
throw new IllegalArgumentException(ERROR_UNEXPECTED_MESSAGE_TYPE);
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(
|
||||||
|
UNEXPECTED_MESSAGE_TYPE_TEMPLATE,
|
||||||
|
Service.GetResponse.Body.CHUNK_FIELD_NUMBER,
|
||||||
|
response.getBody().getObjectPartCase().getNumber()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.getBody().getChunk().toByteArray();
|
return response.getBody().getChunk().toByteArray();
|
||||||
|
|
|
@ -2,9 +2,12 @@ package info.frostfs.sdk.services.impl.rwhelper;
|
||||||
|
|
||||||
import frostfs.object.ObjectServiceGrpc;
|
import frostfs.object.ObjectServiceGrpc;
|
||||||
import frostfs.object.Service;
|
import frostfs.object.Service;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.utils.WaitUtil;
|
import info.frostfs.sdk.utils.WaitUtil;
|
||||||
import io.grpc.stub.StreamObserver;
|
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;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ObjectWriter {
|
public class ObjectWriter {
|
||||||
|
@ -21,7 +24,9 @@ public class ObjectWriter {
|
||||||
|
|
||||||
public void write(Service.PutRequest request) {
|
public void write(Service.PutRequest request) {
|
||||||
if (isNull(request)) {
|
if (isNull(request)) {
|
||||||
throw new IllegalArgumentException();
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestObserver.onNext(request);
|
requestObserver.onNext(request);
|
||||||
|
@ -37,6 +42,7 @@ public class ObjectWriter {
|
||||||
return responseObserver.getResponse();
|
return responseObserver.getResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
|
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
|
||||||
private Service.PutResponse response;
|
private Service.PutResponse response;
|
||||||
|
|
||||||
|
@ -47,15 +53,11 @@ public class ObjectWriter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable throwable) {
|
public void onError(Throwable throwable) {
|
||||||
throw new RuntimeException(throwable);
|
throw new ProcessFrostFSException(throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCompleted() {
|
public void onCompleted() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Service.PutResponse getResponse() {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +1,35 @@
|
||||||
package info.frostfs.sdk.tools;
|
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.Channel;
|
import io.grpc.Channel;
|
||||||
import io.grpc.ChannelCredentials;
|
|
||||||
import io.grpc.netty.NettyChannelBuilder;
|
import io.grpc.netty.NettyChannelBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INVALID_HOST_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class GrpcClient {
|
public class GrpcClient {
|
||||||
private static final String ERROR_INVALID_HOST_TEMPLATE = "Host %s has invalid format. Error: %s";
|
|
||||||
private static final String ERROR_EMPTY_HOST_MESSAGE = "Host not provided";
|
|
||||||
|
|
||||||
private GrpcClient() {
|
private GrpcClient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Channel initGrpcChannel(String host, ChannelCredentials credentials) {
|
public static Channel initGrpcChannel(ClientSettings clientSettings) {
|
||||||
if (StringUtils.isBlank(host)) {
|
Validator.validate(clientSettings);
|
||||||
throw new IllegalArgumentException(ERROR_EMPTY_HOST_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URI uri = new URI(host);
|
URI uri = new URI(clientSettings.getHost());
|
||||||
var channelBuilder = isNull(credentials)
|
var channelBuilder = isNull(clientSettings.getCredentials())
|
||||||
? NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext()
|
? NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext()
|
||||||
: NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort(), credentials);
|
: NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort(), clientSettings.getCredentials());
|
||||||
|
|
||||||
return channelBuilder.build();
|
return channelBuilder.build();
|
||||||
} catch (URISyntaxException exp) {
|
} catch (URISyntaxException exp) {
|
||||||
throw new IllegalArgumentException(String.format(ERROR_INVALID_HOST_TEMPLATE, host, exp.getMessage()));
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INVALID_HOST_TEMPLATE, clientSettings.getHost(), exp.getMessage())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.response.MetaHeader;
|
import info.frostfs.sdk.dto.response.MetaHeader;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
import info.frostfs.sdk.jdo.ECDsa;
|
||||||
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
@ -11,6 +12,7 @@ import org.apache.commons.collections4.MapUtils;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.REQUIRED_PROTO_FIELD_TEMPLATE;
|
||||||
import static info.frostfs.sdk.constants.FieldConst.META_HEADER_FIELD_NAME;
|
import static info.frostfs.sdk.constants.FieldConst.META_HEADER_FIELD_NAME;
|
||||||
import static info.frostfs.sdk.tools.RequestSigner.signMessagePart;
|
import static info.frostfs.sdk.tools.RequestSigner.signMessagePart;
|
||||||
import static info.frostfs.sdk.utils.MessageHelper.getField;
|
import static info.frostfs.sdk.utils.MessageHelper.getField;
|
||||||
|
@ -19,8 +21,6 @@ import static java.util.Objects.isNull;
|
||||||
import static java.util.Objects.nonNull;
|
import static java.util.Objects.nonNull;
|
||||||
|
|
||||||
public class RequestConstructor {
|
public class RequestConstructor {
|
||||||
private static final String ERROR_MESSAGE = "The message does not contain a field " + META_HEADER_FIELD_NAME;
|
|
||||||
|
|
||||||
private RequestConstructor() {
|
private RequestConstructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class RequestConstructor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNull(request.getDescriptorForType().findFieldByName(META_HEADER_FIELD_NAME))) {
|
if (isNull(request.getDescriptorForType().findFieldByName(META_HEADER_FIELD_NAME))) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(String.format(REQUIRED_PROTO_FIELD_TEMPLATE, META_HEADER_FIELD_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((Types.RequestMetaHeader) getField(request, META_HEADER_FIELD_NAME)).getSerializedSize() > 0) {
|
if (((Types.RequestMetaHeader) getField(request, META_HEADER_FIELD_NAME)).getSerializedSize() > 0) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.constants.CryptoConst;
|
import info.frostfs.sdk.constants.CryptoConst;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import info.frostfs.sdk.jdo.ECDsa;
|
import info.frostfs.sdk.jdo.ECDsa;
|
||||||
import info.frostfs.sdk.utils.MessageHelper;
|
import info.frostfs.sdk.utils.MessageHelper;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
@ -17,15 +18,14 @@ import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.CryptoConst.HASH_SIGNATURE_SIZE;
|
||||||
|
import static info.frostfs.sdk.constants.CryptoConst.RFC6979_SIGNATURE_SIZE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE;
|
||||||
import static info.frostfs.sdk.constants.FieldConst.*;
|
import static info.frostfs.sdk.constants.FieldConst.*;
|
||||||
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
|
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
|
||||||
import static org.bouncycastle.util.BigIntegers.asUnsignedByteArray;
|
import static org.bouncycastle.util.BigIntegers.asUnsignedByteArray;
|
||||||
|
|
||||||
public class RequestSigner {
|
public class RequestSigner {
|
||||||
public static final String ERROR_UNSUPPORTED_TYPE_TEMPLATE = "Unsupported message type: %s";
|
|
||||||
public static final int RFC6979_SIGNATURE_SIZE = 64;
|
|
||||||
public static final int HASH_SIGNATURE_SIZE = 65;
|
|
||||||
|
|
||||||
private RequestSigner() {
|
private RequestSigner() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class RequestSigner {
|
||||||
byte[] sig = signature.sign();
|
byte[] sig = signature.sign();
|
||||||
System.arraycopy(sig, 0, hash, 1, sig.length);
|
System.arraycopy(sig, 0, hash, 1, sig.length);
|
||||||
} catch (Exception exp) {
|
} catch (Exception exp) {
|
||||||
throw new RuntimeException(exp);
|
throw new ProcessFrostFSException(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
|
@ -104,8 +104,8 @@ public class RequestSigner {
|
||||||
} else if (verify instanceof Types.ResponseVerificationHeader) {
|
} else if (verify instanceof Types.ResponseVerificationHeader) {
|
||||||
verifyBuilder = Types.ResponseVerificationHeader.newBuilder();
|
verifyBuilder = Types.ResponseVerificationHeader.newBuilder();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(ERROR_UNSUPPORTED_TYPE_TEMPLATE, verify.getClass().getName())
|
String.format(UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE, verify.getClass().getName())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,9 @@ package info.frostfs.sdk.tools;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.constants.CryptoConst;
|
import info.frostfs.sdk.constants.CryptoConst;
|
||||||
import info.frostfs.sdk.exceptions.ResponseException;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.mappers.response.ResponseStatusMapper;
|
import info.frostfs.sdk.mappers.response.ResponseStatusMapper;
|
||||||
import info.frostfs.sdk.utils.MessageHelper;
|
import info.frostfs.sdk.utils.MessageHelper;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
@ -20,16 +22,15 @@ import java.security.Signature;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static info.frostfs.sdk.KeyExtension.getPublicKeyFromBytes;
|
import static info.frostfs.sdk.KeyExtension.getPublicKeyFromBytes;
|
||||||
|
import static info.frostfs.sdk.constants.CryptoConst.RFC6979_SIGNATURE_SIZE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INVALID_RESPONSE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.WRONG_SIGNATURE_SIZE_TEMPLATE;
|
||||||
import static info.frostfs.sdk.constants.FieldConst.*;
|
import static info.frostfs.sdk.constants.FieldConst.*;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
|
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
|
||||||
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
|
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
|
||||||
|
|
||||||
public class Verifier {
|
public class Verifier {
|
||||||
public static final String ERROR_WRONG_SIG_SIZE_TEMPLATE = "Wrong signature size. Expected length=%s, actual=%s";
|
|
||||||
public static final String ERROR_INVALID_RESPONSE = "Invalid response";
|
|
||||||
public static final int RFC6979_SIG_SIZE = 64;
|
|
||||||
|
|
||||||
private Verifier() {
|
private Verifier() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,28 +57,30 @@ public class Verifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BigInteger[] decodeSignature(byte[] sig) {
|
private static BigInteger[] decodeSignature(byte[] sig) {
|
||||||
if (sig.length != RFC6979_SIG_SIZE) {
|
if (sig.length != RFC6979_SIGNATURE_SIZE) {
|
||||||
throw new IllegalArgumentException(
|
throw new ValidationFrostFSException(
|
||||||
String.format(ERROR_WRONG_SIG_SIZE_TEMPLATE, RFC6979_SIG_SIZE, sig.length)
|
String.format(WRONG_SIGNATURE_SIZE_TEMPLATE, RFC6979_SIGNATURE_SIZE, sig.length)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rs = new BigInteger[2];
|
var rs = new BigInteger[2];
|
||||||
|
|
||||||
rs[0] = fromUnsignedByteArray(Arrays.copyOfRange(sig, 0, (RFC6979_SIG_SIZE / 2) - 1));
|
rs[0] = fromUnsignedByteArray(Arrays.copyOfRange(sig, 0, (RFC6979_SIGNATURE_SIZE / 2) - 1));
|
||||||
rs[1] = fromUnsignedByteArray(Arrays.copyOfRange(sig, RFC6979_SIG_SIZE / 2, RFC6979_SIG_SIZE - 1));
|
rs[1] = fromUnsignedByteArray(
|
||||||
|
Arrays.copyOfRange(sig, RFC6979_SIGNATURE_SIZE / 2, RFC6979_SIGNATURE_SIZE - 1)
|
||||||
|
);
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkResponse(Message response) {
|
public static void checkResponse(Message response) {
|
||||||
if (!verify(response)) {
|
if (!verify(response)) {
|
||||||
throw new IllegalArgumentException(ERROR_INVALID_RESPONSE);
|
throw new ResponseFrostFSException(INVALID_RESPONSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME);
|
var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME);
|
||||||
var status = ResponseStatusMapper.toModel(metaHeader.getStatus());
|
var status = ResponseStatusMapper.toModel(metaHeader.getStatus());
|
||||||
if (!status.isSuccess()) {
|
if (!status.isSuccess()) {
|
||||||
throw new ResponseException(status);
|
throw new ResponseFrostFSException(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +130,7 @@ public class Verifier {
|
||||||
signature.update(DigestUtils.sha512(data));
|
signature.update(DigestUtils.sha512(data));
|
||||||
return signature.verify(Arrays.copyOfRange(sig, 1, sig.length));
|
return signature.verify(Arrays.copyOfRange(sig, 1, sig.length));
|
||||||
} catch (Exception exp) {
|
} catch (Exception exp) {
|
||||||
throw new RuntimeException(exp);
|
throw new ProcessFrostFSException(exp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,19 @@ package info.frostfs.sdk.utils;
|
||||||
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
import com.google.protobuf.MessageOrBuilder;
|
import com.google.protobuf.MessageOrBuilder;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class MessageHelper {
|
public class MessageHelper {
|
||||||
private static final String ERROR_MESSAGE = "One of the input parameters is null";
|
|
||||||
|
|
||||||
private MessageHelper() {
|
private MessageHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getField(MessageOrBuilder messageOrBuilder, String fieldName) {
|
public static Object getField(MessageOrBuilder messageOrBuilder, String fieldName) {
|
||||||
if (isNull(messageOrBuilder) || StringUtils.isBlank(fieldName)) {
|
if (isNull(messageOrBuilder) || StringUtils.isBlank(fieldName)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return messageOrBuilder.getField(messageOrBuilder.getDescriptorForType().findFieldByName(fieldName));
|
return messageOrBuilder.getField(messageOrBuilder.getDescriptorForType().findFieldByName(fieldName));
|
||||||
|
@ -22,7 +22,7 @@ public class MessageHelper {
|
||||||
|
|
||||||
public static void setField(Message.Builder builder, String fieldName, Object value) {
|
public static void setField(Message.Builder builder, String fieldName, Object value) {
|
||||||
if (isNull(builder) || StringUtils.isBlank(fieldName) || isNull(value)) {
|
if (isNull(builder) || StringUtils.isBlank(fieldName) || isNull(value)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setField(builder.getDescriptorForType().findFieldByName(fieldName), value);
|
builder.setField(builder.getDescriptorForType().findFieldByName(fieldName), value);
|
||||||
|
|
120
client/src/main/java/info/frostfs/sdk/utils/Validator.java
Normal file
120
client/src/main/java/info/frostfs/sdk/utils/Validator.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
package info.frostfs.sdk.utils;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
|
||||||
|
import info.frostfs.sdk.annotations.NotBlank;
|
||||||
|
import info.frostfs.sdk.annotations.NotNull;
|
||||||
|
import info.frostfs.sdk.annotations.Validate;
|
||||||
|
import info.frostfs.sdk.constants.ErrorConst;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_COMMA;
|
||||||
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
public class Validator {
|
||||||
|
public static <T> void validate(T object) {
|
||||||
|
StringBuilder errorMessage = new StringBuilder().append(System.lineSeparator());
|
||||||
|
process(object, errorMessage);
|
||||||
|
|
||||||
|
if (errorMessage.length() != 0) {
|
||||||
|
throw new ValidationFrostFSException(errorMessage.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static <T> void process(T object, StringBuilder errorMessage) {
|
||||||
|
if (isNull(object)) {
|
||||||
|
errorMessage.append(ErrorConst.OBJECT_IS_NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> clazz = object.getClass();
|
||||||
|
|
||||||
|
if (clazz.isAnnotationPresent(AtLeastOneIsFilled.class)) {
|
||||||
|
processAtLeastOneIsFilled(object, clazz, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
if (field.isAnnotationPresent(Validate.class)) {
|
||||||
|
processValidate(object, errorMessage, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.isAnnotationPresent(NotNull.class)) {
|
||||||
|
processNotNull(object, errorMessage, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field.isAnnotationPresent(NotBlank.class)) {
|
||||||
|
processNotBlank(object, errorMessage, field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> void processNotNull(T object, StringBuilder errorMessage, Field field) {
|
||||||
|
if (isNull(getFieldValue(object, field))) {
|
||||||
|
errorMessage
|
||||||
|
.append(String.format(ErrorConst.REQUIRED_FIELD_TEMPLATE, field.getName()))
|
||||||
|
.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> void processNotBlank(T object, StringBuilder errorMessage, Field field) {
|
||||||
|
var value = getFieldValue(object, field);
|
||||||
|
if (isNull(value) || (value instanceof String && StringUtils.isBlank((String) value))) {
|
||||||
|
errorMessage
|
||||||
|
.append(String.format(ErrorConst.REQUIRED_FIELD_TEMPLATE, field.getName()))
|
||||||
|
.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> void processValidate(T object, StringBuilder errorMessage, Field field) {
|
||||||
|
if (isNull(object)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
process(getFieldValue(object, field), errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> void processAtLeastOneIsFilled(T object, Class<?> clazz, StringBuilder errorMessage) {
|
||||||
|
var annotation = clazz.getAnnotation(AtLeastOneIsFilled.class);
|
||||||
|
var emptyFieldsCount = 0;
|
||||||
|
for (String fieldName : annotation.fields()) {
|
||||||
|
var field = getField(clazz, fieldName);
|
||||||
|
field.setAccessible(true);
|
||||||
|
|
||||||
|
var value = getFieldValue(object, field);
|
||||||
|
if (isNull(value) || (value instanceof String && StringUtils.isBlank((String) value))) {
|
||||||
|
emptyFieldsCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emptyFieldsCount == annotation.fields().length) {
|
||||||
|
errorMessage
|
||||||
|
.append(String.format(
|
||||||
|
annotation.message(),
|
||||||
|
String.join(FIELDS_DELIMITER_COMMA, annotation.fields())
|
||||||
|
))
|
||||||
|
.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> Object getFieldValue(T object, Field field) {
|
||||||
|
try {
|
||||||
|
return field.get(object);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new ProcessFrostFSException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Field getField(Class<?> clazz, String fieldName) {
|
||||||
|
try {
|
||||||
|
return clazz.getDeclaredField(fieldName);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
throw new ProcessFrostFSException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,10 +15,14 @@
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<protobuf.version>3.23.0</protobuf.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
|
<artifactId>exceptions</artifactId>
|
||||||
|
<version>0.1.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.protobuf</groupId>
|
<groupId>com.google.protobuf</groupId>
|
||||||
<artifactId>protobuf-java</artifactId>
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
@ -29,11 +33,6 @@
|
||||||
<artifactId>bcprov-jdk18on</artifactId>
|
<artifactId>bcprov-jdk18on</artifactId>
|
||||||
<version>1.78.1</version>
|
<version>1.78.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.14.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,16 +1,17 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ArrayHelper {
|
public class ArrayHelper {
|
||||||
private static final String ERROR_MESSAGE = "One of the input parameters is null";
|
|
||||||
|
|
||||||
private ArrayHelper() {
|
private ArrayHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] concat(byte[] startArray, byte[] endArray) {
|
public static byte[] concat(byte[] startArray, byte[] endArray) {
|
||||||
if (isNull(startArray) || isNull(endArray)) {
|
if (isNull(startArray) || isNull(endArray)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] joinedArray = new byte[startArray.length + endArray.length];
|
byte[] joinedArray = new byte[startArray.length + endArray.length];
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static info.frostfs.sdk.ArrayHelper.concat;
|
import static info.frostfs.sdk.ArrayHelper.concat;
|
||||||
import static info.frostfs.sdk.Helper.getSha256;
|
import static info.frostfs.sdk.Helper.getSha256;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class Base58 {
|
public class Base58 {
|
||||||
|
@ -16,8 +19,6 @@ public class Base58 {
|
||||||
private static final char ENCODED_ZERO = ALPHABET[0];
|
private static final char ENCODED_ZERO = ALPHABET[0];
|
||||||
private static final char BASE58_ASCII_MAX_VALUE = 128;
|
private static final char BASE58_ASCII_MAX_VALUE = 128;
|
||||||
private static final int[] INDEXES = new int[BASE58_ASCII_MAX_VALUE];
|
private static final int[] INDEXES = new int[BASE58_ASCII_MAX_VALUE];
|
||||||
private static final String ERROR_VALUE_MISSING_MESSAGE = "Input value is missing";
|
|
||||||
private static final String ERROR_INVALID_CHARACTER_TEMPLATE = "Invalid character in Base58: 0x%04x";
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Arrays.fill(INDEXES, -1);
|
Arrays.fill(INDEXES, -1);
|
||||||
|
@ -31,12 +32,12 @@ public class Base58 {
|
||||||
|
|
||||||
public static byte[] base58CheckDecode(String input) {
|
public static byte[] base58CheckDecode(String input) {
|
||||||
if (StringUtils.isEmpty(input)) {
|
if (StringUtils.isEmpty(input)) {
|
||||||
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] buffer = decode(input);
|
byte[] buffer = decode(input);
|
||||||
if (buffer.length < 4) {
|
if (buffer.length < 4) {
|
||||||
throw new IllegalArgumentException();
|
throw new ProcessFrostFSException(String.format(DECODE_LENGTH_VALUE_TEMPLATE, buffer.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] decode = Arrays.copyOfRange(buffer, 0, buffer.length - 4);
|
byte[] decode = Arrays.copyOfRange(buffer, 0, buffer.length - 4);
|
||||||
|
@ -44,7 +45,7 @@ public class Base58 {
|
||||||
var bufferEnd = Arrays.copyOfRange(buffer, buffer.length - 4, buffer.length);
|
var bufferEnd = Arrays.copyOfRange(buffer, buffer.length - 4, buffer.length);
|
||||||
var checksumStart = Arrays.copyOfRange(checksum, 0, 4);
|
var checksumStart = Arrays.copyOfRange(checksum, 0, 4);
|
||||||
if (!Arrays.equals(bufferEnd, checksumStart)) {
|
if (!Arrays.equals(bufferEnd, checksumStart)) {
|
||||||
throw new IllegalArgumentException();
|
throw new ProcessFrostFSException(INVALID_CHECKSUM);
|
||||||
}
|
}
|
||||||
|
|
||||||
return decode;
|
return decode;
|
||||||
|
@ -52,7 +53,7 @@ public class Base58 {
|
||||||
|
|
||||||
public static String base58CheckEncode(byte[] data) {
|
public static String base58CheckEncode(byte[] data) {
|
||||||
if (isNull(data)) {
|
if (isNull(data)) {
|
||||||
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] checksum = getSha256(getSha256(data));
|
byte[] checksum = getSha256(getSha256(data));
|
||||||
|
@ -101,7 +102,7 @@ public class Base58 {
|
||||||
char c = input.charAt(i);
|
char c = input.charAt(i);
|
||||||
int digit = c < BASE58_ASCII_MAX_VALUE ? INDEXES[c] : -1;
|
int digit = c < BASE58_ASCII_MAX_VALUE ? INDEXES[c] : -1;
|
||||||
if (digit < 0) {
|
if (digit < 0) {
|
||||||
throw new IllegalArgumentException(String.format(ERROR_INVALID_CHARACTER_TEMPLATE, (int) c));
|
throw new ValidationFrostFSException(String.format(INVALID_BASE58_CHARACTER_TEMPLATE, (int) c));
|
||||||
}
|
}
|
||||||
input58[i] = (byte) digit;
|
input58[i] = (byte) digit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,17 @@ package info.frostfs.sdk;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class Helper {
|
public class Helper {
|
||||||
private static final String ERROR_MESSAGE = "Input value is missing";
|
|
||||||
private static final String SHA256 = "SHA-256";
|
private static final String SHA256 = "SHA-256";
|
||||||
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
|
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ public class Helper {
|
||||||
|
|
||||||
public static byte[] getRipemd160(byte[] value) {
|
public static byte[] getRipemd160(byte[] value) {
|
||||||
if (isNull(value)) {
|
if (isNull(value)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
var hash = new byte[RIPEMD_160_HASH_BYTE_LENGTH];
|
var hash = new byte[RIPEMD_160_HASH_BYTE_LENGTH];
|
||||||
|
@ -40,7 +41,7 @@ public class Helper {
|
||||||
|
|
||||||
public static byte[] getSha256(byte[] value) {
|
public static byte[] getSha256(byte[] value) {
|
||||||
if (isNull(value)) {
|
if (isNull(value)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getSha256Instance().digest(value);
|
return getSha256Instance().digest(value);
|
||||||
|
@ -48,7 +49,7 @@ public class Helper {
|
||||||
|
|
||||||
public static ByteString getSha256(Message value) {
|
public static ByteString getSha256(Message value) {
|
||||||
if (isNull(value)) {
|
if (isNull(value)) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ByteString.copyFrom(getSha256(value.toByteArray()));
|
return ByteString.copyFrom(getSha256(value.toByteArray()));
|
||||||
|
@ -56,7 +57,7 @@ public class Helper {
|
||||||
|
|
||||||
public static String getHexString(byte[] value) {
|
public static String getHexString(byte[] value) {
|
||||||
if (isNull(value) || value.length == 0) {
|
if (isNull(value) || value.length == 0) {
|
||||||
throw new IllegalArgumentException(ERROR_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));
|
return String.format("%0" + (value.length << 1) + "x", new BigInteger(1, value));
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bouncycastle.asn1.sec.SECNamedCurves;
|
import org.bouncycastle.asn1.sec.SECNamedCurves;
|
||||||
import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
|
import org.bouncycastle.asn1.sec.SECObjectIdentifiers;
|
||||||
|
@ -26,6 +28,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
import static info.frostfs.sdk.Helper.getRipemd160;
|
import static info.frostfs.sdk.Helper.getRipemd160;
|
||||||
import static info.frostfs.sdk.Helper.getSha256;
|
import static info.frostfs.sdk.Helper.getSha256;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
|
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
|
||||||
|
|
||||||
|
@ -40,13 +43,6 @@ public class KeyExtension {
|
||||||
private static final int CHECK_SIG_DESCRIPTOR = ByteBuffer
|
private static final int CHECK_SIG_DESCRIPTOR = ByteBuffer
|
||||||
.wrap(getSha256("System.Crypto.CheckSig".getBytes(StandardCharsets.US_ASCII)))
|
.wrap(getSha256("System.Crypto.CheckSig".getBytes(StandardCharsets.US_ASCII)))
|
||||||
.order(ByteOrder.LITTLE_ENDIAN).getInt();
|
.order(ByteOrder.LITTLE_ENDIAN).getInt();
|
||||||
private static final String ERROR_VALUE_MISSING_MESSAGE = "Input value is missing";
|
|
||||||
private static final String ERROR_ENCODED_COMPRESSED_PUBLIC_KEY_TEMPLATE =
|
|
||||||
"PublicKey isn't encoded compressed public key. Expected length=%s, actual=%s";
|
|
||||||
private static final String ERROR_UNCOMPRESSED_PUBLIC_KEY_TEMPLATE =
|
|
||||||
"Compress argument isn't uncompressed public key. Expected length=%s, actual=%s";
|
|
||||||
private static final String ERROR_COMPRESSED_PUBLIC_KEY_TEMPLATE =
|
|
||||||
"Decompress argument isn't compressed public key. Expected length=%s, actual=%s";
|
|
||||||
|
|
||||||
private KeyExtension() {
|
private KeyExtension() {
|
||||||
}
|
}
|
||||||
|
@ -54,8 +50,8 @@ public class KeyExtension {
|
||||||
public static byte[] compress(byte[] publicKey) {
|
public static byte[] compress(byte[] publicKey) {
|
||||||
checkInputValue(publicKey);
|
checkInputValue(publicKey);
|
||||||
if (publicKey.length != UNCOMPRESSED_PUBLIC_KEY_LENGTH) {
|
if (publicKey.length != UNCOMPRESSED_PUBLIC_KEY_LENGTH) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new ValidationFrostFSException(String.format(
|
||||||
ERROR_UNCOMPRESSED_PUBLIC_KEY_TEMPLATE, UNCOMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
UNCOMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE, UNCOMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +62,7 @@ public class KeyExtension {
|
||||||
|
|
||||||
public static byte[] getPrivateKeyFromWIF(String wif) {
|
public static byte[] getPrivateKeyFromWIF(String wif) {
|
||||||
if (StringUtils.isEmpty(wif)) {
|
if (StringUtils.isEmpty(wif)) {
|
||||||
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = Base58.base58CheckDecode(wif);
|
var data = Base58.base58CheckDecode(wif);
|
||||||
|
@ -102,7 +98,7 @@ public class KeyExtension {
|
||||||
KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM);
|
KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM);
|
||||||
return kf.generatePrivate(privateKeySpec);
|
return kf.generatePrivate(privateKeySpec);
|
||||||
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ProcessFrostFSException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,9 +106,9 @@ public class KeyExtension {
|
||||||
checkInputValue(publicKey);
|
checkInputValue(publicKey);
|
||||||
|
|
||||||
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
||||||
throw new IllegalArgumentException(
|
throw new ValidationFrostFSException(String.format(
|
||||||
String.format(ERROR_COMPRESSED_PUBLIC_KEY_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length)
|
COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
X9ECParameters secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
X9ECParameters secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
|
||||||
|
@ -134,7 +130,7 @@ public class KeyExtension {
|
||||||
KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM);
|
KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM);
|
||||||
return kf.generatePublic(publicKeySpec);
|
return kf.generatePublic(publicKeySpec);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new ProcessFrostFSException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,8 +144,8 @@ public class KeyExtension {
|
||||||
public static String publicKeyToAddress(byte[] publicKey) {
|
public static String publicKeyToAddress(byte[] publicKey) {
|
||||||
checkInputValue(publicKey);
|
checkInputValue(publicKey);
|
||||||
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new ValidationFrostFSException(String.format(
|
||||||
ERROR_ENCODED_COMPRESSED_PUBLIC_KEY_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
ENCODED_COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,8 +173,8 @@ public class KeyExtension {
|
||||||
private static byte[] createSignatureRedeemScript(byte[] publicKey) {
|
private static byte[] createSignatureRedeemScript(byte[] publicKey) {
|
||||||
checkInputValue(publicKey);
|
checkInputValue(publicKey);
|
||||||
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
|
||||||
throw new IllegalArgumentException(String.format(
|
throw new ValidationFrostFSException(String.format(
|
||||||
ERROR_ENCODED_COMPRESSED_PUBLIC_KEY_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
ENCODED_COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +188,7 @@ public class KeyExtension {
|
||||||
|
|
||||||
private static void checkInputValue(byte[] data) {
|
private static void checkInputValue(byte[] data) {
|
||||||
if (isNull(data) || data.length == 0) {
|
if (isNull(data) || data.length == 0) {
|
||||||
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -59,8 +60,8 @@ public class ArrayHelperTest {
|
||||||
var endBytes = new byte[]{6, 7, 8, 9};
|
var endBytes = new byte[]{6, 7, 8, 9};
|
||||||
|
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(startBytes, null));
|
assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(startBytes, null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(null, endBytes));
|
assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(null, endBytes));
|
||||||
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(null, null));
|
assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(null, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -31,10 +33,10 @@ public class Base58Test {
|
||||||
@Test
|
@Test
|
||||||
void base58Decode_wrong() {
|
void base58Decode_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode(null));
|
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckDecode(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode(""));
|
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckDecode(""));
|
||||||
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode("WIF"));
|
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckDecode("WIF"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode("fh"));
|
assertThrows(ProcessFrostFSException.class, () -> Base58.base58CheckDecode("fh"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -49,6 +51,6 @@ public class Base58Test {
|
||||||
@Test
|
@Test
|
||||||
void base58Encode_wrong() {
|
void base58Encode_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckEncode(null));
|
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckEncode(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
import com.google.protobuf.Message;
|
import com.google.protobuf.Message;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -25,7 +26,7 @@ public class HelperTest {
|
||||||
@Test
|
@Test
|
||||||
void getRipemd160_givenParamIsNull() {
|
void getRipemd160_givenParamIsNull() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> Helper.getRipemd160(null));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getRipemd160(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -69,8 +70,8 @@ public class HelperTest {
|
||||||
@Test
|
@Test
|
||||||
void getSha256_bytes_givenParamIsNull() {
|
void getSha256_bytes_givenParamIsNull() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> Helper.getSha256((byte[]) null));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getSha256((byte[]) null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> Helper.getSha256((Message) null));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getSha256((Message) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -104,7 +105,7 @@ public class HelperTest {
|
||||||
@Test
|
@Test
|
||||||
void getHexString_wrong() {
|
void getHexString_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> Helper.getHexString(null));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> Helper.getHexString(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(new byte[]{}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -35,8 +36,8 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void getPrivateKeyFromWIF_wrong() {
|
void getPrivateKeyFromWIF_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPrivateKeyFromWIF(""));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPrivateKeyFromWIF(""));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPrivateKeyFromWIF(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPrivateKeyFromWIF(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,8 +52,8 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void loadPublicKey_wrong() {
|
void loadPublicKey_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPublicKey(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPublicKey(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPublicKey(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPublicKey(new byte[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -69,8 +70,8 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void loadPrivateKey_wrong() {
|
void loadPrivateKey_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPrivateKey(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPrivateKey(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPrivateKey(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPrivateKey(new byte[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -87,9 +88,9 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void getPublicKeyFromBytes_wrong() {
|
void getPublicKeyFromBytes_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPublicKeyFromBytes(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPublicKeyFromBytes(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(new byte[]{}));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPublicKeyFromBytes(PRIVATE_KEY));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(PRIVATE_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -109,9 +110,9 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void getScriptHash_wrong() {
|
void getScriptHash_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getScriptHash(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getScriptHash(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getScriptHash(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getScriptHash(new byte[]{}));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getScriptHash(PRIVATE_KEY));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getScriptHash(PRIVATE_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,9 +127,9 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void publicKeyToAddress_wrong() {
|
void publicKeyToAddress_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.publicKeyToAddress(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.publicKeyToAddress(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.publicKeyToAddress(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.publicKeyToAddress(new byte[]{}));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.publicKeyToAddress(PRIVATE_KEY));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.publicKeyToAddress(PRIVATE_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -143,9 +144,9 @@ public class KeyExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void compress_wrong() {
|
void compress_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.compress(null));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.compress(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.compress(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.compress(new byte[]{}));
|
||||||
assertThrows(IllegalArgumentException.class, () -> KeyExtension.compress(PUBLIC_KEY));
|
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.compress(PUBLIC_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
20
exceptions/pom.xml
Normal file
20
exceptions/pom.xml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
|
<artifactId>frostfs-sdk-java</artifactId>
|
||||||
|
<version>0.1.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>exceptions</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,49 @@
|
||||||
|
package info.frostfs.sdk.constants;
|
||||||
|
|
||||||
|
public class ErrorConst {
|
||||||
|
public static final String OBJECT_IS_NULL = "object must not be null";
|
||||||
|
public static final String INPUT_PARAM_IS_MISSING = "input parameter is not present";
|
||||||
|
public static final String SOME_PARAM_IS_MISSING = "one of the input parameters is not present";
|
||||||
|
public static final String PARAM_IS_MISSING_TEMPLATE = "param %s is not present";
|
||||||
|
public static final String PARAMS_ARE_MISSING_TEMPLATE = "params %s are not present";
|
||||||
|
public static final String INPUT_PARAM_IS_MISSING_TEMPLATE = "%s value is not present";
|
||||||
|
|
||||||
|
public static final String INPUT_PARAM_GREATER_OR_EQUAL_ZERO = "%s must be greater than or equal to zero";
|
||||||
|
public static final String INPUT_PARAM_GREATER_ZERO = "%s must be greater than zero";
|
||||||
|
|
||||||
|
public static final String REQUIRED_FIELD_TEMPLATE = "%s required field";
|
||||||
|
|
||||||
|
public static final String REQUIRED_PROTO_FIELD_TEMPLATE = "the proto message does not contain a field %s";
|
||||||
|
public static final String UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE = "unsupported proto message type: %s";
|
||||||
|
public static final String PROTO_MESSAGE_IS_EMPTY_TEMPLATE = "proto message %s must not be empty";
|
||||||
|
public static final String UNEXPECTED_MESSAGE_TYPE_TEMPLATE = "unexpected message type, expected %s, actually %s";
|
||||||
|
|
||||||
|
public static final String WIF_IS_INVALID = "WIF is invalid";
|
||||||
|
public static final String UNEXPECTED_STREAM = "unexpected end of stream";
|
||||||
|
public static final String INVALID_HOST_TEMPLATE = "host %s has invalid format. Error: %s";
|
||||||
|
public static final String INVALID_RESPONSE = "invalid response";
|
||||||
|
public static final String VERSION_UNSUPPORTED_TEMPLATE = "frostFS %s is not supported.";
|
||||||
|
|
||||||
|
public static final String UNKNOWN_ENUM_VALUE_TEMPLATE = "unknown %s value: %s";
|
||||||
|
|
||||||
|
public static final String INPUT_PARAM_IS_NOT_SHA256 = "%s must be a sha256 hash";
|
||||||
|
public static final String DECODE_LENGTH_VALUE_TEMPLATE = "decode array length must be >= 4, but %s";
|
||||||
|
public static final String INVALID_BASE58_CHARACTER_TEMPLATE = "invalid character in Base58: 0x%04x";
|
||||||
|
public static final String INVALID_CHECKSUM = "checksum does not match";
|
||||||
|
public static final String WRONG_SIGNATURE_SIZE_TEMPLATE = "wrong signature size. Expected length=%s, actual=%s";
|
||||||
|
public static final String ENCODED_COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE =
|
||||||
|
"publicKey isn't encoded compressed public key. Expected length=%s, actual=%s";
|
||||||
|
public static final String UNCOMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE =
|
||||||
|
"compress argument isn't uncompressed public key. Expected length=%s, actual=%s";
|
||||||
|
public static final String COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE =
|
||||||
|
"decompress argument isn't compressed public key. Expected length=%s, actual=%s";
|
||||||
|
|
||||||
|
public static final String WRONG_UUID_SIZE_TEMPLATE = "uuid byte array length must be %s";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String FIELDS_DELIMITER_COMMA = ", ";
|
||||||
|
public static final String FIELDS_DELIMITER_OR = " or ";
|
||||||
|
|
||||||
|
private ErrorConst() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
public class ProcessFrostFSException extends RuntimeException {
|
||||||
|
public ProcessFrostFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProcessFrostFSException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
public class TimeoutFrostFSException extends RuntimeException {
|
||||||
|
public TimeoutFrostFSException() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package info.frostfs.sdk.exceptions;
|
||||||
|
|
||||||
|
public class ValidationFrostFSException extends RuntimeException {
|
||||||
|
public ValidationFrostFSException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,14 +29,9 @@
|
||||||
<version>0.1.0</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>info.frostfs.sdk</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>exceptions</artifactId>
|
||||||
<version>3.14.0</version>
|
<version>0.1.0</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-collections4</artifactId>
|
|
||||||
<version>4.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.AppConst.UUID_BYTE_ARRAY_LENGTH;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.WRONG_UUID_SIZE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class UuidExtension {
|
public class UuidExtension {
|
||||||
private static final int UUID_BYTE_ARRAY_LENGTH = 16;
|
|
||||||
private static final String ERROR_WRONG_UUID_SIZE = "Uuid byte array length must be " + UUID_BYTE_ARRAY_LENGTH;
|
|
||||||
private static final String ERROR_UUID_MISSING = "Uuid is not present";
|
|
||||||
|
|
||||||
private UuidExtension() {
|
private UuidExtension() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID asUuid(byte[] bytes) {
|
public static UUID asUuid(byte[] bytes) {
|
||||||
if (isNull(bytes) || bytes.length != UUID_BYTE_ARRAY_LENGTH) {
|
if (isNull(bytes) || bytes.length != UUID_BYTE_ARRAY_LENGTH) {
|
||||||
throw new IllegalArgumentException(ERROR_WRONG_UUID_SIZE);
|
throw new ValidationFrostFSException(String.format(WRONG_UUID_SIZE_TEMPLATE, UUID_BYTE_ARRAY_LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||||
|
@ -26,7 +27,9 @@ public class UuidExtension {
|
||||||
|
|
||||||
public static byte[] asBytes(UUID uuid) {
|
public static byte[] asBytes(UUID uuid) {
|
||||||
if (isNull(uuid)) {
|
if (isNull(uuid)) {
|
||||||
throw new IllegalArgumentException(ERROR_UUID_MISSING);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, UUID.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer bb = ByteBuffer.allocate(UUID_BYTE_ARRAY_LENGTH);
|
ByteBuffer bb = ByteBuffer.allocate(UUID_BYTE_ARRAY_LENGTH);
|
||||||
|
|
|
@ -9,6 +9,7 @@ public class AppConst {
|
||||||
public static final int MIB = KIB << BYTE_SHIFT;
|
public static final int MIB = KIB << BYTE_SHIFT;
|
||||||
public static final int OBJECT_CHUNK_SIZE = 3 * MIB;
|
public static final int OBJECT_CHUNK_SIZE = 3 * MIB;
|
||||||
public static final int SHA256_HASH_LENGTH = 32;
|
public static final int SHA256_HASH_LENGTH = 32;
|
||||||
|
public static final int UUID_BYTE_ARRAY_LENGTH = 16;
|
||||||
|
|
||||||
private AppConst() {
|
private AppConst() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package info.frostfs.sdk.dto;
|
package info.frostfs.sdk.dto;
|
||||||
|
|
||||||
import info.frostfs.sdk.Helper;
|
import info.frostfs.sdk.Helper;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class CheckSum {
|
public class CheckSum {
|
||||||
// type is always Sha256
|
// type is always Sha256
|
||||||
public byte[] hash;
|
public byte[] hash;
|
||||||
|
@ -10,14 +14,6 @@ public class CheckSum {
|
||||||
this.hash = Helper.getSha256(content);
|
this.hash = Helper.getSha256(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getHash() {
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHash(byte[] hash) {
|
|
||||||
this.hash = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Helper.getHexString(hash);
|
return Helper.getHexString(hash);
|
||||||
|
|
|
@ -3,9 +3,13 @@ package info.frostfs.sdk.dto.container;
|
||||||
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
import info.frostfs.sdk.enums.BasicAcl;
|
import info.frostfs.sdk.enums.BasicAcl;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class Container {
|
public class Container {
|
||||||
private UUID nonce;
|
private UUID nonce;
|
||||||
private BasicAcl basicAcl;
|
private BasicAcl basicAcl;
|
||||||
|
@ -17,36 +21,4 @@ public class Container {
|
||||||
this.basicAcl = basicAcl;
|
this.basicAcl = basicAcl;
|
||||||
this.placementPolicy = placementPolicy;
|
this.placementPolicy = placementPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getNonce() {
|
|
||||||
return nonce;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNonce(UUID nonce) {
|
|
||||||
this.nonce = nonce;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicAcl getBasicAcl() {
|
|
||||||
return basicAcl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBasicAcl(BasicAcl basicAcl) {
|
|
||||||
this.basicAcl = basicAcl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlacementPolicy getPlacementPolicy() {
|
|
||||||
return placementPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlacementPolicy(PlacementPolicy placementPolicy) {
|
|
||||||
this.placementPolicy = placementPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(Version version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,24 @@ package info.frostfs.sdk.dto.container;
|
||||||
|
|
||||||
import info.frostfs.sdk.Base58;
|
import info.frostfs.sdk.Base58;
|
||||||
import info.frostfs.sdk.constants.AppConst;
|
import info.frostfs.sdk.constants.AppConst;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_NOT_SHA256;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class ContainerId {
|
public class ContainerId {
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public ContainerId(String value) {
|
public ContainerId(String value) {
|
||||||
if (StringUtils.isEmpty(value)) {
|
if (StringUtils.isEmpty(value)) {
|
||||||
throw new IllegalArgumentException("ContainerId value is missing");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ContainerId.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -19,16 +27,14 @@ public class ContainerId {
|
||||||
|
|
||||||
public ContainerId(byte[] hash) {
|
public ContainerId(byte[] hash) {
|
||||||
if (isNull(hash) || hash.length != AppConst.SHA256_HASH_LENGTH) {
|
if (isNull(hash) || hash.length != AppConst.SHA256_HASH_LENGTH) {
|
||||||
throw new IllegalArgumentException("ContainerId must be a sha256 hash.");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_NOT_SHA256, ContainerId.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.value = Base58.encode(hash);
|
this.value = Base58.encode(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -1,22 +1,13 @@
|
||||||
package info.frostfs.sdk.dto.netmap;
|
package info.frostfs.sdk.dto.netmap;
|
||||||
|
|
||||||
import java.util.Collections;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class NetmapSnapshot {
|
public class NetmapSnapshot {
|
||||||
private final Long epoch;
|
private final Long epoch;
|
||||||
private final List<NodeInfo> nodeInfoCollection;
|
private final List<NodeInfo> nodeInfoCollection;
|
||||||
|
|
||||||
public NetmapSnapshot(Long epoch, List<NodeInfo> nodeInfoCollection) {
|
|
||||||
this.epoch = epoch;
|
|
||||||
this.nodeInfoCollection = Collections.unmodifiableList(nodeInfoCollection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getEpoch() {
|
|
||||||
return epoch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<NodeInfo> getNodeInfoCollection() {
|
|
||||||
return nodeInfoCollection;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package info.frostfs.sdk.dto.netmap;
|
package info.frostfs.sdk.dto.netmap;
|
||||||
|
|
||||||
import info.frostfs.sdk.enums.NodeState;
|
import info.frostfs.sdk.enums.NodeState;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class NodeInfo {
|
public class NodeInfo {
|
||||||
private final NodeState state;
|
private final NodeState state;
|
||||||
private final Version version;
|
private final Version version;
|
||||||
|
@ -21,24 +23,4 @@ public class NodeInfo {
|
||||||
this.attributes = Collections.unmodifiableMap(attributes);
|
this.attributes = Collections.unmodifiableMap(attributes);
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeState getState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPublicKey() {
|
|
||||||
return publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getAttributes() {
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getAddresses() {
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,11 @@
|
||||||
package info.frostfs.sdk.dto.netmap;
|
package info.frostfs.sdk.dto.netmap;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class PlacementPolicy {
|
public class PlacementPolicy {
|
||||||
private final Replica[] replicas;
|
private final Replica[] replicas;
|
||||||
private final boolean unique;
|
private final boolean unique;
|
||||||
|
|
||||||
public PlacementPolicy(boolean unique, Replica[] replicas) {
|
|
||||||
this.replicas = replicas;
|
|
||||||
this.unique = unique;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Replica[] getReplicas() {
|
|
||||||
return replicas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUnique() {
|
|
||||||
return unique;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,24 @@
|
||||||
package info.frostfs.sdk.dto.netmap;
|
package info.frostfs.sdk.dto.netmap;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.FieldNameConstants;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_GREATER_ZERO;
|
||||||
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
|
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@FieldNameConstants
|
||||||
public class Replica {
|
public class Replica {
|
||||||
private final int count;
|
private final int count;
|
||||||
private final String selector;
|
private final String selector;
|
||||||
|
|
||||||
public Replica(int count, String selector) {
|
public Replica(int count, String selector) {
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
throw new IllegalArgumentException("Replica count must be positive");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_GREATER_ZERO, Fields.count)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.count = count;
|
this.count = count;
|
||||||
|
@ -19,18 +27,13 @@ public class Replica {
|
||||||
|
|
||||||
public Replica(int count) {
|
public Replica(int count) {
|
||||||
if (count <= 0) {
|
if (count <= 0) {
|
||||||
throw new IllegalArgumentException("Replica count must be positive");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_GREATER_ZERO, Fields.count)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.count = count;
|
this.count = count;
|
||||||
this.selector = EMPTY_STRING;
|
this.selector = EMPTY_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSelector() {
|
|
||||||
return selector;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,23 @@
|
||||||
package info.frostfs.sdk.dto.netmap;
|
package info.frostfs.sdk.dto.netmap;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MAJOR_VERSION;
|
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MAJOR_VERSION;
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MINOR_VERSION;
|
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MINOR_VERSION;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class Version {
|
public class Version {
|
||||||
private final int major;
|
private final int major;
|
||||||
private final int minor;
|
private final int minor;
|
||||||
|
|
||||||
public Version(int major, int minor) {
|
|
||||||
this.major = major;
|
|
||||||
this.minor = minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version() {
|
public Version() {
|
||||||
this.major = DEFAULT_MAJOR_VERSION;
|
this.major = DEFAULT_MAJOR_VERSION;
|
||||||
this.minor = DEFAULT_MINOR_VERSION;
|
this.minor = DEFAULT_MINOR_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMajor() {
|
|
||||||
return major;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMinor() {
|
|
||||||
return minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "v" + major + "." + minor;
|
return "v" + major + "." + minor;
|
||||||
|
|
|
@ -1,25 +1,22 @@
|
||||||
package info.frostfs.sdk.dto.object;
|
package info.frostfs.sdk.dto.object;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class ObjectAttribute {
|
public class ObjectAttribute {
|
||||||
private final String key;
|
private final String key;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public ObjectAttribute(String key, String value) {
|
public ObjectAttribute(String key, String value) {
|
||||||
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
if (StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) {
|
||||||
throw new IllegalArgumentException("One of the input attributes is missing");
|
throw new ValidationFrostFSException(SOME_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,43 +6,18 @@ import info.frostfs.sdk.dto.CheckSum;
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
import info.frostfs.sdk.enums.ObjectMatchType;
|
import info.frostfs.sdk.enums.ObjectMatchType;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
public abstract class ObjectFilter<T> {
|
public abstract class ObjectFilter<T> {
|
||||||
private ObjectMatchType matchType;
|
private ObjectMatchType matchType;
|
||||||
private String key;
|
private String key;
|
||||||
private T value;
|
private T value;
|
||||||
|
|
||||||
|
|
||||||
public ObjectFilter(ObjectMatchType matchType, String key, T value) {
|
|
||||||
this.matchType = matchType;
|
|
||||||
this.key = key;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectMatchType getMatchType() {
|
|
||||||
return matchType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMatchType(ObjectMatchType matchType) {
|
|
||||||
this.matchType = matchType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKey(String key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(T value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSerializedValue() {
|
public String getSerializedValue() {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,17 @@ package info.frostfs.sdk.dto.object;
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class ObjectFrostFS {
|
public class ObjectFrostFS {
|
||||||
private final ObjectHeader header;
|
private final ObjectHeader header;
|
||||||
private ObjectId objectId;
|
private ObjectId objectId;
|
||||||
|
@ -15,7 +21,9 @@ public class ObjectFrostFS {
|
||||||
|
|
||||||
public ObjectFrostFS(ObjectHeader header, ObjectId objectId, byte[] payload) {
|
public ObjectFrostFS(ObjectHeader header, ObjectId objectId, byte[] payload) {
|
||||||
if (isNull(header)) {
|
if (isNull(header)) {
|
||||||
throw new IllegalArgumentException("Object header is missing");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ObjectHeader.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.header = header;
|
this.header = header;
|
||||||
|
@ -33,34 +41,6 @@ public class ObjectFrostFS {
|
||||||
this.header = new ObjectHeader(containerId, objectType);
|
this.header = new ObjectHeader(containerId, objectType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObjectReader getObjectReader() {
|
|
||||||
return objectReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setObjectReader(ObjectReader objectReader) {
|
|
||||||
this.objectReader = objectReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectHeader getHeader() {
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectId getObjectId() {
|
|
||||||
return objectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setObjectId(ObjectId objectId) {
|
|
||||||
this.objectId = objectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayload(byte[] payload) {
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSplit(Split split) {
|
public void setSplit(Split split) {
|
||||||
header.setSplit(split);
|
header.setSplit(split);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +59,9 @@ public class ObjectFrostFS {
|
||||||
|
|
||||||
public void setParent(LargeObject largeObject) {
|
public void setParent(LargeObject largeObject) {
|
||||||
if (isNull(header.getSplit())) {
|
if (isNull(header.getSplit())) {
|
||||||
throw new IllegalArgumentException("The object is not initialized properly");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Split.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
header.getSplit().setParentHeader(largeObject.getHeader());
|
header.getSplit().setParentHeader(largeObject.getHeader());
|
||||||
|
|
|
@ -3,13 +3,20 @@ package info.frostfs.sdk.dto.object;
|
||||||
import info.frostfs.sdk.dto.container.ContainerId;
|
import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_OR;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class ObjectHeader {
|
public class ObjectHeader {
|
||||||
private final ContainerId containerId;
|
private final ContainerId containerId;
|
||||||
private final ObjectType objectType;
|
private final ObjectType objectType;
|
||||||
|
@ -23,7 +30,12 @@ public class ObjectHeader {
|
||||||
public ObjectHeader(ContainerId containerId, ObjectType objectType,
|
public ObjectHeader(ContainerId containerId, ObjectType objectType,
|
||||||
List<ObjectAttribute> attributes, long payloadLength, Version version) {
|
List<ObjectAttribute> attributes, long payloadLength, Version version) {
|
||||||
if (isNull(containerId) || isNull(objectType)) {
|
if (isNull(containerId) || isNull(objectType)) {
|
||||||
throw new IllegalArgumentException("ContainerId or objectType is not present");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(
|
||||||
|
INPUT_PARAM_IS_MISSING_TEMPLATE,
|
||||||
|
String.join(FIELDS_DELIMITER_OR, ContainerId.class.getName(), ObjectType.class.getName())
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
|
@ -47,67 +59,17 @@ public class ObjectHeader {
|
||||||
this(containerId, ObjectType.REGULAR, attributes);
|
this(containerId, ObjectType.REGULAR, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OwnerId getOwnerId() {
|
|
||||||
return ownerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwnerId(OwnerId ownerId) {
|
|
||||||
this.ownerId = ownerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getPayloadLength() {
|
|
||||||
return payloadLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayloadLength(long payloadLength) {
|
|
||||||
this.payloadLength = payloadLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void increasePayloadLength(long payloadLength) {
|
public void increasePayloadLength(long payloadLength) {
|
||||||
this.payloadLength += payloadLength;
|
this.payloadLength += payloadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getPayloadCheckSum() {
|
|
||||||
return payloadCheckSum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayloadCheckSum(byte[] payloadCheckSum) {
|
|
||||||
this.payloadCheckSum = payloadCheckSum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Split getSplit() {
|
|
||||||
return split;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSplit(Split split) {
|
public void setSplit(Split split) {
|
||||||
if (isNull(split)) {
|
if (isNull(split)) {
|
||||||
throw new IllegalArgumentException("Split is not present");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Split.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.split = split;
|
this.split = split;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ObjectAttribute> getAttributes() {
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAttributes(List<ObjectAttribute> attributes) {
|
|
||||||
this.attributes = attributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContainerId getContainerId() {
|
|
||||||
return containerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectType getObjectType() {
|
|
||||||
return objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(Version version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,23 @@ package info.frostfs.sdk.dto.object;
|
||||||
|
|
||||||
import info.frostfs.sdk.Base58;
|
import info.frostfs.sdk.Base58;
|
||||||
import info.frostfs.sdk.constants.AppConst;
|
import info.frostfs.sdk.constants.AppConst;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_NOT_SHA256;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class ObjectId {
|
public class ObjectId {
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public ObjectId(String value) {
|
public ObjectId(String value) {
|
||||||
if (StringUtils.isEmpty(value)) {
|
if (StringUtils.isEmpty(value)) {
|
||||||
throw new IllegalArgumentException("ObjectId value is missing");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ObjectId.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -19,16 +26,14 @@ public class ObjectId {
|
||||||
|
|
||||||
public ObjectId(byte[] hash) {
|
public ObjectId(byte[] hash) {
|
||||||
if (isNull(hash) || hash.length != AppConst.SHA256_HASH_LENGTH) {
|
if (isNull(hash) || hash.length != AppConst.SHA256_HASH_LENGTH) {
|
||||||
throw new IllegalArgumentException("ObjectId must be a sha256 hash.");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_NOT_SHA256, ObjectId.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.value = Base58.encode(hash);
|
this.value = Base58.encode(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -1,29 +1,37 @@
|
||||||
package info.frostfs.sdk.dto.object;
|
package info.frostfs.sdk.dto.object;
|
||||||
|
|
||||||
import info.frostfs.sdk.Base58;
|
import info.frostfs.sdk.Base58;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import static info.frostfs.sdk.KeyExtension.publicKeyToAddress;
|
import static info.frostfs.sdk.KeyExtension.publicKeyToAddress;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class OwnerId {
|
public class OwnerId {
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
public OwnerId(String value) {
|
public OwnerId(String value) {
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, OwnerId.class.getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OwnerId(byte[] publicKey) {
|
public OwnerId(byte[] publicKey) {
|
||||||
if (isNull(publicKey) || publicKey.length == 0) {
|
if (isNull(publicKey) || publicKey.length == 0) {
|
||||||
throw new IllegalArgumentException("PublicKey is invalid");
|
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.value = publicKeyToAddress(publicKey);
|
this.value = publicKeyToAddress(publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] toHash() {
|
public byte[] toHash() {
|
||||||
return Base58.decode(value);
|
return Base58.decode(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,18 @@ package info.frostfs.sdk.dto.object;
|
||||||
|
|
||||||
import frostfs.refs.Types;
|
import frostfs.refs.Types;
|
||||||
import info.frostfs.sdk.dto.response.Signature;
|
import info.frostfs.sdk.dto.response.Signature;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class Split {
|
public class Split {
|
||||||
private final List<ObjectId> children;
|
private final List<ObjectId> children;
|
||||||
private final SplitId splitId;
|
private final SplitId splitId;
|
||||||
|
@ -23,58 +29,12 @@ public class Split {
|
||||||
|
|
||||||
public Split(SplitId splitId) {
|
public Split(SplitId splitId) {
|
||||||
if (isNull(splitId)) {
|
if (isNull(splitId)) {
|
||||||
throw new IllegalArgumentException("SplitId is not present");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, SplitId.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.splitId = splitId;
|
this.splitId = splitId;
|
||||||
this.children = new ArrayList<>();
|
this.children = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SplitId getSplitId() {
|
|
||||||
return splitId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectId getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParent(ObjectId parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectId getPrevious() {
|
|
||||||
return previous;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrevious(ObjectId previous) {
|
|
||||||
this.previous = previous;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Signature getParentSignature() {
|
|
||||||
return parentSignature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParentSignature(Signature parentSignature) {
|
|
||||||
this.parentSignature = parentSignature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectHeader getParentHeader() {
|
|
||||||
return parentHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParentHeader(ObjectHeader parentHeader) {
|
|
||||||
this.parentHeader = parentHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ObjectId> getChildren() {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Types.Signature getParentSignatureGrpc() {
|
|
||||||
return parentSignatureGrpc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParentSignatureGrpc(Types.Signature parentSignatureGrpc) {
|
|
||||||
this.parentSignatureGrpc = parentSignatureGrpc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package info.frostfs.sdk.dto.object;
|
package info.frostfs.sdk.dto.object;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static info.frostfs.sdk.UuidExtension.asBytes;
|
import static info.frostfs.sdk.UuidExtension.asBytes;
|
||||||
import static info.frostfs.sdk.UuidExtension.asUuid;
|
import static info.frostfs.sdk.UuidExtension.asUuid;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class SplitId {
|
public class SplitId {
|
||||||
private final UUID id;
|
private final UUID id;
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
package info.frostfs.sdk.dto.response;
|
package info.frostfs.sdk.dto.response;
|
||||||
|
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.experimental.FieldNameConstants;
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MAJOR_VERSION;
|
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MAJOR_VERSION;
|
||||||
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MINOR_VERSION;
|
import static info.frostfs.sdk.constants.AppConst.DEFAULT_MINOR_VERSION;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@FieldNameConstants
|
||||||
public class MetaHeader {
|
public class MetaHeader {
|
||||||
private Version version;
|
private Version version;
|
||||||
private int epoch;
|
private int epoch;
|
||||||
private int ttl;
|
private int ttl;
|
||||||
|
|
||||||
public MetaHeader(Version version, int epoch, int ttl) {
|
public MetaHeader(Version version, int epoch, int ttl) {
|
||||||
if (isNull(version) || epoch < 0 || ttl <= 0) {
|
setVersion(version);
|
||||||
throw new IllegalArgumentException("One of the input attributes is invalid or missing");
|
setEpoch(epoch);
|
||||||
}
|
setTtl(ttl);
|
||||||
|
|
||||||
this.version = version;
|
|
||||||
this.epoch = epoch;
|
|
||||||
this.ttl = ttl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetaHeader() {
|
public MetaHeader() {
|
||||||
|
@ -27,37 +29,31 @@ public class MetaHeader {
|
||||||
this.ttl = 2;
|
this.ttl = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(Version version) {
|
public void setVersion(Version version) {
|
||||||
if (isNull(version)) {
|
if (isNull(version)) {
|
||||||
throw new IllegalArgumentException("Version is missing.");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Version.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEpoch() {
|
|
||||||
return epoch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEpoch(int epoch) {
|
public void setEpoch(int epoch) {
|
||||||
if (epoch < 0) {
|
if (epoch < 0) {
|
||||||
throw new IllegalArgumentException("The epoch must be greater than or equal to zero.");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_GREATER_OR_EQUAL_ZERO, Fields.epoch)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.epoch = epoch;
|
this.epoch = epoch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTtl() {
|
|
||||||
return ttl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTtl(int ttl) {
|
public void setTtl(int ttl) {
|
||||||
if (ttl <= 0) {
|
if (ttl <= 0) {
|
||||||
throw new IllegalArgumentException("The ttl must be greater than zero.");
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_GREATER_ZERO, Fields.ttl)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ttl = ttl;
|
this.ttl = ttl;
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package info.frostfs.sdk.dto.response;
|
package info.frostfs.sdk.dto.response;
|
||||||
|
|
||||||
import info.frostfs.sdk.enums.StatusCode;
|
import info.frostfs.sdk.enums.StatusCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
|
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class ResponseStatus {
|
public class ResponseStatus {
|
||||||
private StatusCode code;
|
private StatusCode code;
|
||||||
private String message;
|
private String message;
|
||||||
|
@ -19,22 +23,6 @@ public class ResponseStatus {
|
||||||
this.message = EMPTY_STRING;
|
this.message = EMPTY_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StatusCode getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(StatusCode code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("Response status: %s. Message: %s.", code, message);
|
return String.format("Response status: %s. Message: %s.", code, message);
|
||||||
|
|
|
@ -1,33 +1,13 @@
|
||||||
package info.frostfs.sdk.dto.response;
|
package info.frostfs.sdk.dto.response;
|
||||||
|
|
||||||
import info.frostfs.sdk.enums.SignatureScheme;
|
import info.frostfs.sdk.enums.SignatureScheme;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class Signature {
|
public class Signature {
|
||||||
private byte[] key;
|
private byte[] key;
|
||||||
private byte[] sign;
|
private byte[] sign;
|
||||||
private SignatureScheme scheme;
|
private SignatureScheme scheme;
|
||||||
|
|
||||||
public byte[] getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKey(byte[] key) {
|
|
||||||
this.key = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getSign() {
|
|
||||||
return sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSign(byte[] sign) {
|
|
||||||
this.sign = sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SignatureScheme getScheme() {
|
|
||||||
return scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScheme(SignatureScheme scheme) {
|
|
||||||
this.scheme = scheme;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package info.frostfs.sdk.dto.session;
|
package info.frostfs.sdk.dto.session;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class SessionToken {
|
public class SessionToken {
|
||||||
private final byte[] token;
|
private final byte[] token;
|
||||||
|
|
||||||
public SessionToken(byte[] token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,16 @@ import com.google.protobuf.ByteString;
|
||||||
import frostfs.container.Types;
|
import frostfs.container.Types;
|
||||||
import info.frostfs.sdk.dto.container.Container;
|
import info.frostfs.sdk.dto.container.Container;
|
||||||
import info.frostfs.sdk.enums.BasicAcl;
|
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.PlacementPolicyMapper;
|
||||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||||
|
|
||||||
import static info.frostfs.sdk.UuidExtension.asBytes;
|
import static info.frostfs.sdk.UuidExtension.asBytes;
|
||||||
import static info.frostfs.sdk.UuidExtension.asUuid;
|
import static info.frostfs.sdk.UuidExtension.asUuid;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ContainerMapper {
|
public class ContainerMapper {
|
||||||
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown BasicACL rule. Value: %s.";
|
|
||||||
|
|
||||||
private ContainerMapper() {
|
private ContainerMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ public class ContainerMapper {
|
||||||
|
|
||||||
var basicAcl = BasicAcl.get(containerGrpc.getBasicAcl());
|
var basicAcl = BasicAcl.get(containerGrpc.getBasicAcl());
|
||||||
if (isNull(basicAcl)) {
|
if (isNull(basicAcl)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, containerGrpc.getBasicAcl())
|
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, BasicAcl.class.getName(), containerGrpc.getBasicAcl())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@ import frostfs.netmap.Types;
|
||||||
import frostfs.netmap.Types.NodeInfo.Attribute;
|
import frostfs.netmap.Types.NodeInfo.Attribute;
|
||||||
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
import info.frostfs.sdk.dto.netmap.NodeInfo;
|
||||||
import info.frostfs.sdk.enums.NodeState;
|
import info.frostfs.sdk.enums.NodeState;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class NodeInfoMapper {
|
public class NodeInfoMapper {
|
||||||
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown NodeState. Value: %s.";
|
|
||||||
|
|
||||||
private NodeInfoMapper() {
|
private NodeInfoMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,9 @@ public class NodeInfoMapper {
|
||||||
|
|
||||||
NodeState nodeState = NodeState.get(nodeInfo.getState().getNumber());
|
NodeState nodeState = NodeState.get(nodeInfo.getState().getNumber());
|
||||||
if (isNull(nodeState)) {
|
if (isNull(nodeState)) {
|
||||||
throw new IllegalArgumentException(String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, nodeInfo.getState()));
|
throw new ProcessFrostFSException(
|
||||||
|
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, NodeState.class.getName(), nodeInfo.getState())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NodeInfo(
|
return new NodeInfo(
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.netmap.Replica;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class PlacementPolicyMapper {
|
public class PlacementPolicyMapper {
|
||||||
|
|
||||||
private PlacementPolicyMapper() {
|
private PlacementPolicyMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +31,8 @@ public class PlacementPolicyMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PlacementPolicy(
|
return new PlacementPolicy(
|
||||||
placementPolicy.getUnique(),
|
placementPolicy.getReplicasList().stream().map(ReplicaMapper::toModel).toArray(Replica[]::new),
|
||||||
placementPolicy.getReplicasList().stream().map(ReplicaMapper::toModel).toArray(Replica[]::new)
|
placementPolicy.getUnique()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ package info.frostfs.sdk.mappers.object;
|
||||||
import frostfs.object.Service;
|
import frostfs.object.Service;
|
||||||
import frostfs.object.Types;
|
import frostfs.object.Types;
|
||||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ObjectFilterMapper {
|
public class ObjectFilterMapper {
|
||||||
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown MatchType. Value: %s.";
|
|
||||||
|
|
||||||
private ObjectFilterMapper() {
|
private ObjectFilterMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,11 @@ public class ObjectFilterMapper {
|
||||||
|
|
||||||
var objectMatchType = Types.MatchType.forNumber(filter.getMatchType().value);
|
var objectMatchType = Types.MatchType.forNumber(filter.getMatchType().value);
|
||||||
if (isNull(objectMatchType)) {
|
if (isNull(objectMatchType)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(String.format(
|
||||||
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, filter.getMatchType().name())
|
UNKNOWN_ENUM_VALUE_TEMPLATE,
|
||||||
);
|
Types.MatchType.class.getName(),
|
||||||
|
filter.getMatchType().name()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Service.SearchRequest.Body.Filter.newBuilder()
|
return Service.SearchRequest.Body.Filter.newBuilder()
|
||||||
|
|
|
@ -6,32 +6,37 @@ import info.frostfs.sdk.dto.container.ContainerId;
|
||||||
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
|
||||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||||
import org.apache.commons.collections4.ListUtils;
|
import org.apache.commons.collections4.ListUtils;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
import static java.util.Objects.nonNull;
|
import static java.util.Objects.nonNull;
|
||||||
|
|
||||||
public class ObjectHeaderMapper {
|
public class ObjectHeaderMapper {
|
||||||
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown ObjectType. Value: %s.";
|
|
||||||
private static final String ERROR_OBJECT_HEADER_MISSING_ERROR = "ObjectHeader is not present";
|
|
||||||
|
|
||||||
private ObjectHeaderMapper() {
|
private ObjectHeaderMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Types.Header toGrpcMessage(ObjectHeader header) {
|
public static Types.Header toGrpcMessage(ObjectHeader header) {
|
||||||
if (isNull(header)) {
|
if (isNull(header)) {
|
||||||
throw new IllegalArgumentException(ERROR_OBJECT_HEADER_MISSING_ERROR);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, ObjectHeader.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var objectType = Types.ObjectType.forNumber(header.getObjectType().value);
|
var objectType = Types.ObjectType.forNumber(header.getObjectType().value);
|
||||||
if (isNull(objectType)) {
|
if (isNull(objectType)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(String.format(
|
||||||
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, header.getObjectType().name())
|
UNKNOWN_ENUM_VALUE_TEMPLATE,
|
||||||
);
|
Types.ObjectType.class.getName(),
|
||||||
|
header.getObjectType().name()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
var head = Types.Header.newBuilder()
|
var head = Types.Header.newBuilder()
|
||||||
|
@ -62,8 +67,8 @@ public class ObjectHeaderMapper {
|
||||||
|
|
||||||
var objectType = ObjectType.get(header.getObjectTypeValue());
|
var objectType = ObjectType.get(header.getObjectTypeValue());
|
||||||
if (isNull(objectType)) {
|
if (isNull(objectType)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, header.getObjectType())
|
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, ObjectType.class.getName(), header.getObjectType())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,21 @@ package info.frostfs.sdk.mappers.response;
|
||||||
|
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.response.MetaHeader;
|
import info.frostfs.sdk.dto.response.MetaHeader;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class MetaHeaderMapper {
|
public class MetaHeaderMapper {
|
||||||
private static final String ERROR_META_HEADER_MISSING_ERROR = "MetaHeader is not present";
|
|
||||||
|
|
||||||
private MetaHeaderMapper() {
|
private MetaHeaderMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Types.RequestMetaHeader toGrpcMessage(MetaHeader metaHeader) {
|
public static Types.RequestMetaHeader toGrpcMessage(MetaHeader metaHeader) {
|
||||||
if (isNull(metaHeader)) {
|
if (isNull(metaHeader)) {
|
||||||
throw new IllegalArgumentException(ERROR_META_HEADER_MISSING_ERROR);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, MetaHeader.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return toGrpcMessageBuilder(metaHeader).build();
|
return toGrpcMessageBuilder(metaHeader).build();
|
||||||
|
@ -22,7 +24,9 @@ public class MetaHeaderMapper {
|
||||||
|
|
||||||
public static Types.RequestMetaHeader.Builder toGrpcMessageBuilder(MetaHeader metaHeader) {
|
public static Types.RequestMetaHeader.Builder toGrpcMessageBuilder(MetaHeader metaHeader) {
|
||||||
if (isNull(metaHeader)) {
|
if (isNull(metaHeader)) {
|
||||||
throw new IllegalArgumentException(ERROR_META_HEADER_MISSING_ERROR);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, MetaHeader.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Types.RequestMetaHeader.newBuilder()
|
return Types.RequestMetaHeader.newBuilder()
|
||||||
|
|
|
@ -3,12 +3,12 @@ package info.frostfs.sdk.mappers.response;
|
||||||
import frostfs.status.Types;
|
import frostfs.status.Types;
|
||||||
import info.frostfs.sdk.dto.response.ResponseStatus;
|
import info.frostfs.sdk.dto.response.ResponseStatus;
|
||||||
import info.frostfs.sdk.enums.StatusCode;
|
import info.frostfs.sdk.enums.StatusCode;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class ResponseStatusMapper {
|
public class ResponseStatusMapper {
|
||||||
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown StatusCode. Value: %s.";
|
|
||||||
|
|
||||||
private ResponseStatusMapper() {
|
private ResponseStatusMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ public class ResponseStatusMapper {
|
||||||
|
|
||||||
var statusCode = StatusCode.get(status.getCode());
|
var statusCode = StatusCode.get(status.getCode());
|
||||||
if (isNull(statusCode)) {
|
if (isNull(statusCode)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(
|
||||||
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, status.getCode())
|
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, StatusCode.class.getName(), status.getCode())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ package info.frostfs.sdk.mappers.response;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import frostfs.refs.Types;
|
import frostfs.refs.Types;
|
||||||
import info.frostfs.sdk.dto.response.Signature;
|
import info.frostfs.sdk.dto.response.Signature;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class SignatureMapper {
|
public class SignatureMapper {
|
||||||
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown SignatureScheme. Value: %s.";
|
|
||||||
|
|
||||||
private SignatureMapper() {
|
private SignatureMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,11 @@ public class SignatureMapper {
|
||||||
|
|
||||||
var scheme = Types.SignatureScheme.forNumber(signature.getScheme().value);
|
var scheme = Types.SignatureScheme.forNumber(signature.getScheme().value);
|
||||||
if (isNull(scheme)) {
|
if (isNull(scheme)) {
|
||||||
throw new IllegalArgumentException(
|
throw new ProcessFrostFSException(String.format(
|
||||||
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, signature.getScheme().name())
|
UNKNOWN_ENUM_VALUE_TEMPLATE,
|
||||||
);
|
Types.SignatureScheme.class.getName(),
|
||||||
|
signature.getScheme().name()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Types.Signature.newBuilder()
|
return Types.Signature.newBuilder()
|
||||||
|
|
|
@ -3,20 +3,23 @@ package info.frostfs.sdk.mappers.session;
|
||||||
import com.google.protobuf.CodedOutputStream;
|
import com.google.protobuf.CodedOutputStream;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||||
import static java.util.Objects.isNull;
|
import static java.util.Objects.isNull;
|
||||||
|
|
||||||
public class SessionMapper {
|
public class SessionMapper {
|
||||||
private static final String ERROR_TOKEN_MISSING_MESSAGE = "Token is not present";
|
|
||||||
|
|
||||||
private SessionMapper() {
|
private SessionMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] serialize(Types.SessionToken token) {
|
public static byte[] serialize(Types.SessionToken token) {
|
||||||
if (isNull(token)) {
|
if (isNull(token)) {
|
||||||
throw new IllegalArgumentException(ERROR_TOKEN_MISSING_MESSAGE);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Types.SessionToken.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -25,19 +28,21 @@ public class SessionMapper {
|
||||||
token.writeTo(stream);
|
token.writeTo(stream);
|
||||||
return bytes;
|
return bytes;
|
||||||
} catch (IOException exp) {
|
} catch (IOException exp) {
|
||||||
throw new IllegalArgumentException(exp.getMessage());
|
throw new ProcessFrostFSException(exp.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Types.SessionToken deserializeSessionToken(byte[] bytes) {
|
public static Types.SessionToken deserializeSessionToken(byte[] bytes) {
|
||||||
if (isNull(bytes) || bytes.length == 0) {
|
if (isNull(bytes) || bytes.length == 0) {
|
||||||
throw new IllegalArgumentException(ERROR_TOKEN_MISSING_MESSAGE);
|
throw new ValidationFrostFSException(
|
||||||
|
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Types.SessionToken.class.getName())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Types.SessionToken.newBuilder().mergeFrom(bytes).build();
|
return Types.SessionToken.newBuilder().mergeFrom(bytes).build();
|
||||||
} catch (InvalidProtocolBufferException exp) {
|
} catch (InvalidProtocolBufferException exp) {
|
||||||
throw new IllegalArgumentException(exp.getMessage());
|
throw new ProcessFrostFSException(exp.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.frostfs.sdk;
|
package info.frostfs.sdk;
|
||||||
|
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -25,7 +26,7 @@ public class UuidExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void uuidAsBytes_givenParamsIsNull() {
|
void uuidAsBytes_givenParamsIsNull() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asBytes(null));
|
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asBytes(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -40,7 +41,7 @@ public class UuidExtensionTest {
|
||||||
@Test
|
@Test
|
||||||
void bytesAsUuid_givenParamsIsNull() {
|
void bytesAsUuid_givenParamsIsNull() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(null));
|
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,7 +52,7 @@ public class UuidExtensionTest {
|
||||||
|
|
||||||
|
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(valueLength15));
|
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength15));
|
||||||
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(valueLength17));
|
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength17));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import info.frostfs.sdk.dto.container.Container;
|
||||||
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
||||||
import info.frostfs.sdk.dto.netmap.Replica;
|
import info.frostfs.sdk.dto.netmap.Replica;
|
||||||
import info.frostfs.sdk.enums.BasicAcl;
|
import info.frostfs.sdk.enums.BasicAcl;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
@ -21,7 +22,7 @@ public class ContainerMapperTest {
|
||||||
@Test
|
@Test
|
||||||
void toGrpcMessage_success() {
|
void toGrpcMessage_success() {
|
||||||
//Given
|
//Given
|
||||||
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
|
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
||||||
var container = new Container(BasicAcl.PUBLIC_RW, placementPolicy);
|
var container = new Container(BasicAcl.PUBLIC_RW, placementPolicy);
|
||||||
|
|
||||||
//When
|
//When
|
||||||
|
@ -111,6 +112,6 @@ public class ContainerMapperTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> ContainerMapper.toModel(container));
|
assertThrows(ProcessFrostFSException.class, () -> ContainerMapper.toModel(container));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
|
||||||
import frostfs.netmap.Service;
|
import frostfs.netmap.Service;
|
||||||
import frostfs.netmap.Types;
|
import frostfs.netmap.Types;
|
||||||
import info.frostfs.sdk.enums.NodeState;
|
import info.frostfs.sdk.enums.NodeState;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
@ -117,7 +118,7 @@ public class NodeInfoMapperTest {
|
||||||
mockStatic.when(() -> NodeState.get(Types.NodeInfo.State.ONLINE.getNumber()))
|
mockStatic.when(() -> NodeState.get(Types.NodeInfo.State.ONLINE.getNumber()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> NodeInfoMapper.toModel(body));
|
assertThrows(ProcessFrostFSException.class, () -> NodeInfoMapper.toModel(body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class PlacementPolicyMapperTest {
|
||||||
var replica1 = new Replica(1, "test1");
|
var replica1 = new Replica(1, "test1");
|
||||||
var replica2 = new Replica(2, "test2");
|
var replica2 = new Replica(2, "test2");
|
||||||
|
|
||||||
var placementPolicy = new PlacementPolicy(true, new Replica[]{replica1, replica2});
|
var placementPolicy = new PlacementPolicy(new Replica[]{replica1, replica2}, true);
|
||||||
|
|
||||||
//When
|
//When
|
||||||
var result = PlacementPolicyMapper.toGrpcMessage(placementPolicy);
|
var result = PlacementPolicyMapper.toGrpcMessage(placementPolicy);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.frostfs.sdk.mappers.object;
|
||||||
import frostfs.object.Types;
|
import frostfs.object.Types;
|
||||||
import info.frostfs.sdk.dto.object.ObjectFilter;
|
import info.frostfs.sdk.dto.object.ObjectFilter;
|
||||||
import info.frostfs.sdk.enums.ObjectMatchType;
|
import info.frostfs.sdk.enums.ObjectMatchType;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
@ -47,7 +48,7 @@ public class ObjectFilterMapperTest {
|
||||||
mockStatic.when(() -> Types.MatchType.forNumber(objectFilter.getMatchType().value))
|
mockStatic.when(() -> Types.MatchType.forNumber(objectFilter.getMatchType().value))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> ObjectFilterMapper.toGrpcMessage(objectFilter));
|
assertThrows(ProcessFrostFSException.class, () -> ObjectFilterMapper.toGrpcMessage(objectFilter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||||
import info.frostfs.sdk.dto.object.OwnerId;
|
import info.frostfs.sdk.dto.object.OwnerId;
|
||||||
import info.frostfs.sdk.enums.ObjectType;
|
import info.frostfs.sdk.enums.ObjectType;
|
||||||
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
@ -56,7 +57,7 @@ public class ObjectHeaderMapperTest {
|
||||||
@Test
|
@Test
|
||||||
void toGrpcMessage_null() {
|
void toGrpcMessage_null() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> ObjectHeaderMapper.toGrpcMessage(null));
|
assertThrows(ValidationFrostFSException.class, () -> ObjectHeaderMapper.toGrpcMessage(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -70,7 +71,7 @@ public class ObjectHeaderMapperTest {
|
||||||
mockStatic.when(() -> Types.ObjectType.forNumber(objectHeader.getObjectType().value))
|
mockStatic.when(() -> Types.ObjectType.forNumber(objectHeader.getObjectType().value))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> ObjectHeaderMapper.toGrpcMessage(objectHeader));
|
assertThrows(ProcessFrostFSException.class, () -> ObjectHeaderMapper.toGrpcMessage(objectHeader));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ public class ObjectHeaderMapperTest {
|
||||||
mockStatic.when(() -> ObjectType.get(Types.ObjectType.TOMBSTONE.getNumber()))
|
mockStatic.when(() -> ObjectType.get(Types.ObjectType.TOMBSTONE.getNumber()))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> ObjectHeaderMapper.toModel(header));
|
assertThrows(ProcessFrostFSException.class, () -> ObjectHeaderMapper.toModel(header));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.frostfs.sdk.mappers.response;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
import info.frostfs.sdk.dto.netmap.Version;
|
import info.frostfs.sdk.dto.netmap.Version;
|
||||||
import info.frostfs.sdk.dto.response.MetaHeader;
|
import info.frostfs.sdk.dto.response.MetaHeader;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
@ -29,7 +30,7 @@ public class MetaHeaderMapperTest {
|
||||||
@Test
|
@Test
|
||||||
void toGrpcMessage_null() {
|
void toGrpcMessage_null() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> MetaHeaderMapper.toGrpcMessage(null));
|
assertThrows(ValidationFrostFSException.class, () -> MetaHeaderMapper.toGrpcMessage(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,6 +53,6 @@ public class MetaHeaderMapperTest {
|
||||||
@Test
|
@Test
|
||||||
void toGrpcMessageBuilder_null() {
|
void toGrpcMessageBuilder_null() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> MetaHeaderMapper.toGrpcMessageBuilder(null));
|
assertThrows(ValidationFrostFSException.class, () -> MetaHeaderMapper.toGrpcMessageBuilder(null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.frostfs.sdk.mappers.response;
|
||||||
|
|
||||||
import frostfs.status.Types;
|
import frostfs.status.Types;
|
||||||
import info.frostfs.sdk.enums.StatusCode;
|
import info.frostfs.sdk.enums.StatusCode;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
@ -48,6 +49,6 @@ public class ResponseStatusMapperTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> ResponseStatusMapper.toModel(status));
|
assertThrows(ProcessFrostFSException.class, () -> ResponseStatusMapper.toModel(status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.frostfs.sdk.mappers.response;
|
||||||
import frostfs.refs.Types;
|
import frostfs.refs.Types;
|
||||||
import info.frostfs.sdk.dto.response.Signature;
|
import info.frostfs.sdk.dto.response.Signature;
|
||||||
import info.frostfs.sdk.enums.SignatureScheme;
|
import info.frostfs.sdk.enums.SignatureScheme;
|
||||||
|
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
|
@ -50,7 +51,7 @@ public class SignatureMapperTest {
|
||||||
mockStatic.when(() -> Types.SignatureScheme.forNumber(signature.getScheme().value))
|
mockStatic.when(() -> Types.SignatureScheme.forNumber(signature.getScheme().value))
|
||||||
.thenReturn(null);
|
.thenReturn(null);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> SignatureMapper.toGrpcMessage(signature));
|
assertThrows(ProcessFrostFSException.class, () -> SignatureMapper.toGrpcMessage(signature));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.frostfs.sdk.mappers.session;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import frostfs.session.Types;
|
import frostfs.session.Types;
|
||||||
|
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -27,7 +28,7 @@ public class SessionMapperTest {
|
||||||
@Test
|
@Test
|
||||||
void serialize_wrong() {
|
void serialize_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> SessionMapper.serialize(null));
|
assertThrows(ValidationFrostFSException.class, () -> SessionMapper.serialize(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -43,8 +44,8 @@ public class SessionMapperTest {
|
||||||
@Test
|
@Test
|
||||||
void deserialize_wrong() {
|
void deserialize_wrong() {
|
||||||
//When + Then
|
//When + Then
|
||||||
assertThrows(IllegalArgumentException.class, () -> SessionMapper.deserializeSessionToken(null));
|
assertThrows(ValidationFrostFSException.class, () -> SessionMapper.deserializeSessionToken(null));
|
||||||
assertThrows(IllegalArgumentException.class, () -> SessionMapper.deserializeSessionToken(new byte[]{}));
|
assertThrows(ValidationFrostFSException.class, () -> SessionMapper.deserializeSessionToken(new byte[]{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Types.SessionToken createSessionToken() {
|
private Types.SessionToken createSessionToken() {
|
||||||
|
|
20
pom.xml
20
pom.xml
|
@ -13,6 +13,7 @@
|
||||||
<module>cryptography</module>
|
<module>cryptography</module>
|
||||||
<module>models</module>
|
<module>models</module>
|
||||||
<module>protos</module>
|
<module>protos</module>
|
||||||
|
<module>exceptions</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -23,9 +24,28 @@
|
||||||
<mockito.version>5.12.0</mockito.version>
|
<mockito.version>5.12.0</mockito.version>
|
||||||
<junit.version>5.10.3</junit.version>
|
<junit.version>5.10.3</junit.version>
|
||||||
<assertj.version>3.26.3</assertj.version>
|
<assertj.version>3.26.3</assertj.version>
|
||||||
|
<lombok.version>1.18.34</lombok.version>
|
||||||
|
<protobuf.version>3.23.0</protobuf.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
<version>4.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.14.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
<protobuf.version>3.23.0</protobuf.version>
|
|
||||||
<grpc.version>1.65.1</grpc.version>
|
<grpc.version>1.65.1</grpc.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
Loading…
Reference in a new issue