use of com.att.cdp.zones.model.LoadBalancerPool in project AJSC by att.
the class TestNetworkService method testLoadBalancer.
/**
* Verifies all load balancer apis
*
* @throws ZoneException
* If the connection fails, user is not authorized, or the provider cannot perform the operation.
*/
@Ignore
@Test
public void testLoadBalancer() throws ZoneException {
Context context = connect();
NetworkService service = context.getNetworkService();
String poolName = "TestNewPool";
String tenantId = context.getTenant().getId();
String subnetId = "2de8b5a0-1f7d-4736-8655-874c506e8f1b";
// Step 1: Check if pool exists with this name
LoadBalancerPool loadBalancerPool = null;
try {
List<LoadBalancerPool> loadBalancePools = service.getLoadBalancerPoolByName(poolName);
assertNotNull(loadBalancePools);
if (loadBalancePools.size() == 1) {
loadBalancerPool = loadBalancePools.get(0);
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to find the pool with name: " + ze.getMessage());
}
// Step 2: If pool exists delete it
if (loadBalancerPool != null) {
try {
service.deleteLoadBalancerPool(loadBalancerPool);
List<LoadBalancerPool> loadBalancePools = service.getLoadBalancerPoolByName(poolName);
assertNotNull(loadBalancePools);
assertEquals(loadBalancePools.size(), 0);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer pool: " + ze.getMessage());
}
}
// Step 3: Create a new pool
try {
LoadBalancerPool testlbPool = new LoadBalancerPool();
testlbPool.setProtocol(ProtocolType.HTTP);
testlbPool.setName(poolName);
testlbPool.setSubnetId(subnetId);
testlbPool.setLbAlgorithm(AlgorithmType.ROUND_ROBIN);
loadBalancerPool = service.createLoadBalancerPool(testlbPool);
LoadBalancerPool returnedLoadBalancerPool = service.getLoadBalancerPoolById(loadBalancerPool.getId());
assertNotNull(returnedLoadBalancerPool);
assertEquals(returnedLoadBalancerPool.getName(), poolName);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer pool: " + ze.getMessage());
}
// Step 4: Create a new load balancer vip and assign to the pool
LoadBalancerListener loadBalancerListener = null;
try {
LoadBalancerListener testlbVIP = new LoadBalancerListener();
testlbVIP.setProtocol(ProtocolType.HTTP);
testlbVIP.setName("TestNewVip");
testlbVIP.setPoolId(loadBalancerPool.getId());
testlbVIP.setSubnetId(subnetId);
loadBalancerListener = service.createLoadBalancerListener(testlbVIP);
LoadBalancerListener returnedloadBalancerVIP = service.getLoadBalancerListenerById(loadBalancerListener.getId());
assertNotNull(returnedloadBalancerVIP);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer VIP: " + ze.getMessage());
}
// Step 5: Fetch load balancer vips
try {
List<LoadBalancerListener> loadBalanceVIPs = service.getLoadBalancerListeners();
assertNotNull(loadBalanceVIPs);
for (LoadBalancerListener loadBalanceVIP : loadBalanceVIPs) {
assertNotNull(loadBalanceVIP.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to fetch the test load balancer VIPs: " + ze.getMessage());
}
// Step 7: Create load balancer health monitor
LoadBalancerHealthMonitor loadBalancerHealthMonitor = null;
try {
LoadBalancerHealthMonitor testlbHM = new LoadBalancerHealthMonitor();
testlbHM.setType(ProtocolType.PING);
testlbHM.setMaxRetries(1);
loadBalancerHealthMonitor = service.createLoadBalancerHealthMonitor(testlbHM);
LoadBalancerHealthMonitor returnedloadBalancerHealthMonitor = service.getLoadBalancerHealthMonitorById(loadBalancerHealthMonitor.getId());
assertNotNull(returnedloadBalancerHealthMonitor);
assertNotNull(returnedloadBalancerHealthMonitor.getId());
List<LoadBalancerHealthMonitor> loadBalancerHealthMonitors = service.getLoadBalancerHealthMonitors();
assertNotNull(loadBalancerHealthMonitors);
for (LoadBalancerHealthMonitor monitor : loadBalancerHealthMonitors) {
assertNotNull(monitor.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer health monitor : " + ze.getMessage());
}
// associate the health monitor to pool
try {
service.associateLoadBalancerHealthMonitorWithPool(loadBalancerPool.getId(), loadBalancerHealthMonitor.getId());
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to associate health monitor to pool: " + ze.getMessage());
}
// Step 9: Create a new load balancer member and assign to the pool
LoadBalancerMember loadBalancerMember = null;
// test load balancer vip creation
try {
LoadBalancerMember testlbMember = new LoadBalancerMember();
testlbMember.setAddress("135.144.122.19");
testlbMember.setPoolId(loadBalancerPool.getId());
loadBalancerMember = service.createLoadBalancerMember(testlbMember);
LoadBalancerMember returnedLoadBalancerMembers = service.getLoadBalancerMemberById(loadBalancerMember.getId());
assertNotNull(returnedLoadBalancerMembers);
List<LoadBalancerMember> loadBalancerMembers = service.getLoadBalancerMembers();
assertNotNull(loadBalancerMembers);
for (LoadBalancerMember loadBalancerMembe : loadBalancerMembers) {
assertNotNull(loadBalancerMembe.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer member : " + ze.getMessage());
}
// Step 10: Fetch load balancer member
try {
List<LoadBalancerMember> loadBalanceMembers = service.getLoadBalancerMembers();
assertNotNull(loadBalanceMembers);
for (LoadBalancerMember loadBalanceMember : loadBalanceMembers) {
assertNotNull(loadBalanceMember.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to fetch the test load balancer members: " + ze.getMessage());
}
// Step 6: Delete load balancer vip
try {
assertNotNull(loadBalancerListener);
// test network deletion
service.deleteLoadBalancerListener(loadBalancerListener);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer vip: " + ze.getMessage());
}
// disassociate the health monitor to pool
try {
service.disassociateLoadBalancerHealthMonitorWithPool(loadBalancerPool.getId(), loadBalancerHealthMonitor.getId());
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to disassociate health monitor to pool: " + ze.getMessage());
}
// Step 11: Delete load balancer member
try {
assertNotNull(loadBalancerMember);
// test network deletion
service.deleteLoadBalancerMember(loadBalancerMember);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer member: " + ze.getMessage());
}
// Step 12: pool delete
if (loadBalancerPool != null) {
try {
service.deleteLoadBalancerPool(loadBalancerPool);
List<LoadBalancerPool> loadBalancePools = service.getLoadBalancerPoolByName(poolName);
assertNotNull(loadBalancePools);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer pool: " + ze.getMessage());
}
}
// Step 8: Delete load balancer health monitor
try {
LoadBalancerHealthMonitor loadBalancerHM = service.getLoadBalancerHealthMonitorById(loadBalancerHealthMonitor.getId());
assertNotNull(loadBalancerHM);
// test network deletion
service.deleteLoadBalancerHealthMonitor(loadBalancerHM);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer health montor: " + ze.getMessage());
}
}
Aggregations