Java implementation of FrostFS SDK
sdk
Find a file
Ori Bruk 33f7198ace
All checks were successful
DCO / DCO (pull_request) Successful in 25s
Verify code phase / Verify code (pull_request) Successful in 1m32s
[#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance.
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
2025-01-30 14:00:41 +03:00
.forgejo/workflows [#21] add forgejo maven verify action 2024-10-29 13:18:18 +03:00
client [#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance. 2025-01-30 14:00:41 +03:00
cryptography [#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance. 2025-01-30 14:00:41 +03:00
exceptions [#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance. 2025-01-30 14:00:41 +03:00
models [#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance. 2025-01-30 14:00:41 +03:00
protos [#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance. 2025-01-30 14:00:41 +03:00
.gitignore [#1] Define SDK structure, add operations with container and object 2024-07-24 15:49:11 +03:00
checkstyle.xml [#27] Add more modules to CheckStyle 2024-11-13 17:17:29 +03:00
CODEOWNERS [#31] Add CODEOWNERS 2024-12-10 18:52:58 +03:00
CONTRIBUTING.md [#1] Define SDK structure, add operations with container and object 2024-07-24 15:49:11 +03:00
LICENSE Initial commit 2024-05-23 10:51:32 +03:00
pom.xml [#37] Add tree service methods: getRange(), getRangeHash(), patchObject(). Maven project version inheritance. 2025-01-30 14:00:41 +03:00
README.md [#34] Provide input parameters for all grpc methods 2025-01-23 19:23:06 +03:00

frostfs-sdk-java

Java implementation of FrostFS SDK

Prerequisites

Get the key for your wallet

  1. Get the address
cat <path_to_your_wallet> | jq .accounts[0].address | tr -d '"'
  1. Get the key
neo-go wallet export -w <path_to_your_wallet> -d <address_from_p1>

Example usage

Container operations

import info.frostfs.sdk.FrostFSClient;
import info.frostfs.sdk.dto.container.Container;
import info.frostfs.sdk.dto.netmap.PlacementPolicy;
import info.frostfs.sdk.dto.netmap.Replica;
import info.frostfs.sdk.enums.BasicAcl;
import info.frostfs.sdk.jdo.ClientSettings;
import info.frostfs.sdk.jdo.parameters.CallContext;
import info.frostfs.sdk.jdo.parameters.container.PrmContainerCreate;
import info.frostfs.sdk.jdo.parameters.container.PrmContainerDelete;
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGet;
import info.frostfs.sdk.jdo.parameters.container.PrmContainerGetAll;

public class ContainerExample {

    public void example() {
        var callContext = new CallContext();
        ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
        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 containerId = frostFSClient.createContainer(prmContainerCreate, callContext);

        // Get container
        var prmContainerGet = new PrmContainerGet(containerId);
        var container = frostFSClient.getContainer(prmContainerGet, callContext);

        // List containers
        var containerIds = frostFSClient.listContainers(new PrmContainerGetAll(), callContext);

        // Delete container
        var prmContainerDelete = new PrmContainerDelete(containerId);
        frostFSClient.deleteContainer(prmContainerDelete, callContext);
    }
}

Object operations

import info.frostfs.sdk.dto.object.*;
import info.frostfs.sdk.enums.ObjectType;
import info.frostfs.sdk.jdo.ClientSettings;
import info.frostfs.sdk.jdo.parameters.CallContext;
import info.frostfs.sdk.jdo.parameters.object.*;
import org.apache.commons.lang3.ArrayUtils;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import static java.util.Objects.isNull;

public class ObjectExample {

    public void example() {
        CallContext callContext = new CallContext();
        ClientSettings clientSettings = new ClientSettings(<your_key>, <your_host>);
        FrostFSClient frostFSClient = new FrostFSClient(clientSettings);

        // Put object
        ObjectId objectId;
        try (FileInputStream file = new FileInputStream("/path/to/file/cat.jpg")) {
            var attribute = new ObjectAttribute("Filename", "cat.jpg");
            var cat = new ObjectHeader(containerId, ObjectType.REGULAR, attribute);
            var prmObjectPut = PrmObjectPut.builder().objectHeader(cat).build();
            var writer = frostFSClient.putObject(prmObjectPut, callContext);

            writer.write(file.readAllBytes());
            objectId = writer.complete();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        // Get object
        var prmObjectGet = new PrmObjectGet(containerId, oid);
        ObjectFrostFS object = frostFSClient.getObject(prmObjectGet, callContext);

        var reader = object.getObjectReader();
        var chunk = reader.readChunk();
        var length = chunk.length;
        byte[] buffer = null;
        while (length > 0) {
            buffer = isNull(buffer) ? chunk : ArrayHelper.concat(buffer, chunk);

            chunk = object.getObjectReader().readChunk();
            length = ArrayUtils.isEmpty(chunk) ? 0 : chunk.length;
        }

        try (FileOutputStream fos = new FileOutputStream("/path/to/file/newCat.jpg")) {
            fos.write(buffer);
        } catch (Exception ignored) {
        }

        // Get object header
        var prmObjectHeadGet = new PrmObjectHeadGet(containerId, objectId);
        var objectHeader = frostFSClient.getObjectHead(prmObjectHeadGet, callContext);

        // Search regular objects
        var prmObjectSearch = new PrmObjectSearch(containerId, new ObjectFilter.FilterByRootObject());
        var objectIds = frostFSClient.searchObjects(prmObjectSearch, callContext);

        // Delete object
        var prmObjectDelete = new PrmObjectDelete(containerId, objectId);
        frostFSClient.deleteObject(prmObjectDelete, callContext);
    }
}

Pool init

import info.frostfs.sdk.jdo.ECDsa;
import info.frostfs.sdk.jdo.parameters.CallContext;
import info.frostfs.sdk.jdo.pool.NodeParameters;
import info.frostfs.sdk.jdo.pool.PoolInitParameters;
import info.frostfs.sdk.pool.Pool;

public class PoolExample {

    public static void example() {
        CallContext callContext = new CallContext();

        //Init
        var nodeParam1 = new NodeParameters(1, <your_host1>, 1);
        var nodeParam2 = new NodeParameters(1, <your_host2>, 1);
        var nodeParam3 = new NodeParameters(1, <your_host3>, 1);
        var nodeParam4 = new NodeParameters(1, <your_host4>, 1);

        PoolInitParameters initParameters = new PoolInitParameters();
        initParameters.setKey(new ECDsa(<your_key>));
        initParameters.setNodeParams(new NodeParameters[]{nodeParam1, nodeParam2, nodeParam3, nodeParam4});


        Pool pool = new Pool(initParameters);

        //Dial (Required!)
        pool.dial(callContext);
    }
}