Search in sources :

Example 46 with ResourceUnavailableException

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

the class NetworkOrchestrator method implementNetworkElementsAndResources.

@Override
public void implementNetworkElementsAndResources(final DeployDestination dest, final ReservationContext context, final Network network, final NetworkOffering offering) throws ConcurrentOperationException, InsufficientAddressCapacityException, ResourceUnavailableException, InsufficientCapacityException {
    // Associate a source NAT IP (if one isn't already associated with the network) if this is a
    // 1) 'Isolated' or 'Shared' guest virtual network in the advance zone
    // 2) network has sourceNat service
    // 3) network offering does not support a shared source NAT rule
    final boolean sharedSourceNat = offering.isSharedSourceNat();
    final DataCenter zone = _dcDao.findById(network.getDataCenterId());
    if (!sharedSourceNat && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat) && (network.getGuestType() == Network.GuestType.Isolated || network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced)) {
        List<IPAddressVO> ips = null;
        final Account owner = _entityMgr.findById(Account.class, network.getAccountId());
        if (network.getVpcId() != null) {
            ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
            if (ips.isEmpty()) {
                final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
                s_logger.debug("Creating a source nat ip for vpc " + vpc);
                _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
            }
        } else {
            ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
            if (ips.isEmpty()) {
                s_logger.debug("Creating a source nat ip for network " + network);
                _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
            }
        }
    }
    // get providers to implement
    final List<Provider> providersToImplement = getNetworkProviders(network.getId());
    implementNetworkElements(dest, context, network, offering, providersToImplement);
    // Reset the extra DHCP option that may have been cleared per nic.
    List<NicVO> nicVOs = _nicDao.listByNetworkId(network.getId());
    for (NicVO nicVO : nicVOs) {
        if (nicVO.getState() == Nic.State.Reserved) {
            configureExtraDhcpOptions(network, nicVO.getId());
        }
    }
    for (final NetworkElement element : networkElements) {
        if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
            ((AggregatedCommandExecutor) element).prepareAggregatedExecution(network, dest);
        }
    }
    try {
        // reapply all the firewall/staticNat/lb rules
        s_logger.debug("Reprogramming network " + network + " as a part of network implement");
        if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) {
            s_logger.warn("Failed to re-program the network as a part of network " + network + " implement");
            // see DataCenterVO.java
            final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
            ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
            throw ex;
        }
        for (final NetworkElement element : networkElements) {
            if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
                if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) {
                    s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!");
                    // see DataCenterVO.java
                    final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId());
                    ex.addProxyObject(_entityMgr.findById(DataCenter.class, network.getDataCenterId()).getUuid());
                    throw ex;
                }
            }
        }
    } finally {
        for (final NetworkElement element : networkElements) {
            if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) {
                ((AggregatedCommandExecutor) element).cleanupAggregatedExecution(network, dest);
            }
        }
    }
}
Also used : Account(com.cloud.user.Account) AggregatedCommandExecutor(com.cloud.network.element.AggregatedCommandExecutor) Vpc(com.cloud.network.vpc.Vpc) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) DataCenter(com.cloud.dc.DataCenter) NetworkElement(com.cloud.network.element.NetworkElement) ConfigDriveNetworkElement(com.cloud.network.element.ConfigDriveNetworkElement) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IPAddressVO(com.cloud.network.dao.IPAddressVO) NicVO(com.cloud.vm.NicVO)

Example 47 with ResourceUnavailableException

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

the class NetworkOrchestrator method restartNetwork.

@Override
public boolean restartNetwork(final Long networkId, final Account callerAccount, final User callerUser, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    boolean status = true;
    boolean restartRequired = false;
    final NetworkVO network = _networksDao.findById(networkId);
    s_logger.debug("Restarting network " + networkId + "...");
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount);
    final NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
    final DeployDestination dest = new DeployDestination(_dcDao.findById(network.getDataCenterId()), null, null, null);
    if (cleanup) {
        if (!rollingRestartRouters(network, offering, dest, context)) {
            status = false;
            restartRequired = true;
        }
        setRestartRequired(network, restartRequired);
        return status;
    }
    s_logger.debug("Implementing the network " + network + " elements and resources as a part of network restart without cleanup");
    try {
        implementNetworkElementsAndResources(dest, context, network, offering);
        setRestartRequired(network, false);
        return true;
    } catch (final Exception ex) {
        s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network restart due to ", ex);
        return false;
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurationException(javax.naming.ConfigurationException) ReservationContext(com.cloud.vm.ReservationContext)

Example 48 with ResourceUnavailableException

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

the class NetworkOrchestrator method cleanupConfigForServicesInNetwork.

@Override
public void cleanupConfigForServicesInNetwork(List<String> services, final Network network) {
    long networkId = network.getId();
    Account caller = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
    long userId = User.UID_SYSTEM;
    // remove all PF/Static Nat rules for the network
    s_logger.info("Services:" + services + " are no longer supported in network:" + network.getUuid() + " after applying new network offering:" + network.getNetworkOfferingId() + " removing the related configuration");
    if (services.contains(Service.StaticNat.getName()) || services.contains(Service.PortForwarding.getName())) {
        try {
            if (_rulesMgr.revokeAllPFStaticNatRulesForNetwork(networkId, userId, caller)) {
                s_logger.debug("Successfully cleaned up portForwarding/staticNat rules for network id=" + networkId);
            } else {
                s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup");
            }
            if (services.contains(Service.StaticNat.getName())) {
                // removing static nat configured on ips.
                // optimizing the db operations using transaction.
                Transaction.execute(new TransactionCallbackNoReturn() {

                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus status) {
                        List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
                        for (IPAddressVO ip : ips) {
                            ip.setOneToOneNat(false);
                            ip.setAssociatedWithVmId(null);
                            ip.setVmIp(null);
                            _ipAddressDao.update(ip.getId(), ip);
                        }
                    }
                });
            }
        } catch (ResourceUnavailableException ex) {
            s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex);
        }
    }
    if (services.contains(Service.SourceNat.getName())) {
        Transaction.execute(new TransactionCallbackNoReturn() {

            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                List<IPAddressVO> ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
                // removing static nat configured on ips.
                for (IPAddressVO ip : ips) {
                    ip.setSourceNat(false);
                    _ipAddressDao.update(ip.getId(), ip);
                }
            }
        });
    }
    if (services.contains(Service.Lb.getName())) {
        // remove all LB rules for the network
        if (_lbMgr.removeAllLoadBalanacersForNetwork(networkId, caller, userId)) {
            s_logger.debug("Successfully cleaned up load balancing rules for network id=" + networkId);
        } else {
            s_logger.warn("Failed to cleanup LB rules as a part of network id=" + networkId + " cleanup");
        }
    }
    if (services.contains(Service.Firewall.getName())) {
        // revoke all firewall rules for the network
        try {
            if (_firewallMgr.revokeAllFirewallRulesForNetwork(networkId, userId, caller)) {
                s_logger.debug("Successfully cleaned up firewallRules rules for network id=" + networkId);
            } else {
                s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup");
            }
        } catch (ResourceUnavailableException ex) {
            s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex);
        }
    }
    // do not remove vpn service for vpc networks.
    if (services.contains(Service.Vpn.getName()) && network.getVpcId() == null) {
        RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByAccountAndNetwork(network.getAccountId(), networkId);
        try {
            _vpnMgr.destroyRemoteAccessVpnForIp(vpn.getServerAddressId(), caller, true);
        } catch (ResourceUnavailableException ex) {
            s_logger.warn("Failed to cleanup remote access vpn resources of network:" + network.getUuid() + " due to Exception: ", ex);
        }
    }
}
Also used : Account(com.cloud.user.Account) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 49 with ResourceUnavailableException

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

the class NetworkOrchestrator method removeDhcpServiceInSubnet.

@DB
@Override
public void removeDhcpServiceInSubnet(final Nic nic) {
    final Network network = _networksDao.findById(nic.getNetworkId());
    final DhcpServiceProvider dhcpServiceProvider = getDhcpServiceProvider(network);
    try {
        final NicIpAliasVO ipAlias = _nicIpAliasDao.findByGatewayAndNetworkIdAndState(nic.getIPv4Gateway(), network.getId(), NicIpAlias.State.active);
        if (ipAlias != null) {
            ipAlias.setState(NicIpAlias.State.revoked);
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    _nicIpAliasDao.update(ipAlias.getId(), ipAlias);
                    final IPAddressVO aliasIpaddressVo = _publicIpAddressDao.findByIpAndSourceNetworkId(ipAlias.getNetworkId(), ipAlias.getIp4Address());
                    _publicIpAddressDao.unassignIpAddress(aliasIpaddressVo.getId());
                }
            });
            if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) {
                s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address());
            }
        }
    } catch (final ResourceUnavailableException e) {
        // failed to remove the dhcpconfig on the router.
        s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter.");
    }
}
Also used : Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) IPAddressVO(com.cloud.network.dao.IPAddressVO) NicIpAliasVO(com.cloud.vm.dao.NicIpAliasVO) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) DB(com.cloud.utils.db.DB)

Example 50 with ResourceUnavailableException

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

the class VMEntityManagerImpl method deployVirtualMachine.

@Override
public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params, boolean deployOnGivenHost) throws InsufficientCapacityException, ResourceUnavailableException {
    // grab the VM Id and destination using the reservationId.
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
    if (vmReservation != null) {
        DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
        try {
            _itMgr.start(vm.getUuid(), params, reservedPlan, _planningMgr.getDeploymentPlannerByName(vmReservation.getDeploymentPlanner()));
        } catch (Exception ex) {
            // the instance may be started on another host instead of the intended one.
            if (!deployOnGivenHost) {
                DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
                if (reservedPlan.getAvoids() != null) {
                    plan.setAvoids(reservedPlan.getAvoids());
                }
                _itMgr.start(vm.getUuid(), params, plan, null);
            } else {
                throw ex;
            }
        }
    } else {
        // no reservation found. Let VirtualMachineManager retry
        _itMgr.start(vm.getUuid(), params, null, null);
    }
}
Also used : VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VMInstanceVO(com.cloud.vm.VMInstanceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AffinityConflictException(com.cloud.exception.AffinityConflictException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

Aggregations

ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)446 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)191 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)175 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)153 ArrayList (java.util.ArrayList)99 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)91 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)74 Account (com.cloud.user.Account)62 DomainRouterVO (com.cloud.vm.DomainRouterVO)60 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)59 ConfigurationException (javax.naming.ConfigurationException)53 DB (com.cloud.utils.db.DB)52 ServerApiException (org.apache.cloudstack.api.ServerApiException)51 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)47 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)47 ActionEvent (com.cloud.event.ActionEvent)46 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)46 DataCenter (com.cloud.dc.DataCenter)45 ServerApiException (com.cloud.api.ServerApiException)43 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)42