Search in sources :

Example 16 with ResourceAllocationException

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

the class DeleteBaremetalRctCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        vlanMgr.deleteRct(this);
        SuccessResponse response = new SuccessResponse(getCommandName());
        setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn(String.format("unable to add baremetal RCT[%s]", getId()), e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) 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 17 with ResourceAllocationException

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

the class ListBaremetalRctCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    try {
        ListResponse<BaremetalRctResponse> response = new ListResponse<>();
        List<BaremetalRctResponse> rctResponses = new ArrayList<>();
        BaremetalRctResponse rsp = vlanMgr.listRct();
        if (rsp != null) {
            rctResponses.add(rsp);
        }
        response.setResponses(rctResponses);
        response.setResponseName(getCommandName());
        response.setObjectName("baremetalrcts");
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.debug("Exception happened while executing ListBaremetalRctCmd", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse) 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 18 with ResourceAllocationException

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

the class CommandCreationWorker method handle.

@Override
public void handle(final DispatchTask task) {
    final BaseCmd cmd = task.getCmd();
    if (cmd instanceof BaseAsyncCreateCmd) {
        try {
            CallContext.current().setEventDisplayEnabled(cmd.isDisplay());
            ((BaseAsyncCreateCmd) cmd).create();
        } catch (final ResourceAllocationException e) {
            throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, e.getMessage(), e);
        }
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ATTEMP_TO_CREATE_NON_CREATION_CMD);
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) BaseAsyncCreateCmd(org.apache.cloudstack.api.BaseAsyncCreateCmd) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) BaseCmd(org.apache.cloudstack.api.BaseCmd)

Example 19 with ResourceAllocationException

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

the class NetworkServiceImpl method commitNetwork.

private Network commitNetwork(final Long networkOfferingId, final String gateway, final String startIP, final String endIP, final String netmask, final String networkDomain, final String vlanId, final String name, final String displayText, final Account caller, final Long physicalNetworkId, final Long zoneId, final Long domainId, final boolean isDomainSpecific, final Boolean subdomainAccessFinal, final Long vpcId, final String startIPv6, final String endIPv6, final String ip6Gateway, final String ip6Cidr, final Boolean displayNetwork, final Long aclId, final String isolatedPvlan, final NetworkOfferingVO ntwkOff, final PhysicalNetwork pNtwk, final ACLType aclType, final Account ownerFinal, final String cidr, final boolean createVlan) throws InsufficientCapacityException, ResourceAllocationException {
    try {
        Network network = Transaction.execute(new TransactionCallbackWithException<Network, Exception>() {

            @Override
            public Network doInTransaction(TransactionStatus status) throws InsufficientCapacityException, ResourceAllocationException {
                Account owner = ownerFinal;
                Boolean subdomainAccess = subdomainAccessFinal;
                Long sharedDomainId = null;
                if (isDomainSpecific) {
                    if (domainId != null) {
                        sharedDomainId = domainId;
                    } else {
                        sharedDomainId = _domainMgr.getDomain(Domain.ROOT_DOMAIN).getId();
                        subdomainAccess = true;
                    }
                }
                // default owner to system if network has aclType=Domain
                if (aclType == ACLType.Domain) {
                    owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
                }
                // Create guest network
                Network network = null;
                if (vpcId != null) {
                    if (!_configMgr.isOfferingForVpc(ntwkOff)) {
                        throw new InvalidParameterValueException("Network offering can't be used for VPC networks");
                    }
                    if (aclId != null) {
                        NetworkACL acl = _networkACLDao.findById(aclId);
                        if (acl == null) {
                            throw new InvalidParameterValueException("Unable to find specified NetworkACL");
                        }
                        if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
                            // ACL should be associated with a VPC
                            if (!vpcId.equals(acl.getVpcId())) {
                                throw new InvalidParameterValueException("ACL: " + aclId + " do not belong to the VPC");
                            }
                        }
                    }
                    network = _vpcMgr.createVpcGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, aclId, caller, displayNetwork);
                } else {
                    if (_configMgr.isOfferingForVpc(ntwkOff)) {
                        throw new InvalidParameterValueException("Network offering can be used for VPC networks only");
                    }
                    if (ntwkOff.getInternalLb()) {
                        throw new InvalidParameterValueException("Internal Lb can be enabled on vpc networks only");
                    }
                    network = _networkMgr.createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, sharedDomainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr, displayNetwork, isolatedPvlan);
                }
                if (_accountMgr.isRootAdmin(caller.getId()) && createVlan && network != null) {
                    // Create vlan ip range
                    _configMgr.createVlanAndPublicIpRange(pNtwk.getDataCenterId(), network.getId(), physicalNetworkId, false, null, startIP, endIP, gateway, netmask, vlanId, null, null, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
                }
                return network;
            }
        });
        if (domainId != null && aclType == ACLType.Domain) {
            // send event for storing the domain wide resource access
            Map<String, Object> params = new HashMap<String, Object>();
            params.put(ApiConstants.ENTITY_TYPE, Network.class);
            params.put(ApiConstants.ENTITY_ID, network.getId());
            params.put(ApiConstants.DOMAIN_ID, domainId);
            params.put(ApiConstants.SUBDOMAIN_ACCESS, subdomainAccessFinal == null ? Boolean.TRUE : subdomainAccessFinal);
            _messageBus.publish(_name, EntityManager.MESSAGE_ADD_DOMAIN_WIDE_ENTITY_EVENT, PublishScope.LOCAL, params);
        }
        return network;
    } catch (Exception e) {
        ExceptionUtil.rethrowRuntime(e);
        ExceptionUtil.rethrow(e, InsufficientCapacityException.class);
        ExceptionUtil.rethrow(e, ResourceAllocationException.class);
        throw new IllegalStateException(e);
    }
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) TransactionStatus(com.cloud.utils.db.TransactionStatus) NetworkACL(com.cloud.network.vpc.NetworkACL) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException)

Example 20 with ResourceAllocationException

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

the class NetworkServiceImpl method createPrivateNetwork.

@Override
@DB
public Network createPrivateNetwork(final String networkName, final String displayText, long physicalNetworkId, String broadcastUriString, final String startIp, String endIp, final String gateway, String netmask, final long networkOwnerId, final Long vpcId, final Boolean sourceNat, final Long networkOfferingId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    final Account owner = _accountMgr.getAccount(networkOwnerId);
    // Get system network offering
    NetworkOfferingVO ntwkOff = null;
    if (networkOfferingId != null) {
        ntwkOff = _networkOfferingDao.findById(networkOfferingId);
    }
    if (ntwkOff == null) {
        ntwkOff = findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
    }
    // Validate physical network
    final PhysicalNetwork pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
    if (pNtwk == null) {
        InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a physical network" + " having the given id");
        ex.addProxyObject(String.valueOf(physicalNetworkId), "physicalNetworkId");
        throw ex;
    }
    // if end ip is not specified, default it to startIp
    if (!NetUtils.isValidIp(startIp)) {
        throw new InvalidParameterValueException("Invalid format for the ip address parameter");
    }
    if (endIp == null) {
        endIp = startIp;
    } else if (!NetUtils.isValidIp(endIp)) {
        throw new InvalidParameterValueException("Invalid format for the endIp address parameter");
    }
    if (!NetUtils.isValidIp(gateway)) {
        throw new InvalidParameterValueException("Invalid gateway");
    }
    if (!NetUtils.isValidNetmask(netmask)) {
        throw new InvalidParameterValueException("Invalid netmask");
    }
    final String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask);
    URI uri = BroadcastDomainType.fromString(broadcastUriString);
    final String uriString = uri.toString();
    BroadcastDomainType tiep = BroadcastDomainType.getSchemeValue(uri);
    // TODO make a test for any supported scheme
    if (!(tiep == BroadcastDomainType.Vlan || tiep == BroadcastDomainType.Lswitch)) {
        throw new InvalidParameterValueException("unsupported type of broadcastUri specified: " + broadcastUriString);
    }
    final NetworkOfferingVO ntwkOffFinal = ntwkOff;
    try {
        return Transaction.execute(new TransactionCallbackWithException<Network, Exception>() {

            @Override
            public Network doInTransaction(TransactionStatus status) throws ResourceAllocationException, InsufficientCapacityException {
                //lock datacenter as we need to get mac address seq from there
                DataCenterVO dc = _dcDao.lockRow(pNtwk.getDataCenterId(), true);
                //check if we need to create guest network
                Network privateNetwork = _networksDao.getPrivateNetwork(uriString, cidr, networkOwnerId, pNtwk.getDataCenterId(), networkOfferingId);
                if (privateNetwork == null) {
                    //create Guest network
                    privateNetwork = _networkMgr.createGuestNetwork(ntwkOffFinal.getId(), networkName, displayText, gateway, cidr, uriString, null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null, vpcId, null, null, true, null);
                    if (privateNetwork != null) {
                        s_logger.debug("Successfully created guest network " + privateNetwork);
                    } else {
                        throw new CloudRuntimeException("Creating guest network failed");
                    }
                } else {
                    s_logger.debug("Private network already exists: " + privateNetwork);
                    //Do not allow multiple private gateways with same Vlan within a VPC
                    if (vpcId != null && vpcId.equals(privateNetwork.getVpcId())) {
                        throw new InvalidParameterValueException("Private network for the vlan: " + uriString + " and cidr  " + cidr + "  already exists " + "for Vpc " + vpcId + " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
                    }
                }
                if (vpcId != null) {
                    //add entry to private_ip_address table
                    PrivateIpVO privateIp = _privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(), startIp, vpcId);
                    if (privateIp != null) {
                        throw new InvalidParameterValueException("Private ip address " + startIp + " already used for private gateway" + " in zone " + _entityMgr.findById(DataCenter.class, pNtwk.getDataCenterId()).getName());
                    }
                    Long mac = dc.getMacAddress();
                    Long nextMac = mac + 1;
                    dc.setMacAddress(nextMac);
                    privateIp = new PrivateIpVO(startIp, privateNetwork.getId(), nextMac, vpcId, sourceNat);
                    _privateIpDao.persist(privateIp);
                    _dcDao.update(dc.getId(), dc);
                }
                s_logger.debug("Private network " + privateNetwork + " is created");
                return privateNetwork;
            }
        });
    } catch (Exception e) {
        ExceptionUtil.rethrowRuntime(e);
        ExceptionUtil.rethrow(e, ResourceAllocationException.class);
        ExceptionUtil.rethrow(e, InsufficientCapacityException.class);
        throw new IllegalStateException(e);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) TransactionStatus(com.cloud.utils.db.TransactionStatus) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) URI(java.net.URI) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) DB(com.cloud.utils.db.DB)

Aggregations

ResourceAllocationException (com.cloud.exception.ResourceAllocationException)58 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)40 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)40 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)37 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)21 ServerApiException (org.apache.cloudstack.api.ServerApiException)19 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)17 Account (com.cloud.user.Account)14 DB (com.cloud.utils.db.DB)14 ArrayList (java.util.ArrayList)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)12 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)11 ConfigurationException (javax.naming.ConfigurationException)10 TransactionStatus (com.cloud.utils.db.TransactionStatus)9 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)8 DataCenter (com.cloud.dc.DataCenter)7 StorageNetworkIpRange (com.cloud.dc.StorageNetworkIpRange)6 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)6 Date (java.util.Date)6