Search in sources :

Example 31 with NetworkRuleConflictException

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

the class BaremetalProvisionDoneNotificationCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        bmMgr.notifyProvisionDone(this);
        this.setResponseObject(new SuccessResponse(getCommandName()));
    } catch (Exception e) {
        s_logger.warn(String.format("unable to notify baremetal provision done[mac:%s]", mac), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 32 with NetworkRuleConflictException

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

the class AddBaremetalDhcpCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        BaremetalDhcpVO vo = mgr.addDchpServer(this);
        BaremetalDhcpResponse response = mgr.generateApiResponse(vo);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn("Unable to add external dhcp server with url: " + getUrl(), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : BaremetalDhcpVO(com.cloud.baremetal.database.BaremetalDhcpVO) BaremetalDhcpResponse(com.cloud.baremetal.networkservice.BaremetalDhcpResponse) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 33 with NetworkRuleConflictException

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

the class AddUcsManagerCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        UcsManagerResponse rsp = mgr.addUcsManager(this);
        rsp.setObjectName("ucsmanager");
        rsp.setResponseName(getCommandName());
        this.setResponseObject(rsp);
    } catch (Exception e) {
        s_logger.warn("Exception: ", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : UcsManagerResponse(org.apache.cloudstack.api.response.UcsManagerResponse) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 34 with NetworkRuleConflictException

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

the class FirewallManagerImpl method createFirewallRule.

@DB
protected FirewallRule createFirewallRule(final Long ipAddrId, Account caller, final String xId, final Integer portStart, final Integer portEnd, final String protocol, final List<String> sourceCidrList, final Integer icmpCode, final Integer icmpType, final Long relatedRuleId, final FirewallRule.FirewallRuleType type, final Long networkId, final FirewallRule.TrafficType trafficType, final Boolean forDisplay) throws NetworkRuleConflictException {
    IPAddressVO ipAddress = null;
    if (ipAddrId != null) {
        // this for ingress firewall rule, for egress id is null
        ipAddress = _ipAddressDao.findById(ipAddrId);
        // Validate ip address
        if (ipAddress == null && type == FirewallRule.FirewallRuleType.User) {
            throw new InvalidParameterValueException("Unable to create firewall rule; " + "couldn't locate IP address by id in the system");
        }
        _networkModel.checkIpForService(ipAddress, Service.Firewall, null);
    }
    validateFirewallRule(caller, ipAddress, portStart, portEnd, protocol, Purpose.Firewall, type, networkId, trafficType);
    // icmp code and icmp type can't be passed in for any other protocol rather than icmp
    if (!protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (icmpCode != null || icmpType != null)) {
        throw new InvalidParameterValueException("Can specify icmpCode and icmpType for ICMP protocol only");
    }
    if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO) && (portStart != null || portEnd != null)) {
        throw new InvalidParameterValueException("Can't specify start/end port when protocol is ICMP");
    }
    Long accountId = null;
    Long domainId = null;
    if (ipAddress != null) {
        //Ingress firewall rule
        accountId = ipAddress.getAllocatedToAccountId();
        domainId = ipAddress.getAllocatedInDomainId();
    } else if (networkId != null) {
        //egress firewall rule
        Network network = _networkModel.getNetwork(networkId);
        accountId = network.getAccountId();
        domainId = network.getDomainId();
    }
    final Long accountIdFinal = accountId;
    final Long domainIdFinal = domainId;
    return Transaction.execute(new TransactionCallbackWithException<FirewallRuleVO, NetworkRuleConflictException>() {

        @Override
        public FirewallRuleVO doInTransaction(TransactionStatus status) throws NetworkRuleConflictException {
            FirewallRuleVO newRule = new FirewallRuleVO(xId, ipAddrId, portStart, portEnd, protocol.toLowerCase(), networkId, accountIdFinal, domainIdFinal, Purpose.Firewall, sourceCidrList, icmpCode, icmpType, relatedRuleId, trafficType);
            newRule.setType(type);
            if (forDisplay != null) {
                newRule.setDisplay(forDisplay);
            }
            newRule = _firewallDao.persist(newRule);
            if (type == FirewallRuleType.User)
                detectRulesConflict(newRule);
            if (!_firewallDao.setStateToAdd(newRule)) {
                throw new CloudRuntimeException("Unable to update the state to add for " + newRule);
            }
            CallContext.current().setEventDetails("Rule Id: " + newRule.getId());
            return newRule;
        }
    });
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) TransactionStatus(com.cloud.utils.db.TransactionStatus) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) DB(com.cloud.utils.db.DB)

Example 35 with NetworkRuleConflictException

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

the class LoadBalancingRulesManagerImpl method createPublicLoadBalancerRule.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String description, int srcPortStart, int srcPortEnd, int defPortStart, int defPortEnd, Long ipAddrId, String protocol, String algorithm, long networkId, long lbOwnerId, boolean openFirewall, String lbProtocol, Boolean forDisplay) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
    Account lbOwner = _accountMgr.getAccount(lbOwnerId);
    if (srcPortStart != srcPortEnd) {
        throw new InvalidParameterValueException("Port ranges are not supported by the load balancer");
    }
    IPAddressVO ipVO = null;
    if (ipAddrId != null) {
        ipVO = _ipAddressDao.findById(ipAddrId);
    }
    Network network = _networkModel.getNetwork(networkId);
    // FIXME: breaking the dependency on ELB manager. This breaks
    // functionality of ELB using virtual router
    // Bug CS-15411 opened to document this
    // LoadBalancer result = _elbMgr.handleCreateLoadBalancerRule(lb,
    // lbOwner, lb.getNetworkId());
    LoadBalancer result = null;
    if (result == null) {
        IpAddress systemIp = null;
        NetworkOffering off = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        if (off.getElasticLb() && ipVO == null && network.getVpcId() == null) {
            systemIp = _ipAddrMgr.assignSystemIp(networkId, lbOwner, true, false);
            if (systemIp != null) {
                ipVO = _ipAddressDao.findById(systemIp.getId());
            }
        }
        // Validate ip address
        if (ipVO == null) {
            throw new InvalidParameterValueException("Unable to create load balance rule; can't find/allocate source IP");
        } else if (ipVO.isOneToOneNat()) {
            throw new NetworkRuleConflictException("Can't do load balance on ip address: " + ipVO.getAddress());
        }
        boolean performedIpAssoc = false;
        try {
            if (ipVO.getAssociatedWithNetworkId() == null) {
                boolean assignToVpcNtwk = network.getVpcId() != null && ipVO.getVpcId() != null && ipVO.getVpcId().longValue() == network.getVpcId();
                if (assignToVpcNtwk) {
                    // set networkId just for verification purposes
                    _networkModel.checkIpForService(ipVO, Service.Lb, networkId);
                    s_logger.debug("The ip is not associated with the VPC network id=" + networkId + " so assigning");
                    ipVO = _ipAddrMgr.associateIPToGuestNetwork(ipAddrId, networkId, false);
                    performedIpAssoc = true;
                }
            } else {
                _networkModel.checkIpForService(ipVO, Service.Lb, null);
            }
            if (ipVO.getAssociatedWithNetworkId() == null) {
                throw new InvalidParameterValueException("Ip address " + ipVO + " is not assigned to the network " + network);
            }
            result = createPublicLoadBalancer(xId, name, description, srcPortStart, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, CallContext.current(), lbProtocol, forDisplay);
        } catch (Exception ex) {
            s_logger.warn("Failed to create load balancer due to ", ex);
            if (ex instanceof NetworkRuleConflictException) {
                throw (NetworkRuleConflictException) ex;
            }
            if (ex instanceof InvalidParameterValueException) {
                throw (InvalidParameterValueException) ex;
            }
        } finally {
            if (result == null && systemIp != null) {
                s_logger.debug("Releasing system IP address " + systemIp + " as corresponding lb rule failed to create");
                _ipAddrMgr.handleSystemIpRelease(systemIp);
            }
            // release ip address if ipassoc was perfored
            if (performedIpAssoc) {
                ipVO = _ipAddressDao.findById(ipVO.getId());
                _vpcMgr.unassignIPFromVpcNetwork(ipVO.getId(), networkId);
            }
        }
    }
    if (result == null) {
        throw new CloudRuntimeException("Failed to create load balancer rule: " + name);
    }
    return result;
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) LoadBalancer(com.cloud.network.rules.LoadBalancer) IPAddressVO(com.cloud.network.dao.IPAddressVO) IpAddress(com.cloud.network.IpAddress) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)44 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)19 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)18 ServerApiException (org.apache.cloudstack.api.ServerApiException)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)12 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 Network (com.cloud.network.Network)10 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)9 IPAddressVO (com.cloud.network.dao.IPAddressVO)9 DB (com.cloud.utils.db.DB)8 TransactionStatus (com.cloud.utils.db.TransactionStatus)8 ServerApiException (com.cloud.api.ServerApiException)6 Account (com.cloud.user.Account)6 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)6 SuccessResponse (org.apache.cloudstack.api.response.SuccessResponse)5 ActionEvent (com.cloud.event.ActionEvent)4 IpAddress (com.cloud.network.IpAddress)4 FirewallRule (com.cloud.network.rules.FirewallRule)4