Search in sources :

Example 1 with HealthCheckLBConfigAnswer

use of com.cloud.agent.api.routing.HealthCheckLBConfigAnswer in project cloudstack by apache.

the class NetscalerResource method execute.

private Answer execute(final HealthCheckLBConfigCommand cmd, final int numRetries) {
    final List<LoadBalancerTO> hcLB = new ArrayList<LoadBalancerTO>();
    try {
        if (_isSdx) {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        final LoadBalancerTO[] loadBalancers = cmd.getLoadBalancers();
        if (loadBalancers == null) {
            return new HealthCheckLBConfigAnswer(hcLB);
        }
        for (final LoadBalancerTO loadBalancer : loadBalancers) {
            final HealthCheckPolicyTO[] healthCheckPolicies = loadBalancer.getHealthCheckPolicies();
            if (healthCheckPolicies != null && healthCheckPolicies.length > 0 && healthCheckPolicies[0] != null) {
                final String nsVirtualServerName = generateNSVirtualServerName(loadBalancer.getSrcIp(), loadBalancer.getSrcPort());
                final com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding[] serviceBindings = com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding.get(_netscalerService, nsVirtualServerName);
                if (serviceBindings != null) {
                    for (final DestinationTO destination : loadBalancer.getDestinations()) {
                        final String nsServiceName = generateNSServiceName(destination.getDestIp(), destination.getDestPort());
                        for (final com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding binding : serviceBindings) {
                            if (nsServiceName.equalsIgnoreCase(binding.get_servicename())) {
                                destination.setMonitorState(binding.get_curstate());
                                break;
                            }
                        }
                    }
                    hcLB.add(loadBalancer);
                }
            }
        }
    } catch (final ExecutionException e) {
        s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e);
        if (shouldRetry(numRetries)) {
            return retry(cmd, numRetries);
        } else {
            return new HealthCheckLBConfigAnswer(hcLB);
        }
    } catch (final Exception e) {
        s_logger.error("Failed to execute HealthCheckLBConfigCommand due to ", e);
        if (shouldRetry(numRetries)) {
            return retry(cmd, numRetries);
        } else {
            return new HealthCheckLBConfigAnswer(hcLB);
        }
    }
    return new HealthCheckLBConfigAnswer(hcLB);
}
Also used : ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) DestinationTO(com.cloud.agent.api.to.LoadBalancerTO.DestinationTO) ExecutionException(com.cloud.utils.exception.ExecutionException) IOException(java.io.IOException) ConfigurationException(javax.naming.ConfigurationException) HealthCheckPolicyTO(com.cloud.agent.api.to.LoadBalancerTO.HealthCheckPolicyTO) com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding(com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ExecutionException(com.cloud.utils.exception.ExecutionException) com.citrix.netscaler.nitro.resource.config.ns.nsconfig(com.citrix.netscaler.nitro.resource.config.ns.nsconfig) com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding(com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding)

Example 2 with HealthCheckLBConfigAnswer

use of com.cloud.agent.api.routing.HealthCheckLBConfigAnswer in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method getLBHealthChecks.

@Override
public List<LoadBalancerTO> getLBHealthChecks(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    // Find the external load balancer in this zone
    long zoneId = network.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return null;
    }
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        s_logger.warn("There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning");
        return null;
    }
    HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
    boolean externalLoadBalancerIsInline = _networkMgr.isNetworkInlineMode(network);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External load balancer was asked to apply LB rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return null;
    }
    List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
    List<MappingState> mappingStates = new ArrayList<MappingState>();
    for (final LoadBalancingRule rule : loadBalancingRules) {
        boolean revoked = (FirewallRule.State.Revoke.equals(rule.getState()));
        String protocol = rule.getProtocol();
        String algorithm = rule.getAlgorithm();
        String uuid = rule.getUuid();
        String srcIp = rule.getSourceIp().addr();
        int srcPort = rule.getSourcePortStart();
        List<LbDestination> destinations = rule.getDestinations();
        if (externalLoadBalancerIsInline) {
            long sourceIpId = _networkModel.getPublicIpAddress(rule.getSourceIp().addr(), network.getDataCenterId()).getId();
            MappingNic nic = getLoadBalancingIpNic(zone, network, sourceIpId, revoked, null);
            mappingStates.add(nic.getState());
            Nic loadBalancingIpNic = nic.getNic();
            if (loadBalancingIpNic == null) {
                continue;
            }
            // Change the source IP address for the load balancing rule to
            // be the load balancing IP address
            srcIp = loadBalancingIpNic.getIPv4Address();
        }
        if ((destinations != null && !destinations.isEmpty()) || !rule.isAutoScaleConfig()) {
            boolean inline = _networkMgr.isNetworkInlineMode(network);
            LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            loadBalancersToApply.add(loadBalancer);
        }
    }
    try {
        if (loadBalancersToApply.size() > 0) {
            int numLoadBalancersForCommand = loadBalancersToApply.size();
            LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
            // LoadBalancerConfigCommand cmd = new
            // LoadBalancerConfigCommand(loadBalancersForCommand, null);
            HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand);
            long guestVlanTag = Integer.parseInt(BroadcastDomainType.getValue(network.getBroadcastUri()));
            cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
            HealthCheckLBConfigAnswer answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
            // easySend will return null on error
            return answer == null ? null : answer.getLoadBalancers();
        }
    } catch (Exception ex) {
        s_logger.error("Exception Occured ", ex);
    }
    //null return is handled by clients
    return null;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) HealthCheckLBConfigCommand(com.cloud.agent.api.routing.HealthCheckLBConfigCommand) HostVO(com.cloud.host.HostVO) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)

Example 3 with HealthCheckLBConfigAnswer

use of com.cloud.agent.api.routing.HealthCheckLBConfigAnswer in project cloudstack by apache.

the class NetscalerElement method getElasticLBRulesHealthCheck.

public List<LoadBalancerTO> getElasticLBRulesHealthCheck(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    HealthCheckLBConfigAnswer answer = null;
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return null;
    }
    String errMsg = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        s_logger.warn("There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning");
        return null;
    }
    if (!isNetscalerDevice(lbDeviceVO.getDeviceName())) {
        errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element can not be handle elastic load balancer rules.";
        s_logger.error(errMsg);
        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
    }
    List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
    for (int i = 0; i < loadBalancingRules.size(); i++) {
        LoadBalancingRule rule = loadBalancingRules.get(i);
        boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
        String protocol = rule.getProtocol();
        String algorithm = rule.getAlgorithm();
        String lbUuid = rule.getUuid();
        String srcIp = rule.getSourceIp().addr();
        int srcPort = rule.getSourcePortStart();
        List<LbDestination> destinations = rule.getDestinations();
        if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
            LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, null, rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            loadBalancersToApply.add(loadBalancer);
        }
    }
    if (loadBalancersToApply.size() > 0) {
        int numLoadBalancersForCommand = loadBalancersToApply.size();
        LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
        HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand);
        HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
        return answer.getLoadBalancers();
    }
    return null;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) HealthCheckLBConfigCommand(com.cloud.agent.api.routing.HealthCheckLBConfigCommand) HostVO(com.cloud.host.HostVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)

Example 4 with HealthCheckLBConfigAnswer

use of com.cloud.agent.api.routing.HealthCheckLBConfigAnswer in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImplTest method getLBHealthChecks.

@Test
public void getLBHealthChecks() throws ResourceUnavailableException, URISyntaxException {
    setupLBHealthChecksMocks();
    HealthCheckLBConfigAnswer answer = Mockito.mock(HealthCheckLBConfigAnswer.class);
    Mockito.when(answer.getLoadBalancers()).thenReturn(Collections.<LoadBalancerTO>emptyList());
    Mockito.when(_agentMgr.easySend(Mockito.anyLong(), Mockito.any(Command.class))).thenReturn(answer);
    Assert.assertNotNull(externalLoadBalancerDeviceManager.getLBHealthChecks(network, Arrays.asList(rule)));
}
Also used : Command(com.cloud.agent.api.Command) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) Test(org.junit.Test)

Aggregations

HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)4 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)3 ArrayList (java.util.ArrayList)3 HealthCheckLBConfigCommand (com.cloud.agent.api.routing.HealthCheckLBConfigCommand)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 HostVO (com.cloud.host.HostVO)2 ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)2 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)2 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)2 ConfigurationException (javax.naming.ConfigurationException)2 com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding (com.citrix.netscaler.nitro.resource.config.lb.lbvserver_service_binding)1 com.citrix.netscaler.nitro.resource.config.ns.nsconfig (com.citrix.netscaler.nitro.resource.config.ns.nsconfig)1 Command (com.cloud.agent.api.Command)1 DestinationTO (com.cloud.agent.api.to.LoadBalancerTO.DestinationTO)1 HealthCheckPolicyTO (com.cloud.agent.api.to.LoadBalancerTO.HealthCheckPolicyTO)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)1