Search in sources :

Example 61 with ConcurrentOperationException

use of com.cloud.exception.ConcurrentOperationException 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)

Example 62 with ConcurrentOperationException

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

the class AutoScaleManagerImpl method createNewVM.

private long createNewVM(AutoScaleVmGroupVO asGroup) {
    AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
    long templateId = profileVo.getTemplateId();
    long serviceOfferingId = profileVo.getServiceOfferingId();
    if (templateId == -1) {
        return -1;
    }
    // create new VM into DB
    try {
        //Verify that all objects exist before passing them to the service
        Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
        DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone by id=" + profileVo.getZoneId());
        }
        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
        }
        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
        // Make sure a valid template ID was specified
        if (template == null) {
            throw new InvalidParameterValueException("Unable to use template " + templateId);
        }
        if (!zone.isLocalStorageEnabled()) {
            if (serviceOffering.getUseLocalStorage()) {
                throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
            }
        }
        UserVm vm = null;
        IpAddresses addrs = new IpAddresses(null, null);
        if (zone.getNetworkType() == NetworkType.Basic) {
            vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, null, true, null, null, null, null);
        } else {
            if (zone.isSecurityGroupEnabled()) {
                vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, null, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, null, true, null, null, null, null);
            } else {
                vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, addrs, true, null, null, null, null);
            }
        }
        if (vm != null) {
            return vm.getId();
        } else {
            return -1;
        }
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex.getMessage(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (ResourceAllocationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServiceOffering(com.cloud.offering.ServiceOffering) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) IpAddresses(com.cloud.network.Network.IpAddresses) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException)

Example 63 with ConcurrentOperationException

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

the class CreateStorageNetworkIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        StorageNetworkIpRange result = _storageNetworkService.createIpRange(this);
        StorageNetworkIpRangeResponse response = _responseGenerator.createStorageNetworkIpRangeResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn("Create storage network IP range failed", e);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageNetworkIpRange(com.cloud.dc.StorageNetworkIpRange) StorageNetworkIpRangeResponse(org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 64 with ConcurrentOperationException

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

the class ListStorageNetworkIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        List<StorageNetworkIpRange> results = _storageNetworkService.listIpRange(this);
        ListResponse<StorageNetworkIpRangeResponse> response = new ListResponse<StorageNetworkIpRangeResponse>();
        List<StorageNetworkIpRangeResponse> resList = new ArrayList<StorageNetworkIpRangeResponse>(results.size());
        for (StorageNetworkIpRange r : results) {
            StorageNetworkIpRangeResponse resp = _responseGenerator.createStorageNetworkIpRangeResponse(r);
            resList.add(resp);
        }
        response.setResponses(resList);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } catch (Exception e) {
        s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId());
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageNetworkIpRange(com.cloud.dc.StorageNetworkIpRange) StorageNetworkIpRangeResponse(org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse) ArrayList(java.util.ArrayList) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 65 with ConcurrentOperationException

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

the class DataObjectManagerImpl method deleteAsynCallback.

protected Void deleteAsynCallback(AsyncCallbackDispatcher<DataObjectManagerImpl, CommandResult> callback, DeleteContext<CommandResult> context) {
    DataObject destObj = context.obj;
    CommandResult res = callback.getResult();
    if (res.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (NoTransitionException e) {
            s_logger.debug("delete failed", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("delete failed", e);
        }
    } else {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationSuccessed);
        } catch (NoTransitionException e) {
            s_logger.debug("delete failed", e);
        } catch (ConcurrentOperationException e) {
            s_logger.debug("delete failed", e);
        }
    }
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult)

Aggregations

ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)153 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)96 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)80 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)71 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)43 ServerApiException (org.apache.cloudstack.api.ServerApiException)32 Account (com.cloud.user.Account)24 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)23 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)21 DB (com.cloud.utils.db.DB)21 AsyncJobExecutionContext (org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext)20 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)20 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 ConfigurationException (javax.naming.ConfigurationException)17 ArrayList (java.util.ArrayList)16 ActionEvent (com.cloud.event.ActionEvent)14 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)14 UserVm (com.cloud.uservm.UserVm)14 ManagementServerException (com.cloud.exception.ManagementServerException)13