Search in sources :

Example 51 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class BigSwitchBcfElement method applyFWRules.

@Override
public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
    SubnetUtils utils;
    String cidr = null;
    List<String> cidrList;
    for (FirewallRule r : rules) {
        if (r.getState() == FirewallRule.State.Revoke) {
            continue;
        }
        cidrList = r.getSourceCidrList();
        if (cidrList != null) {
            if (cidrList.size() > 1 || !r.getSourcePortEnd().equals(r.getSourcePortStart())) {
                throw new ResourceUnavailableException("One CIDR and one port only please.", Network.class, network.getId());
            } else {
                cidr = cidrList.get(0);
            }
        }
        if (cidr == null || cidr.equalsIgnoreCase("0.0.0.0/0")) {
            cidr = "";
        } else {
            utils = new SubnetUtils(cidr);
            if (!utils.getInfo().getNetworkAddress().equals(utils.getInfo().getAddress())) {
                throw new ResourceUnavailableException("Invalid CIDR in Firewall rule.", Network.class, network.getId());
            }
        }
    }
    updateBcfRouter(network);
    return true;
}
Also used : SubnetUtils(org.apache.commons.net.util.SubnetUtils) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) FirewallRule(com.cloud.network.rules.FirewallRule)

Example 52 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class NetscalerElement method applyGlobalLoadBalancerRule.

@Override
public boolean applyGlobalLoadBalancerRule(long zoneId, long physicalNetworkId, GlobalLoadBalancerConfigCommand gslbConfigCmd) throws ResourceUnavailableException {
    long zoneGslbProviderHosId = 0;
    // find the NetScaler device configured as gslb service provider in the
    // zone
    ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId, physicalNetworkId);
    if (nsGslbProvider == null) {
        String msg = "Unable to find a NetScaler configured as gslb service provider in zone " + zoneId;
        s_logger.debug(msg);
        throw new ResourceUnavailableException(msg, DataCenter.class, zoneId);
    }
    // get the host Id corresponding to NetScaler acting as GSLB service
    // provider in the zone
    zoneGslbProviderHosId = nsGslbProvider.getHostId();
    // send gslb configuration to NetScaler device
    Answer answer = _agentMgr.easySend(zoneGslbProviderHosId, gslbConfigCmd);
    if (answer == null || !answer.getResult()) {
        String msg = "Unable to apply global load balancer rule to the gslb service provider in zone " + zoneId;
        s_logger.debug(msg);
        throw new ResourceUnavailableException(msg, DataCenter.class, zoneId);
    }
    return true;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 53 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class NetscalerElement method applyElasticLoadBalancerRules.

public boolean applyElasticLoadBalancerRules(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return true;
    }
    String errMsg = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        try {
            lbDeviceVO = allocateLoadBalancerForNetwork(network);
        } catch (Exception e) {
            errMsg = "Could not allocate a NetSclaer load balancer for configuring elastic load balancer rules due to " + e.getMessage();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
        }
    }
    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, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            if (rule.isAutoScaleConfig()) {
                loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
            }
            loadBalancersToApply.add(loadBalancer);
        }
    }
    if (loadBalancersToApply.size() > 0) {
        int numLoadBalancersForCommand = loadBalancersToApply.size();
        LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
        LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(loadBalancersForCommand, null);
        HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        Answer answer = _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply elastic load balancer rules to the external load balancer appliance in zone " + network.getDataCenterId() + " due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) 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) HostVO(com.cloud.host.HostVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GlobalLoadBalancerConfigCommand(com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 54 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class NetscalerElement method applyStaticNats.

@Override
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    if (!canHandle(config, Service.StaticNat)) {
        return false;
    }
    boolean multiNetScalerDeployment = Boolean.valueOf(_configDao.getValue(Config.EIPWithMultipleNetScalersEnabled.key()));
    try {
        if (!multiNetScalerDeployment) {
            String errMsg;
            ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(config);
            if (lbDevice == null) {
                try {
                    lbDevice = allocateLoadBalancerForNetwork(config);
                } catch (Exception e) {
                    errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage();
                    s_logger.error(errMsg);
                    throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
                }
            }
            if (!isNetscalerDevice(lbDevice.getDeviceName())) {
                errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules.";
                s_logger.error(errMsg);
                throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
            }
            SetStaticNatRulesAnswer answer = null;
            List<StaticNatRuleTO> rulesTO = null;
            if (rules != null) {
                rulesTO = new ArrayList<StaticNatRuleTO>();
                for (StaticNat rule : rules) {
                    IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
                    StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                    rulesTO.add(ruleTO);
                }
            }
            SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, null);
            answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
            if (answer == null) {
                return false;
            } else {
                return answer.getResult();
            }
        } else {
            if (rules != null) {
                for (StaticNat rule : rules) {
                    // validate if EIP rule can be configured.
                    ExternalLoadBalancerDeviceVO lbDevice = getNetScalerForEIP(rule);
                    if (lbDevice == null) {
                        String errMsg = "There is no NetScaler device configured to perform EIP to guest IP address: " + rule.getDestIpAddress();
                        s_logger.error(errMsg);
                        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
                    }
                    List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
                    IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
                    StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                    rulesTO.add(ruleTO);
                    SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, null);
                    // send commands to configure INAT rule on the NetScaler
                    // device
                    SetStaticNatRulesAnswer answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
                    if (answer == null) {
                        String errMsg = "Failed to configure INAT rule on NetScaler device " + lbDevice.getHostId();
                        s_logger.error(errMsg);
                        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
                    }
                }
                return true;
            }
        }
        return true;
    } catch (Exception e) {
        s_logger.error("Failed to configure StaticNat rule due to " + e.getMessage());
        return false;
    }
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) 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) StaticNat(com.cloud.network.rules.StaticNat) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer)

Example 55 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class NetScalerVMManagerImpl method stopNetScalerVm.

protected VirtualRouter stopNetScalerVm(final long vmId, final boolean forced, final Account caller, final long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
    final DomainRouterVO netscalerVm = _routerDao.findById(vmId);
    s_logger.debug("Stopping NetScaler vm " + netscalerVm);
    if (netscalerVm == null || netscalerVm.getRole() != Role.NETSCALER_VM) {
        throw new InvalidParameterValueException("Can't find NetScaler vm by id specified");
    }
    _accountMgr.checkAccess(caller, null, true, netscalerVm);
    try {
        _itMgr.expunge(netscalerVm.getUuid());
        return _routerDao.findById(netscalerVm.getId());
    } catch (final Exception e) {
        throw new CloudRuntimeException("Unable to stop " + netscalerVm, e);
    }
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DomainRouterVO(com.cloud.vm.DomainRouterVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)446 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)191 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)175 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)153 ArrayList (java.util.ArrayList)99 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)91 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)74 Account (com.cloud.user.Account)62 DomainRouterVO (com.cloud.vm.DomainRouterVO)60 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)59 ConfigurationException (javax.naming.ConfigurationException)53 DB (com.cloud.utils.db.DB)52 ServerApiException (org.apache.cloudstack.api.ServerApiException)51 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)47 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)47 ActionEvent (com.cloud.event.ActionEvent)46 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)46 DataCenter (com.cloud.dc.DataCenter)45 ServerApiException (com.cloud.api.ServerApiException)43 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)42