Search in sources :

Example 36 with ResourceUnavailableException

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

the class NetworkHelperImpl method sendCommandsToRouter.

@Override
public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException, ResourceUnavailableException {
    if (!checkRouterVersion(router)) {
        s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + ", minimal required version : " + NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId()));
        throw new ResourceUnavailableException("Unable to send command. Router requires upgrade", VirtualRouter.class, router.getId());
    }
    Answer[] answers = null;
    try {
        answers = _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Timed Out", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e);
    }
    if (answers == null || answers.length != cmds.size()) {
        return false;
    }
    // FIXME: Have to return state for individual command in the future
    boolean result = true;
    for (final Answer answer : answers) {
        if (!answer.getResult()) {
            result = false;
            break;
        }
    }
    return result;
}
Also used : Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 37 with ResourceUnavailableException

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

the class FirewallManagerImpl method applyFirewallRules.

@Override
public boolean applyFirewallRules(List<FirewallRuleVO> rules, boolean continueOnError, Account caller) {
    if (rules.size() == 0) {
        s_logger.debug("There are no firewall rules to apply");
        return true;
    }
    for (FirewallRuleVO rule : rules) {
        // load cidrs if any
        rule.setSourceCidrList(_firewallCidrsDao.getSourceCidrs(rule.getId()));
        rule.setDestinationCidrsList(_firewallDcidrsDao.getDestCidrs(rule.getId()));
    }
    if (caller != null) {
        _accountMgr.checkAccess(caller, null, true, rules.toArray(new FirewallRuleVO[rules.size()]));
    }
    try {
        if (!applyRules(rules, continueOnError, true)) {
            return false;
        }
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Failed to apply firewall rules due to : " + ex.getMessage());
        return false;
    }
    return true;
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO)

Example 38 with ResourceUnavailableException

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

the class LoadBalancingRulesManagerImpl method applyLbRules.

public boolean applyLbRules(List<LoadBalancingRule> rules, boolean continueOnError) throws ResourceUnavailableException {
    if (rules == null || rules.size() == 0) {
        s_logger.debug("There are no Load Balancing Rules to forward to the network elements");
        return true;
    }
    boolean success = true;
    Network network = _networkModel.getNetwork(rules.get(0).getNetworkId());
    List<PublicIp> publicIps = new ArrayList<PublicIp>();
    // get the list of public ip's owned by the network
    List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
    if (userIps != null && !userIps.isEmpty()) {
        for (IPAddressVO userIp : userIps) {
            PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
            publicIps.add(publicIp);
        }
    }
    // rules can not programmed unless IP is associated with network
    // service provider, so run IP assoication for
    // the network so as to ensure IP is associated before applying
    // rules (in add state)
    _ipAddrMgr.applyIpAssociations(network, false, continueOnError, publicIps);
    try {
        applyLbRules(network, rules);
    } catch (ResourceUnavailableException e) {
        if (!continueOnError) {
            throw e;
        }
        s_logger.warn("Problems with applying load balancing rules but pushing on", e);
        success = false;
    }
    // if all the rules configured on public IP are revoked then
    // dis-associate IP with network service provider
    _ipAddrMgr.applyIpAssociations(network, true, continueOnError, publicIps);
    return success;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 39 with ResourceUnavailableException

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

the class LoadBalancingRulesManagerImpl method updateLoadBalancerRule.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_UPDATE, eventDescription = "updating load balancer", async = true)
public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
    Account caller = CallContext.current().getCallingAccount();
    Long lbRuleId = cmd.getId();
    String name = cmd.getLoadBalancerName();
    String description = cmd.getDescription();
    String algorithm = cmd.getAlgorithm();
    LoadBalancerVO lb = _lbDao.findById(lbRuleId);
    LoadBalancerVO lbBackup = _lbDao.findById(lbRuleId);
    String customId = cmd.getCustomId();
    Boolean forDisplay = cmd.getDisplay();
    if (lb == null) {
        throw new InvalidParameterValueException("Unable to find lb rule by id=" + lbRuleId);
    }
    // check permissions
    _accountMgr.checkAccess(caller, null, true, lb);
    if (name != null) {
        lb.setName(name);
    }
    if (description != null) {
        lb.setDescription(description);
    }
    if (algorithm != null) {
        lb.setAlgorithm(algorithm);
    }
    if (customId != null) {
        lb.setUuid(customId);
    }
    if (forDisplay != null) {
        lb.setDisplay(forDisplay);
    }
    // Validate rule in LB provider
    LoadBalancingRule rule = getLoadBalancerRuleToApply(lb);
    if (!validateLbRule(rule)) {
        throw new InvalidParameterValueException("Modifications in lb rule " + lbRuleId + " are not supported.");
    }
    LoadBalancerVO tmplbVo = _lbDao.findById(lbRuleId);
    boolean success = _lbDao.update(lbRuleId, lb);
    // If algorithm is changed, have to reapply the lb config
    if ((algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0)) {
        try {
            lb.setState(FirewallRule.State.Add);
            _lbDao.persist(lb);
            applyLoadBalancerConfig(lbRuleId);
        } catch (ResourceUnavailableException e) {
            if (isRollBackAllowedForProvider(lb)) {
                /*
                     * NOTE : We use lb object to update db instead of lbBackup
                     * object since db layer will fail to update if there is no
                     * change in the object.
                     */
                if (lbBackup.getName() != null) {
                    lb.setName(lbBackup.getName());
                }
                if (lbBackup.getDescription() != null) {
                    lb.setDescription(lbBackup.getDescription());
                }
                if (lbBackup.getAlgorithm() != null) {
                    lb.setAlgorithm(lbBackup.getAlgorithm());
                }
                lb.setState(lbBackup.getState());
                _lbDao.update(lb.getId(), lb);
                _lbDao.persist(lb);
                s_logger.debug("LB Rollback rule id: " + lbRuleId + " while updating LB rule.");
            }
            s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
            success = false;
        }
    }
    if (!success) {
        throw new CloudRuntimeException("Failed to update load balancer rule: " + lbRuleId);
    }
    return lb;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ActionEvent(com.cloud.event.ActionEvent)

Example 40 with ResourceUnavailableException

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

the class NetworkHelperImpl method startVirtualRouter.

@Override
public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
        return start(router, user, caller, params, null);
    }
    if (router.getState() == State.Running) {
        s_logger.debug("Redundant router " + router.getInstanceName() + " is already running!");
        return router;
    }
    // We will wait until VR is up or fail
    if (router.getState() == State.Starting) {
        return waitRouter(router);
    }
    final DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
    DomainRouterVO result = null;
    assert router.getIsRedundantRouter();
    final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
    DomainRouterVO routerToBeAvoid = null;
    List<DomainRouterVO> routerList = null;
    if (networkIds.size() != 0) {
        routerList = _routerDao.findByNetwork(networkIds.get(0));
    } else if (router.getVpcId() != null) {
        routerList = _routerDao.listByVpcId(router.getVpcId());
    }
    if (routerList != null) {
        for (final DomainRouterVO rrouter : routerList) {
            if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) {
                if (routerToBeAvoid != null) {
                    throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" + ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" + rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class, rrouter.getDataCenterId());
                }
                routerToBeAvoid = rrouter;
            }
        }
    }
    if (routerToBeAvoid == null) {
        return start(router, user, caller, params, null);
    }
    // We would try best to deploy the router to another place
    final int retryIndex = 5;
    final ExcludeList[] avoids = new ExcludeList[5];
    avoids[0] = new ExcludeList();
    avoids[0].addPod(routerToBeAvoid.getPodIdToDeployIn());
    avoids[1] = new ExcludeList();
    avoids[1].addCluster(_hostDao.findById(routerToBeAvoid.getHostId()).getClusterId());
    avoids[2] = new ExcludeList();
    final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
    if (volumes != null && volumes.size() != 0) {
        avoids[2].addPool(volumes.get(0).getPoolId());
    }
    avoids[2].addHost(routerToBeAvoid.getHostId());
    avoids[3] = new ExcludeList();
    avoids[3].addHost(routerToBeAvoid.getHostId());
    avoids[4] = new ExcludeList();
    for (int i = 0; i < retryIndex; i++) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Try to deploy redundant virtual router:" + router.getHostName() + ", for " + i + " time");
        }
        plan.setAvoids(avoids[i]);
        try {
            result = start(router, user, caller, params, plan);
        } catch (final InsufficientServerCapacityException ex) {
            result = null;
        }
        if (result != null) {
            break;
        }
    }
    return result;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VolumeVO(com.cloud.storage.VolumeVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

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