[#2] update examples for v0.6.0
This commit is contained in:
parent
8314427dfe
commit
0170ab226f
4 changed files with 81 additions and 9 deletions
2
pom.xml
2
pom.xml
|
@ -24,7 +24,7 @@
|
|||
<dependency>
|
||||
<groupId>info.frostfs.sdk</groupId>
|
||||
<artifactId>client</artifactId>
|
||||
<version>0.3.0</version>
|
||||
<version>0.6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -2,27 +2,33 @@ package info.frostfs.sdk.examples;
|
|||
|
||||
import info.frostfs.sdk.ArrayHelper;
|
||||
import info.frostfs.sdk.FrostFSClient;
|
||||
import info.frostfs.sdk.dto.ape.*;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import info.frostfs.sdk.dto.container.Container;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
|
||||
import info.frostfs.sdk.dto.netmap.Replica;
|
||||
import info.frostfs.sdk.dto.object.ObjectAttribute;
|
||||
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.enums.BasicAcl;
|
||||
import info.frostfs.sdk.enums.ObjectType;
|
||||
import info.frostfs.sdk.enums.*;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
|
||||
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectClientCutPut;
|
||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectDelete;
|
||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectGet;
|
||||
import info.frostfs.sdk.jdo.parameters.object.PrmObjectSearch;
|
||||
import info.frostfs.sdk.utils.WaitUtil;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
|
@ -34,6 +40,11 @@ public class ObjectExample {
|
|||
prmContainerCreate.getContainer().getAttributes().put("__SYSTEM__DISABLE_HOMOMORPHIC_HASHING", "false");
|
||||
var containerId = frostFSClient.createContainer(prmContainerCreate, callContext);
|
||||
|
||||
frostFSClient.addChain(generatePrmApeChainAdd(containerId), callContext);
|
||||
|
||||
//Some wait
|
||||
WaitUtil.sleep(10000);
|
||||
|
||||
//CREATE
|
||||
ObjectId oid;
|
||||
try (FileInputStream file = new FileInputStream("/home/ori/Desktop/DemoExample/cat.jpg")) {
|
||||
|
@ -44,7 +55,7 @@ public class ObjectExample {
|
|||
.payload(file)
|
||||
.bufferMaxSize(1024)
|
||||
.build();
|
||||
oid = frostFSClient.putClientCutObject(prmObjectPut, callContext);
|
||||
oid = frostFSClient.putClientCutObject(prmObjectPut, new CallContext(10, TimeUnit.MINUTES));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -80,4 +91,24 @@ public class ObjectExample {
|
|||
var prmContainerDelete = new PrmContainerDelete(containerId);
|
||||
frostFSClient.deleteContainer(prmContainerDelete, callContext);
|
||||
}
|
||||
|
||||
private static PrmApeChainAdd generatePrmApeChainAdd(ContainerId containerId) {
|
||||
var chainTarget = new ChainTarget(containerId.getValue(), TargetType.CONTAINER);
|
||||
var resources = new Resources(false, new String[]{"native:object/*"});
|
||||
var actions = new Actions(false, new String[]{"*"});
|
||||
var rule = new Rule();
|
||||
rule.setStatus(RuleStatus.ALLOW);
|
||||
rule.setResources(resources);
|
||||
rule.setActions(actions);
|
||||
rule.setAny(false);
|
||||
rule.setConditions(new 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 new PrmApeChainAdd(chain, chainTarget);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ public class PoolExample {
|
|||
|
||||
public static void initPool(CallContext callContext) {
|
||||
//Init
|
||||
var nodeParam1 = new NodeParameters(1, "http://ip1:8080", 1);
|
||||
var nodeParam2 = new NodeParameters(1, "http://ip2:8080", 1);
|
||||
var nodeParam3 = new NodeParameters(1, "http://ip3:8080", 1);
|
||||
var nodeParam4 = new NodeParameters(1, "http://ip4:8080", 1);
|
||||
NodeParameters nodeParam1 = new NodeParameters(1, "http://10.78.130.160:8080", 1);
|
||||
NodeParameters nodeParam2 = new NodeParameters(1, "http://10.78.130.161:8080", 1);
|
||||
NodeParameters nodeParam3 = new NodeParameters(1, "http://10.78.130.167:8080", 1);
|
||||
NodeParameters nodeParam4 = new NodeParameters(2, "http://10.78.130.169:8080", 1);
|
||||
|
||||
PoolInitParameters initParameters = new PoolInitParameters();
|
||||
initParameters.setKey(new ECDsa("KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq"));
|
||||
initParameters.setKey(new ECDsa("L4NzJXAFDXxhBPY6CupwAATpCyhMSoQXyQesyLcJ79eQHnmVmuMh"));
|
||||
initParameters.setNodeParams(new NodeParameters[]{nodeParam1, nodeParam2, nodeParam3, nodeParam4});
|
||||
|
||||
|
||||
|
|
41
src/main/java/info/frostfs/sdk/examples/ape/ApeAddChain.java
Normal file
41
src/main/java/info/frostfs/sdk/examples/ape/ApeAddChain.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package info.frostfs.sdk.examples.ape;
|
||||
|
||||
import info.frostfs.sdk.FrostFSClient;
|
||||
import info.frostfs.sdk.dto.ape.*;
|
||||
import info.frostfs.sdk.dto.chain.ChainTarget;
|
||||
import info.frostfs.sdk.dto.container.ContainerId;
|
||||
import info.frostfs.sdk.enums.RuleMatchType;
|
||||
import info.frostfs.sdk.enums.RuleStatus;
|
||||
import info.frostfs.sdk.enums.TargetType;
|
||||
import info.frostfs.sdk.jdo.parameters.CallContext;
|
||||
import info.frostfs.sdk.jdo.parameters.ape.PrmApeChainAdd;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ApeAddChain {
|
||||
|
||||
public static void example(FrostFSClient frostFSClient, ContainerId containerId, CallContext callContext) {
|
||||
frostFSClient.addChain(generatePrmApeChainAdd(containerId), callContext);
|
||||
}
|
||||
|
||||
private static PrmApeChainAdd generatePrmApeChainAdd(ContainerId containerId) {
|
||||
var chainTarget = new ChainTarget(containerId.getValue(), TargetType.CONTAINER);
|
||||
var resources = new Resources(false, new String[]{"native:object/*"});
|
||||
var actions = new Actions(false, new String[]{"*"});
|
||||
var rule = new Rule();
|
||||
rule.setStatus(RuleStatus.ALLOW);
|
||||
rule.setResources(resources);
|
||||
rule.setActions(actions);
|
||||
rule.setAny(false);
|
||||
rule.setConditions(new 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 new PrmApeChainAdd(chain, chainTarget);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue