Search in sources :

Example 6 with LoadBalancerPool

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());
    }
}
Also used : Context(com.att.cdp.zones.Context) LoadBalancerMember(com.att.cdp.zones.model.LoadBalancerMember) LoadBalancerListener(com.att.cdp.zones.model.LoadBalancerListener) ZoneException(com.att.cdp.exceptions.ZoneException) NetworkService(com.att.cdp.zones.NetworkService) LoadBalancerHealthMonitor(com.att.cdp.zones.model.LoadBalancerHealthMonitor) LoadBalancerPool(com.att.cdp.zones.model.LoadBalancerPool) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Context (com.att.cdp.zones.Context)6 LoadBalancerPool (com.att.cdp.zones.model.LoadBalancerPool)6 OpenStackContext (com.att.cdp.openstack.OpenStackContext)5 OpenStackLoadBalancerPool (com.att.cdp.openstack.model.OpenStackLoadBalancerPool)5 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)5 Quantum (com.woorea.openstack.quantum.Quantum)5 LoadBalancerResource (com.woorea.openstack.quantum.api.LoadBalancerResource)3 ArrayList (java.util.ArrayList)2 ZoneException (com.att.cdp.exceptions.ZoneException)1 NetworkService (com.att.cdp.zones.NetworkService)1 LoadBalancerHealthMonitor (com.att.cdp.zones.model.LoadBalancerHealthMonitor)1 LoadBalancerListener (com.att.cdp.zones.model.LoadBalancerListener)1 LoadBalancerMember (com.att.cdp.zones.model.LoadBalancerMember)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1