forked from TrueCloudLab/frostfs-sdk-java
Compare commits
3 commits
master
...
feature/36
Author | SHA1 | Date | |
---|---|---|---|
|
fe7d2968b8 | ||
|
3861eb0dc2 | ||
|
532db56f1b |
62 changed files with 1436 additions and 219 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@ target/
|
|||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
**/.flattened-pom.xml
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
|
|
21
CHANGELOG.md
Normal file
21
CHANGELOG.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Changelog
|
||||
|
||||
## [0.7.0] - 2025-02-20
|
||||
|
||||
### Added
|
||||
- Expanding the parameters for creating a container
|
||||
|
||||
### Fixed
|
||||
- Creating a session for working with objects
|
||||
|
||||
## [0.6.0] - 2025-02-13
|
||||
|
||||
### Added
|
||||
- APE rules serializer
|
||||
|
||||
## [0.5.0] - 2025-02-11
|
||||
|
||||
### Fixed
|
||||
- Loading large objects in chunks
|
||||
- .gitignore
|
||||
- pom revision
|
|
@ -41,8 +41,8 @@ public class ContainerExample {
|
|||
FrostFSClient frostFSClient = new FrostFSClient(clientSettings);
|
||||
|
||||
// Create container
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
||||
var prmContainerCreate = new PrmContainerCreate(new Container(BasicAcl.PUBLIC_RW, placementPolicy));
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true, 0);
|
||||
var prmContainerCreate = new PrmContainerCreate(new Container(placementPolicy));
|
||||
var containerId = frostFSClient.createContainer(prmContainerCreate, callContext);
|
||||
|
||||
// Get container
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package info.frostfs.sdk;
|
||||
|
||||
import frostfs.accounting.Types;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||
|
@ -194,7 +193,7 @@ public class FrostFSClient implements CommonClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
public List<frostfs.ape.Types.Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
return apeManagerClient.listChains(args, ctx);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package info.frostfs.sdk.constants;
|
||||
|
||||
public class RuleConst {
|
||||
public static final byte VERSION = 0;
|
||||
|
||||
public static final int BYTE_SIZE = 1;
|
||||
public static final int U_INT_8_SIZE = BYTE_SIZE;
|
||||
public static final int BOOL_SIZE = BYTE_SIZE;
|
||||
|
||||
public static final long NULL_SLICE = -1L;
|
||||
public static final int NULL_SLICE_SIZE = 1;
|
||||
|
||||
public static final byte BYTE_TRUE = 1;
|
||||
public static final byte BYTE_FALSE = 0;
|
||||
|
||||
// maxSliceLen taken from
|
||||
// https://github.com/neo-project/neo/blob/38218bbee5bbe8b33cd8f9453465a19381c9a547/src/Neo/IO/Helper.cs#L77
|
||||
public static final int MAX_SLICE_LENGTH = 0x1000000;
|
||||
|
||||
public static final int CHAIN_MARSHAL_VERSION = 0;
|
||||
|
||||
public static final long OFFSET128 = 0x80;
|
||||
public static final long UNSIGNED_SERIALIZE_SIZE = 7;
|
||||
|
||||
private RuleConst() {
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package info.frostfs.sdk.jdo.parameters.ape;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.ape.Chain;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package info.frostfs.sdk.jdo.parameters.ape;
|
||||
|
||||
import info.frostfs.sdk.annotations.NotNull;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
|
@ -14,14 +13,15 @@ import java.util.Map;
|
|||
@AllArgsConstructor
|
||||
public class PrmApeChainRemove {
|
||||
@NotNull
|
||||
private Chain chain;
|
||||
private byte[] chainId;
|
||||
|
||||
@NotNull
|
||||
private ChainTarget chainTarget;
|
||||
|
||||
private Map<String, String> xHeaders;
|
||||
|
||||
public PrmApeChainRemove(Chain chain, ChainTarget chainTarget) {
|
||||
this.chain = chain;
|
||||
public PrmApeChainRemove(byte[] chainId, ChainTarget chainTarget) {
|
||||
this.chainId = chainId;
|
||||
this.chainTarget = chainTarget;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package info.frostfs.sdk.pool;
|
||||
|
||||
import frostfs.refs.Types;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.netmap.NetmapSnapshot;
|
||||
|
@ -515,7 +514,7 @@ public class Pool implements CommonClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
public List<frostfs.ape.Types.Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
ClientWrapper client = connection();
|
||||
return client.getClient().listChains(args, ctx);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package info.frostfs.sdk.services;
|
||||
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import frostfs.ape.Types;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
|
@ -13,5 +13,5 @@ public interface ApeManagerClient {
|
|||
|
||||
void removeChain(PrmApeChainRemove args, CallContext ctx);
|
||||
|
||||
List<Chain> listChains(PrmApeChainList args, CallContext ctx);
|
||||
List<Types.Chain> listChains(PrmApeChainList args, CallContext ctx);
|
||||
}
|
||||
|
|
|
@ -4,18 +4,17 @@ import com.google.protobuf.ByteString;
|
|||
import frostfs.ape.Types;
|
||||
import frostfs.apemanager.APEManagerServiceGrpc;
|
||||
import frostfs.apemanager.Service;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainList;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainRemove;
|
||||
import info.frostfs.sdk.mappers.chain.ChainMapper;
|
||||
import info.frostfs.sdk.mappers.chain.ChainTargetMapper;
|
||||
import info.frostfs.sdk.services.ApeManagerClient;
|
||||
import info.frostfs.sdk.services.ContextAccessor;
|
||||
import info.frostfs.sdk.tools.RequestConstructor;
|
||||
import info.frostfs.sdk.tools.RequestSigner;
|
||||
import info.frostfs.sdk.tools.RuleSerializer;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -58,7 +57,7 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
public List<Types.Chain> listChains(PrmApeChainList args, CallContext ctx) {
|
||||
validate(args);
|
||||
|
||||
var request = createListChainsRequest(args);
|
||||
|
@ -68,12 +67,14 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
|||
|
||||
Verifier.checkResponse(response);
|
||||
|
||||
return ChainMapper.toModels(response.getBody().getChainsList());
|
||||
return response.getBody().getChainsList();
|
||||
}
|
||||
|
||||
private Service.AddChainRequest createAddChainRequest(PrmApeChainAdd args) {
|
||||
var raw = RuleSerializer.serialize(args.getChain());
|
||||
|
||||
var chainGrpc = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(args.getChain().getRaw()))
|
||||
.setRaw(ByteString.copyFrom(raw))
|
||||
.build();
|
||||
var body = Service.AddChainRequest.Body.newBuilder()
|
||||
.setChain(chainGrpc)
|
||||
|
@ -90,7 +91,7 @@ public class ApeManagerClientImpl extends ContextAccessor implements ApeManagerC
|
|||
|
||||
private Service.RemoveChainRequest createRemoveChainRequest(PrmApeChainRemove args) {
|
||||
var body = Service.RemoveChainRequest.Body.newBuilder()
|
||||
.setChainId(ByteString.copyFrom(args.getChain().getRaw()))
|
||||
.setChainId(ByteString.copyFrom(args.getChainId()))
|
||||
.setTarget(ChainTargetMapper.toGrpcMessage(args.getChainTarget()))
|
||||
.build();
|
||||
var request = Service.RemoveChainRequest.newBuilder()
|
||||
|
|
|
@ -186,11 +186,15 @@ public class ContainerClientImpl extends ContextAccessor implements ContainerCli
|
|||
|
||||
private Service.PutRequest createPutRequest(PrmContainerCreate args, CallContext ctx) {
|
||||
syncContainerWithNetwork(args.getContainer(), ctx);
|
||||
var container = ContainerMapper.toGrpcMessage(args.getContainer()).toBuilder()
|
||||
.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()))
|
||||
.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()))
|
||||
.build();
|
||||
var builder = ContainerMapper.toGrpcMessage(args.getContainer());
|
||||
if (!builder.hasOwnerId()) {
|
||||
builder.setOwnerId(OwnerIdMapper.toGrpcMessage(getContext().getOwnerId()));
|
||||
}
|
||||
if (!builder.hasVersion()) {
|
||||
builder.setVersion(VersionMapper.toGrpcMessage(getContext().getVersion()));
|
||||
}
|
||||
|
||||
var container = builder.build();
|
||||
var body = Service.PutRequest.Body.newBuilder()
|
||||
.setContainer(container)
|
||||
.setSignature(RequestSigner.signRFC6979(getContext().getKey(), container))
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.io.InputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static info.frostfs.sdk.Helper.getSha256;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.PROTO_MESSAGE_IS_EMPTY_TEMPLATE;
|
||||
import static info.frostfs.sdk.tools.RequestSigner.sign;
|
||||
import static info.frostfs.sdk.utils.DeadLineUtil.deadLineAfter;
|
||||
|
@ -166,8 +165,10 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
|
||||
// send the last part and create linkObject
|
||||
if (CollectionUtils.isNotEmpty(sentObjectIds)) {
|
||||
var largeObjectHeader =
|
||||
new ObjectHeader(header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, null);
|
||||
var largeObjectHeader = new ObjectHeader(
|
||||
header.getContainerId(), ObjectType.REGULAR, attributes, fullLength, header.getVersion()
|
||||
);
|
||||
largeObjectHeader.setOwnerId(header.getOwnerId());
|
||||
|
||||
split.setParentHeader(largeObjectHeader);
|
||||
|
||||
|
@ -333,6 +334,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
.setBody(body)
|
||||
.clearVerifyHeader();
|
||||
|
||||
RequestConstructor.addMetaHeader(chunkRequest, args.getXHeaders());
|
||||
sign(chunkRequest, getContext().getKey());
|
||||
|
||||
stream.write(chunkRequest.build());
|
||||
|
@ -357,9 +359,7 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
grpcHeader = objectToolsImpl.updateSplitValues(grpcHeader, header.getSplit());
|
||||
}
|
||||
|
||||
var oid = Types.ObjectID.newBuilder().setValue(getSha256(grpcHeader)).build();
|
||||
|
||||
var initRequest = createInitPutRequest(oid, grpcHeader, args, ctx);
|
||||
var initRequest = createInitPutRequest(grpcHeader, args, ctx);
|
||||
|
||||
return putObjectInit(initRequest, ctx);
|
||||
}
|
||||
|
@ -525,13 +525,11 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
return request.build();
|
||||
}
|
||||
|
||||
private Service.PutRequest createInitPutRequest(Types.ObjectID oid,
|
||||
frostfs.object.Types.Header header,
|
||||
private Service.PutRequest createInitPutRequest(frostfs.object.Types.Header header,
|
||||
PrmObjectPutBase args,
|
||||
CallContext ctx) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(header.getContainerId())
|
||||
.setObjectId(oid)
|
||||
.build();
|
||||
var init = Service.PutRequest.Body.Init.newBuilder()
|
||||
.setHeader(header)
|
||||
|
@ -561,7 +559,6 @@ public class ObjectClientImpl extends ContextAccessor implements ObjectClient {
|
|||
CallContext ctx) {
|
||||
var address = Types.Address.newBuilder()
|
||||
.setContainerId(grpcObject.getHeader().getContainerId())
|
||||
.setObjectId(grpcObject.getObjectId())
|
||||
.build();
|
||||
var body = Service.PutSingleRequest.Body.newBuilder()
|
||||
.setObject(grpcObject)
|
||||
|
|
|
@ -105,7 +105,10 @@ public class ObjectToolsImpl extends ContextAccessor implements ToolsClient {
|
|||
split.setParent(ObjectIdMapper.toModel(parentObjectId));
|
||||
}
|
||||
|
||||
if (nonNull(split.getPrevious())) {
|
||||
grpcSplit.setPrevious(ObjectIdMapper.toGrpcMessage(split.getPrevious())).build();
|
||||
}
|
||||
|
||||
return grpcHeader.toBuilder().setSplit(grpcSplit.build()).build();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import frostfs.object.Service;
|
|||
import info.frostfs.sdk.dto.object.ObjectId;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectPutBase;
|
||||
import info.frostfs.sdk.tools.RequestConstructor;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
@ -27,6 +28,7 @@ public class ObjectWriter {
|
|||
.setBody(body)
|
||||
.clearVerifyHeader();
|
||||
|
||||
RequestConstructor.addMetaHeader(chunkRequest, args.getXHeaders());
|
||||
sign(chunkRequest, environment.getKey());
|
||||
|
||||
streamer.write(chunkRequest.build());
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package info.frostfs.sdk.tools;
|
||||
|
||||
public interface MarshalFunction<T> {
|
||||
int marshal(byte[] buf, int offset, T t);
|
||||
}
|
|
@ -86,7 +86,6 @@ public class RequestConstructor {
|
|||
.build();
|
||||
var body = protoToken.getBody().toBuilder()
|
||||
.setObject(ctx)
|
||||
.setSessionKey(ByteString.copyFrom(key.getPublicKeyByte()))
|
||||
.build();
|
||||
|
||||
return protoToken.toBuilder()
|
||||
|
|
256
client/src/main/java/info/frostfs/sdk/tools/RuleSerializer.java
Normal file
256
client/src/main/java/info/frostfs/sdk/tools/RuleSerializer.java
Normal file
|
@ -0,0 +1,256 @@
|
|||
package info.frostfs.sdk.tools;
|
||||
|
||||
import info.frostfs.sdk.dto.ape.*;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.*;
|
||||
import static info.frostfs.sdk.constants.RuleConst.*;
|
||||
import static java.util.Objects.isNull;
|
||||
import static java.util.Objects.nonNull;
|
||||
|
||||
public class RuleSerializer {
|
||||
private RuleSerializer() {
|
||||
}
|
||||
|
||||
public static byte[] serialize(Chain chain) {
|
||||
int s = U_INT_8_SIZE // Marshaller version
|
||||
+ U_INT_8_SIZE // Chain version
|
||||
+ sliceSize(chain.getId(), b -> BYTE_SIZE)
|
||||
+ sliceSize(chain.getRules(), RuleSerializer::ruleSize)
|
||||
+ U_INT_8_SIZE; // MatchType
|
||||
|
||||
byte[] buf = new byte[s];
|
||||
|
||||
int offset = uInt8Marshal(buf, 0, VERSION);
|
||||
offset = uInt8Marshal(buf, offset, (byte) CHAIN_MARSHAL_VERSION);
|
||||
offset = sliceMarshal(buf, offset, chain.getId(), RuleSerializer::byteMarshal);
|
||||
offset = sliceMarshal(buf, offset, chain.getRules(), RuleSerializer::marshalRule);
|
||||
offset = uInt8Marshal(buf, offset, (byte) chain.getMatchType().value);
|
||||
|
||||
verifyMarshal(buf, offset);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
private static <T> int sliceSize(T[] slice, Function<T, Integer> sizeOf) {
|
||||
if (isNull(slice)) {
|
||||
return NULL_SLICE_SIZE;
|
||||
}
|
||||
|
||||
// Assuming int64Size is the size of the slice
|
||||
int size = int64Size(slice.length);
|
||||
for (T v : slice) {
|
||||
size += sizeOf.apply(v);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/*
|
||||
* https://cs.opensource.google/go/go/+/master:src/encoding/binary/varint.go;l=92;drc=dac9b9ddbd5160c5f4552410f5f828
|
||||
* 1bd5eed38c
|
||||
*
|
||||
* and
|
||||
*
|
||||
* https://cs.opensource.google/go/go/+/master:src/encoding/binary/varint.go;l=41;drc=dac9b9ddbd5160c5f4552410f5f828
|
||||
* 1bd5eed38c
|
||||
* */
|
||||
private static int int64Size(long value) {
|
||||
long ux = value << 1;
|
||||
if (value < 0) {
|
||||
ux = ~ux;
|
||||
}
|
||||
|
||||
int size = 0;
|
||||
while (ux >= OFFSET128) {
|
||||
size++;
|
||||
ux >>>= UNSIGNED_SERIALIZE_SIZE;
|
||||
}
|
||||
|
||||
return size + 1;
|
||||
}
|
||||
|
||||
private static int stringSize(String s) {
|
||||
int len = nonNull(s) ? s.length() : 0;
|
||||
return int64Size(len) + len;
|
||||
}
|
||||
|
||||
private static int actionsSize(Actions action) {
|
||||
return BOOL_SIZE // Inverted
|
||||
+ (nonNull(action) ? sliceSize(action.getNames(), RuleSerializer::stringSize) : 0);
|
||||
}
|
||||
|
||||
private static int resourcesSize(Resources resource) {
|
||||
return BOOL_SIZE // Inverted
|
||||
+ (nonNull(resource) ? sliceSize(resource.getNames(), RuleSerializer::stringSize) : 0);
|
||||
}
|
||||
|
||||
private static int conditionSize(Condition condition) {
|
||||
if (isNull(condition)) {
|
||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName()));
|
||||
}
|
||||
|
||||
return BYTE_SIZE // Op
|
||||
+ BYTE_SIZE // Object
|
||||
+ stringSize(condition.getKey())
|
||||
+ stringSize(condition.getValue());
|
||||
}
|
||||
|
||||
private static int ruleSize(Rule rule) {
|
||||
if (isNull(rule)) {
|
||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName()));
|
||||
}
|
||||
|
||||
return BYTE_SIZE // Status
|
||||
+ actionsSize(rule.getActions())
|
||||
+ resourcesSize(rule.getResources())
|
||||
+ BOOL_SIZE // Any
|
||||
+ sliceSize(rule.getConditions(), RuleSerializer::conditionSize);
|
||||
}
|
||||
|
||||
private static int uInt8Marshal(byte[] buf, int offset, byte value) {
|
||||
if (buf.length - offset < 1) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, Byte.class.getName(), 1)
|
||||
);
|
||||
}
|
||||
|
||||
buf[offset] = value;
|
||||
|
||||
return offset + 1;
|
||||
}
|
||||
|
||||
private static int byteMarshal(byte[] buf, int offset, byte value) {
|
||||
return uInt8Marshal(buf, offset, value);
|
||||
}
|
||||
|
||||
// putVarInt encodes an int64 into buf and returns the number of bytes written.
|
||||
private static int putVarInt(byte[] buf, int offset, long x) {
|
||||
long ux = x << 1;
|
||||
if (x < 0) {
|
||||
ux = ~ux;
|
||||
}
|
||||
|
||||
return putUVarInt(buf, offset, ux);
|
||||
}
|
||||
|
||||
private static int putUVarInt(byte[] buf, int offset, long x) {
|
||||
while (x >= OFFSET128) {
|
||||
buf[offset] = (byte) (x | OFFSET128);
|
||||
x >>>= UNSIGNED_SERIALIZE_SIZE;
|
||||
offset++;
|
||||
}
|
||||
buf[offset] = (byte) x;
|
||||
return offset + 1;
|
||||
}
|
||||
|
||||
private static int int64Marshal(byte[] buf, int offset, long v) {
|
||||
var size = int64Size(v);
|
||||
if (buf.length - offset < size) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, Long.class.getName(), size)
|
||||
);
|
||||
}
|
||||
|
||||
return putVarInt(buf, offset, v);
|
||||
}
|
||||
|
||||
private static <T> int sliceMarshal(byte[] buf, int offset, T[] slice, MarshalFunction<T> marshalT) {
|
||||
if (isNull(slice)) {
|
||||
return int64Marshal(buf, offset, NULL_SLICE);
|
||||
}
|
||||
|
||||
if (slice.length > MAX_SLICE_LENGTH) {
|
||||
throw new ValidationFrostFSException(String.format(SLICE_IS_TOO_BIG_TEMPLATE, slice.length));
|
||||
}
|
||||
|
||||
offset = int64Marshal(buf, offset, slice.length);
|
||||
for (T v : slice) {
|
||||
offset = marshalT.marshal(buf, offset, v);
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
private static int boolMarshal(byte[] buf, int offset, boolean value) {
|
||||
return uInt8Marshal(buf, offset, value ? BYTE_TRUE : BYTE_FALSE);
|
||||
}
|
||||
|
||||
private static int stringMarshal(byte[] buf, int offset, String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
throw new ValidationFrostFSException(STRING_IS_BLANK);
|
||||
}
|
||||
|
||||
if (value.length() > MAX_SLICE_LENGTH) {
|
||||
throw new ValidationFrostFSException(String.format(STRING_IS_TOO_BIG_TEMPLATE, value.length()));
|
||||
}
|
||||
|
||||
if (buf.length - offset < int64Size(value.length()) + value.length()) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE, String.class.getName(), value.length())
|
||||
);
|
||||
}
|
||||
|
||||
offset = int64Marshal(buf, offset, value.length());
|
||||
if (value.isEmpty()) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
byte[] stringBytes = value.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
// Copy exactly value.length() bytes as in the original code
|
||||
System.arraycopy(stringBytes, 0, buf, offset, value.length());
|
||||
return offset + value.length();
|
||||
}
|
||||
|
||||
private static int marshalActions(byte[] buf, int offset, Actions action) {
|
||||
if (isNull(action)) {
|
||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Actions.class.getName()));
|
||||
}
|
||||
|
||||
offset = boolMarshal(buf, offset, action.isInverted());
|
||||
return sliceMarshal(buf, offset, action.getNames(), RuleSerializer::stringMarshal);
|
||||
}
|
||||
|
||||
private static int marshalCondition(byte[] buf, int offset, Condition condition) {
|
||||
if (isNull(condition)) {
|
||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Condition.class.getName()));
|
||||
}
|
||||
|
||||
offset = byteMarshal(buf, offset, (byte) condition.getOp().value);
|
||||
offset = byteMarshal(buf, offset, (byte) condition.getKind().value);
|
||||
offset = stringMarshal(buf, offset, condition.getKey());
|
||||
return stringMarshal(buf, offset, condition.getValue());
|
||||
}
|
||||
|
||||
private static int marshalRule(byte[] buf, int offset, Rule rule) {
|
||||
if (isNull(rule)) {
|
||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Rule.class.getName()));
|
||||
}
|
||||
|
||||
offset = byteMarshal(buf, offset, (byte) rule.getStatus().value);
|
||||
offset = marshalActions(buf, offset, rule.getActions());
|
||||
offset = marshalResources(buf, offset, rule.getResources());
|
||||
offset = boolMarshal(buf, offset, rule.isAny());
|
||||
return sliceMarshal(buf, offset, rule.getConditions(), RuleSerializer::marshalCondition);
|
||||
}
|
||||
|
||||
private static int marshalResources(byte[] buf, int offset, Resources resources) {
|
||||
if (isNull(resources)) {
|
||||
throw new ValidationFrostFSException(String.format(REQUIRED_FIELD_TEMPLATE, Resources.class.getName()));
|
||||
}
|
||||
|
||||
offset = boolMarshal(buf, offset, resources.isInverted());
|
||||
return sliceMarshal(buf, offset, resources.getNames(), RuleSerializer::stringMarshal);
|
||||
}
|
||||
|
||||
private static void verifyMarshal(byte[] buf, int lastOffset) {
|
||||
if (buf.length != lastOffset) {
|
||||
throw new ValidationFrostFSException(MARSHAL_SIZE_DIFFERS);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -78,6 +78,10 @@ public class Verifier {
|
|||
}
|
||||
|
||||
var metaHeader = (Types.ResponseMetaHeader) MessageHelper.getField(response, META_HEADER_FIELD_NAME);
|
||||
if (isNull(metaHeader) || metaHeader.getSerializedSize() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var status = ResponseStatusMapper.toModel(metaHeader.getStatus());
|
||||
if (!status.isSuccess()) {
|
||||
throw new ResponseFrostFSException(status);
|
||||
|
|
|
@ -2,10 +2,9 @@ package info.frostfs.sdk.services;
|
|||
|
||||
import frostfs.apemanager.APEManagerServiceGrpc;
|
||||
import frostfs.apemanager.Service;
|
||||
import info.frostfs.sdk.FileUtils;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import info.frostfs.sdk.dto.ape.*;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import info.frostfs.sdk.enums.TargetType;
|
||||
import info.frostfs.sdk.enums.*;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import info.frostfs.sdk.jdo.ClientEnvironment;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
|
@ -18,6 +17,7 @@ import info.frostfs.sdk.tools.RequestConstructor;
|
|||
import info.frostfs.sdk.tools.RequestSigner;
|
||||
import info.frostfs.sdk.tools.Verifier;
|
||||
import io.grpc.Channel;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -30,7 +30,8 @@ import org.mockito.Mockito;
|
|||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.stream.Collectors;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@ -39,6 +40,9 @@ import static org.mockito.Mockito.*;
|
|||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ApeManagerClientTest {
|
||||
private static final String CHAIN_BASE64 =
|
||||
"AAAaY2hhaW4taWQtdGVzdAIAAAISR2V0T2JqZWN0AAIebmF0aXZlOm9iamVjdC8qAAIAABREZXBhcnRtZW50BEhSAA==";
|
||||
|
||||
private ApeManagerClientImpl apeManagerClient;
|
||||
|
||||
@Mock
|
||||
|
@ -107,7 +111,9 @@ class ApeManagerClientTest {
|
|||
assertThat(result).containsOnly(response.getBody().getChainId().toByteArray());
|
||||
|
||||
var request = captor.getValue();
|
||||
assertThat(request.getBody().getChain().getRaw().toByteArray()).containsOnly(chain.getRaw());
|
||||
assertEquals(
|
||||
Base64.getEncoder().encodeToString(request.getBody().getChain().getRaw().toByteArray()), CHAIN_BASE64)
|
||||
;
|
||||
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||
}
|
||||
|
@ -133,7 +139,7 @@ class ApeManagerClientTest {
|
|||
//Given
|
||||
Chain chain = generateChain();
|
||||
ChainTarget chainTarget = generateChainTarget();
|
||||
PrmApeChainRemove params = new PrmApeChainRemove(chain, chainTarget);
|
||||
PrmApeChainRemove params = new PrmApeChainRemove(Base64.getDecoder().decode(CHAIN_BASE64), chainTarget);
|
||||
|
||||
var response = ApeManagerGenerator.generateRemoveChainResponse();
|
||||
|
||||
|
@ -156,7 +162,7 @@ class ApeManagerClientTest {
|
|||
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||
|
||||
var request = captor.getValue();
|
||||
assertThat(request.getBody().getChainId().toByteArray()).containsOnly(chain.getRaw());
|
||||
assertThat(request.getBody().getChainId().toByteArray()).containsOnly(Base64.getDecoder().decode(CHAIN_BASE64));
|
||||
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||
assertEquals(chainTarget.getType().value, request.getBody().getTarget().getType().getNumber());
|
||||
}
|
||||
|
@ -167,7 +173,7 @@ class ApeManagerClientTest {
|
|||
Chain chain = generateChain();
|
||||
ChainTarget chainTarget = generateChainTarget();
|
||||
PrmApeChainRemove params1 = new PrmApeChainRemove(null, chainTarget);
|
||||
PrmApeChainRemove params2 = new PrmApeChainRemove(chain, null);
|
||||
PrmApeChainRemove params2 = new PrmApeChainRemove(Base64.getDecoder().decode(CHAIN_BASE64), null);
|
||||
PrmApeChainRemove params3 = new PrmApeChainRemove(null, null);
|
||||
|
||||
//When + Then
|
||||
|
@ -202,11 +208,8 @@ class ApeManagerClientTest {
|
|||
);
|
||||
verifierMock.verify(() -> Verifier.checkResponse(response), times(1));
|
||||
|
||||
var actual = result.stream().map(Chain::getRaw).collect(Collectors.toList());
|
||||
var expected = response.getBody().getChainsList().stream()
|
||||
.map(chain -> chain.getRaw().toByteArray())
|
||||
.collect(Collectors.toList());
|
||||
assertThat(actual).hasSize(10).containsAll(expected);
|
||||
var expected = response.getBody().getChainsList();
|
||||
assertThat(result).hasSize(10).containsAll(expected);
|
||||
|
||||
var request = captor.getValue();
|
||||
assertEquals(chainTarget.getName(), request.getBody().getTarget().getName());
|
||||
|
@ -221,8 +224,24 @@ class ApeManagerClientTest {
|
|||
}
|
||||
|
||||
private Chain generateChain() {
|
||||
byte[] chainRaw = FileUtils.resourceToBytes("test_chain_raw.json");
|
||||
return new Chain(chainRaw);
|
||||
var resources = new Resources(false, new String[]{"native:object/*"});
|
||||
var actions = new Actions(false, new String[]{"GetObject"});
|
||||
var condition = new Condition(
|
||||
ConditionType.COND_STRING_EQUALS, ConditionKindType.RESOURCE, "Department", "HR"
|
||||
);
|
||||
|
||||
var rule = new Rule();
|
||||
rule.setStatus(RuleStatus.ALLOW);
|
||||
rule.setResources(resources);
|
||||
rule.setActions(actions);
|
||||
rule.setAny(false);
|
||||
rule.setConditions(new Condition[]{condition});
|
||||
|
||||
var chain = new Chain();
|
||||
chain.setId(ArrayUtils.toObject("chain-id-test".getBytes(StandardCharsets.UTF_8)));
|
||||
chain.setRules(new Rule[]{rule});
|
||||
chain.setMatchType(RuleMatchType.DENY_PRIORITY);
|
||||
return chain;
|
||||
}
|
||||
|
||||
private ChainTarget generateChainTarget() {
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.frostfs.sdk.constants;
|
|||
|
||||
public class ErrorConst {
|
||||
public static final String OBJECT_IS_NULL = "object must not be null";
|
||||
public static final String STRING_IS_BLANK = "string must not be blank";
|
||||
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";
|
||||
|
@ -51,6 +52,12 @@ public class ErrorConst {
|
|||
public static final String FIELDS_DELIMITER_COMMA = ", ";
|
||||
public static final String FIELDS_DELIMITER_OR = " or ";
|
||||
|
||||
public static final String MARSHAL_SIZE_DIFFERS = "actual data size differs from expected";
|
||||
public static final String BYTES_ARE_OVER_FOR_SERIALIZE_TEMPLATE =
|
||||
"not enough bytes left to serialize value of type %s with length=%s";
|
||||
public static final String SLICE_IS_TOO_BIG_TEMPLATE = "slice size is too big=%s";
|
||||
public static final String STRING_IS_TOO_BIG_TEMPLATE = "string size is too big=%s";
|
||||
|
||||
private ErrorConst() {
|
||||
}
|
||||
}
|
||||
|
|
15
models/src/main/java/info/frostfs/sdk/dto/ape/Actions.java
Normal file
15
models/src/main/java/info/frostfs/sdk/dto/ape/Actions.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package info.frostfs.sdk.dto.ape;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Actions {
|
||||
private boolean inverted;
|
||||
private String[] names;
|
||||
}
|
17
models/src/main/java/info/frostfs/sdk/dto/ape/Chain.java
Normal file
17
models/src/main/java/info/frostfs/sdk/dto/ape/Chain.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package info.frostfs.sdk.dto.ape;
|
||||
|
||||
import info.frostfs.sdk.enums.RuleMatchType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Chain {
|
||||
private Byte[] id;
|
||||
private Rule[] rules;
|
||||
private RuleMatchType matchType;
|
||||
}
|
19
models/src/main/java/info/frostfs/sdk/dto/ape/Condition.java
Normal file
19
models/src/main/java/info/frostfs/sdk/dto/ape/Condition.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package info.frostfs.sdk.dto.ape;
|
||||
|
||||
import info.frostfs.sdk.enums.ConditionKindType;
|
||||
import info.frostfs.sdk.enums.ConditionType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Condition {
|
||||
private ConditionType op;
|
||||
private ConditionKindType kind;
|
||||
private String key;
|
||||
private String value;
|
||||
}
|
15
models/src/main/java/info/frostfs/sdk/dto/ape/Resources.java
Normal file
15
models/src/main/java/info/frostfs/sdk/dto/ape/Resources.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package info.frostfs.sdk.dto.ape;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Resources {
|
||||
private boolean inverted;
|
||||
private String[] names;
|
||||
}
|
27
models/src/main/java/info/frostfs/sdk/dto/ape/Rule.java
Normal file
27
models/src/main/java/info/frostfs/sdk/dto/ape/Rule.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package info.frostfs.sdk.dto.ape;
|
||||
|
||||
import info.frostfs.sdk.enums.RuleStatus;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Rule {
|
||||
private RuleStatus status;
|
||||
|
||||
// Actions the operation is applied to.
|
||||
private Actions actions;
|
||||
|
||||
// List of the resources the operation is applied to.
|
||||
private Resources resources;
|
||||
|
||||
// True if individual conditions must be combined with the logical OR.
|
||||
// By default, AND is used, so _each_ condition must pass.
|
||||
private boolean any;
|
||||
|
||||
private Condition[] conditions;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package info.frostfs.sdk.dto.chain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Chain {
|
||||
private final byte[] raw;
|
||||
}
|
|
@ -2,7 +2,8 @@ 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 info.frostfs.sdk.dto.object.OwnerId;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
@ -12,16 +13,16 @@ import java.util.UUID;
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class Container {
|
||||
private UUID nonce;
|
||||
private BasicAcl basicAcl;
|
||||
private PlacementPolicy placementPolicy;
|
||||
private Version version;
|
||||
private OwnerId ownerId;
|
||||
private Map<String, String> attributes = new HashMap<>();
|
||||
|
||||
public Container(BasicAcl basicAcl, PlacementPolicy placementPolicy) {
|
||||
public Container(PlacementPolicy placementPolicy) {
|
||||
this.nonce = UUID.randomUUID();
|
||||
this.basicAcl = basicAcl;
|
||||
this.placementPolicy = placementPolicy;
|
||||
}
|
||||
}
|
||||
|
|
15
models/src/main/java/info/frostfs/sdk/dto/netmap/Filter.java
Normal file
15
models/src/main/java/info/frostfs/sdk/dto/netmap/Filter.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package info.frostfs.sdk.dto.netmap;
|
||||
|
||||
import info.frostfs.sdk.enums.FilterOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Filter {
|
||||
private final String name;
|
||||
private final String key;
|
||||
private final FilterOperation operation;
|
||||
private final String value;
|
||||
private final Filter[] filters;
|
||||
}
|
|
@ -8,4 +8,15 @@ import lombok.Getter;
|
|||
public class PlacementPolicy {
|
||||
private final Replica[] replicas;
|
||||
private final boolean unique;
|
||||
private final int backupFactory;
|
||||
private final Filter[] filters;
|
||||
private final Selector[] selectors;
|
||||
|
||||
public PlacementPolicy(Replica[] replicas, boolean unique, int backupFactory) {
|
||||
this.replicas = replicas;
|
||||
this.unique = unique;
|
||||
this.backupFactory = backupFactory;
|
||||
this.filters = null;
|
||||
this.selectors = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package info.frostfs.sdk.dto.netmap;
|
||||
|
||||
import info.frostfs.sdk.enums.SelectorClause;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Selector {
|
||||
private final String name;
|
||||
private final int count;
|
||||
private final SelectorClause clause;
|
||||
private final String attribute;
|
||||
private final String filter;
|
||||
}
|
|
@ -3,19 +3,21 @@ package info.frostfs.sdk.dto.response;
|
|||
import info.frostfs.sdk.enums.StatusCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
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;
|
||||
private String details;
|
||||
|
||||
public ResponseStatus(StatusCode code, String message) {
|
||||
public ResponseStatus(StatusCode code, String message, String details) {
|
||||
this.code = code;
|
||||
this.message = isNull(message) ? EMPTY_STRING : message;
|
||||
this.message = StringUtils.isBlank(message) ? EMPTY_STRING : message;
|
||||
this.details = StringUtils.isBlank(details) ? EMPTY_STRING : details;
|
||||
}
|
||||
|
||||
public ResponseStatus(StatusCode code) {
|
||||
|
@ -25,7 +27,7 @@ public class ResponseStatus {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Response status: %s. Message: %s.", code, message);
|
||||
return String.format("Response status: %s. Message: %s. Details: %s", code, message, details);
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
public enum ConditionKindType {
|
||||
RESOURCE(0),
|
||||
REQUEST(1),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
ConditionKindType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
public enum ConditionType {
|
||||
COND_STRING_EQUALS(0),
|
||||
COND_STRING_NOT_EQUALS(1),
|
||||
COND_STRING_EQUALS_IGNORE_CASE(2),
|
||||
COND_STRING_NOT_EQUALS_IGNORE_CASE(3),
|
||||
|
||||
COND_STRING_LIKE(4),
|
||||
COND_STRING_NOT_LIKE(5),
|
||||
|
||||
COND_STRING_LESS_THAN(6),
|
||||
COND_STRING_LESS_THAN_EQUALS(7),
|
||||
COND_STRING_GREATER_THAN(8),
|
||||
COND_STRING_GREATER_THAN_EQUALS(9),
|
||||
|
||||
COND_NUMERIC_EQUALS(10),
|
||||
COND_NUMERIC_NOT_EQUALS(11),
|
||||
|
||||
COND_NUMERIC_LESS_THAN(12),
|
||||
COND_NUMERIC_LESS_THAN_EQUALS(13),
|
||||
COND_NUMERIC_GREATER_THAN(14),
|
||||
COND_NUMERIC_GREATER_THAN_EQUALS(15),
|
||||
|
||||
COND_SLICE_CONTAINS(16),
|
||||
|
||||
COND_IP_ADDRESS(17),
|
||||
COND_NOT_IP_ADDRESS(18),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
ConditionType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum FilterOperation {
|
||||
OPERATION_UNSPECIFIED(0),
|
||||
EQ(1),
|
||||
NE(2),
|
||||
GT(3),
|
||||
GE(4),
|
||||
LT(5),
|
||||
LE(6),
|
||||
OR(7),
|
||||
AND(8),
|
||||
NOT(9),
|
||||
LIKE(10),
|
||||
;
|
||||
|
||||
private static final Map<Integer, FilterOperation> ENUM_MAP_BY_VALUE;
|
||||
|
||||
static {
|
||||
Map<Integer, FilterOperation> map = new HashMap<>();
|
||||
for (FilterOperation nodeState : FilterOperation.values()) {
|
||||
map.put(nodeState.value, nodeState);
|
||||
}
|
||||
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public final int value;
|
||||
|
||||
FilterOperation(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static FilterOperation get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
public enum RuleMatchType {
|
||||
// DENY_PRIORITY rejects the request if any `Deny` is specified.
|
||||
DENY_PRIORITY(0),
|
||||
|
||||
// FIRST_MATCH returns the first rule action matched to the request.
|
||||
FIRST_MATCH(1),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
RuleMatchType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
15
models/src/main/java/info/frostfs/sdk/enums/RuleStatus.java
Normal file
15
models/src/main/java/info/frostfs/sdk/enums/RuleStatus.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
public enum RuleStatus {
|
||||
ALLOW(0),
|
||||
NO_RULE_FOUND(1),
|
||||
ACCESS_DENIED(2),
|
||||
QUOTA_LIMIT_REACHED(3),
|
||||
;
|
||||
|
||||
public final int value;
|
||||
|
||||
RuleStatus(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package info.frostfs.sdk.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum SelectorClause {
|
||||
CLAUSE_UNSPECIFIED(0),
|
||||
SAME(1),
|
||||
DISTINCT(2),
|
||||
;
|
||||
|
||||
private static final Map<Integer, SelectorClause> ENUM_MAP_BY_VALUE;
|
||||
|
||||
static {
|
||||
Map<Integer, SelectorClause> map = new HashMap<>();
|
||||
for (SelectorClause nodeState : SelectorClause.values()) {
|
||||
map.put(nodeState.value, nodeState);
|
||||
}
|
||||
ENUM_MAP_BY_VALUE = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
public final int value;
|
||||
|
||||
SelectorClause(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static SelectorClause get(int value) {
|
||||
return ENUM_MAP_BY_VALUE.get(value);
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package info.frostfs.sdk.mappers.chain;
|
||||
|
||||
import frostfs.ape.Types;
|
||||
import info.frostfs.sdk.dto.chain.Chain;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ChainMapper {
|
||||
private ChainMapper() {
|
||||
}
|
||||
|
||||
public static List<Chain> toModels(List<Types.Chain> chains) {
|
||||
if (CollectionUtils.isEmpty(chains)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return chains.stream().map(ChainMapper::toModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Chain toModel(Types.Chain chain) {
|
||||
if (isNull(chain) || chain.getSerializedSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Chain(chain.getRaw().toByteArray());
|
||||
}
|
||||
}
|
|
@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.container.ContainerId;
|
|||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ContainerIdMapper {
|
||||
|
||||
private ContainerIdMapper() {
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,9 @@ import info.frostfs.sdk.enums.BasicAcl;
|
|||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.mappers.netmap.PlacementPolicyMapper;
|
||||
import info.frostfs.sdk.mappers.netmap.VersionMapper;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static info.frostfs.sdk.UuidExtension.asBytes;
|
||||
|
@ -20,16 +21,11 @@ public class ContainerMapper {
|
|||
private ContainerMapper() {
|
||||
}
|
||||
|
||||
public static Types.Container toGrpcMessage(Container container) {
|
||||
public static Types.Container.Builder toGrpcMessage(Container container) {
|
||||
if (isNull(container)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var containerGrpc = Types.Container.newBuilder()
|
||||
.setBasicAcl(container.getBasicAcl().value)
|
||||
.setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy()))
|
||||
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())));
|
||||
|
||||
var attributes = container.getAttributes().entrySet().stream()
|
||||
.map(entry ->
|
||||
Types.Container.Attribute.newBuilder()
|
||||
|
@ -38,9 +34,16 @@ public class ContainerMapper {
|
|||
.build()
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
containerGrpc.addAllAttributes(attributes);
|
||||
|
||||
return containerGrpc.build();
|
||||
var containerGrpc = Types.Container.newBuilder()
|
||||
.setPlacementPolicy(PlacementPolicyMapper.toGrpcMessage(container.getPlacementPolicy()))
|
||||
.setNonce(ByteString.copyFrom(asBytes(container.getNonce())))
|
||||
.addAllAttributes(attributes);
|
||||
|
||||
Optional.ofNullable(OwnerIdMapper.toGrpcMessage(container.getOwnerId())).ifPresent(containerGrpc::setOwnerId);
|
||||
Optional.ofNullable(VersionMapper.toGrpcMessage(container.getVersion())).ifPresent(containerGrpc::setVersion);
|
||||
|
||||
return containerGrpc;
|
||||
}
|
||||
|
||||
public static Container toModel(Types.Container containerGrpc) {
|
||||
|
@ -55,17 +58,15 @@ public class ContainerMapper {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
var container = new Container(basicAcl, PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()));
|
||||
container.setNonce(asUuid(containerGrpc.getNonce().toByteArray()));
|
||||
container.setVersion(VersionMapper.toModel(containerGrpc.getVersion()));
|
||||
|
||||
if (CollectionUtils.isNotEmpty(containerGrpc.getAttributesList())) {
|
||||
var attributes = containerGrpc.getAttributesList().stream()
|
||||
.collect(Collectors.toMap(Types.Container.Attribute::getKey, Types.Container.Attribute::getValue));
|
||||
container.setAttributes(attributes);
|
||||
}
|
||||
|
||||
return container;
|
||||
return new Container(
|
||||
asUuid(containerGrpc.getNonce().toByteArray()),
|
||||
PlacementPolicyMapper.toModel(containerGrpc.getPlacementPolicy()),
|
||||
VersionMapper.toModel(containerGrpc.getVersion()),
|
||||
OwnerIdMapper.toModel(containerGrpc.getOwnerId()),
|
||||
attributes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package info.frostfs.sdk.mappers.netmap;
|
||||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.Filter;
|
||||
import info.frostfs.sdk.enums.FilterOperation;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
public class FilterMapper {
|
||||
private FilterMapper() {
|
||||
}
|
||||
|
||||
public static List<Types.Filter> toGrpcMessages(Filter[] filters) {
|
||||
if (ArrayUtils.isEmpty(filters)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Arrays.stream(filters).map(FilterMapper::toGrpcMessage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Types.Filter toGrpcMessage(Filter filter) {
|
||||
if (isNull(filter)) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Filter.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
var operation = Types.Operation.forNumber(filter.getOperation().value);
|
||||
if (isNull(operation)) {
|
||||
throw new ProcessFrostFSException(String.format(
|
||||
UNKNOWN_ENUM_VALUE_TEMPLATE,
|
||||
Types.Operation.class.getName(),
|
||||
filter.getOperation().name()
|
||||
));
|
||||
}
|
||||
|
||||
return Types.Filter.newBuilder()
|
||||
.setName(filter.getName())
|
||||
.setKey(filter.getKey())
|
||||
.setOp(operation)
|
||||
.setValue(filter.getValue())
|
||||
.addAllFilters(toGrpcMessages(filter.getFilters()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Filter[] toModels(List<Types.Filter> filters) {
|
||||
if (CollectionUtils.isEmpty(filters)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filters.stream().map(FilterMapper::toModel).toArray(Filter[]::new);
|
||||
}
|
||||
|
||||
public static Filter toModel(Types.Filter filter) {
|
||||
if (isNull(filter) || filter.getSerializedSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var operation = FilterOperation.get(filter.getOpValue());
|
||||
if (isNull(operation)) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, FilterOperation.class.getName(), filter.getOp())
|
||||
);
|
||||
}
|
||||
|
||||
return new Filter(
|
||||
filter.getName(),
|
||||
filter.getKey(),
|
||||
operation,
|
||||
filter.getValue(),
|
||||
toModels(filter.getFiltersList())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ import java.util.stream.Collectors;
|
|||
import static java.util.Objects.isNull;
|
||||
|
||||
public class NetmapSnapshotMapper {
|
||||
|
||||
private NetmapSnapshotMapper() {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.frostfs.sdk.mappers.netmap;
|
|||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.frostfs.sdk.dto.netmap.Replica;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
|
@ -15,14 +14,13 @@ public class PlacementPolicyMapper {
|
|||
return null;
|
||||
}
|
||||
|
||||
var pp = Types.PlacementPolicy.newBuilder()
|
||||
.setUnique(placementPolicy.isUnique());
|
||||
|
||||
for (Replica replica : placementPolicy.getReplicas()) {
|
||||
pp.addReplicas(ReplicaMapper.toGrpcMessage(replica));
|
||||
}
|
||||
|
||||
return pp.build();
|
||||
return Types.PlacementPolicy.newBuilder()
|
||||
.setUnique(placementPolicy.isUnique())
|
||||
.setContainerBackupFactor(placementPolicy.getBackupFactory())
|
||||
.addAllFilters(FilterMapper.toGrpcMessages(placementPolicy.getFilters()))
|
||||
.addAllSelectors(SelectorMapper.toGrpcMessages(placementPolicy.getSelectors()))
|
||||
.addAllReplicas(ReplicaMapper.toGrpcMessages(placementPolicy.getReplicas()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static PlacementPolicy toModel(Types.PlacementPolicy placementPolicy) {
|
||||
|
@ -31,8 +29,11 @@ public class PlacementPolicyMapper {
|
|||
}
|
||||
|
||||
return new PlacementPolicy(
|
||||
placementPolicy.getReplicasList().stream().map(ReplicaMapper::toModel).toArray(Replica[]::new),
|
||||
placementPolicy.getUnique()
|
||||
ReplicaMapper.toModels(placementPolicy.getReplicasList()),
|
||||
placementPolicy.getUnique(),
|
||||
placementPolicy.getContainerBackupFactor(),
|
||||
FilterMapper.toModels(placementPolicy.getFiltersList()),
|
||||
SelectorMapper.toModels(placementPolicy.getSelectorsList())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,17 +2,35 @@ package info.frostfs.sdk.mappers.netmap;
|
|||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.Replica;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.INPUT_PARAM_IS_MISSING_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ReplicaMapper {
|
||||
|
||||
private ReplicaMapper() {
|
||||
}
|
||||
|
||||
public static List<Types.Replica> toGrpcMessages(Replica[] replicas) {
|
||||
if (ArrayUtils.isEmpty(replicas)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Arrays.stream(replicas).map(ReplicaMapper::toGrpcMessage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Types.Replica toGrpcMessage(Replica replica) {
|
||||
if (isNull(replica)) {
|
||||
return null;
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Replica.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
return Types.Replica.newBuilder()
|
||||
|
@ -21,6 +39,14 @@ public class ReplicaMapper {
|
|||
.build();
|
||||
}
|
||||
|
||||
public static Replica[] toModels(List<Types.Replica> filters) {
|
||||
if (CollectionUtils.isEmpty(filters)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filters.stream().map(ReplicaMapper::toModel).toArray(Replica[]::new);
|
||||
}
|
||||
|
||||
public static Replica toModel(Types.Replica replica) {
|
||||
if (isNull(replica) || replica.getSerializedSize() == 0) {
|
||||
return null;
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package info.frostfs.sdk.mappers.netmap;
|
||||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.Selector;
|
||||
import info.frostfs.sdk.enums.SelectorClause;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
public class SelectorMapper {
|
||||
private SelectorMapper() {
|
||||
}
|
||||
|
||||
public static List<Types.Selector> toGrpcMessages(Selector[] selectors) {
|
||||
if (ArrayUtils.isEmpty(selectors)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return Arrays.stream(selectors).map(SelectorMapper::toGrpcMessage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Types.Selector toGrpcMessage(Selector selector) {
|
||||
if (isNull(selector)) {
|
||||
throw new ValidationFrostFSException(
|
||||
String.format(INPUT_PARAM_IS_MISSING_TEMPLATE, Selector.class.getName())
|
||||
);
|
||||
}
|
||||
|
||||
var clause = Types.Clause.forNumber(selector.getClause().value);
|
||||
if (isNull(clause)) {
|
||||
throw new ProcessFrostFSException(String.format(
|
||||
UNKNOWN_ENUM_VALUE_TEMPLATE,
|
||||
Types.Clause.class.getName(),
|
||||
selector.getClause().name()
|
||||
));
|
||||
}
|
||||
|
||||
return Types.Selector.newBuilder()
|
||||
.setName(selector.getName())
|
||||
.setCount(selector.getCount())
|
||||
.setClause(clause)
|
||||
.setAttribute(selector.getAttribute())
|
||||
.setFilter(selector.getFilter())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Selector[] toModels(List<Types.Selector> selectors) {
|
||||
if (CollectionUtils.isEmpty(selectors)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return selectors.stream().map(SelectorMapper::toModel).toArray(Selector[]::new);
|
||||
}
|
||||
|
||||
public static Selector toModel(Types.Selector selector) {
|
||||
if (isNull(selector) || selector.getSerializedSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var clause = SelectorClause.get(selector.getClauseValue());
|
||||
if (isNull(clause)) {
|
||||
throw new ProcessFrostFSException(
|
||||
String.format(UNKNOWN_ENUM_VALUE_TEMPLATE, SelectorClause.class.getName(), selector.getClause())
|
||||
);
|
||||
}
|
||||
|
||||
return new Selector(
|
||||
selector.getName(),
|
||||
selector.getCount(),
|
||||
clause,
|
||||
selector.getAttribute(),
|
||||
selector.getFilter()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ import info.frostfs.sdk.dto.netmap.Version;
|
|||
import static java.util.Objects.isNull;
|
||||
|
||||
public class VersionMapper {
|
||||
|
||||
private VersionMapper() {
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ import frostfs.object.Types;
|
|||
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectAttributeMapper {
|
||||
|
||||
private ObjectAttributeMapper() {
|
||||
}
|
||||
|
||||
public static List<Types.Header.Attribute> toGrpcMessages(List<ObjectAttribute> attributes) {
|
||||
if (CollectionUtils.isEmpty(attributes)) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return attributes.stream().map(ObjectAttributeMapper::toGrpcMessage).collect(Collectors.toList());
|
||||
|
|
|
@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.object.ObjectId;
|
|||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectFrostFSMapper {
|
||||
|
||||
private ObjectFrostFSMapper() {
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import info.frostfs.sdk.dto.object.ObjectId;
|
|||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ObjectIdMapper {
|
||||
|
||||
private ObjectIdMapper() {
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ package info.frostfs.sdk.mappers.object;
|
|||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostfs.refs.Types;
|
||||
import info.frostfs.sdk.Base58;
|
||||
import info.frostfs.sdk.dto.object.OwnerId;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class OwnerIdMapper {
|
||||
|
||||
private OwnerIdMapper() {
|
||||
}
|
||||
|
||||
|
@ -20,4 +20,12 @@ public class OwnerIdMapper {
|
|||
.setValue(ByteString.copyFrom(ownerId.toHash()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static OwnerId toModel(Types.OwnerID ownerId) {
|
||||
if (isNull(ownerId) || ownerId.getSerializedSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OwnerId(Base58.encode(ownerId.getValue().toByteArray()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import info.frostfs.sdk.mappers.object.ObjectIdMapper;
|
|||
import static java.util.Objects.isNull;
|
||||
|
||||
public class AddressMapper {
|
||||
|
||||
private AddressMapper() {
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ import frostfs.object.Service;
|
|||
import info.frostfs.sdk.dto.object.patch.Range;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class RangeMapper {
|
||||
|
||||
private RangeMapper() {
|
||||
}
|
||||
|
||||
public static List<Service.Range> toGrpcMessages(List<Range> ranges) {
|
||||
if (CollectionUtils.isEmpty(ranges)) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return ranges.stream().map(RangeMapper::toGrpcMessage).collect(Collectors.toList());
|
||||
|
|
|
@ -5,6 +5,9 @@ import info.frostfs.sdk.dto.response.ResponseStatus;
|
|||
import info.frostfs.sdk.enums.StatusCode;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static info.frostfs.sdk.constants.ErrorConst.FIELDS_DELIMITER_COMMA;
|
||||
import static info.frostfs.sdk.constants.ErrorConst.UNKNOWN_ENUM_VALUE_TEMPLATE;
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
|
@ -24,6 +27,10 @@ public class ResponseStatusMapper {
|
|||
);
|
||||
}
|
||||
|
||||
return new ResponseStatus(statusCode, status.getMessage());
|
||||
var stringDetails = status.getDetailsList().stream()
|
||||
.map(t -> t.getValue().toStringUtf8())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new ResponseStatus(statusCode, status.getMessage(), String.join(FIELDS_DELIMITER_COMMA, stringDetails));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
package info.frostfs.sdk.mappers.chain;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import frostfs.ape.Types;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ChainMapperTest {
|
||||
|
||||
@Test
|
||||
void toModels_success() {
|
||||
//Given
|
||||
var chain1 = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}))
|
||||
.build();
|
||||
var chain2 = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(new byte[]{6, 7, 8, 9, 10}))
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = ChainMapper.toModels(List.of(chain1, chain2));
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result.get(0).getRaw()).containsOnly(chain1.getRaw().toByteArray());
|
||||
assertThat(result.get(1).getRaw()).containsOnly(chain2.getRaw().toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModels_null() {
|
||||
//When + Then
|
||||
assertNull(ChainMapper.toModels(null));
|
||||
assertNull(ChainMapper.toModels(Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_success() {
|
||||
//Given
|
||||
var chain = Types.Chain.newBuilder()
|
||||
.setRaw(ByteString.copyFrom(new byte[]{1, 2, 3, 4, 5}))
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = ChainMapper.toModel(chain);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertThat(result.getRaw()).containsOnly(chain.getRaw().toByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_null() {
|
||||
//When + Then
|
||||
assertNull(ChainMapper.toModel(null));
|
||||
assertNull(ChainMapper.toModel(Types.Chain.getDefaultInstance()));
|
||||
}
|
||||
}
|
|
@ -5,8 +5,11 @@ import frostfs.container.Types;
|
|||
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.dto.netmap.Version;
|
||||
import info.frostfs.sdk.dto.object.OwnerId;
|
||||
import info.frostfs.sdk.enums.BasicAcl;
|
||||
import info.frostfs.sdk.exceptions.ProcessFrostFSException;
|
||||
import info.frostfs.sdk.mappers.object.OwnerIdMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
@ -19,12 +22,54 @@ import static info.frostfs.sdk.constants.AttributeConst.DISABLE_HOMOMORPHIC_HASH
|
|||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ContainerMapperTest {
|
||||
private static final String OWNER_ID = "NVxUSpEEJzYXZZtUs18PrJTD9QZkLLNQ8S";
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_successFullMessage() {
|
||||
//Given
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(3)}, true, 1);
|
||||
var container = new Container(placementPolicy);
|
||||
container.getAttributes().put("key1", "val1");
|
||||
container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, "false");
|
||||
container.setVersion(new Version());
|
||||
container.setOwnerId(new OwnerId(OWNER_ID));
|
||||
|
||||
//When
|
||||
var result = ContainerMapper.toGrpcMessage(container);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(container.getNonce(), asUuid(result.getNonce().toByteArray()));
|
||||
assertEquals(container.getPlacementPolicy().isUnique(), result.getPlacementPolicy().getUnique());
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getBackupFactory(),
|
||||
result.getPlacementPolicy().getContainerBackupFactor()
|
||||
);
|
||||
assertEquals(placementPolicy.getReplicas().length, result.getPlacementPolicy().getReplicasCount());
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getReplicas()[0].getCount(),
|
||||
result.getPlacementPolicy().getReplicasList().get(0).getCount()
|
||||
);
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getReplicas()[0].getSelector(),
|
||||
result.getPlacementPolicy().getReplicasList().get(0).getSelector()
|
||||
);
|
||||
|
||||
assertEquals("key1", result.getAttributes(0).getKey());
|
||||
assertEquals("val1", result.getAttributes(0).getValue());
|
||||
assertEquals(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, result.getAttributes(1).getKey());
|
||||
assertEquals("false", result.getAttributes(1).getValue());
|
||||
|
||||
assertEquals(container.getVersion().getMajor(), result.getVersion().getMajor());
|
||||
assertEquals(container.getVersion().getMinor(), result.getVersion().getMinor());
|
||||
assertEquals(container.getOwnerId().toString(), OwnerIdMapper.toModel(result.getOwnerId()).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_success() {
|
||||
//Given
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(1)}, true);
|
||||
var container = new Container(BasicAcl.PUBLIC_RW, placementPolicy);
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{new Replica(3)}, true, 1);
|
||||
var container = new Container(placementPolicy);
|
||||
container.getAttributes().put("key1", "val1");
|
||||
container.getAttributes().put(DISABLE_HOMOMORPHIC_HASHING_ATTRIBUTE, "false");
|
||||
|
||||
|
@ -33,9 +78,12 @@ public class ContainerMapperTest {
|
|||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(container.getBasicAcl().value, result.getBasicAcl());
|
||||
assertEquals(container.getNonce(), asUuid(result.getNonce().toByteArray()));
|
||||
assertEquals(container.getPlacementPolicy().isUnique(), result.getPlacementPolicy().getUnique());
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getBackupFactory(),
|
||||
result.getPlacementPolicy().getContainerBackupFactor()
|
||||
);
|
||||
assertEquals(placementPolicy.getReplicas().length, result.getPlacementPolicy().getReplicasCount());
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getReplicas()[0].getCount(),
|
||||
|
@ -75,6 +123,7 @@ public class ContainerMapperTest {
|
|||
var placementPolicy = frostfs.netmap.Types.PlacementPolicy.newBuilder()
|
||||
.setUnique(true)
|
||||
.addReplicas(replica)
|
||||
.setContainerBackupFactor(2)
|
||||
.build();
|
||||
|
||||
var attribute1 = Types.Container.Attribute.newBuilder()
|
||||
|
@ -101,9 +150,12 @@ public class ContainerMapperTest {
|
|||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(container.getBasicAcl(), result.getBasicAcl().value);
|
||||
assertEquals(asUuid(container.getNonce().toByteArray()), result.getNonce());
|
||||
assertEquals(container.getPlacementPolicy().getUnique(), result.getPlacementPolicy().isUnique());
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getContainerBackupFactor(),
|
||||
result.getPlacementPolicy().getBackupFactory()
|
||||
);
|
||||
assertEquals(placementPolicy.getReplicasCount(), result.getPlacementPolicy().getReplicas().length);
|
||||
assertEquals(
|
||||
container.getPlacementPolicy().getReplicasList().get(0).getCount(),
|
||||
|
|
|
@ -0,0 +1,209 @@
|
|||
package info.frostfs.sdk.mappers.netmap;
|
||||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.Filter;
|
||||
import info.frostfs.sdk.enums.FilterOperation;
|
||||
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;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class FilterMapperTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = FilterOperation.class)
|
||||
void toGrpcMessages_success(FilterOperation operation) {
|
||||
//Given
|
||||
var filter1 = new Filter("name1", "key1", operation, "value1", null);
|
||||
var filter2 = new Filter("name2", "key2", operation, "value2", null);
|
||||
|
||||
//When
|
||||
var result = FilterMapper.toGrpcMessages(new Filter[]{filter1, filter2});
|
||||
|
||||
//Then
|
||||
assertThat(result).isNotNull().hasSize(2);
|
||||
|
||||
assertEquals(filter1.getKey(), result.get(0).getKey());
|
||||
assertEquals(filter1.getName(), result.get(0).getName());
|
||||
assertEquals(filter1.getOperation().value, result.get(0).getOpValue());
|
||||
assertEquals(filter1.getValue(), result.get(0).getValue());
|
||||
assertEquals(0, result.get(0).getFiltersCount());
|
||||
|
||||
assertEquals(filter2.getKey(), result.get(1).getKey());
|
||||
assertEquals(filter2.getName(), result.get(1).getName());
|
||||
assertEquals(filter2.getOperation().value, result.get(1).getOpValue());
|
||||
assertEquals(filter2.getValue(), result.get(1).getValue());
|
||||
assertEquals(0, result.get(1).getFiltersCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessages_null() {
|
||||
//When + Then
|
||||
assertEquals(Collections.emptyList(), FilterMapper.toGrpcMessages(null));
|
||||
assertEquals(Collections.emptyList(), FilterMapper.toGrpcMessages(new Filter[]{}));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = FilterOperation.class)
|
||||
void toGrpcMessage_success(FilterOperation operation) {
|
||||
//Given
|
||||
var filterChild = new Filter("name1", "key1", operation, "value1", null);
|
||||
var filterParent = new Filter("name2", "key2", operation, "value2", new Filter[]{filterChild});
|
||||
|
||||
//When
|
||||
var result = FilterMapper.toGrpcMessage(filterParent);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(filterParent.getKey(), result.getKey());
|
||||
assertEquals(filterParent.getName(), result.getName());
|
||||
assertEquals(filterParent.getOperation().value, result.getOpValue());
|
||||
assertEquals(filterParent.getValue(), result.getValue());
|
||||
assertEquals(filterParent.getFilters().length, result.getFiltersCount());
|
||||
|
||||
var filterChildGrpc = result.getFilters(0);
|
||||
assertEquals(filterChild.getKey(), filterChildGrpc.getKey());
|
||||
assertEquals(filterChild.getName(), filterChildGrpc.getName());
|
||||
assertEquals(filterChild.getOperation().value, filterChildGrpc.getOpValue());
|
||||
assertEquals(filterChild.getValue(), filterChildGrpc.getValue());
|
||||
assertEquals(0, filterChildGrpc.getFiltersCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_null() {
|
||||
//When + Then
|
||||
assertThrows(ValidationFrostFSException.class, () -> FilterMapper.toGrpcMessage(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_notValidOperation() {
|
||||
//Given
|
||||
var filter = new Filter("name1", "key1", FilterOperation.EQ, "value1", null);
|
||||
|
||||
|
||||
//When + Then
|
||||
try (MockedStatic<Types.Operation> mockStatic = mockStatic(Types.Operation.class)) {
|
||||
mockStatic.when(() -> Types.Operation.forNumber(filter.getOperation().value))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThrows(ProcessFrostFSException.class, () -> FilterMapper.toGrpcMessage(filter));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Types.Operation.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE)
|
||||
void toModels_success(Types.Operation operation) {
|
||||
//Given
|
||||
var filter1 = Types.Filter.newBuilder()
|
||||
.setName("name1")
|
||||
.setKey("key1")
|
||||
.setOp(operation)
|
||||
.setValue("value1")
|
||||
.build();
|
||||
var filter2 = Types.Filter.newBuilder()
|
||||
.setName("name2")
|
||||
.setKey("key2")
|
||||
.setOp(operation)
|
||||
.setValue("value2")
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = FilterMapper.toModels(List.of(filter1, filter2));
|
||||
|
||||
//Then
|
||||
assertThat(result).isNotNull().hasSize(2);
|
||||
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(filter1.getKey(), result[0].getKey());
|
||||
assertEquals(filter1.getName(), result[0].getName());
|
||||
assertEquals(filter1.getOpValue(), result[0].getOperation().value);
|
||||
assertEquals(filter1.getValue(), result[0].getValue());
|
||||
assertNull(result[0].getFilters());
|
||||
|
||||
assertEquals(filter2.getKey(), result[1].getKey());
|
||||
assertEquals(filter2.getName(), result[1].getName());
|
||||
assertEquals(filter2.getOpValue(), result[1].getOperation().value);
|
||||
assertEquals(filter2.getValue(), result[1].getValue());
|
||||
assertNull(result[1].getFilters());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModels_null() {
|
||||
//When + Then
|
||||
assertNull(FilterMapper.toModels(null));
|
||||
assertNull(FilterMapper.toModels(Collections.emptyList()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Types.Operation.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE)
|
||||
void toModel_success(Types.Operation operation) {
|
||||
//Given
|
||||
var filterChild = Types.Filter.newBuilder()
|
||||
.setName("name1")
|
||||
.setKey("key1")
|
||||
.setOp(operation)
|
||||
.setValue("value1")
|
||||
.build();
|
||||
var filterParent = Types.Filter.newBuilder()
|
||||
.setName("name2")
|
||||
.setKey("key2")
|
||||
.setOp(operation)
|
||||
.setValue("value2")
|
||||
.addFilters(filterChild)
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = FilterMapper.toModel(filterParent);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(filterParent.getKey(), result.getKey());
|
||||
assertEquals(filterParent.getName(), result.getName());
|
||||
assertEquals(filterParent.getOpValue(), result.getOperation().value);
|
||||
assertEquals(filterParent.getValue(), result.getValue());
|
||||
assertEquals(filterParent.getFiltersCount(), result.getFilters().length);
|
||||
|
||||
var filterChildModel = result.getFilters()[0];
|
||||
assertEquals(filterChild.getKey(), filterChildModel.getKey());
|
||||
assertEquals(filterChild.getName(), filterChildModel.getName());
|
||||
assertEquals(filterChild.getOpValue(), filterChildModel.getOperation().value);
|
||||
assertEquals(filterChild.getValue(), filterChildModel.getValue());
|
||||
assertNull(filterChildModel.getFilters());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_null() {
|
||||
//When + Then
|
||||
assertNull(FilterMapper.toModel(null));
|
||||
assertNull(FilterMapper.toModel(Types.Filter.getDefaultInstance()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_notValidScheme() {
|
||||
//Given
|
||||
var filter = Types.Filter.newBuilder()
|
||||
.setName("name1")
|
||||
.setKey("key1")
|
||||
.setOp(Types.Operation.EQ)
|
||||
.setValue("value1")
|
||||
.build();
|
||||
|
||||
//When + Then
|
||||
try (MockedStatic<FilterOperation> mockStatic = mockStatic(FilterOperation.class)) {
|
||||
mockStatic.when(() -> FilterOperation.get(Types.Operation.EQ.getNumber()))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThrows(ProcessFrostFSException.class, () -> FilterMapper.toModel(filter));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ public class PlacementPolicyMapperTest {
|
|||
var replica1 = new Replica(1, "test1");
|
||||
var replica2 = new Replica(2, "test2");
|
||||
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{replica1, replica2}, true);
|
||||
var placementPolicy = new PlacementPolicy(new Replica[]{replica1, replica2}, true, 1);
|
||||
|
||||
//When
|
||||
var result = PlacementPolicyMapper.toGrpcMessage(placementPolicy);
|
||||
|
@ -23,6 +23,7 @@ public class PlacementPolicyMapperTest {
|
|||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(placementPolicy.isUnique(), result.getUnique());
|
||||
assertEquals(placementPolicy.getBackupFactory(), result.getContainerBackupFactor());
|
||||
assertEquals(placementPolicy.getReplicas().length, result.getReplicasCount());
|
||||
assertEquals(replica1.getCount(), result.getReplicas(0).getCount());
|
||||
assertEquals(replica1.getSelector(), result.getReplicas(0).getSelector());
|
||||
|
@ -53,6 +54,7 @@ public class PlacementPolicyMapperTest {
|
|||
.setUnique(true)
|
||||
.addReplicas(replica1)
|
||||
.addReplicas(replica2)
|
||||
.setContainerBackupFactor(1)
|
||||
.build();
|
||||
|
||||
//When
|
||||
|
@ -61,6 +63,7 @@ public class PlacementPolicyMapperTest {
|
|||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(placementPolicy.getUnique(), result.isUnique());
|
||||
assertEquals(placementPolicy.getContainerBackupFactor(), result.getBackupFactory());
|
||||
assertEquals(placementPolicy.getReplicasCount(), result.getReplicas().length);
|
||||
assertEquals(replica1.getCount(), result.getReplicas()[0].getCount());
|
||||
assertEquals(replica1.getSelector(), result.getReplicas()[0].getSelector());
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.frostfs.sdk.mappers.netmap;
|
|||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.Replica;
|
||||
import info.frostfs.sdk.exceptions.ValidationFrostFSException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
@ -25,7 +26,7 @@ public class ReplicaMapperTest {
|
|||
@Test
|
||||
void toGrpcMessage_null() {
|
||||
//When + Then
|
||||
assertNull(ReplicaMapper.toGrpcMessage(null));
|
||||
assertThrows(ValidationFrostFSException.class, () -> ReplicaMapper.toGrpcMessage(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,191 @@
|
|||
package info.frostfs.sdk.mappers.netmap;
|
||||
|
||||
import frostfs.netmap.Types;
|
||||
import info.frostfs.sdk.dto.netmap.Selector;
|
||||
import info.frostfs.sdk.enums.SelectorClause;
|
||||
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;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class SelectorMapperTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = SelectorClause.class)
|
||||
void toGrpcMessages_success(SelectorClause clause) {
|
||||
//Given
|
||||
var selector1 = new Selector("name1", 1, clause, "attribute1", "filter1");
|
||||
var selector2 = new Selector("name2", 2, clause, "attribute2", "filter2");
|
||||
|
||||
//When
|
||||
var result = SelectorMapper.toGrpcMessages(new Selector[]{selector1, selector2});
|
||||
|
||||
//Then
|
||||
assertThat(result).isNotNull().hasSize(2);
|
||||
|
||||
assertEquals(selector1.getName(), result.get(0).getName());
|
||||
assertEquals(selector1.getCount(), result.get(0).getCount());
|
||||
assertEquals(selector1.getClause().value, result.get(0).getClauseValue());
|
||||
assertEquals(selector1.getAttribute(), result.get(0).getAttribute());
|
||||
assertEquals(selector1.getFilter(), result.get(0).getFilter());
|
||||
|
||||
assertEquals(selector2.getName(), result.get(1).getName());
|
||||
assertEquals(selector2.getCount(), result.get(1).getCount());
|
||||
assertEquals(selector2.getClause().value, result.get(1).getClauseValue());
|
||||
assertEquals(selector2.getAttribute(), result.get(1).getAttribute());
|
||||
assertEquals(selector2.getFilter(), result.get(1).getFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessages_null() {
|
||||
//When + Then
|
||||
assertEquals(Collections.emptyList(), SelectorMapper.toGrpcMessages(null));
|
||||
assertEquals(Collections.emptyList(), SelectorMapper.toGrpcMessages(new Selector[]{}));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = SelectorClause.class)
|
||||
void toGrpcMessage_success(SelectorClause clause) {
|
||||
//Given
|
||||
var selector = new Selector("name", 1, clause, "attribute", "filter");
|
||||
|
||||
//When
|
||||
var result = SelectorMapper.toGrpcMessage(selector);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(selector.getName(), result.getName());
|
||||
assertEquals(selector.getCount(), result.getCount());
|
||||
assertEquals(selector.getClause().value, result.getClauseValue());
|
||||
assertEquals(selector.getAttribute(), result.getAttribute());
|
||||
assertEquals(selector.getFilter(), result.getFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_null() {
|
||||
//When + Then
|
||||
assertThrows(ValidationFrostFSException.class, () -> SelectorMapper.toGrpcMessage(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toGrpcMessage_notValidOperation() {
|
||||
//Given
|
||||
var selector = new Selector("name", 1, SelectorClause.SAME, "attribute", "filter");
|
||||
|
||||
|
||||
//When + Then
|
||||
try (MockedStatic<Types.Clause> mockStatic = mockStatic(Types.Clause.class)) {
|
||||
mockStatic.when(() -> Types.Clause.forNumber(selector.getClause().value))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThrows(ProcessFrostFSException.class, () -> SelectorMapper.toGrpcMessage(selector));
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Types.Clause.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE)
|
||||
void toModels_success(Types.Clause clause) {
|
||||
//Given
|
||||
var selector1 = Types.Selector.newBuilder()
|
||||
.setName("name1")
|
||||
.setCount(1)
|
||||
.setClause(clause)
|
||||
.setAttribute("attribute1")
|
||||
.setFilter("filter1")
|
||||
.build();
|
||||
var selector2 = Types.Selector.newBuilder()
|
||||
.setName("name2")
|
||||
.setCount(2)
|
||||
.setClause(clause)
|
||||
.setAttribute("attribute2")
|
||||
.setFilter("filter2")
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = SelectorMapper.toModels(List.of(selector1, selector2));
|
||||
|
||||
//Then
|
||||
assertThat(result).isNotNull().hasSize(2);
|
||||
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(selector1.getName(), result[0].getName());
|
||||
assertEquals(selector1.getCount(), result[0].getCount());
|
||||
assertEquals(selector1.getClauseValue(), result[0].getClause().value);
|
||||
assertEquals(selector1.getAttribute(), result[0].getAttribute());
|
||||
assertEquals(selector1.getFilter(), result[0].getFilter());
|
||||
|
||||
assertEquals(selector2.getName(), result[1].getName());
|
||||
assertEquals(selector2.getCount(), result[1].getCount());
|
||||
assertEquals(selector2.getClauseValue(), result[1].getClause().value);
|
||||
assertEquals(selector2.getAttribute(), result[1].getAttribute());
|
||||
assertEquals(selector2.getFilter(), result[1].getFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModels_null() {
|
||||
//When + Then
|
||||
assertNull(SelectorMapper.toModels(null));
|
||||
assertNull(SelectorMapper.toModels(Collections.emptyList()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Types.Clause.class, names = "UNRECOGNIZED", mode = EnumSource.Mode.EXCLUDE)
|
||||
void toModel_success(Types.Clause clause) {
|
||||
//Given
|
||||
var selector = Types.Selector.newBuilder()
|
||||
.setName("name")
|
||||
.setCount(1)
|
||||
.setClause(clause)
|
||||
.setAttribute("attribute")
|
||||
.setFilter("filter")
|
||||
.build();
|
||||
|
||||
//When
|
||||
var result = SelectorMapper.toModel(selector);
|
||||
|
||||
//Then
|
||||
assertNotNull(result);
|
||||
assertEquals(selector.getName(), result.getName());
|
||||
assertEquals(selector.getCount(), result.getCount());
|
||||
assertEquals(selector.getClauseValue(), result.getClause().value);
|
||||
assertEquals(selector.getAttribute(), result.getAttribute());
|
||||
assertEquals(selector.getFilter(), result.getFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_null() {
|
||||
//When + Then
|
||||
assertNull(SelectorMapper.toModel(null));
|
||||
assertNull(SelectorMapper.toModel(Types.Selector.getDefaultInstance()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toModel_notValidScheme() {
|
||||
//Given
|
||||
var selector = Types.Selector.newBuilder()
|
||||
.setName("name")
|
||||
.setCount(1)
|
||||
.setClause(Types.Clause.SAME)
|
||||
.setAttribute("attribute")
|
||||
.setFilter("filter")
|
||||
.build();
|
||||
|
||||
//When + Then
|
||||
try (MockedStatic<SelectorClause> mockStatic = mockStatic(SelectorClause.class)) {
|
||||
mockStatic.when(() -> SelectorClause.get(Types.Clause.SAME.getNumber()))
|
||||
.thenReturn(null);
|
||||
|
||||
assertThrows(ProcessFrostFSException.class, () -> SelectorMapper.toModel(selector));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package info.frostfs.sdk.mappers.object;
|
|||
|
||||
import frostfs.object.Types;
|
||||
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -33,8 +34,8 @@ public class ObjectAttributeMapperTest {
|
|||
@Test
|
||||
void toGrpcMessages_null() {
|
||||
//When + Then
|
||||
assertNull(ObjectAttributeMapper.toGrpcMessages(null));
|
||||
assertNull(ObjectAttributeMapper.toGrpcMessages(Collections.emptyList()));
|
||||
assertTrue(CollectionUtils.isEmpty(ObjectAttributeMapper.toGrpcMessages(null)));
|
||||
assertTrue(CollectionUtils.isEmpty(ObjectAttributeMapper.toGrpcMessages(Collections.emptyList())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.frostfs.sdk.mappers.object.patch;
|
||||
|
||||
import info.frostfs.sdk.dto.object.patch.Range;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -32,8 +33,8 @@ public class RangeMapperTest {
|
|||
@Test
|
||||
void toGrpcMessages_null() {
|
||||
//When + Then
|
||||
assertNull(RangeMapper.toGrpcMessages(null));
|
||||
assertNull(RangeMapper.toGrpcMessages(Collections.emptyList()));
|
||||
assertTrue(CollectionUtils.isEmpty(RangeMapper.toGrpcMessages(null)));
|
||||
assertTrue(CollectionUtils.isEmpty(RangeMapper.toGrpcMessages(Collections.emptyList())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
26
pom.xml
26
pom.xml
|
@ -17,7 +17,7 @@
|
|||
</modules>
|
||||
|
||||
<properties>
|
||||
<revision>0.4.0</revision>
|
||||
<revision>0.7.0</revision>
|
||||
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
|
@ -128,6 +128,30 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
Loading…
Add table
Add a link
Reference in a new issue