Search in sources :

Example 1 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO in project cloudstack by apache.

the class ConfigureNetscalerLoadBalancerCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        ExternalLoadBalancerDeviceVO lbDeviceVO = _netsclarLbService.configureNetscalerLoadBalancer(this);
        if (lbDeviceVO != null) {
            NetscalerLoadBalancerResponse response = _netsclarLbService.createNetscalerLoadBalancerResponse(lbDeviceVO);
            response.setObjectName("netscalerloadbalancer");
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure netscaler load balancer due to internal error.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetscalerLoadBalancerResponse(com.cloud.api.response.NetscalerLoadBalancerResponse)

Example 2 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO in project cloudstack by apache.

the class AddNetscalerLoadBalancerCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        ExternalLoadBalancerDeviceVO lbDeviceVO = _netsclarLbService.addNetscalerLoadBalancer(this);
        if (lbDeviceVO != null) {
            NetscalerLoadBalancerResponse response = _netsclarLbService.createNetscalerLoadBalancerResponse(lbDeviceVO);
            response.setObjectName("netscalerloadbalancer");
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add netscaler load balancer due to internal error.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetscalerLoadBalancerResponse(com.cloud.api.response.NetscalerLoadBalancerResponse)

Example 3 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO in project cloudstack by apache.

the class NetscalerElement method listNetscalerLoadBalancers.

@Override
public List<ExternalLoadBalancerDeviceVO> listNetscalerLoadBalancers(ListNetscalerLoadBalancersCmd cmd) {
    Long physcialNetworkId = cmd.getPhysicalNetworkId();
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    PhysicalNetworkVO pNetwork = null;
    List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO>();
    if (physcialNetworkId == null && lbDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
    }
    if (lbDeviceId != null) {
        ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
        if (lbDeviceVo == null || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
            throw new InvalidParameterValueException("Could not find Netscaler load balancer device with ID: " + lbDeviceId);
        }
        lbDevices.add(lbDeviceVo);
        return lbDevices;
    }
    if (physcialNetworkId != null) {
        pNetwork = _physicalNetworkDao.findById(physcialNetworkId);
        if (pNetwork == null) {
            throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId);
        }
        lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.Netscaler.getName());
        return lbDevices;
    }
    return null;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 4 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO in project cloudstack by apache.

the class NetscalerElement method listNetworks.

@Override
public List<? extends Network> listNetworks(ListNetscalerLoadBalancerNetworksCmd cmd) {
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    List<NetworkVO> networks = new ArrayList<NetworkVO>();
    ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
    if (lbDeviceVo == null || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
        throw new InvalidParameterValueException("Could not find Netscaler load balancer device with ID " + lbDeviceId);
    }
    List<NetworkExternalLoadBalancerVO> networkLbMaps = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId);
    if (networkLbMaps != null && !networkLbMaps.isEmpty()) {
        for (NetworkExternalLoadBalancerVO networkLbMap : networkLbMaps) {
            NetworkVO network = _networkDao.findById(networkLbMap.getNetworkId());
            networks.add(network);
        }
    }
    return networks;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO)

Example 5 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO in project cloudstack by apache.

the class NetscalerElement method addNetscalerLoadBalancer.

@Override
public ExternalLoadBalancerDeviceVO addNetscalerLoadBalancer(AddNetscalerLoadBalancerCmd cmd) {
    String deviceName = cmd.getDeviceType();
    if (!isNetscalerDevice(deviceName)) {
        throw new InvalidParameterValueException("Invalid Netscaler device type");
    }
    URI uri;
    try {
        uri = new URI(cmd.getUrl());
    } catch (Exception e) {
        String msg = "Error parsing the url parameter specified in addNetscalerLoadBalancer command due to " + e.getMessage();
        s_logger.debug(msg);
        throw new InvalidParameterValueException(msg);
    }
    Map<String, String> configParams = new HashMap<String, String>();
    UrlUtil.parseQueryParameters(uri.getQuery(), false, configParams);
    boolean dedicatedUse = (configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null) ? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
    if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
        String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
        s_logger.debug(msg);
        throw new InvalidParameterValueException(msg);
    }
    if (cmd.isGslbProvider()) {
        if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName()) && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
            String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
            s_logger.debug(msg);
            throw new InvalidParameterValueException(msg);
        }
        if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
            String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
            s_logger.debug(msg);
            throw new InvalidParameterValueException(msg);
        }
        if (dedicatedUse) {
            throw new InvalidParameterValueException("NetScaler provisioned to be GSLB service provider can only be configured for shared usage.");
        }
    }
    if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) {
        throw new InvalidParameterValueException("NetScaler can be provisioned to be exclusive GSLB service provider" + " only if its being configured as GSLB service provider also.");
    }
    ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(), cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp());
    return lbDeviceVO;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) HashMap(java.util.HashMap) NetscalerResource(com.cloud.network.resource.NetscalerResource) URI(java.net.URI) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)36 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 ArrayList (java.util.ArrayList)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 NetworkExternalLoadBalancerVO (com.cloud.network.dao.NetworkExternalLoadBalancerVO)12 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)11 HostVO (com.cloud.host.HostVO)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 ConfigurationException (javax.naming.ConfigurationException)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)8 HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)5 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)5 URISyntaxException (java.net.URISyntaxException)5 Answer (com.cloud.agent.api.Answer)4 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)4 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4