[#14] add lombok and refactor exceptions. Provide validator.

Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
Ori Bruk 2024-09-17 17:47:03 +03:00
parent 15cf0893c7
commit 388428af76
87 changed files with 819 additions and 970 deletions

View file

@ -35,7 +35,7 @@ public class ContainerExample {
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
// Create container
var placementPolicy = new PlacementPolicy(true, new Replica[]{new Replica(1)});
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
var containerId = frostFSClient.createContainer(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
// Get container
@ -91,7 +91,7 @@ public class ObjectExample {
var objectHeader = frostFSClient.getObjectHead(containerId, objectId);
// Search regular objects
var objectIds = frostFSClient.searchObjects(containerId, ObjectFilter.RootFilter());
var objectIds = frostFSClient.searchObjects(containerId, new ObjectFilter.FilterByRootObject());
}
}
```

View file

@ -29,9 +29,9 @@
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
<groupId>info.frostfs.sdk</groupId>
<artifactId>exceptions</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>

View file

@ -11,24 +11,23 @@ import info.frostfs.sdk.dto.object.ObjectFrostFS;
import info.frostfs.sdk.dto.object.ObjectHeader;
import info.frostfs.sdk.dto.object.ObjectId;
import info.frostfs.sdk.dto.session.SessionToken;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.jdo.ClientEnvironment;
import info.frostfs.sdk.jdo.ClientSettings;
import info.frostfs.sdk.jdo.NetworkSettings;
import info.frostfs.sdk.jdo.PutObjectParameters;
import info.frostfs.sdk.services.*;
import info.frostfs.sdk.services.impl.*;
import info.frostfs.sdk.utils.Validator;
import io.grpc.Channel;
import java.util.List;
import static info.frostfs.sdk.constants.ErrorConst.VERSION_UNSUPPORTED_TEMPLATE;
import static info.frostfs.sdk.tools.GrpcClient.initGrpcChannel;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
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 NetmapClientImpl netmapClientImpl;
private final ObjectClientImpl objectClientImpl;
@ -36,16 +35,16 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
private final ObjectToolsImpl objectToolsImpl;
public FrostFSClient(ClientSettings clientSettings) {
if (isNull(clientSettings)) {
throw new IllegalArgumentException(ERROR_CLIENT_OPTIONS_INIT);
}
Channel channel = nonNull(clientSettings.getChannel()) ? clientSettings.getChannel()
: initGrpcChannel(clientSettings.getHost(), clientSettings.getCredentials());
Validator.validate(clientSettings);
Channel channel = nonNull(clientSettings.getChannel())
? clientSettings.getChannel()
: initGrpcChannel(clientSettings);
ClientEnvironment clientEnvironment =
new ClientEnvironment(clientSettings.getKey(), channel, new Version(), this);
Validator.validate(clientEnvironment);
this.containerClientImpl = new ContainerClientImpl(clientEnvironment);
this.netmapClientImpl = new NetmapClientImpl(clientEnvironment);
this.sessionClientImpl = new SessionClientImpl(clientEnvironment);
@ -57,8 +56,8 @@ public class FrostFSClient implements ContainerClient, ObjectClient, NetmapClien
private void checkFrostFsVersionSupport(Version version) {
var localNodeInfo = netmapClientImpl.getLocalNodeInfo();
if (!localNodeInfo.getVersion().isSupported(version)) {
throw new IllegalArgumentException(
String.format(ERROR_VERSION_SUPPORT_TEMPLATE, localNodeInfo.getVersion())
throw new ProcessFrostFSException(
String.format(VERSION_UNSUPPORTED_TEMPLATE, localNodeInfo.getVersion())
);
}
}

View file

@ -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();
}

View file

@ -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 {
}

View file

@ -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 {
}

View file

@ -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 {
}

View file

@ -2,6 +2,8 @@ package info.frostfs.sdk.constants;
public class CryptoConst {
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() {
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -1,6 +0,0 @@
package info.frostfs.sdk.exceptions;
public class TimeoutException extends RuntimeException {
public TimeoutException() {
}
}

View file

@ -1,60 +1,41 @@
package info.frostfs.sdk.jdo;
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.object.OwnerId;
import io.grpc.Channel;
import org.apache.commons.lang3.StringUtils;
import static java.util.Objects.isNull;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ClientEnvironment {
private static final String ERROR_MESSAGE = "One of the input attributes is missing";
@NotNull
private final OwnerId ownerId;
@NotNull
private final Version version;
@NotNull
@Validate
private final ECDsa key;
@NotNull
private final Channel channel;
@NotNull
private final FrostFSClient frostFSClient;
private NetworkSettings networkSettings;
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.ownerId = new OwnerId(key.getPublicKeyByte());
this.version = version;
this.channel = channel;
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;
}
}

View file

@ -1,17 +1,20 @@
package info.frostfs.sdk.jdo;
import info.frostfs.sdk.annotations.AtLeastOneIsFilled;
import info.frostfs.sdk.annotations.NotNull;
import io.grpc.Channel;
import io.grpc.ChannelCredentials;
import org.apache.commons.lang3.StringUtils;
import static java.util.Objects.isNull;
import lombok.Getter;
import lombok.experimental.FieldNameConstants;
@Getter
@FieldNameConstants
@AtLeastOneIsFilled(fields = {ClientSettings.Fields.host, ClientSettings.Fields.channel})
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 String host;
private ChannelCredentials credentials;
private Channel channel;
@ -19,51 +22,16 @@ public class ClientSettings {
public ClientSettings(String key, String host) {
this.key = key;
this.host = host;
validate();
}
public ClientSettings(String key, String host, ChannelCredentials credentials) {
this.key = key;
this.host = host;
this.credentials = credentials;
validate();
}
public ClientSettings(String key, Channel channel) {
this.key = key;
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());
}
}
}

View file

@ -1,37 +1,34 @@
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 java.security.PrivateKey;
import static info.frostfs.sdk.KeyExtension.*;
import static info.frostfs.sdk.constants.ErrorConst.WIF_IS_INVALID;
@Getter
public class ECDsa {
private static final String ERROR_MESSAGE = "WIF is invalid";
@NotNull
private final byte[] publicKeyByte;
@NotNull
private final byte[] privateKeyByte;
@NotNull
private final PrivateKey privateKey;
public ECDsa(String wif) {
if (StringUtils.isEmpty(wif)) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(WIF_IS_INVALID);
}
this.privateKeyByte = getPrivateKeyFromWIF(wif);
this.publicKeyByte = loadPublicKey(privateKeyByte);
this.privateKey = loadPrivateKey(privateKeyByte);
}
public byte[] getPublicKeyByte() {
return publicKeyByte;
}
public byte[] getPrivateKeyByte() {
return privateKeyByte;
}
public PrivateKey getPrivateKey() {
return privateKey;
}
}

View file

@ -1,8 +1,13 @@
package info.frostfs.sdk.jdo;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
import java.util.Map;
@Getter
@Setter
public class NetworkSettings {
private Long auditFee;
@ -20,124 +25,4 @@ public class NetworkSettings {
private Boolean homomorphicHashingDisabled;
private Boolean maintenanceModeAllowed;
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;
}
}

View file

@ -1,19 +1,23 @@
package info.frostfs.sdk.jdo;
import info.frostfs.sdk.annotations.NotNull;
import info.frostfs.sdk.dto.object.ObjectHeader;
import info.frostfs.sdk.dto.session.SessionToken;
import lombok.Getter;
import lombok.Setter;
import java.io.FileInputStream;
import static java.util.Objects.isNull;
@Getter
@Setter
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;
@NotNull
private FileInputStream payload;
private boolean clientCut;
private int bufferMaxSize;
private byte[] customerBuffer;
@ -27,102 +31,10 @@ public class PutObjectParameters {
this.payload = payload;
this.clientCut = clientCut;
this.bufferMaxSize = bufferMaxSize;
validate();
}
public PutObjectParameters(ObjectHeader header, FileInputStream payload) {
this.header = header;
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());
}
}
}

View file

@ -1,21 +1,13 @@
package info.frostfs.sdk.jdo;
import info.frostfs.sdk.dto.object.ObjectId;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class PutObjectResult {
private final ObjectId objectId;
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;
}
}

View file

@ -1,8 +1,13 @@
package info.frostfs.sdk.jdo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.time.Duration;
import java.time.LocalDateTime;
@Getter
@AllArgsConstructor
public class WaitParameters {
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(120);
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofSeconds(5);
@ -15,19 +20,6 @@ public class WaitParameters {
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() {
return LocalDateTime.now().plus(timeout);
}

View file

@ -1,7 +1,9 @@
package info.frostfs.sdk.services;
import info.frostfs.sdk.jdo.ClientEnvironment;
import lombok.Getter;
@Getter
public class ContextAccessor {
private final ClientEnvironment context;
@ -9,7 +11,4 @@ public class ContextAccessor {
this.context = context;
}
public ClientEnvironment getContext() {
return context;
}
}

View file

@ -8,8 +8,9 @@ import info.frostfs.sdk.dto.container.ContainerId;
import info.frostfs.sdk.dto.session.SessionToken;
import info.frostfs.sdk.enums.StatusCode;
import info.frostfs.sdk.enums.WaitExpects;
import info.frostfs.sdk.exceptions.ResponseException;
import info.frostfs.sdk.exceptions.TimeoutException;
import info.frostfs.sdk.exceptions.ResponseFrostFSException;
import info.frostfs.sdk.exceptions.TimeoutFrostFSException;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import info.frostfs.sdk.jdo.ClientEnvironment;
import info.frostfs.sdk.jdo.WaitParameters;
import info.frostfs.sdk.mappers.container.ContainerIdMapper;
@ -28,12 +29,10 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static info.frostfs.sdk.constants.ErrorConst.PARAM_IS_MISSING_TEMPLATE;
import static java.util.Objects.isNull;
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 SessionToolsImpl sessionTools;
@ -50,7 +49,7 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
@Override
public Container getContainer(ContainerId 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);
@ -77,7 +76,7 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
@Override
public ContainerId createContainer(Container 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);
@ -95,7 +94,7 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
@Override
public void deleteContainer(ContainerId 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);
@ -124,13 +123,13 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
}
if (LocalDateTime.now().isAfter(deadLine)) {
throw new TimeoutException();
throw new TimeoutFrostFSException();
}
WaitUtil.sleep(waitParams.getPollInterval().toMillis());
} catch (ResponseException exp) {
} catch (ResponseFrostFSException exp) {
if (LocalDateTime.now().isAfter(deadLine)) {
throw new TimeoutException();
throw new TimeoutFrostFSException();
}
if (exp.getStatus().getCode() != StatusCode.CONTAINER_NOT_FOUND) {

View file

@ -10,6 +10,8 @@ import info.frostfs.sdk.dto.container.ContainerId;
import info.frostfs.sdk.dto.object.*;
import info.frostfs.sdk.dto.session.SessionToken;
import info.frostfs.sdk.enums.ObjectType;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import info.frostfs.sdk.jdo.ClientEnvironment;
import info.frostfs.sdk.jdo.PutObjectParameters;
import info.frostfs.sdk.jdo.PutObjectResult;
@ -26,6 +28,7 @@ import info.frostfs.sdk.services.impl.rwhelper.ObjectWriter;
import info.frostfs.sdk.services.impl.rwhelper.SearchReader;
import info.frostfs.sdk.tools.RequestConstructor;
import info.frostfs.sdk.tools.Verifier;
import info.frostfs.sdk.utils.Validator;
import org.apache.commons.collections4.CollectionUtils;
import java.io.FileInputStream;
@ -34,12 +37,11 @@ import java.util.ArrayList;
import java.util.List;
import static info.frostfs.sdk.Helper.getSha256;
import static info.frostfs.sdk.constants.ErrorConst.*;
import static info.frostfs.sdk.tools.RequestSigner.sign;
import static java.util.Objects.isNull;
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.ObjectServiceStub objectServiceClient;
private final ObjectToolsImpl objectToolsImpl;
@ -60,7 +62,12 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
@Override
public ObjectHeader getObjectHead(ContainerId cid, ObjectId 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));
@ -89,7 +96,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
}
@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 objectsIds = searchObjects(request);
@ -99,7 +106,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
@Override
public ObjectId putObject(PutObjectParameters parameters) {
parameters.validate();
Validator.validate(parameters);
if (parameters.isClientCut()) {
return putClientCutObject(parameters);
@ -140,7 +147,9 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
private ObjectReaderImpl getObjectInit(Service.GetRequest initRequest) {
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));
@ -209,7 +218,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
if (parameters.getMaxObjectSizeCache() == 0) {
var networkSettings = getContext().getFrostFSClient().getNetworkSettings();
parameters.setMaxObjectSizeCache((int) networkSettings.getMaxObjectSize());
parameters.setMaxObjectSizeCache(networkSettings.getMaxObjectSize().intValue());
}
var restBytes = fullLength - parameters.getCurrentStreamPosition();
@ -287,7 +296,9 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
private ObjectWriter putObjectInit(Service.PutRequest initRequest) {
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);
@ -310,7 +321,9 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
private SearchReader getSearchReader(Service.SearchRequest initRequest) {
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));
@ -320,7 +333,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
try {
return fileInputStream.readNBytes(buffer, 0, size);
} 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 {
return fileInputStream.getChannel().size();
} catch (IOException exp) {
throw new IllegalArgumentException(exp.getMessage());
throw new ProcessFrostFSException(exp.getMessage());
}
}

View file

@ -3,14 +3,15 @@ package info.frostfs.sdk.services.impl.rwhelper;
import frostfs.object.Service;
import frostfs.object.Types;
import info.frostfs.sdk.dto.object.ObjectReader;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.tools.Verifier;
import java.util.Iterator;
public class ObjectReaderImpl implements ObjectReader {
public static final String ERROR_UNEXPECTED_STREAM = "unexpected end of stream";
public static final String ERROR_UNEXPECTED_MESSAGE_TYPE = "unexpected message type";
import static info.frostfs.sdk.constants.ErrorConst.UNEXPECTED_MESSAGE_TYPE_TEMPLATE;
import static info.frostfs.sdk.constants.ErrorConst.UNEXPECTED_STREAM;
public class ObjectReaderImpl implements ObjectReader {
public Iterator<Service.GetResponse> call;
public ObjectReaderImpl(Iterator<Service.GetResponse> call) {
@ -19,14 +20,20 @@ public class ObjectReaderImpl implements ObjectReader {
public Types.Object readHeader() {
if (!call.hasNext()) {
throw new IllegalArgumentException(ERROR_UNEXPECTED_STREAM);
throw new ProcessFrostFSException(UNEXPECTED_STREAM);
}
var response = call.next();
Verifier.checkResponse(response);
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()
@ -44,7 +51,13 @@ public class ObjectReaderImpl implements ObjectReader {
Verifier.checkResponse(response);
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();

View file

@ -2,9 +2,12 @@ package info.frostfs.sdk.services.impl.rwhelper;
import frostfs.object.ObjectServiceGrpc;
import frostfs.object.Service;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.utils.WaitUtil;
import io.grpc.stub.StreamObserver;
import lombok.Getter;
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
import static java.util.Objects.isNull;
public class ObjectWriter {
@ -21,7 +24,9 @@ public class ObjectWriter {
public void write(Service.PutRequest request) {
if (isNull(request)) {
throw new IllegalArgumentException();
throw new ProcessFrostFSException(
String.format(PROTO_MESSAGE_IS_EMPTY_TEMPLATE, Service.PutRequest.class.getName())
);
}
requestObserver.onNext(request);
@ -37,6 +42,7 @@ public class ObjectWriter {
return responseObserver.getResponse();
}
@Getter
private static class PutResponseCallback implements StreamObserver<Service.PutResponse> {
private Service.PutResponse response;
@ -47,15 +53,11 @@ public class ObjectWriter {
@Override
public void onError(Throwable throwable) {
throw new RuntimeException(throwable);
throw new ProcessFrostFSException(throwable);
}
@Override
public void onCompleted() {
}
public Service.PutResponse getResponse() {
return response;
}
}
}

View file

@ -1,36 +1,35 @@
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.ChannelCredentials;
import io.grpc.netty.NettyChannelBuilder;
import org.apache.commons.lang3.StringUtils;
import java.net.URI;
import java.net.URISyntaxException;
import static info.frostfs.sdk.constants.ErrorConst.INVALID_HOST_TEMPLATE;
import static java.util.Objects.isNull;
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() {
}
public static Channel initGrpcChannel(String host, ChannelCredentials credentials) {
if (StringUtils.isBlank(host)) {
throw new IllegalArgumentException(ERROR_EMPTY_HOST_MESSAGE);
}
public static Channel initGrpcChannel(ClientSettings clientSettings) {
Validator.validate(clientSettings);
try {
URI uri = new URI(host);
var channelBuilder = isNull(credentials)
URI uri = new URI(clientSettings.getHost());
var channelBuilder = isNull(clientSettings.getCredentials())
? 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();
} 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())
);
}
}
}

View file

@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import frostfs.session.Types;
import info.frostfs.sdk.dto.response.MetaHeader;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import info.frostfs.sdk.jdo.ECDsa;
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
import org.apache.commons.collections4.MapUtils;
@ -11,6 +12,7 @@ import org.apache.commons.collections4.MapUtils;
import java.util.Map;
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.tools.RequestSigner.signMessagePart;
import static info.frostfs.sdk.utils.MessageHelper.getField;
@ -19,8 +21,6 @@ import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
public class RequestConstructor {
private static final String ERROR_MESSAGE = "The message does not contain a field " + META_HEADER_FIELD_NAME;
private RequestConstructor() {
}
@ -40,7 +40,7 @@ public class RequestConstructor {
}
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) {

View file

@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import frostfs.session.Types;
import info.frostfs.sdk.constants.CryptoConst;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.jdo.ECDsa;
import info.frostfs.sdk.utils.MessageHelper;
import org.apache.commons.codec.digest.DigestUtils;
@ -17,15 +18,14 @@ import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
import java.math.BigInteger;
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 org.bouncycastle.crypto.util.DigestFactory.createSHA256;
import static org.bouncycastle.util.BigIntegers.asUnsignedByteArray;
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() {
}
@ -39,7 +39,7 @@ public class RequestSigner {
byte[] sig = signature.sign();
System.arraycopy(sig, 0, hash, 1, sig.length);
} catch (Exception exp) {
throw new RuntimeException(exp);
throw new ProcessFrostFSException(exp);
}
return hash;
@ -104,8 +104,8 @@ public class RequestSigner {
} else if (verify instanceof Types.ResponseVerificationHeader) {
verifyBuilder = Types.ResponseVerificationHeader.newBuilder();
} else {
throw new IllegalArgumentException(
String.format(ERROR_UNSUPPORTED_TYPE_TEMPLATE, verify.getClass().getName())
throw new ProcessFrostFSException(
String.format(UNSUPPORTED_PROTO_MESSAGE_TYPE_TEMPLATE, verify.getClass().getName())
);
}

View file

@ -3,7 +3,9 @@ package info.frostfs.sdk.tools;
import com.google.protobuf.Message;
import frostfs.session.Types;
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.utils.MessageHelper;
import org.apache.commons.codec.digest.DigestUtils;
@ -20,16 +22,15 @@ import java.security.Signature;
import java.util.Arrays;
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 java.util.Objects.isNull;
import static org.bouncycastle.crypto.util.DigestFactory.createSHA256;
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
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() {
}
@ -56,28 +57,30 @@ public class Verifier {
}
private static BigInteger[] decodeSignature(byte[] sig) {
if (sig.length != RFC6979_SIG_SIZE) {
throw new IllegalArgumentException(
String.format(ERROR_WRONG_SIG_SIZE_TEMPLATE, RFC6979_SIG_SIZE, sig.length)
if (sig.length != RFC6979_SIGNATURE_SIZE) {
throw new ValidationFrostFSException(
String.format(WRONG_SIGNATURE_SIZE_TEMPLATE, RFC6979_SIGNATURE_SIZE, sig.length)
);
}
var rs = new BigInteger[2];
rs[0] = fromUnsignedByteArray(Arrays.copyOfRange(sig, 0, (RFC6979_SIG_SIZE / 2) - 1));
rs[1] = fromUnsignedByteArray(Arrays.copyOfRange(sig, RFC6979_SIG_SIZE / 2, RFC6979_SIG_SIZE - 1));
rs[0] = fromUnsignedByteArray(Arrays.copyOfRange(sig, 0, (RFC6979_SIGNATURE_SIZE / 2) - 1));
rs[1] = fromUnsignedByteArray(
Arrays.copyOfRange(sig, RFC6979_SIGNATURE_SIZE / 2, RFC6979_SIGNATURE_SIZE - 1)
);
return rs;
}
public static void checkResponse(Message 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 status = ResponseStatusMapper.toModel(metaHeader.getStatus());
if (!status.isSuccess()) {
throw new ResponseException(status);
throw new ResponseFrostFSException(status);
}
}
@ -127,7 +130,7 @@ public class Verifier {
signature.update(DigestUtils.sha512(data));
return signature.verify(Arrays.copyOfRange(sig, 1, sig.length));
} catch (Exception exp) {
throw new RuntimeException(exp);
throw new ProcessFrostFSException(exp);
}
}
}

View file

@ -2,19 +2,19 @@ package info.frostfs.sdk.utils;
import com.google.protobuf.Message;
import com.google.protobuf.MessageOrBuilder;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.apache.commons.lang3.StringUtils;
import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING;
import static java.util.Objects.isNull;
public class MessageHelper {
private static final String ERROR_MESSAGE = "One of the input parameters is null";
private MessageHelper() {
}
public static Object getField(MessageOrBuilder messageOrBuilder, String 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));
@ -22,7 +22,7 @@ public class MessageHelper {
public static void setField(Message.Builder builder, String fieldName, Object 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);

View 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);
}
}
}

View file

@ -15,10 +15,14 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<protobuf.version>3.23.0</protobuf.version>
</properties>
<dependencies>
<dependency>
<groupId>info.frostfs.sdk</groupId>
<artifactId>exceptions</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
@ -29,11 +33,6 @@
<artifactId>bcprov-jdk18on</artifactId>
<version>1.78.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>

View file

@ -1,16 +1,17 @@
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;
public class ArrayHelper {
private static final String ERROR_MESSAGE = "One of the input parameters is null";
private ArrayHelper() {
}
public static byte[] concat(byte[] startArray, byte[] 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];

View file

@ -1,11 +1,14 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import static info.frostfs.sdk.ArrayHelper.concat;
import static info.frostfs.sdk.Helper.getSha256;
import static info.frostfs.sdk.constants.ErrorConst.*;
import static java.util.Objects.isNull;
public class Base58 {
@ -16,8 +19,6 @@ public class Base58 {
private static final char ENCODED_ZERO = ALPHABET[0];
private static final char BASE58_ASCII_MAX_VALUE = 128;
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 {
Arrays.fill(INDEXES, -1);
@ -31,12 +32,12 @@ public class Base58 {
public static byte[] base58CheckDecode(String input) {
if (StringUtils.isEmpty(input)) {
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
byte[] buffer = decode(input);
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);
@ -44,7 +45,7 @@ public class Base58 {
var bufferEnd = Arrays.copyOfRange(buffer, buffer.length - 4, buffer.length);
var checksumStart = Arrays.copyOfRange(checksum, 0, 4);
if (!Arrays.equals(bufferEnd, checksumStart)) {
throw new IllegalArgumentException();
throw new ProcessFrostFSException(INVALID_CHECKSUM);
}
return decode;
@ -52,7 +53,7 @@ public class Base58 {
public static String base58CheckEncode(byte[] data) {
if (isNull(data)) {
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
byte[] checksum = getSha256(getSha256(data));
@ -101,7 +102,7 @@ public class Base58 {
char c = input.charAt(i);
int digit = c < BASE58_ASCII_MAX_VALUE ? INDEXES[c] : -1;
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;
}

View file

@ -2,16 +2,17 @@ package info.frostfs.sdk;
import com.google.protobuf.ByteString;
import com.google.protobuf.Message;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.bouncycastle.crypto.digests.RIPEMD160Digest;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING;
import static java.util.Objects.isNull;
public class Helper {
private static final String ERROR_MESSAGE = "Input value is missing";
private static final String SHA256 = "SHA-256";
private static final int RIPEMD_160_HASH_BYTE_LENGTH = 20;
@ -20,7 +21,7 @@ public class Helper {
public static byte[] getRipemd160(byte[] 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];
@ -40,7 +41,7 @@ public class Helper {
public static byte[] getSha256(byte[] value) {
if (isNull(value)) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
return getSha256Instance().digest(value);
@ -48,7 +49,7 @@ public class Helper {
public static ByteString getSha256(Message value) {
if (isNull(value)) {
throw new IllegalArgumentException(ERROR_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
return ByteString.copyFrom(getSha256(value.toByteArray()));
@ -56,7 +57,7 @@ public class Helper {
public static String getHexString(byte[] value) {
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));

View file

@ -1,5 +1,7 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.asn1.sec.SECNamedCurves;
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.getSha256;
import static info.frostfs.sdk.constants.ErrorConst.*;
import static java.util.Objects.isNull;
import static org.bouncycastle.util.BigIntegers.fromUnsignedByteArray;
@ -40,13 +43,6 @@ public class KeyExtension {
private static final int CHECK_SIG_DESCRIPTOR = ByteBuffer
.wrap(getSha256("System.Crypto.CheckSig".getBytes(StandardCharsets.US_ASCII)))
.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() {
}
@ -54,8 +50,8 @@ public class KeyExtension {
public static byte[] compress(byte[] publicKey) {
checkInputValue(publicKey);
if (publicKey.length != UNCOMPRESSED_PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(String.format(
ERROR_UNCOMPRESSED_PUBLIC_KEY_TEMPLATE, UNCOMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
throw new ValidationFrostFSException(String.format(
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) {
if (StringUtils.isEmpty(wif)) {
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
var data = Base58.base58CheckDecode(wif);
@ -102,7 +98,7 @@ public class KeyExtension {
KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM);
return kf.generatePrivate(privateKeySpec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new RuntimeException(e);
throw new ProcessFrostFSException(e);
}
}
@ -110,9 +106,9 @@ public class KeyExtension {
checkInputValue(publicKey);
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(
String.format(ERROR_COMPRESSED_PUBLIC_KEY_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length)
);
throw new ValidationFrostFSException(String.format(
COMPRESSED_PUBLIC_KEY_WRONG_LENGTH_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
));
}
X9ECParameters secp256R1 = SECNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
@ -134,7 +130,7 @@ public class KeyExtension {
KeyFactory kf = KeyFactory.getInstance(SECURITY_ALGORITHM);
return kf.generatePublic(publicKeySpec);
} catch (Exception e) {
throw new RuntimeException(e);
throw new ProcessFrostFSException(e);
}
}
@ -148,8 +144,8 @@ public class KeyExtension {
public static String publicKeyToAddress(byte[] publicKey) {
checkInputValue(publicKey);
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(String.format(
ERROR_ENCODED_COMPRESSED_PUBLIC_KEY_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
throw new ValidationFrostFSException(String.format(
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) {
checkInputValue(publicKey);
if (publicKey.length != COMPRESSED_PUBLIC_KEY_LENGTH) {
throw new IllegalArgumentException(String.format(
ERROR_ENCODED_COMPRESSED_PUBLIC_KEY_TEMPLATE, COMPRESSED_PUBLIC_KEY_LENGTH, publicKey.length
throw new ValidationFrostFSException(String.format(
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) {
if (isNull(data) || data.length == 0) {
throw new IllegalArgumentException(ERROR_VALUE_MISSING_MESSAGE);
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
}
}

View file

@ -1,5 +1,6 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -59,8 +60,8 @@ public class ArrayHelperTest {
var endBytes = new byte[]{6, 7, 8, 9};
//When + Then
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(startBytes, null));
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(null, endBytes));
assertThrows(IllegalArgumentException.class, () -> ArrayHelper.concat(null, null));
assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(startBytes, null));
assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(null, endBytes));
assertThrows(ValidationFrostFSException.class, () -> ArrayHelper.concat(null, null));
}
}

View file

@ -1,5 +1,7 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -31,10 +33,10 @@ public class Base58Test {
@Test
void base58Decode_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode(null));
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode(""));
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode("WIF"));
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckDecode("fh"));
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckDecode(null));
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckDecode(""));
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckDecode("WIF"));
assertThrows(ProcessFrostFSException.class, () -> Base58.base58CheckDecode("fh"));
}
@Test
@ -49,6 +51,6 @@ public class Base58Test {
@Test
void base58Encode_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> Base58.base58CheckEncode(null));
assertThrows(ValidationFrostFSException.class, () -> Base58.base58CheckEncode(null));
}
}

View file

@ -1,6 +1,7 @@
package info.frostfs.sdk;
import com.google.protobuf.Message;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -25,7 +26,7 @@ public class HelperTest {
@Test
void getRipemd160_givenParamIsNull() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> Helper.getRipemd160(null));
assertThrows(ValidationFrostFSException.class, () -> Helper.getRipemd160(null));
}
@Test
@ -69,8 +70,8 @@ public class HelperTest {
@Test
void getSha256_bytes_givenParamIsNull() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> Helper.getSha256((byte[]) null));
assertThrows(IllegalArgumentException.class, () -> Helper.getSha256((Message) null));
assertThrows(ValidationFrostFSException.class, () -> Helper.getSha256((byte[]) null));
assertThrows(ValidationFrostFSException.class, () -> Helper.getSha256((Message) null));
}
@Test
@ -104,7 +105,7 @@ public class HelperTest {
@Test
void getHexString_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> Helper.getHexString(null));
assertThrows(IllegalArgumentException.class, () -> Helper.getHexString(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(null));
assertThrows(ValidationFrostFSException.class, () -> Helper.getHexString(new byte[]{}));
}
}

View file

@ -1,5 +1,6 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -35,8 +36,8 @@ public class KeyExtensionTest {
@Test
void getPrivateKeyFromWIF_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPrivateKeyFromWIF(""));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPrivateKeyFromWIF(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPrivateKeyFromWIF(""));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPrivateKeyFromWIF(null));
}
@Test
@ -51,8 +52,8 @@ public class KeyExtensionTest {
@Test
void loadPublicKey_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPublicKey(null));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPublicKey(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPublicKey(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPublicKey(new byte[]{}));
}
@Test
@ -69,8 +70,8 @@ public class KeyExtensionTest {
@Test
void loadPrivateKey_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPrivateKey(null));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.loadPrivateKey(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPrivateKey(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.loadPrivateKey(new byte[]{}));
}
@Test
@ -87,9 +88,9 @@ public class KeyExtensionTest {
@Test
void getPublicKeyFromBytes_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPublicKeyFromBytes(null));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPublicKeyFromBytes(new byte[]{}));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getPublicKeyFromBytes(PRIVATE_KEY));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getPublicKeyFromBytes(PRIVATE_KEY));
}
@Test
@ -109,9 +110,9 @@ public class KeyExtensionTest {
@Test
void getScriptHash_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getScriptHash(null));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getScriptHash(new byte[]{}));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.getScriptHash(PRIVATE_KEY));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getScriptHash(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getScriptHash(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.getScriptHash(PRIVATE_KEY));
}
@Test
@ -126,9 +127,9 @@ public class KeyExtensionTest {
@Test
void publicKeyToAddress_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.publicKeyToAddress(null));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.publicKeyToAddress(new byte[]{}));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.publicKeyToAddress(PRIVATE_KEY));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.publicKeyToAddress(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.publicKeyToAddress(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.publicKeyToAddress(PRIVATE_KEY));
}
@Test
@ -143,9 +144,9 @@ public class KeyExtensionTest {
@Test
void compress_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> KeyExtension.compress(null));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.compress(new byte[]{}));
assertThrows(IllegalArgumentException.class, () -> KeyExtension.compress(PUBLIC_KEY));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.compress(null));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.compress(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> KeyExtension.compress(PUBLIC_KEY));
}
}

20
exceptions/pom.xml Normal file
View 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>

View file

@ -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() {
}
}

View file

@ -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);
}
}

View file

@ -0,0 +1,6 @@
package info.frostfs.sdk.exceptions;
public class TimeoutFrostFSException extends RuntimeException {
public TimeoutFrostFSException() {
}
}

View file

@ -0,0 +1,7 @@
package info.frostfs.sdk.exceptions;
public class ValidationFrostFSException extends RuntimeException {
public ValidationFrostFSException(String message) {
super(message);
}
}

View file

@ -29,14 +29,9 @@
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
<groupId>info.frostfs.sdk</groupId>
<artifactId>exceptions</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>

View file

@ -1,21 +1,22 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import java.nio.ByteBuffer;
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;
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() {
}
public static UUID asUuid(byte[] bytes) {
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);
@ -26,7 +27,9 @@ public class UuidExtension {
public static byte[] asBytes(UUID 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);

View file

@ -9,6 +9,7 @@ public class AppConst {
public static final int MIB = KIB << BYTE_SHIFT;
public static final int OBJECT_CHUNK_SIZE = 3 * MIB;
public static final int SHA256_HASH_LENGTH = 32;
public static final int UUID_BYTE_ARRAY_LENGTH = 16;
private AppConst() {
}

View file

@ -1,7 +1,11 @@
package info.frostfs.sdk.dto;
import info.frostfs.sdk.Helper;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CheckSum {
// type is always Sha256
public byte[] hash;
@ -10,14 +14,6 @@ public class CheckSum {
this.hash = Helper.getSha256(content);
}
public byte[] getHash() {
return hash;
}
public void setHash(byte[] hash) {
this.hash = hash;
}
@Override
public String toString() {
return Helper.getHexString(hash);

View file

@ -3,9 +3,13 @@ package info.frostfs.sdk.dto.container;
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
import info.frostfs.sdk.dto.netmap.Version;
import info.frostfs.sdk.enums.BasicAcl;
import lombok.Getter;
import lombok.Setter;
import java.util.UUID;
@Getter
@Setter
public class Container {
private UUID nonce;
private BasicAcl basicAcl;
@ -17,36 +21,4 @@ public class Container {
this.basicAcl = basicAcl;
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;
}
}

View file

@ -2,16 +2,24 @@ package info.frostfs.sdk.dto.container;
import info.frostfs.sdk.Base58;
import info.frostfs.sdk.constants.AppConst;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import lombok.Getter;
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;
@Getter
public class ContainerId {
private final String value;
public ContainerId(String 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;
@ -19,16 +27,14 @@ public class ContainerId {
public ContainerId(byte[] hash) {
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);
}
public String getValue() {
return value;
}
@Override
public String toString() {
return value;

View file

@ -1,22 +1,13 @@
package info.frostfs.sdk.dto.netmap;
import java.util.Collections;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.List;
@Getter
@AllArgsConstructor
public class NetmapSnapshot {
private final Long epoch;
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;
}
}

View file

@ -1,11 +1,13 @@
package info.frostfs.sdk.dto.netmap;
import info.frostfs.sdk.enums.NodeState;
import lombok.Getter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Getter
public class NodeInfo {
private final NodeState state;
private final Version version;
@ -21,24 +23,4 @@ public class NodeInfo {
this.attributes = Collections.unmodifiableMap(attributes);
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;
}
}

View file

@ -1,19 +1,11 @@
package info.frostfs.sdk.dto.netmap;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class PlacementPolicy {
private final Replica[] replicas;
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;
}
}

View file

@ -1,16 +1,24 @@
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 static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_GREATER_ZERO;
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
@Getter
@FieldNameConstants
public class Replica {
private final int count;
private final String selector;
public Replica(int count, String selector) {
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;
@ -19,18 +27,13 @@ public class Replica {
public Replica(int count) {
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.selector = EMPTY_STRING;
}
public int getCount() {
return count;
}
public String getSelector() {
return selector;
}
}

View file

@ -1,31 +1,23 @@
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_MINOR_VERSION;
import static java.util.Objects.isNull;
@Getter
@AllArgsConstructor
public class Version {
private final int major;
private final int minor;
public Version(int major, int minor) {
this.major = major;
this.minor = minor;
}
public Version() {
this.major = DEFAULT_MAJOR_VERSION;
this.minor = DEFAULT_MINOR_VERSION;
}
public int getMajor() {
return major;
}
public int getMinor() {
return minor;
}
@Override
public String toString() {
return "v" + major + "." + minor;

View file

@ -1,25 +1,22 @@
package info.frostfs.sdk.dto.object;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import static info.frostfs.sdk.constants.ErrorConst.SOME_PARAM_IS_MISSING;
@Getter
public class ObjectAttribute {
private final String key;
private final String value;
public ObjectAttribute(String key, String 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.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
}

View file

@ -6,43 +6,18 @@ import info.frostfs.sdk.dto.CheckSum;
import info.frostfs.sdk.dto.container.ContainerId;
import info.frostfs.sdk.dto.netmap.Version;
import info.frostfs.sdk.enums.ObjectMatchType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
public abstract class ObjectFilter<T> {
private ObjectMatchType matchType;
private String key;
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() {
return value.toString();
}

View file

@ -2,11 +2,17 @@ package info.frostfs.sdk.dto.object;
import info.frostfs.sdk.dto.container.ContainerId;
import info.frostfs.sdk.enums.ObjectType;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
import static java.util.Objects.isNull;
@Getter
@Setter
public class ObjectFrostFS {
private final ObjectHeader header;
private ObjectId objectId;
@ -15,7 +21,9 @@ public class ObjectFrostFS {
public ObjectFrostFS(ObjectHeader header, ObjectId objectId, byte[] payload) {
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;
@ -33,34 +41,6 @@ public class ObjectFrostFS {
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) {
header.setSplit(split);
}
@ -79,7 +59,9 @@ public class ObjectFrostFS {
public void setParent(LargeObject largeObject) {
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());

View file

@ -3,13 +3,20 @@ package info.frostfs.sdk.dto.object;
import info.frostfs.sdk.dto.container.ContainerId;
import info.frostfs.sdk.dto.netmap.Version;
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.List;
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;
@Getter
@Setter
public class ObjectHeader {
private final ContainerId containerId;
private final ObjectType objectType;
@ -23,7 +30,12 @@ public class ObjectHeader {
public ObjectHeader(ContainerId containerId, ObjectType objectType,
List<ObjectAttribute> attributes, long payloadLength, Version version) {
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;
@ -47,67 +59,17 @@ public class ObjectHeader {
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) {
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) {
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;
}
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;
}
}

View file

@ -2,16 +2,23 @@ package info.frostfs.sdk.dto.object;
import info.frostfs.sdk.Base58;
import info.frostfs.sdk.constants.AppConst;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import lombok.Getter;
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;
@Getter
public class ObjectId {
private final String value;
public ObjectId(String 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;
@ -19,16 +26,14 @@ public class ObjectId {
public ObjectId(byte[] hash) {
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);
}
public String getValue() {
return value;
}
@Override
public String toString() {
return value;

View file

@ -1,29 +1,37 @@
package info.frostfs.sdk.dto.object;
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.constants.ErrorConst.INPUT_PARAM_IS_MISSING;
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
import static java.util.Objects.isNull;
@Getter
public class OwnerId {
private final 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;
}
public OwnerId(byte[] publicKey) {
if (isNull(publicKey) || publicKey.length == 0) {
throw new IllegalArgumentException("PublicKey is invalid");
throw new ValidationFrostFSException(INPUT_PARAM_IS_MISSING);
}
this.value = publicKeyToAddress(publicKey);
}
public String getValue() {
return value;
}
public byte[] toHash() {
return Base58.decode(value);
}

View file

@ -2,12 +2,18 @@ package info.frostfs.sdk.dto.object;
import frostfs.refs.Types;
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.List;
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
import static java.util.Objects.isNull;
@Getter
@Setter
public class Split {
private final List<ObjectId> children;
private final SplitId splitId;
@ -23,58 +29,12 @@ public class Split {
public Split(SplitId 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.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;
}
}

View file

@ -1,11 +1,14 @@
package info.frostfs.sdk.dto.object;
import lombok.Getter;
import java.util.UUID;
import static info.frostfs.sdk.UuidExtension.asBytes;
import static info.frostfs.sdk.UuidExtension.asUuid;
import static java.util.Objects.isNull;
@Getter
public class SplitId {
private final UUID id;

View file

@ -1,24 +1,26 @@
package info.frostfs.sdk.dto.response;
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_MINOR_VERSION;
import static info.frostfs.sdk.constants.ErrorConst.*;
import static java.util.Objects.isNull;
@Getter
@FieldNameConstants
public class MetaHeader {
private Version version;
private int epoch;
private int ttl;
public MetaHeader(Version version, int epoch, int ttl) {
if (isNull(version) || epoch < 0 || ttl <= 0) {
throw new IllegalArgumentException("One of the input attributes is invalid or missing");
}
this.version = version;
this.epoch = epoch;
this.ttl = ttl;
setVersion(version);
setEpoch(epoch);
setTtl(ttl);
}
public MetaHeader() {
@ -27,37 +29,31 @@ public class MetaHeader {
this.ttl = 2;
}
public Version getVersion() {
return version;
}
public void setVersion(Version 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;
}
public int getEpoch() {
return epoch;
}
public void setEpoch(int epoch) {
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;
}
public int getTtl() {
return ttl;
}
public void setTtl(int ttl) {
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;

View file

@ -1,10 +1,14 @@
package info.frostfs.sdk.dto.response;
import info.frostfs.sdk.enums.StatusCode;
import lombok.Getter;
import lombok.Setter;
import static info.frostfs.sdk.constants.FieldConst.EMPTY_STRING;
import static java.util.Objects.isNull;
@Getter
@Setter
public class ResponseStatus {
private StatusCode code;
private String message;
@ -19,22 +23,6 @@ public class ResponseStatus {
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
public String toString() {
return String.format("Response status: %s. Message: %s.", code, message);

View file

@ -1,33 +1,13 @@
package info.frostfs.sdk.dto.response;
import info.frostfs.sdk.enums.SignatureScheme;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Signature {
private byte[] key;
private byte[] sign;
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;
}
}

View file

@ -1,13 +1,10 @@
package info.frostfs.sdk.dto.session;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class SessionToken {
private final byte[] token;
public SessionToken(byte[] token) {
this.token = token;
}
public byte[] getToken() {
return token;
}
}

View file

@ -4,16 +4,16 @@ import com.google.protobuf.ByteString;
import frostfs.container.Types;
import info.frostfs.sdk.dto.container.Container;
import info.frostfs.sdk.enums.BasicAcl;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.mappers.netmap.PlacementPolicyMapper;
import info.frostfs.sdk.mappers.netmap.VersionMapper;
import static info.frostfs.sdk.UuidExtension.asBytes;
import static info.frostfs.sdk.UuidExtension.asUuid;
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
import static java.util.Objects.isNull;
public class ContainerMapper {
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown BasicACL rule. Value: %s.";
private ContainerMapper() {
}
@ -36,8 +36,8 @@ public class ContainerMapper {
var basicAcl = BasicAcl.get(containerGrpc.getBasicAcl());
if (isNull(basicAcl)) {
throw new IllegalArgumentException(
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, containerGrpc.getBasicAcl())
throw new ProcessFrostFSException(
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, BasicAcl.class.getName(), containerGrpc.getBasicAcl())
);
}

View file

@ -5,14 +5,14 @@ import frostfs.netmap.Types;
import frostfs.netmap.Types.NodeInfo.Attribute;
import info.frostfs.sdk.dto.netmap.NodeInfo;
import info.frostfs.sdk.enums.NodeState;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import java.util.stream.Collectors;
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
import static java.util.Objects.isNull;
public class NodeInfoMapper {
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown NodeState. Value: %s.";
private NodeInfoMapper() {
}
@ -31,7 +31,9 @@ public class NodeInfoMapper {
NodeState nodeState = NodeState.get(nodeInfo.getState().getNumber());
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(

View file

@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.netmap.Replica;
import static java.util.Objects.isNull;
public class PlacementPolicyMapper {
private PlacementPolicyMapper() {
}
@ -32,8 +31,8 @@ public class PlacementPolicyMapper {
}
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()
);
}
}

View file

@ -3,12 +3,12 @@ package info.frostfs.sdk.mappers.object;
import frostfs.object.Service;
import frostfs.object.Types;
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;
public class ObjectFilterMapper {
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown MatchType. Value: %s.";
private ObjectFilterMapper() {
}
@ -19,9 +19,11 @@ public class ObjectFilterMapper {
var objectMatchType = Types.MatchType.forNumber(filter.getMatchType().value);
if (isNull(objectMatchType)) {
throw new IllegalArgumentException(
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, filter.getMatchType().name())
);
throw new ProcessFrostFSException(String.format(
UNKNOWN_ENUM_VALUE_TEMPLATE,
Types.MatchType.class.getName(),
filter.getMatchType().name()
));
}
return Service.SearchRequest.Body.Filter.newBuilder()

View file

@ -6,32 +6,37 @@ import info.frostfs.sdk.dto.container.ContainerId;
import info.frostfs.sdk.dto.object.ObjectAttribute;
import info.frostfs.sdk.dto.object.ObjectHeader;
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.netmap.VersionMapper;
import org.apache.commons.collections4.ListUtils;
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.nonNull;
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() {
}
public static Types.Header toGrpcMessage(ObjectHeader 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);
if (isNull(objectType)) {
throw new IllegalArgumentException(
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, header.getObjectType().name())
);
throw new ProcessFrostFSException(String.format(
UNKNOWN_ENUM_VALUE_TEMPLATE,
Types.ObjectType.class.getName(),
header.getObjectType().name()
));
}
var head = Types.Header.newBuilder()
@ -62,8 +67,8 @@ public class ObjectHeaderMapper {
var objectType = ObjectType.get(header.getObjectTypeValue());
if (isNull(objectType)) {
throw new IllegalArgumentException(
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, header.getObjectType())
throw new ProcessFrostFSException(
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, ObjectType.class.getName(), header.getObjectType())
);
}

View file

@ -2,19 +2,21 @@ package info.frostfs.sdk.mappers.response;
import frostfs.session.Types;
import info.frostfs.sdk.dto.response.MetaHeader;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
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;
public class MetaHeaderMapper {
private static final String ERROR_META_HEADER_MISSING_ERROR = "MetaHeader is not present";
private MetaHeaderMapper() {
}
public static Types.RequestMetaHeader toGrpcMessage(MetaHeader 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();
@ -22,7 +24,9 @@ public class MetaHeaderMapper {
public static Types.RequestMetaHeader.Builder toGrpcMessageBuilder(MetaHeader 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()

View file

@ -3,12 +3,12 @@ package info.frostfs.sdk.mappers.response;
import frostfs.status.Types;
import info.frostfs.sdk.dto.response.ResponseStatus;
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;
public class ResponseStatusMapper {
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown StatusCode. Value: %s.";
private ResponseStatusMapper() {
}
@ -19,8 +19,8 @@ public class ResponseStatusMapper {
var statusCode = StatusCode.get(status.getCode());
if (isNull(statusCode)) {
throw new IllegalArgumentException(
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, status.getCode())
throw new ProcessFrostFSException(
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, StatusCode.class.getName(), status.getCode())
);
}

View file

@ -3,12 +3,12 @@ package info.frostfs.sdk.mappers.response;
import com.google.protobuf.ByteString;
import frostfs.refs.Types;
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;
public class SignatureMapper {
private static final String ERROR_UNKNOWN_VALUE_TEMPLATE = "Unknown SignatureScheme. Value: %s.";
private SignatureMapper() {
}
@ -19,9 +19,11 @@ public class SignatureMapper {
var scheme = Types.SignatureScheme.forNumber(signature.getScheme().value);
if (isNull(scheme)) {
throw new IllegalArgumentException(
String.format(ERROR_UNKNOWN_VALUE_TEMPLATE, signature.getScheme().name())
);
throw new ProcessFrostFSException(String.format(
UNKNOWN_ENUM_VALUE_TEMPLATE,
Types.SignatureScheme.class.getName(),
signature.getScheme().name()
));
}
return Types.Signature.newBuilder()

View file

@ -3,20 +3,23 @@ package info.frostfs.sdk.mappers.session;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.InvalidProtocolBufferException;
import frostfs.session.Types;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import java.io.IOException;
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
import static java.util.Objects.isNull;
public class SessionMapper {
private static final String ERROR_TOKEN_MISSING_MESSAGE = "Token is not present";
private SessionMapper() {
}
public static byte[] serialize(Types.SessionToken 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 {
@ -25,19 +28,21 @@ public class SessionMapper {
token.writeTo(stream);
return bytes;
} catch (IOException exp) {
throw new IllegalArgumentException(exp.getMessage());
throw new ProcessFrostFSException(exp.getMessage());
}
}
public static Types.SessionToken deserializeSessionToken(byte[] bytes) {
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 {
return Types.SessionToken.newBuilder().mergeFrom(bytes).build();
} catch (InvalidProtocolBufferException exp) {
throw new IllegalArgumentException(exp.getMessage());
throw new ProcessFrostFSException(exp.getMessage());
}
}
}

View file

@ -1,5 +1,6 @@
package info.frostfs.sdk;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import java.util.UUID;
@ -25,7 +26,7 @@ public class UuidExtensionTest {
@Test
void uuidAsBytes_givenParamsIsNull() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asBytes(null));
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asBytes(null));
}
@Test
@ -40,7 +41,7 @@ public class UuidExtensionTest {
@Test
void bytesAsUuid_givenParamsIsNull() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(null));
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(null));
}
@Test
@ -51,7 +52,7 @@ public class UuidExtensionTest {
//When + Then
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(valueLength15));
assertThrows(IllegalArgumentException.class, () -> UuidExtension.asUuid(valueLength17));
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength15));
assertThrows(ValidationFrostFSException.class, () -> UuidExtension.asUuid(valueLength17));
}
}

View file

@ -6,6 +6,7 @@ import info.frostfs.sdk.dto.container.Container;
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
import info.frostfs.sdk.dto.netmap.Replica;
import info.frostfs.sdk.enums.BasicAcl;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -21,7 +22,7 @@ public class ContainerMapperTest {
@Test
void toGrpcMessage_success() {
//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);
//When
@ -111,6 +112,6 @@ public class ContainerMapperTest {
.build();
//When + Then
assertThrows(IllegalArgumentException.class, () -> ContainerMapper.toModel(container));
assertThrows(ProcessFrostFSException.class, () -> ContainerMapper.toModel(container));
}
}

View file

@ -4,6 +4,7 @@ import com.google.protobuf.ByteString;
import frostfs.netmap.Service;
import frostfs.netmap.Types;
import info.frostfs.sdk.enums.NodeState;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -117,7 +118,7 @@ public class NodeInfoMapperTest {
mockStatic.when(() -> NodeState.get(Types.NodeInfo.State.ONLINE.getNumber()))
.thenReturn(null);
assertThrows(IllegalArgumentException.class, () -> NodeInfoMapper.toModel(body));
assertThrows(ProcessFrostFSException.class, () -> NodeInfoMapper.toModel(body));
}
}
}

View file

@ -15,7 +15,7 @@ public class PlacementPolicyMapperTest {
var replica1 = new Replica(1, "test1");
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
var result = PlacementPolicyMapper.toGrpcMessage(placementPolicy);

View file

@ -3,6 +3,7 @@ package info.frostfs.sdk.mappers.object;
import frostfs.object.Types;
import info.frostfs.sdk.dto.object.ObjectFilter;
import info.frostfs.sdk.enums.ObjectMatchType;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -47,7 +48,7 @@ public class ObjectFilterMapperTest {
mockStatic.when(() -> Types.MatchType.forNumber(objectFilter.getMatchType().value))
.thenReturn(null);
assertThrows(IllegalArgumentException.class, () -> ObjectFilterMapper.toGrpcMessage(objectFilter));
assertThrows(ProcessFrostFSException.class, () -> ObjectFilterMapper.toGrpcMessage(objectFilter));
}
}
}

View file

@ -8,7 +8,8 @@ import info.frostfs.sdk.dto.object.ObjectAttribute;
import info.frostfs.sdk.dto.object.ObjectHeader;
import info.frostfs.sdk.dto.object.OwnerId;
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.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -56,7 +57,7 @@ public class ObjectHeaderMapperTest {
@Test
void toGrpcMessage_null() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> ObjectHeaderMapper.toGrpcMessage(null));
assertThrows(ValidationFrostFSException.class, () -> ObjectHeaderMapper.toGrpcMessage(null));
}
@Test
@ -70,7 +71,7 @@ public class ObjectHeaderMapperTest {
mockStatic.when(() -> Types.ObjectType.forNumber(objectHeader.getObjectType().value))
.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()))
.thenReturn(null);
assertThrows(IllegalArgumentException.class, () -> ObjectHeaderMapper.toModel(header));
assertThrows(ProcessFrostFSException.class, () -> ObjectHeaderMapper.toModel(header));
}
}
}

View file

@ -3,6 +3,7 @@ package info.frostfs.sdk.mappers.response;
import frostfs.session.Types;
import info.frostfs.sdk.dto.netmap.Version;
import info.frostfs.sdk.dto.response.MetaHeader;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
@ -29,7 +30,7 @@ public class MetaHeaderMapperTest {
@Test
void toGrpcMessage_null() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> MetaHeaderMapper.toGrpcMessage(null));
assertThrows(ValidationFrostFSException.class, () -> MetaHeaderMapper.toGrpcMessage(null));
}
@Test
@ -52,6 +53,6 @@ public class MetaHeaderMapperTest {
@Test
void toGrpcMessageBuilder_null() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> MetaHeaderMapper.toGrpcMessageBuilder(null));
assertThrows(ValidationFrostFSException.class, () -> MetaHeaderMapper.toGrpcMessageBuilder(null));
}
}

View file

@ -2,6 +2,7 @@ package info.frostfs.sdk.mappers.response;
import frostfs.status.Types;
import info.frostfs.sdk.enums.StatusCode;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -48,6 +49,6 @@ public class ResponseStatusMapperTest {
.build();
//When + Then
assertThrows(IllegalArgumentException.class, () -> ResponseStatusMapper.toModel(status));
assertThrows(ProcessFrostFSException.class, () -> ResponseStatusMapper.toModel(status));
}
}

View file

@ -3,6 +3,7 @@ package info.frostfs.sdk.mappers.response;
import frostfs.refs.Types;
import info.frostfs.sdk.dto.response.Signature;
import info.frostfs.sdk.enums.SignatureScheme;
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -50,7 +51,7 @@ public class SignatureMapperTest {
mockStatic.when(() -> Types.SignatureScheme.forNumber(signature.getScheme().value))
.thenReturn(null);
assertThrows(IllegalArgumentException.class, () -> SignatureMapper.toGrpcMessage(signature));
assertThrows(ProcessFrostFSException.class, () -> SignatureMapper.toGrpcMessage(signature));
}
}
}

View file

@ -2,6 +2,7 @@ package info.frostfs.sdk.mappers.session;
import com.google.protobuf.ByteString;
import frostfs.session.Types;
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -27,7 +28,7 @@ public class SessionMapperTest {
@Test
void serialize_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> SessionMapper.serialize(null));
assertThrows(ValidationFrostFSException.class, () -> SessionMapper.serialize(null));
}
@Test
@ -43,8 +44,8 @@ public class SessionMapperTest {
@Test
void deserialize_wrong() {
//When + Then
assertThrows(IllegalArgumentException.class, () -> SessionMapper.deserializeSessionToken(null));
assertThrows(IllegalArgumentException.class, () -> SessionMapper.deserializeSessionToken(new byte[]{}));
assertThrows(ValidationFrostFSException.class, () -> SessionMapper.deserializeSessionToken(null));
assertThrows(ValidationFrostFSException.class, () -> SessionMapper.deserializeSessionToken(new byte[]{}));
}
private Types.SessionToken createSessionToken() {

20
pom.xml
View file

@ -13,6 +13,7 @@
<module>cryptography</module>
<module>models</module>
<module>protos</module>
<module>exceptions</module>
</modules>
<properties>
@ -23,9 +24,28 @@
<mockito.version>5.12.0</mockito.version>
<junit.version>5.10.3</junit.version>
<assertj.version>3.26.3</assertj.version>
<lombok.version>1.18.34</lombok.version>
<protobuf.version>3.23.0</protobuf.version>
</properties>
<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>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>

View file

@ -14,7 +14,6 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<protobuf.version>3.23.0</protobuf.version>
<grpc.version>1.65.1</grpc.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>