-
Notifications
You must be signed in to change notification settings - Fork 4
2.6 Defining a group hierarchy
It is possible to define a group hierarchy with subgroups and servers in a data center. For example:
GroupHierarchyConfig config = new GroupHierarchyConfig()
.name("Parent Group")
.subitems(
group("Group1").subitems(
group("Group1-1").subitems(
mysqlServer().count(2),
apacheHttpServer()
),
group("Group1-2").subitems(
group("Group1-2-1"),
nginxServer()
)
),
group("Group2")
);
In this code, mysqlServer
, apacheHttpServer
, and nginxServer
are instances of the CreateServerConfig
class. See example below:
apacheHttpServer = new CreateServerConfig()
.name("Apache")
.description(name)
.type(STANDARD)
.machine(new Machine()
.cpuCount(1)
.ram(2)
.antiAffinityPolicy(
AntiAffinityPolicy
.refByName()
.name("anti-affinity")
)
)
.template(Template.refByOs()
.dataCenter(US_CENTRAL_SALT_LAKE_CITY)
.type(CENTOS)
.version("6")
.architecture(x86_64)
)
.timeToLive(
ZonedDateTime.now().plusHours(2)
);
You can specify a structure with any number of similar servers, for example, mysqlServer().count(2)
.
The groupService.defineGroupHierarchy
call will create the defined hierarchy inside the GroupHierarchyConfig
object. First, all the specified groups will be generated. After that, the server creation process will be queued and servers will be created in parallel. This significantly decreases the time necessary for building a hierarchy.
The defineGroupHierarchy
call returns the queued operation that will be executed.
Here is an example:
OperationFuture<Group> future = groupService.defineGroupHierarchy(DE_FRANKFURT, config);
To ensure that the operation has been completed successfully, call waitUntilComplete()
:
OperationFuture<Group> finishedFuture = future.waitUntilComplete();
To get the result of a completed operation, call getResult()
:
Group rootGroupRef = finishedFuture.getResult();
Here, rootGroupRef
is the root group of the provided hierarchy ("Parent Group" in the config above).
There is also a class similar to GroupHierarchyConfig
, but it works for multiple data centers.
OperationFuture<List<Group>> results =
groupService.defineInfrastructure(
new InfrastructureConfig()
.dataCenters(DataCenter.DE_FRANKFURT).subitems(
group("Root Group", "Root Group Description").subitems(
group("Sub Group").subitems(
apacheHttpServer(),
mysqlServer()
),
nginxServer(),
new CreateServerConfig()
.name("SRV")
.type(null)
.machine(new Machine()
.cpuCount(1)
.ram(2)
.antiAffinityPolicy(
AntiAffinityPolicy
.refByName()
.name("anti-affinity")
)
)
)
),
new InfrastructureConfig()
.dataCenters(DataCenter.CA_TORONTO_1, DataCenter.US_CENTRAL_SALT_LAKE_CITY)
.subitems(new GroupHierarchyConfig()
.name(name("Parent Group"))
.subitems(
group(name("Group1-1")).subitems(
group(name("Group1-1-1")).subitems(
mysqlServer().count(2)
),
group(name("Group1-1-2")).subitems(
group(name("Group1-1-2-1")),
apacheHttpServer()
)
),
group(name("Group1-2")
)
)
)
);
List<Group> rootGroupRefs = results.waitUntilComplete().getResult();
rootGroupRefs
is the list of root groups in each data center defined in the config above.
- [Getting Started] (./1.-Getting-started)
- User Guide - Basic Functions
- Server management
- Server actions
- Managing groups
- Group actions
- Searching templates
- Searching data centers
- Invoice statistics
- SDK configuration
- User Guide - Advanced Functions
- Configuring remote servers over SSH
- Defining a group hierarchy
- Billing statistics
- Server monitoring statistics
- Policies management
- Shared load balancers management
- User Guide - Framework adapters