Skip to content

2.4 Managing groups

jwebs1 edited this page Jul 6, 2015 · 3 revisions

This section overviews group management features available in the SDK. Note that in all examples groupService refers to the new ClcSdk().groupService() variable.

Creating groups

To create a group, you need to specify GroupConfig. The available properties are listed in the table below.

Name Type Description Required
name string The name of the group to be created Yes
description string A user-defined description of this group No
parentGroup Group A parent group reference Yes
Here is a sample group configuration: ``` java OperationFuture future = groupService .create(new GroupConfig() .name(newGroupName) .description(newGroupDescription) .parentGroup(Group.refByName() .dataCenter(DataCenter.DE_FRANKFURT) .name(Group.DEFAULT_GROUP) ) ); ```

Modifying groups

To modify a group, you need to specify GroupConfig. The list of available properties can be found in the table in the "Creating Groups" section (above). See this example:

OperationFuture<Group> future = 
groupService
    .modify(groupRef, new GroupConfig()
        .name(groupName)
        .description(groupDescription)
        .parentGroup(Group.refById()
            .dataCenter(DataCenter.DE_FRANKFURT)
            .id(parentGroupId)
        )
    )
    .waitUntilComplete();
        

It is possible to modify multiple groups specified by references or by a group filter.

OperationFuture<List<Group>> future = 
groupService
    .modify(asList(groupRef1, groupRef2), new GroupConfig()
        .name(groupName)
        .description(groupDescription)
        .parentGroup(Group.refById()
            .dataCenter(DataCenter.DE_FRANKFURT)
            .id(parentGroupId)
        )
    )
    .waitUntilComplete();

OperationFuture<List<Group>> future = 
groupService
    .modify(new GroupFilter().name("MyGroup"), new GroupConfig()
        .name(groupName)
        .description(groupDescription)
    )
    .waitUntilComplete();
        

Deleting groups

You may delete a group by reference or by some search criteria, like this:

groupService.delete(groupRef);

groupService.delete(groupRef1, groupRef2);

groupService.delete(new GroupFilter().name("MyGroup"));

Searching groups

It is possible to search groups, using search criteria provided by GroupFilter.

  1. Data center references (dataCenters(dataCenter1, dataCenter2))
  2. Group IDs (id("groupId1", "groupId2"))
  3. A group name, ignoring the case (nameContains("MyGroup"))
  4. A predicate (dataCentersWhere(d -> d.getGroup().getName().equals("groupName"))

Here is an example:

groupService.find(
    new GroupFilter()
        .dataCenters(dataCenter1, dataCenter2)
        .dataCentersWhere(d -> d.getGroup().equals("groupId"))
        .id("groupId1", "groupId2")
        .nameContains("MyGroup")
);

Groups can also be searched by a full group name match.

groupService.find(
    new GroupFilter()
        .dataCenters(dataCenter1, dataCenter2)
        .name("MyGroup")
);