Skip to content

Creating a Container

Creates a container with the specified placement policy.

Arguments:

  1. Execution context
  2. Method arguments, which includes:
    • Container placement policy
    • Container attributes (optional)
    • Result wait parameters (optional)
    • Session token (optional)
    • Additional headers (optional)

Placement Policy includes:

  • Unique flag
  • Backup factor
  • Filters
  • Selectors
  • Replicas

Placement Policies are used to determine on which node(s) of the system an object will be stored. One way to represent a placement policy is to define a sequence of operations that create a selection based on node attributes.

Three main operations:

FILTER: Filters a set of nodes based on their attributes. The operation takes a set of nodes as input and returns a subset of these nodes. It is useful for selecting nodes that have (or do not have) specific attributes.

SELECT: Determines how many and which nodes from the subset previously obtained through filtering will be available to create replica groups for storing objects.

REP: Defines how many copies of an object need to be stored. A placement policy can contain multiple replication operations, each representing a replica group, i.e., a group of objects associated with the same replica.

The internal implementation verifies that the container has been created using periodic requests and the provided readiness wait parameters.

Note

After creating the container, it is also necessary to configure the access policy. For more detailed information, refer to the APE section.

Result:

  • ID of the created container
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var filter netmap.Filter
filter.SetName("filterByGermany")
filter.Equal("Country", "Germany")

var selector netmap.Selector
selector.SetName("selector")
selector.SetClause(1)
selector.SetNumberOfNodes(1)
selector.SetFilterName("filterByGermany")

var replica netmap.ReplicaDescriptor
replica.SetNumberOfObjects(1)
replica.SetSelectorName("selector")

var policy netmap.PlacementPolicy
policy.SetUnique(false)
policy.SetContainerBackupFactor(1)
policy.AddFilters(filter)
policy.AddSelectors(selector)
policy.AddReplicas(replica)

var owner user.ID
user.IDFromKey(&owner, acc.PrivateKey().PrivateKey.PublicKey)

var cnr container.Container
cnr.Init()
cnr.SetPlacementPolicy(policy)
cnr.SetOwner(owner)

container.SetCreationTime(&cnr, time.Now())

err = pool.SyncContainerWithNetwork(ctx, &cnr, p)
checkError(err)

prm := pool.PrmContainerPut{
    ClientParams: sdkClient.PrmContainerPut{
        Container: &cnr,
    },
}

cnrID, err := p.PutContainer(ctx, prm)
checkError(err) 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
public static ContainerId createContainer(FrostFSClient frostFSClient, CallContext callContext, SessionToken token) {
    Filter[] filters = new Filter[]{
            new Filter("filterByGermany", "Country", FilterOperation.EQ, "Germany", null)
    };

    Selector[] selectors = new Selector[]{
            new Selector("selector", 1, SelectorClause.SAME, null, "filterByGermany")
    };

    Replica[] replicas = new Replica[]{new Replica(1, "selector")};
    var placementPolicy = new PlacementPolicy(replicas, true, 0, filters, selectors);

    Container container = new Container(placementPolicy);
    container.setAttributes(Map.of("key", "value"));

    PrmWait prmWait = new PrmWait(Duration.ofSeconds(120L), Duration.ofSeconds(5L));

    var prmContainerCreate = new PrmContainerCreate(container, prmWait, token, Map.of("key", "value"));
    return frostFSClient.createContainer(prmContainerCreate, callContext);
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public static async Task<FrostFsContainerId> CreateContainerAsync(FrostFSClient client, FrostFsSessionToken token)
{
    bool unique = true;
    uint backupFactor = 3;

    Collection<FrostFsFilter> filters = [
        new (name: "filterByGermany", 
            key: "Country",
            operation: FrostFSOperation.Equals, 
            value: "Germany", 
            filters: [])
    ];

        Collection<FrostFsSelector> selectors = [
        new ("selector") {
            Count = 1,
            Clause = 1,
            Filter = "filterByGermany"
        } 
    ];

    Collection<FrostFsReplica> replicas = [new FrostFsReplica(1, "selector")];

    FrostFsPlacementPolicy policy = new (unique, backupFactor, selectors, filters, replicas);

    FrostFsAttributePair[] containerAttributes = [ new FrostFsAttributePair ("key", "value") ];

    FrostFsContainerInfo containerInfo = new (policy, containerAttributes);

    PrmWait prmWait = new(timeout: 30, interval: 5);

    PrmContainerCreate createContainerParam = new (
        containerInfo,
        prmWait,
        token,
        xheaders: ["key", "value"]);

    CallContext ctx = default;
    return await client.PutContainerAsync(createContainerParam, ctx);
}