Control API Enumerations
An Enumeration is a particular datatype with a restricted, named set of values. For example, a Pool has a limited set of load balancing algorithms that are represented by the Pool.LoadBalancingAlgorithm enumeration:
The enumeration is defined as follows:
Pool.LoadBalancingAlgorithm
enum Pool.LoadBalancingAlgorithm {
roundrobin, # Round Robin
wroundrobin, # Weighted Round Robin
cells, # Perceptive
connections, # Least Connections
wconnections, # Weighted Least Connections
responsetimes, # Fastest Response Time
random # Random node
}The Pool interface contains two methods that use that enumeration:
getLoadBalancingAlgorithm( names )
# Get the load balancing algorithms that each of the named pools uses.
Pool.LoadBalancingAlgorithm[] getLoadBalancingAlgorithm(
String[] names
)setLoadBalancingAlgorithm( names, values )
# Set the load balancing algorithms that each of the named pools uses.
void setLoadBalancingAlgorithm(
String[] names
Pool.LoadBalancingAlgorithm[] values
)Perl’s SOAP::Lite library correctly encodes enumerations in SOAP requests, so you can use them in a literal context:
$conn->setLoadBalancingAlgorithm( [ $poolName ], ['connections'] );In a SOAP response, you must provide a custom Deserializer so that the SOAP::Lite library can convert the values in the SOAP response into appropriate internal representations (in other words, literal strings):
BEGIN {
package MyDeserializer;
@MyDeserializer::ISA = 'SOAP::Deserializer';
sub typecast {
my( $self, $val, $name, $attrs, $children, $type ) = @_;
if( $type && $type =~ m@http://soap.zeus.com/zxtm/@ ) {
return $val;
}
return undef;
};
}
my $conn = SOAP::Lite
-> ns('http://soap.zeus.com/zxtm/1.0/Pool/')
-> proxy("$admin_server/soap")
-> deserializer( MyDeserializer->new );The following code sample illustrates how to use Control API methods that use enumerations:
#!/usr/bin/perl -w
use SOAP::Lite 0.6;
# Provide our own Deserializer to deserialize enums correctly
BEGIN {
package MyDeserializer;
@MyDeserializer::ISA = 'SOAP::Deserializer';
sub typecast {
my( $self, $val, $name, $attrs, $children, $type ) = @_;
if( $type && $type =~ m@http://soap.zeus.com/zxtm/@ ) {
return $val;
}
return undef;
};
}
# This is the url of the Admin Server
my $admin_server = 'https://username:password@host:9090';
# The pool to edit
my $poolName = $ARGV[0] or die "No pool specified";
my $conn = SOAP::Lite
-> ns('http://soap.zeus.com/zxtm/1.0/Pool/')
-> proxy("$admin_server/soap")
-> deserializer( MyDeserializer->new )
-> on_fault( sub {
my( $conn, $res ) = @_;
die ref $res?$res->faultstring:$conn->transport->status; } );
# Get the load balancing algorithm
my $res = $conn->getLoadBalancingAlgorithm( [ $poolName ] );
my $alg = @{$res->result}[0];
print "Pool $poolName uses load balancing algorithm $alg\n";
# Change the algorithm to least connections, and check it worked
$conn->setLoadBalancingAlgorithm( [ $poolName ], ['connections'] );
$res = $conn->getLoadBalancingAlgorithm( [ $poolName ] );
print "Algorithm has been changed to @{$res->result}[0]\n";
# Now change it back again
$conn->setLoadBalancingAlgorithm( [ $poolName ], [ $alg ] );
$res = $conn->getLoadBalancingAlgorithm( [ $poolName ] );
print "Algorithm changed back to @{$res->result}[0]\n";