2.6.6.1 Java

Creating a Server Pool in Java is a fairly straightforward operation. The WsDevClient class (the sample application) contains an example of this:

...
// Create a new server pool
ServerPool testPool = new ServerPool();
testPool.setName(testServerPoolName);
testPool.setVirtualIp(testServerPoolIp);

final Job serverPoolCreateJob = api.serverPoolCreate(testPool);
System.out.println("create server pool job id: " + serverPoolCreateJob.getId());
testPoolId = waitForJobComplete(api, serverPoolCreateJob, ServerPool.class); 

In this example, we create a new ServerPool object using the ServerPool model provided by the Oracle VM Manager client model library included in the SDK. Using this model, we set various parameters specific to the object. In this case, we only set the required parameters which include the server pool name and the server pool virtual IP address. In the example code, these are set to the values defined for these variables in the WsDevClient.properties file.

As described previously, a Job object is populated immediately in the return value provided by the serverPoolCreate method. We use this object to call the waitForJobComplete method, which ensures that the server pool object is successfully created before continuing. We use the return value from the waitForJobComplete method to populate testPoolId value, which we use later to handle other server pool related activity for the newly created server pool.

The serverPoolCreate method is called from the OvmWsRestClient class, where the following code is defined:

    @Override
    public Job serverPoolCreate(final ServerPool serverPool) throws WsException
    {
        return create(serverPool);
    }

As you can see, the action uses a more generic method defined within OvmWsRestClient which can be applied to create any ObjectType. This code uses the Jersey Builder to create the required REST request, and creates the required XML using the Java object that is passed to the method:

public <T extends BaseObject<T>> Job create(final T newObject) throws WsException
{
    try
     {
        final Builder b = getResourceForType(newObject.getClass());
        return b.type(getMediaType()).post(Job.class, createJAXBElement(newObject));
     }
    catch (final UniformInterfaceException ex)
     {
        throw convertException(ex);
     }
}