Search in sources :

Example 71 with ConcurrentOperationException

use of com.cloud.legacymodel.exceptions.ConcurrentOperationException in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method addVmToNetwork.

@Override
public NicProfile addVmToNetwork(final VirtualMachine vm, final Network network, final NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.info("Adding VM " + vm + " to network " + network + " with requested nic profile " + requested);
    final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        placeHolder = createPlaceHolderWork(vm.getId());
        try {
            return orchestrateAddVmToNetwork(vm, network, requested);
        } finally {
            if (placeHolder != null) {
                _workJobDao.expunge(placeHolder.getId());
            }
        }
    } else {
        final Outcome<VirtualMachine> outcome = addVmToNetworkThroughJobQueue(vm, network, requested);
        try {
            outcome.get();
        } catch (final InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (final java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution exception", e);
        }
        final Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobException != null) {
            if (jobException instanceof ResourceUnavailableException) {
                throw (ResourceUnavailableException) jobException;
            } else if (jobException instanceof ConcurrentOperationException) {
                throw (ConcurrentOperationException) jobException;
            } else if (jobException instanceof InsufficientCapacityException) {
                throw (InsufficientCapacityException) jobException;
            } else if (jobException instanceof RuntimeException) {
                throw (RuntimeException) jobException;
            } else if (jobException instanceof Throwable) {
                throw new RuntimeException("Unexpected exception", (Throwable) jobException);
            } else if (jobException instanceof NicProfile) {
                return (NicProfile) jobException;
            }
        }
        throw new RuntimeException("Unexpected job execution result");
    }
}
Also used : AsyncJobExecutionContext(com.cloud.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 72 with ConcurrentOperationException

use of com.cloud.legacymodel.exceptions.ConcurrentOperationException in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method migrateForScale.

@Override
public void migrateForScale(final String vmUuid, final long srcHostId, final DeployDestination dest, final Long oldSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException {
    final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
    if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
        // avoid re-entrance
        VmWorkJobVO placeHolder = null;
        final VirtualMachine vm = _vmDao.findByUuid(vmUuid);
        placeHolder = createPlaceHolderWork(vm.getId());
        try {
            orchestrateMigrateForScale(vmUuid, srcHostId, dest, oldSvcOfferingId);
        } finally {
            if (placeHolder != null) {
                _workJobDao.expunge(placeHolder.getId());
            }
        }
    } else {
        final Outcome<VirtualMachine> outcome = migrateVmForScaleThroughJobQueue(vmUuid, srcHostId, dest, oldSvcOfferingId);
        try {
            final VirtualMachine vm = outcome.get();
        } catch (final InterruptedException e) {
            throw new RuntimeException("Operation is interrupted", e);
        } catch (final java.util.concurrent.ExecutionException e) {
            throw new RuntimeException("Execution excetion", e);
        }
        final Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
        if (jobResult != null) {
            if (jobResult instanceof ResourceUnavailableException) {
                throw (ResourceUnavailableException) jobResult;
            } else if (jobResult instanceof ConcurrentOperationException) {
                throw (ConcurrentOperationException) jobResult;
            } else if (jobResult instanceof RuntimeException) {
                throw (RuntimeException) jobResult;
            } else if (jobResult instanceof Throwable) {
                throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
            }
        }
    }
}
Also used : AsyncJobExecutionContext(com.cloud.framework.jobs.AsyncJobExecutionContext) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) VmWorkJobVO(com.cloud.framework.jobs.impl.VmWorkJobVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 73 with ConcurrentOperationException

use of com.cloud.legacymodel.exceptions.ConcurrentOperationException in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method removeNic.

protected void removeNic(final VirtualMachineProfile vm, final NicVO nic) {
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start && nic.getState() != Nic.State.Allocated) {
        // Ensure that release is performed before Nic is to be removed to avoid resource leaks.
        try {
            releaseNic(vm, nic.getId());
        } catch (final Exception ex) {
            s_logger.warn("Failed to release nic: " + nic.toString() + " as part of remove operation due to", ex);
        }
    }
    nic.setState(Nic.State.Deallocating);
    _nicDao.update(nic.getId(), nic);
    final NetworkVO network = _networksDao.findById(nic.getNetworkId());
    final NicProfile profile = new NicProfile(nic, network, null, null, null, _networkModel.getNetworkTag(vm.getHypervisorType(), network));
    /*
         * We need to release the nics with a Create ReservationStrategy here
         * because the nic is now being removed.
         */
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Create) {
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Asking " + element.getName() + " to release " + nic);
                }
                try {
                    element.release(network, profile, vm, null);
                } catch (final ConcurrentOperationException | ResourceUnavailableException ex) {
                    s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex);
                }
            }
        }
    }
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    guru.deallocate(network, profile, vm);
    _nicDao.remove(nic.getId());
    s_logger.debug("Removed nic id=" + nic.getId());
    // remove the secondary ip addresses corresponding to to this nic
    if (!removeVmSecondaryIpsOfNic(nic.getId())) {
        s_logger.debug("Removing nic " + nic.getId() + " secondary ip addreses failed");
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkElement(com.cloud.network.element.NetworkElement) NetworkGuru(com.cloud.network.guru.NetworkGuru) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) ConnectionException(com.cloud.legacymodel.exceptions.ConnectionException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) ResourceAllocationException(com.cloud.legacymodel.exceptions.ResourceAllocationException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.legacymodel.exceptions.InsufficientVirtualNetworkCapacityException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) IllegalVirtualMachineException(com.cloud.legacymodel.exceptions.IllegalVirtualMachineException) UnsupportedServiceException(com.cloud.legacymodel.exceptions.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider)

Example 74 with ConcurrentOperationException

use of com.cloud.legacymodel.exceptions.ConcurrentOperationException in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method setupNetwork.

@Override
@DB
public List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final Network predefined, final DeploymentPlan plan, final String name, final String displayText, final boolean errorIfAlreadySetup, final Long domainId, final ACLType aclType, final Boolean subdomainAccess, final Long vpcId, final Long relatedNetworkId, final Boolean isDisplayNetworkEnabled, final String dns1, final String dns2, final String ipExclusionList, final String dhcpTftpServer, final String dhcpBootfileName) throws ConcurrentOperationException {
    final Account locked = _accountDao.acquireInLockTable(owner.getId());
    if (locked == null) {
        throw new ConcurrentOperationException("Unable to acquire lock on " + owner);
    }
    try {
        if (predefined == null || offering.getTrafficType() != TrafficType.Guest && predefined.getCidr() == null && predefined.getBroadcastUri() == null && !(predefined.getBroadcastDomainType() == BroadcastDomainType.Vlan || predefined.getBroadcastDomainType() == BroadcastDomainType.Lswitch || predefined.getBroadcastDomainType() == BroadcastDomainType.Vxlan)) {
            final List<NetworkVO> configs;
            if (vpcId != null && GuestType.Sync.equals(offering.getGuestType())) {
                configs = _networksDao.listSyncNetworksByVpc(vpcId);
            } else if (relatedNetworkId != null && GuestType.Sync.equals(offering.getGuestType())) {
                configs = _networksDao.listSyncNetworksByRelatedNetwork(relatedNetworkId);
            } else {
                configs = _networksDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId());
            }
            if (configs.size() > 0) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found existing network configuration for offering " + offering + ": " + configs.get(0));
                }
                if (errorIfAlreadySetup) {
                    final InvalidParameterValueException ex = new InvalidParameterValueException("Found existing network configuration (with specified id) for offering (with specified id)");
                    ex.addProxyObject(offering.getUuid(), "offeringId");
                    ex.addProxyObject(configs.get(0).getUuid(), "networkConfigId");
                    throw ex;
                } else {
                    return configs;
                }
            }
        }
        final List<NetworkVO> networks = new ArrayList<>();
        long related = relatedNetworkId != null ? relatedNetworkId : -1;
        for (final NetworkGuru guru : networkGurus) {
            final Network network = guru.design(offering, plan, predefined, owner);
            if (network == null) {
                continue;
            }
            if (network.getId() != -1) {
                if (network instanceof NetworkVO) {
                    networks.add((NetworkVO) network);
                } else {
                    networks.add(_networksDao.findById(network.getId()));
                }
                continue;
            }
            final long id = _networksDao.getNextInSequence(Long.class, "id");
            if (related == -1) {
                related = id;
            }
            final long relatedFinal = related;
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(final TransactionStatus status) {
                    final NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), relatedFinal, name, displayText, predefined != null ? predefined.getNetworkDomain() : null, offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId, offering.getRedundantRouter(), dns1, dns2, ipExclusionList, dhcpTftpServer, dhcpBootfileName);
                    vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
                    vo.setStrechedL2Network(offering.getSupportsStrechedL2());
                    networks.add(_networksDao.persist(vo, vo.getGuestType() == GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
                    if (domainId != null && aclType == ACLType.Domain) {
                        _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess);
                    }
                }
            });
            if (!networks.isEmpty()) {
                return networks;
            }
        }
        if (networks.size() < 1) {
            // see networkOfferingVO.java
            final CloudRuntimeException ex = new CloudRuntimeException("Unable to convert network offering with specified id to network profile");
            ex.addProxyObject(offering.getUuid(), "offeringId");
            throw ex;
        }
        return networks;
    } finally {
        s_logger.debug("Releasing lock for " + locked);
        _accountDao.releaseFromLockTable(locked.getId());
    }
}
Also used : Account(com.cloud.legacymodel.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) ArrayList(java.util.ArrayList) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) DB(com.cloud.utils.db.DB)

Example 75 with ConcurrentOperationException

use of com.cloud.legacymodel.exceptions.ConcurrentOperationException in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method releaseNic.

@DB
protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException {
    final Pair<Network, NicProfile> networkToRelease = Transaction.execute(new TransactionCallback<Pair<Network, NicProfile>>() {

        @Override
        public Pair<Network, NicProfile> doInTransaction(final TransactionStatus status) {
            final NicVO nic = _nicDao.lockRow(nicId, true);
            if (nic == null) {
                throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic);
            }
            final Nic.State originalState = nic.getState();
            final NetworkVO network = _networksDao.findById(nic.getNetworkId());
            if (originalState == Nic.State.Reserved || originalState == Nic.State.Reserving) {
                if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
                    nic.setState(Nic.State.Releasing);
                    _nicDao.update(nic.getId(), nic);
                    final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
                    if (guru.release(profile, vmProfile, nic.getReservationId())) {
                        applyProfileToNicForRelease(nic, profile);
                        nic.setState(Nic.State.Allocated);
                        if (originalState == Nic.State.Reserved) {
                            updateNic(nic, network.getId(), -1);
                        } else {
                            _nicDao.update(nic.getId(), nic);
                        }
                    }
                    // Perform release on network elements
                    return new Pair<>(network, profile);
                } else {
                    nic.setState(Nic.State.Allocated);
                    updateNic(nic, network.getId(), -1);
                }
            }
            return null;
        }
    });
    // cleanup the entry in vm_network_map
    if (vmProfile.getType().equals(VirtualMachineType.User)) {
        final NicVO nic = _nicDao.findById(nicId);
        if (nic != null) {
            final NetworkVO vmNetwork = _networksDao.findById(nic.getNetworkId());
            final VMNetworkMapVO vno = _vmNetworkMapDao.findByVmAndNetworkId(vmProfile.getVirtualMachine().getId(), vmNetwork.getId());
            if (vno != null) {
                _vmNetworkMapDao.remove(vno.getId());
            }
        }
    }
    if (networkToRelease != null) {
        final Network network = networkToRelease.first();
        final NicProfile profile = networkToRelease.second();
        final List<Provider> providersToImplement = getNetworkProviders(network.getId());
        for (final NetworkElement element : networkElements) {
            if (providersToImplement.contains(element.getProvider())) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Asking " + element.getName() + " to release " + profile);
                }
                // NOTE: Context appear to never be used in release method
                // implementations. Consider removing it from interface Element
                element.release(network, profile, vmProfile, null);
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) TransactionStatus(com.cloud.utils.db.TransactionStatus) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.legacymodel.network.Network.Provider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) NetworkElement(com.cloud.network.element.NetworkElement) RedundantState(com.cloud.legacymodel.network.VirtualRouter.RedundantState) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VMNetworkMapVO(com.cloud.engine.cloud.entity.api.db.VMNetworkMapVO) NicVO(com.cloud.vm.NicVO) Pair(com.cloud.legacymodel.utils.Pair) DB(com.cloud.utils.db.DB)

Aggregations

ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)101 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)63 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)58 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)50 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)37 ServerApiException (com.cloud.api.ServerApiException)30 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)28 Account (com.cloud.legacymodel.user.Account)23 AsyncJobExecutionContext (com.cloud.framework.jobs.AsyncJobExecutionContext)20 VmWorkJobVO (com.cloud.framework.jobs.impl.VmWorkJobVO)20 VirtualMachine (com.cloud.legacymodel.vm.VirtualMachine)20 DB (com.cloud.utils.db.DB)19 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)17 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)17 ConfigurationException (javax.naming.ConfigurationException)16 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)14 Network (com.cloud.legacymodel.network.Network)14 ActionEvent (com.cloud.event.ActionEvent)13 NetworkVO (com.cloud.network.dao.NetworkVO)13 VirtualMachineMigrationException (com.cloud.legacymodel.exceptions.VirtualMachineMigrationException)12