Create the Cluster Object
A cluster, in terms of Oracle VM, is a child object of a server pool. The WsDevClient class in the sample code includes an example where a cluster object is created for the server pool created in the previous example. The code is straightforward:
... // Create a new cluster Cluster testCluster = new Cluster(); testCluster.setName(testClusterName); final Job clusterCreateJob = api.serverPoolCreateCluster(testPoolId, testCluster); System.out.println("create cluster job id: " + clusterCreateJob.getId()); testClusterId = waitForJobComplete(api, clusterCreateJob, Cluster.class);
A cluster object only requires that a name is set for the object instance. Once this has been done, the serverPoolCreateCluster method is called from the OvmWsRestClient class. Note that two parameters are passed to this method: the server pool ID value, obtained during the creation of the server pool, and the cluster object itself. The code for the serverPoolCreateCluster method is presented below:
@Override public Job serverPoolCreateCluster(final Id<ServerPool> serverPoolId, final Cluster cluster) throws WsException { return createChildObject(serverPoolId, cluster); }
As expected, this method uses a more generic method that allows you to create a child object for any ObjectType. This method is reused for other actions later in this guide. Once again, the createChildObject method in OvmWsRestClient uses the Jersey Builder to construct the SOAP message:
public <O extends BaseObject<O>, P extends BaseObject<P>> Job createChildObject(final Id<P> parentId, final O newObject, final Map<String, Object> queryParameters) throws WsException { try { final Builder b = getResourceForCreateChild(parentId, newObject.getClass(), queryParameters); return b.type(getMediaType()).post(Job.class, createJAXBElement(newObject)); } catch (final UniformInterfaceException ex) { throw convertException(ex); } }
Create a Cluster Heartbeat Device
A cluster requires a heartbeat device that can be located on shared storage accessible to all servers that get added to the server pool. For this purpose, we need to create the heartbeat device as a child object of the cluster object. The WsDevClient class contains an example of this:
ClusterHeartbeatDevice hbDevice = new ClusterHeartbeatDevice(); hbDevice.setName(clusterHeartbeatDeviceName); hbDevice.setStorageType(clusterHeartbeatStorageDeviceType); switch (clusterHeartbeatStorageDeviceType) { case NFS: hbDevice.setNetworkFileSystemId(clusterHeartbeatNetworkFileSystem.getId()); break; case STORAGE_ELEMENT: hbDevice.setStorageElementId(clusterHeartbeatStorageElement.getId()); break; default: throw new Exception( "Invalid cluster heartbeat storage device type: " + clusterHeartbeatStorageDeviceType); } final Job hbDeviceCreateJob = api.clusterCreateHeartbeatDevice(testClusterId, hbDevice); System.out.println("create cluster heartbeat device job id: " + hbDeviceCreateJob.getId()); testHeartbeatDeviceId = waitForJobComplete(api, hbDeviceCreateJob, ClusterHeartbeatDevice.class);
The cluster heartbeat device requires a number of parameters
that need to be set before the object is created. In the
example, the code sets a variety of parameters based on
variables defined in the
WsDevClient.properties
file. This
provides the user of the example client with the option to
define whether to use an NFS storage repository or an
alternative such as an ISCSI LUN. Depending on the storage
device type selected, the appropriate heartbeat device
parameter, indicating the storage ID within Oracle VM Manager must be
set.
Once the heartbeat device object parameters are set, the clusterCreateHeartbeatDevice method is called from the OvmWsRestClient class. Since the heartbeat device is a child object of the cluster the method expects the parent cluster ID value, as well as the heartbeat device object:
@Override public Job clusterCreateHeartbeatDevice(final Id<Cluster> clusterId, final ClusterHeartbeatDevice heartbeatDevice) throws WsException { return createChildObject(clusterId, heartbeatDevice); }
As expected, this method calls the more generic createChildObject discussed earlier.