Search in sources :

Example 31 with InsufficientCapacityException

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

the class ConsoleProxyManagerImpl method createProxyInstance.

protected Map<String, Object> createProxyInstance(long dataCenterId, VMTemplateVO template) throws ConcurrentOperationException {
    long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
    String name = VirtualMachineName.getConsoleProxyName(id, _instance);
    DataCenterVO dc = _dcDao.findById(dataCenterId);
    Account systemAcct = _accountMgr.getSystemAccount();
    DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
    NetworkVO defaultNetwork = getDefaultNetworkForCreation(dc);
    List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(offerings.size() + 1);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(2);
    networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
    for (NetworkOffering offering : offerings) {
        networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<NicProfile>());
    }
    ServiceOfferingVO serviceOffering = _serviceOffering;
    if (serviceOffering == null) {
        serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.consoleProxyDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
    }
    ConsoleProxyVO proxy = new ConsoleProxyVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), 0, serviceOffering.getOfferHA());
    proxy.setDynamicallyScalable(template.isDynamicallyScalable());
    proxy = _consoleProxyDao.persist(proxy);
    try {
        _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
    } catch (InsufficientCapacityException e) {
        s_logger.warn("InsufficientCapacity", e);
        throw new CloudRuntimeException("Insufficient capacity exception", e);
    }
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("dc", dc);
    HostPodVO pod = _podDao.findById(proxy.getPodIdToDeployIn());
    context.put("pod", pod);
    context.put("proxyVmId", proxy.getId());
    return context;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HostPodVO(com.cloud.dc.HostPodVO) LinkedHashMap(java.util.LinkedHashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 32 with InsufficientCapacityException

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

the class NicPlugInOutRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = getNicsToChangeOnRouter(visitor);
    Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
    Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
    NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
    VirtualMachineManager itMgr = visitor.getVirtualNetworkApplianceFactory().getItMgr();
    // 1) Unplug the nics
    for (Entry<String, PublicIpAddress> entry : nicsToUnplug.entrySet()) {
        Network publicNtwk = null;
        try {
            publicNtwk = networkModel.getNetwork(entry.getValue().getNetworkId());
            URI broadcastUri = BroadcastDomainType.Vlan.toUri(entry.getKey());
            itMgr.removeVmFromNetwork(_router, publicNtwk, broadcastUri);
        } catch (ConcurrentOperationException e) {
            s_logger.warn("Failed to remove router " + _router + " from vlan " + entry.getKey() + " in public network " + publicNtwk + " due to ", e);
            return false;
        }
    }
    _netUsageCommands = new Commands(Command.OnError.Continue);
    VpcDao vpcDao = visitor.getVirtualNetworkApplianceFactory().getVpcDao();
    VpcVO vpc = vpcDao.findById(_router.getVpcId());
    // 2) Plug the nics
    for (String vlanTag : nicsToPlug.keySet()) {
        PublicIpAddress ip = nicsToPlug.get(vlanTag);
        // have to plug the nic(s)
        NicProfile defaultNic = new NicProfile();
        if (ip.isSourceNat()) {
            defaultNic.setDefaultNic(true);
        }
        defaultNic.setIPv4Address(ip.getAddress().addr());
        defaultNic.setIPv4Gateway(ip.getGateway());
        defaultNic.setIPv4Netmask(ip.getNetmask());
        defaultNic.setMacAddress(ip.getMacAddress());
        defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
        defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
        defaultNic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
        NicProfile publicNic = null;
        Network publicNtwk = null;
        try {
            publicNtwk = networkModel.getNetwork(ip.getNetworkId());
            publicNic = itMgr.addVmToNetwork(_router, publicNtwk, defaultNic);
        } catch (ConcurrentOperationException e) {
            s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
        } catch (InsufficientCapacityException e) {
            s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk + " due to ", e);
        } finally {
            if (publicNic == null) {
                s_logger.warn("Failed to add router " + _router + " to vlan " + vlanTag + " in public network " + publicNtwk);
                return false;
            }
        }
        // Create network usage commands. Send commands to router after
        // IPAssoc
        NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(_router.getPrivateIpAddress(), _router.getInstanceName(), true, defaultNic.getIPv4Address(), vpc.getCidr());
        _netUsageCommands.addCommand(netUsageCmd);
        UserStatisticsDao userStatsDao = visitor.getVirtualNetworkApplianceFactory().getUserStatsDao();
        UserStatisticsVO stats = userStatsDao.findBy(_router.getAccountId(), _router.getDataCenterId(), publicNtwk.getId(), publicNic.getIPv4Address(), _router.getId(), _router.getType().toString());
        if (stats == null) {
            stats = new UserStatisticsVO(_router.getAccountId(), _router.getDataCenterId(), publicNic.getIPv4Address(), _router.getId(), _router.getType().toString(), publicNtwk.getId());
            userStatsDao.persist(stats);
        }
    }
    // VpcIpAssociation is done.
    return true;
}
Also used : NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UserStatisticsDao(com.cloud.user.dao.UserStatisticsDao) PublicIpAddress(com.cloud.network.PublicIpAddress) VpcDao(com.cloud.network.vpc.dao.VpcDao) VpcVO(com.cloud.network.vpc.VpcVO) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) NetworkModel(com.cloud.network.NetworkModel) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) HashMap(java.util.HashMap) Map(java.util.Map) UserStatisticsVO(com.cloud.user.UserStatisticsVO)

Example 33 with InsufficientCapacityException

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

the class CreatePrivateGatewayCmd method create.

@Override
public void create() throws ResourceAllocationException {
    PrivateGateway result = null;
    try {
        result = _vpcService.createVpcPrivateGateway(getVpcId(), getPhysicalNetworkId(), getBroadcastUri(), getStartIp(), getGateway(), getNetmask(), getEntityOwnerId(), getNetworkOfferingId(), getIsSourceNat(), getAclId());
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private gateway");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) PrivateGateway(com.cloud.network.vpc.PrivateGateway)

Example 34 with InsufficientCapacityException

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

the class CreateVPCCmd method execute.

@Override
public void execute() {
    Vpc vpc = null;
    try {
        if (isStart()) {
            _vpcService.startVpc(getEntityId(), true);
        } else {
            s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
        }
        vpc = _entityMgr.findById(Vpc.class, getEntityId());
    } 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 (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
    if (vpc != null) {
        VpcResponse response = _responseGenerator.createVpcResponse(ResponseView.Restricted, vpc);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPC");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VpcResponse(org.apache.cloudstack.api.response.VpcResponse) Vpc(com.cloud.network.vpc.Vpc) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 35 with InsufficientCapacityException

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

the class StartVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        CallContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        StringBuilder message = new StringBuilder(ex.getMessage());
        if (ex instanceof InsufficientServerCapacityException) {
            if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
                message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
            }
        }
        s_logger.info(ex);
        s_logger.info(message.toString(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ExecutionException(com.cloud.utils.exception.ExecutionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Aggregations

InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)85 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)77 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)70 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)36 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)23 ServerApiException (org.apache.cloudstack.api.ServerApiException)23 Account (com.cloud.user.Account)18 ConfigurationException (javax.naming.ConfigurationException)17 ArrayList (java.util.ArrayList)15 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)14 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)14 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)12 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)11 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)11 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)10 NetworkVO (com.cloud.network.dao.NetworkVO)10 DB (com.cloud.utils.db.DB)10 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)9 Network (com.cloud.network.Network)9