2.6.8.1 Java

The WsDevClient class includes an example where a server is added to the test server pool. The code checks whether the server belongs to another server pool already, and removes it from the server pool if it does. It then goes on to perform the add operation. This provides an example of both activities. To keep things simple, the code presented in this guide focuses on the actual operations required to perform each action.

Adding a server to a server pool.

Although server objects are not technically child objects, in the case where a server is added to a server pool it is treated as if it was a child object for this action. Therefore, it is necessary to pass the serverPoolAddServer function both the server pool ID value and the server ID object. The code to do this, as extracted from the WsDevClient class in the sample code is as follows:

...
final Job job = api.serverPoolAddServer(testPoolId, testServer.getId());
System.out.println("add server to pool job id: " + job.getId());
waitForJobComplete(api, job); 

Since the action is effectively the same as adding a child object to its parent, the serverPoolAddServer method in the OvmWsRestClient class uses the more generic method addChildObject:

@Override
public Job serverPoolAddServer(final Id<ServerPool> serverPoolId, 
  final Id<Server> serverId) 
  throws WsException
{
    return addChildObject(serverPoolId, serverId);
}

The addChildObject method code follows:

public Job addChildObject(final Id<?> parent, final Id<?> child) throws WsException
{
    try
    {
        return action(parent, "add" + getSimpleName(child.getType()), child);
    }
    catch (final UniformInterfaceException ex)
    {
        throw convertException(ex);
    }
}
Removing a server from a server pool.

Removing a server from a server pool in Java is a similar process to adding one. Example code extracted from the WsDevClient class in the sample code follows:

final Id<ServerPool> testServerPoolId = testServer.getServerPoolId();
Job job = api.serverPoolRemoveServer(testServerPoolId, testServer.getId());
System.out.println("remove server from pool job id: " + job.getId());
waitForJobComplete(api, job);

In a similar manner to other more generic operations, the serverPoolRemoveServer method in the OvmWsRestClient class actually refers to the generic removeChildObject method:

public Job removeChildObject(final Id<?> parent, final Id<?> child) 
 throws WsException
 {
     try
     {
         return action(parent, "remove" + getSimpleName(child.getType()), child);
     }
     catch (final UniformInterfaceException ex)
     {
         throw convertException(ex);
     }
 }

It is important to understand that although the behavior of removing a server from a server pool is essentially the same as removing a child object from its parent, a server is not really a child object. The distinction is important, since the removal of a server pool object cannot result in the removal of the server. Technically, Oracle VM Manager does not allow you to remove a server pool until all of the servers have been removed from it, but the distinction remains.