Search in sources :

Example 21 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (destPool == null) {
        throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
    }
    try {
        stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
    } catch (final NoTransitionException e) {
        s_logger.debug("Unable to migrate vm: " + e.toString());
        throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    boolean migrationResult = false;
    try {
        migrationResult = volumeMgr.storageMigration(profile, destPool);
        if (migrationResult) {
            if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
                final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
                final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
                _networkMgr.reallocate(vmProfile, plan);
            }
            // when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
            vm.setLastHostId(null);
            vm.setPodIdToDeployIn(destPool.getPodId());
        } else {
            s_logger.debug("Storage migration failed");
        }
    } catch (final ConcurrentOperationException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientVirtualNetworkCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final StorageUnavailableException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } finally {
        try {
            stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to change vm state: " + e.toString());
            throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
        }
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 22 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class LoadBalancingRulesManagerImpl method createPublicLoadBalancerRule.

@Override
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
public LoadBalancer createPublicLoadBalancerRule(final String xId, final String name, final String description, final int srcPortStart, final int srcPortEnd, final int defPortStart, final int defPortEnd, final Long ipAddrId, final String protocol, final String algorithm, final long networkId, final long lbOwnerId, final boolean openFirewall, final String lbProtocol, final Boolean forDisplay, Integer clientTimeout, Integer serverTimeout) throws NetworkRuleConflictException, InsufficientAddressCapacityException {
    final 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);
    }
    final Network network = _networkModel.getNetwork(networkId);
    LoadBalancer result = null;
    if (result == null) {
        IpAddress systemIp = null;
        final 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) {
                final 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);
            }
            // Load default values and fallback to hardcoded if not available
            final Integer defaultClientTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerClientTimeout.key()), 60000);
            final Integer defaultServerTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerServerTimeout.key()), 60000);
            // set timeouts, use defaults if not available
            if (clientTimeout != null) {
                clientTimeout = NumbersUtil.parseInt(clientTimeout.toString(), defaultClientTimeout);
            } else {
                clientTimeout = defaultClientTimeout;
            }
            if (serverTimeout != null) {
                serverTimeout = NumbersUtil.parseInt(serverTimeout.toString(), defaultServerTimeout);
            } else {
                serverTimeout = defaultServerTimeout;
            }
            result = createPublicLoadBalancer(xId, name, description, srcPortStart, defPortStart, ipVO.getId(), protocol, algorithm, openFirewall, CallContext.current(), lbProtocol, forDisplay, clientTimeout, serverTimeout);
        } catch (final 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.utils.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.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ActionEvent(com.cloud.event.ActionEvent)

Example 23 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class DirectNetworkGuru method allocate.

@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final Zone zone = zoneRepository.findOne(network.getDataCenterId());
    if (nic == null) {
        nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
    } else if (nic.getIPv4Address() == null && nic.getIPv6Address() == null) {
        nic.setReservationStrategy(ReservationStrategy.Start);
    } else {
        nic.setReservationStrategy(ReservationStrategy.Create);
    }
    allocateDirectIp(nic, network, vm, zone, nic.getRequestedIPv4(), nic.getRequestedIPv6());
    nic.setReservationStrategy(ReservationStrategy.Create);
    if (nic.getMacAddress() == null) {
        nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
        if (nic.getMacAddress() == null) {
            throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
        }
    }
    return nic;
}
Also used : Zone(com.cloud.db.model.Zone) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile)

Example 24 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class DirectPodBasedNetworkGuru method getIp.

@DB
protected void getIp(final NicProfile nic, final Pod pod, final VirtualMachineProfile vm, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    final DataCenter dc = _dcDao.findById(pod.getDataCenterId());
    if (nic.getIPv4Address() == null) {
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientAddressCapacityException>() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientAddressCapacityException {
                PublicIp ip = null;
                final List<PodVlanMapVO> podRefs = _podVlanDao.listPodVlanMapsByPod(pod.getId());
                String podRangeGateway = null;
                if (!podRefs.isEmpty()) {
                    podRangeGateway = _vlanDao.findById(podRefs.get(0).getVlanDbId()).getVlanGateway();
                }
                // Get ip address from the placeholder and don't allocate a new one
                if (vm.getType() == VirtualMachine.Type.DomainRouter) {
                    final Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
                    if (placeholderNic != null) {
                        final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIPv4Address());
                        ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                        s_logger.debug("Nic got an ip address " + placeholderNic.getIPv4Address() + " stored in placeholder nic for the network " + network + " and gateway " + podRangeGateway);
                    }
                }
                if (ip == null) {
                    ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
                }
                nic.setIPv4Address(ip.getAddress().toString());
                nic.setFormat(AddressFormat.Ip4);
                nic.setIPv4Gateway(ip.getGateway());
                nic.setIPv4Netmask(ip.getNetmask());
                if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) {
                    nic.setIsolationUri(IsolationType.Ec2.toUri(Vlan.UNTAGGED));
                    nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED));
                    nic.setBroadcastType(BroadcastDomainType.Native);
                }
                nic.setReservationId(String.valueOf(ip.getVlanTag()));
                nic.setMacAddress(ip.getMacAddress());
                // save the placeholder nic if the vm is the Virtual router
                if (vm.getType() == VirtualMachine.Type.DomainRouter) {
                    final Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
                    if (placeholderNic == null) {
                        s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIPv4Address() + " for the network " + network);
                        _networkMgr.savePlaceholderNic(network, nic.getIPv4Address(), null, VirtualMachine.Type.DomainRouter);
                    }
                }
            }
        });
    }
    nic.setIPv4Dns1(dc.getDns1());
    nic.setIPv4Dns2(dc.getDns2());
}
Also used : DataCenter(com.cloud.dc.DataCenter) PublicIp(com.cloud.network.addr.PublicIp) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) TransactionStatus(com.cloud.utils.db.TransactionStatus) Nic(com.cloud.vm.Nic) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO) DB(com.cloud.utils.db.DB)

Example 25 with InsufficientAddressCapacityException

use of com.cloud.exception.InsufficientAddressCapacityException in project cosmic by MissionCriticalCloud.

the class GuestNetworkGuru method allocate.

@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    assert network.getTrafficType() == TrafficType.Guest : "Look at my name!  Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
    if (nic == null) {
        nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
    }
    final Zone zone = zoneRepository.findOne(network.getDataCenterId());
    if (nic.getIPv4Address() == null && !GuestType.Sync.equals(network.getGuestType())) {
        nic.setBroadcastUri(network.getBroadcastUri());
        nic.setIsolationUri(network.getBroadcastUri());
        nic.setIPv4Gateway(network.getGateway());
        final String guestIp;
        if (network.getSpecifyIpRanges()) {
            _ipAddrMgr.allocateDirectIp(nic, zone, vm, network, nic.getRequestedIPv4(), null);
        } else {
            final VirtualMachine.Type vmtype = vm.getVirtualMachine().getType();
            switch(vmtype) {
                case User:
                    guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
                    break;
                case DomainRouter:
                    if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Gateway, Provider.VPCVirtualRouter)) {
                        // Networks that support the Gateway service acquire the gateway ip on their nic
                        guestIp = network.getGateway();
                    } else {
                        // In other cases, acquire an ip address from the DHCP range (take lowest possible)
                        guestIp = _ipAddrMgr.acquireGuestIpAddressForRouter(network, nic.getRequestedIPv4());
                    }
                    break;
                default:
                    // Backwards compatibility
                    guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
                    break;
            }
            if (guestIp == null) {
                throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, zone.getId());
            }
            nic.setIPv4Address(guestIp);
            nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
            if (network.getDns1() != null && network.getDns1().equals("")) {
                nic.setIPv4Dns1(zone.getDns1());
            } else {
                nic.setIPv4Dns1(network.getDns1());
            }
            if (network.getDns2() != null && network.getDns2().equals("")) {
                nic.setIPv4Dns2(zone.getDns2());
            } else {
                nic.setIPv4Dns2(network.getDns2());
            }
            nic.setFormat(AddressFormat.Ip4);
        }
    }
    nic.setReservationStrategy(ReservationStrategy.Start);
    if (nic.getMacAddress() == null) {
        nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
        if (nic.getMacAddress() == null) {
            throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
        }
    }
    return nic;
}
Also used : Zone(com.cloud.db.model.Zone) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)22 IPAddressVO (com.cloud.network.dao.IPAddressVO)16 TransactionStatus (com.cloud.utils.db.TransactionStatus)15 Account (com.cloud.user.Account)14 DataCenter (com.cloud.dc.DataCenter)13 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 NicProfile (com.cloud.vm.NicProfile)12 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)11 DB (com.cloud.utils.db.DB)11 VlanVO (com.cloud.dc.VlanVO)9 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)9 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 PublicIp (com.cloud.network.addr.PublicIp)8 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)8 NicVO (com.cloud.vm.NicVO)8 ArrayList (java.util.ArrayList)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)7 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)7