Search in sources :

Example 1 with LoadBalancerHealthMonitor

use of com.att.cdp.zones.model.LoadBalancerHealthMonitor in project AJSC by att.

the class OpenStackNetworkService method createLoadBalancerHealthMonitor.

/**
 * @see com.att.cdp.zones.NetworkService#createLoadBalancerHealthMonitor(com.att.cdp.zones.model.LoadBalancerHealthMonitor)
 */
@Override
public LoadBalancerHealthMonitor createLoadBalancerHealthMonitor(LoadBalancerHealthMonitor loadBalancerHealthMonitor) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Network");
    RequestState.put(RequestState.SERVICE_URL, quantumConnector.getEndpoint());
    try {
        Quantum client = quantumConnector.getClient();
        com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor loadBalancerHealthMonitorToCreate = new com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor();
        if (loadBalancerHealthMonitor.getType() != null) {
            loadBalancerHealthMonitorToCreate.setType(loadBalancerHealthMonitor.getType().name());
        }
        loadBalancerHealthMonitorToCreate.setDelay(loadBalancerHealthMonitor.getDelay());
        loadBalancerHealthMonitorToCreate.setTimeout(loadBalancerHealthMonitor.getTimeout());
        loadBalancerHealthMonitorToCreate.setMaxRetries(loadBalancerHealthMonitor.getMaxRetries());
        loadBalancerHealthMonitorToCreate.setUrlPath(loadBalancerHealthMonitor.getUrlPath());
        loadBalancerHealthMonitorToCreate.setExpectedCodes(loadBalancerHealthMonitor.getExpectedCodes());
        com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor openstackLbMonitor = client.lbaas().HealthMonitor().create(loadBalancerHealthMonitorToCreate).execute();
        return new OpenStackLoadBalancerHealthMonitor(context, openstackLbMonitor);
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Quantum(com.woorea.openstack.quantum.Quantum) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackLoadBalancerHealthMonitor(com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor) LoadBalancerHealthMonitor(com.att.cdp.zones.model.LoadBalancerHealthMonitor) OpenStackLoadBalancerHealthMonitor(com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor)

Example 2 with LoadBalancerHealthMonitor

use of com.att.cdp.zones.model.LoadBalancerHealthMonitor in project AJSC by att.

the class OpenStackNetworkService method getLoadBalancerHealthMonitors.

/**
 * @see com.att.cdp.zones.NetworkService#getLoadBalancerHealthMonitors()
 */
@Override
public List<LoadBalancerHealthMonitor> getLoadBalancerHealthMonitors() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Network");
    RequestState.put(RequestState.SERVICE_URL, quantumConnector.getEndpoint());
    ArrayList<LoadBalancerHealthMonitor> list = new ArrayList<>();
    try {
        Quantum client = quantumConnector.getClient();
        LoadBalancerResource.HealthMonitor resource = client.lbaas().HealthMonitor();
        for (com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor loadBalancerHealthMonitor : resource.list().execute()) {
            list.add(new OpenStackLoadBalancerHealthMonitor(context, loadBalancerHealthMonitor));
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList) OpenStackLoadBalancerHealthMonitor(com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor) LoadBalancerHealthMonitor(com.att.cdp.zones.model.LoadBalancerHealthMonitor) LoadBalancerResource(com.woorea.openstack.quantum.api.LoadBalancerResource) Quantum(com.woorea.openstack.quantum.Quantum) OpenStackLoadBalancerHealthMonitor(com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor)

Example 3 with LoadBalancerHealthMonitor

use of com.att.cdp.zones.model.LoadBalancerHealthMonitor in project AJSC by att.

the class OpenStackNetworkService method updateLoadBalancerHealthMonitor.

/**
 * @see com.att.cdp.zones.NetworkService#updateLoadBalancerHealthMonitor(com.att.cdp.zones.model.LoadBalancerHealthMonitor)
 */
@SuppressWarnings("nls")
@Override
public LoadBalancerHealthMonitor updateLoadBalancerHealthMonitor(LoadBalancerHealthMonitor loadBalancerHealthMonitor) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Network");
    RequestState.put(RequestState.SERVICE_URL, quantumConnector.getEndpoint());
    try {
        Quantum client = quantumConnector.getClient();
        com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor loadBalancerHealthMonitorToCreate = new com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor();
        if (loadBalancerHealthMonitor.getType() != null) {
            loadBalancerHealthMonitorToCreate.setType(loadBalancerHealthMonitor.getType().name());
        }
        loadBalancerHealthMonitorToCreate.setDelay(loadBalancerHealthMonitor.getDelay());
        loadBalancerHealthMonitorToCreate.setTimeout(loadBalancerHealthMonitor.getTimeout());
        loadBalancerHealthMonitorToCreate.setMaxRetries(loadBalancerHealthMonitor.getMaxRetries());
        loadBalancerHealthMonitorToCreate.setUrlPath(loadBalancerHealthMonitor.getUrlPath());
        loadBalancerHealthMonitorToCreate.setExpectedCodes(loadBalancerHealthMonitor.getExpectedCodes());
        com.woorea.openstack.quantum.model.LoadBalancerHealthMonitor openstackLbMonitor = client.lbaas().HealthMonitor().update(loadBalancerHealthMonitorToCreate).execute();
        return new OpenStackLoadBalancerHealthMonitor(context, openstackLbMonitor);
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Quantum(com.woorea.openstack.quantum.Quantum) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackLoadBalancerHealthMonitor(com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor) LoadBalancerHealthMonitor(com.att.cdp.zones.model.LoadBalancerHealthMonitor) OpenStackLoadBalancerHealthMonitor(com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor)

Example 4 with LoadBalancerHealthMonitor

use of com.att.cdp.zones.model.LoadBalancerHealthMonitor 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)4 LoadBalancerHealthMonitor (com.att.cdp.zones.model.LoadBalancerHealthMonitor)4 OpenStackContext (com.att.cdp.openstack.OpenStackContext)3 OpenStackLoadBalancerHealthMonitor (com.att.cdp.openstack.model.OpenStackLoadBalancerHealthMonitor)3 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)3 Quantum (com.woorea.openstack.quantum.Quantum)3 ZoneException (com.att.cdp.exceptions.ZoneException)1 NetworkService (com.att.cdp.zones.NetworkService)1 LoadBalancerListener (com.att.cdp.zones.model.LoadBalancerListener)1 LoadBalancerMember (com.att.cdp.zones.model.LoadBalancerMember)1 LoadBalancerPool (com.att.cdp.zones.model.LoadBalancerPool)1 LoadBalancerResource (com.woorea.openstack.quantum.api.LoadBalancerResource)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1