Search in sources :

Example 96 with ResourceUnavailableException

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

the class ListNicsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    try {
        if (this.getKeyword() != null && !this.getKeyword().isEmpty() && this.getNicId() != null) {
            List<? extends NicSecondaryIp> results = _networkService.listVmNicSecondaryIps(this);
            ListResponse<NicSecondaryIpResponse> response = new ListResponse<NicSecondaryIpResponse>();
            List<NicSecondaryIpResponse> resList = new ArrayList<NicSecondaryIpResponse>();
            NicSecondaryIpResponse res = new NicSecondaryIpResponse();
            List<NicSecondaryIpResponse> res_List = new ArrayList<NicSecondaryIpResponse>();
            if (results != null) {
                for (NicSecondaryIp r : results) {
                    NicSecondaryIpResponse ipRes = _responseGenerator.createSecondaryIPToNicResponse(r);
                    resList.add(ipRes);
                    res.setSecondaryIpsList(resList);
                    res.setObjectName("nic");
                }
                res_List.add(res);
                response.setResponses(res_List);
            }
            response.setResponses(res_List);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            List<? extends Nic> results = _networkService.listNics(this);
            ListResponse<NicResponse> response = new ListResponse<NicResponse>();
            List<NicResponse> resList = null;
            if (results != null) {
                resList = new ArrayList<NicResponse>(results.size());
                for (Nic r : results) {
                    NicResponse resp = _responseGenerator.createNicResponse(r);
                    resp.setObjectName("nic");
                    resList.add(resp);
                }
                response.setResponses(resList);
            }
            response.setResponses(resList);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        }
    } catch (Exception e) {
        s_logger.warn("Failed to list secondary ip address per nic ");
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) Nic(com.cloud.vm.Nic) 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) NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 97 with ResourceUnavailableException

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

the class StartVMCmd method execute.

@Override
public void execute() {
    try {
        CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
        UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse(getResponseView(), "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 (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ResourceAllocationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_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) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ExecutionException(com.cloud.utils.exception.ExecutionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 98 with ResourceUnavailableException

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

the class VirtualMachineManagerImpl method orchestrateMigrateAway.

private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        String message = String.format("Unable to find VM with uuid [%s].", vmUuid);
        s_logger.warn(message);
        throw new CloudRuntimeException(message);
    }
    ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    final Long hostId = vm.getHostId();
    if (hostId == null) {
        String message = String.format("Unable to migrate %s due to it does not have a host id.", vm.toString());
        s_logger.warn(message);
        throw new CloudRuntimeException(message);
    }
    final Host host = _hostDao.findById(hostId);
    Long poolId = null;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    for (final VolumeVO rootVolumeOfVm : vols) {
        final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
        if (rootDiskPool != null) {
            poolId = rootDiskPool.getId();
        }
    }
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(hostId);
    DataCenterDeployment plan = getMigrationDeployment(vm, host, poolId, excludes);
    DeployDestination dest = null;
    while (true) {
        try {
            plan.setMigrationPlan(true);
            dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
        } catch (final AffinityConflictException e2) {
            String message = String.format("Unable to create deployment, affinity rules associted to the %s conflict.", vm.toString());
            s_logger.warn(message, e2);
            throw new CloudRuntimeException(message, e2);
        }
        if (dest == null) {
            s_logger.warn("Unable to find destination for migrating the vm " + profile);
            throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", DataCenter.class, host.getDataCenterId());
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found destination " + dest + " for migrating to.");
        }
        excludes.addHost(dest.getHost().getId());
        try {
            migrate(vm, srcHostId, dest);
            return;
        } catch (ResourceUnavailableException | ConcurrentOperationException e) {
            s_logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e);
        }
        try {
            advanceStop(vmUuid, true);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ResourceUnavailableException | ConcurrentOperationException | OperationTimedoutException e) {
            s_logger.error(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        }
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 99 with ResourceUnavailableException

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

the class VirtualMachineManagerImpl method advanceExpunge.

protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
    if (vm == null || vm.getRemoved() != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Unable to find vm or vm is destroyed: " + vm);
        }
        return;
    }
    advanceStop(vm.getUuid(), VmDestroyForcestop.value());
    vm = _vmDao.findByUuid(vm.getUuid());
    try {
        if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) {
            s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm);
            throw new CloudRuntimeException("Unable to destroy " + vm);
        }
    } catch (final NoTransitionException e) {
        s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm);
        throw new CloudRuntimeException("Unable to destroy " + vm, e);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Destroying vm " + vm);
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
    List<NicProfile> vmNics = profile.getNics();
    s_logger.debug(String.format("Cleaning up NICS [%s] of %s.", vmNics.stream().map(nic -> nic.toString()).collect(Collectors.joining(", ")), vm.toString()));
    final List<Command> nicExpungeCommands = hvGuru.finalizeExpungeNics(vm, profile.getNics());
    _networkMgr.cleanupNics(profile);
    s_logger.debug(String.format("Cleaning up hypervisor data structures (ex. SRs in XenServer) for managed storage. Data from %s.", vm.toString()));
    final List<Command> volumeExpungeCommands = hvGuru.finalizeExpungeVolumes(vm);
    final Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
    List<Map<String, String>> targets = getTargets(hostId, vm.getId());
    if (CollectionUtils.isNotEmpty(volumeExpungeCommands) && hostId != null) {
        final Commands cmds = new Commands(Command.OnError.Stop);
        for (final Command volumeExpungeCommand : volumeExpungeCommands) {
            volumeExpungeCommand.setBypassHostMaintenance(expungeCommandCanBypassHostMaintenance(vm));
            cmds.addCommand(volumeExpungeCommand);
        }
        _agentMgr.send(hostId, cmds);
        handleUnsuccessfulCommands(cmds, vm);
    }
    if (hostId != null) {
        volumeMgr.revokeAccess(vm.getId(), hostId);
    }
    volumeMgr.cleanupVolumes(vm.getId());
    if (hostId != null && CollectionUtils.isNotEmpty(targets)) {
        removeDynamicTargets(hostId, targets);
    }
    final VirtualMachineGuru guru = getVmGuru(vm);
    guru.finalizeExpunge(vm);
    userVmDetailsDao.removeDetails(vm.getId());
    userVmDeployAsIsDetailsDao.removeDetails(vm.getId());
    // Remove comments (if any)
    annotationDao.removeByEntityType(AnnotationService.EntityType.VM.name(), vm.getUuid());
    // send hypervisor-dependent commands before removing
    final List<Command> finalizeExpungeCommands = hvGuru.finalizeExpunge(vm);
    if (CollectionUtils.isNotEmpty(finalizeExpungeCommands) || CollectionUtils.isNotEmpty(nicExpungeCommands)) {
        if (hostId != null) {
            final Commands cmds = new Commands(Command.OnError.Stop);
            addAllExpungeCommandsFromList(finalizeExpungeCommands, cmds, vm);
            addAllExpungeCommandsFromList(nicExpungeCommands, cmds, vm);
            _agentMgr.send(hostId, cmds);
            if (!cmds.isSuccessful()) {
                for (final Answer answer : cmds.getAnswers()) {
                    if (!answer.getResult()) {
                        s_logger.warn("Failed to expunge vm due to: " + answer.getDetails());
                        throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails());
                    }
                }
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Expunged " + vm);
    }
}
Also used : SecurityGroupManager(com.cloud.network.security.SecurityGroupManager) NetworkModel(com.cloud.network.NetworkModel) UsageEventUtils(com.cloud.event.UsageEventUtils) HostDao(com.cloud.host.dao.HostDao) HypervisorGuruManager(com.cloud.hypervisor.HypervisorGuruManager) ExecutionException(com.cloud.utils.exception.ExecutionException) ResourceState(com.cloud.resource.ResourceState) Pod(com.cloud.dc.Pod) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DiskOffering(com.cloud.offering.DiskOffering) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) Map(java.util.Map) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) VirtualRouter(com.cloud.network.router.VirtualRouter) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) Network(com.cloud.network.Network) TransactionStatus(com.cloud.utils.db.TransactionStatus) DeploymentPlanner(com.cloud.deploy.DeploymentPlanner) ApiDBUtils(com.cloud.api.ApiDBUtils) PreparedStatement(java.sql.PreparedStatement) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) WorkType(com.cloud.ha.HighAvailabilityManager.WorkType) MessageHandler(org.apache.cloudstack.framework.messagebus.MessageHandler) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ServiceOffering(com.cloud.offering.ServiceOffering) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) VolumeApiServiceImpl(com.cloud.storage.VolumeApiServiceImpl) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) VmWorkJobDao(org.apache.cloudstack.framework.jobs.dao.VmWorkJobDao) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) ManagerBase(com.cloud.utils.component.ManagerBase) ReplugNicCommand(com.cloud.agent.api.ReplugNicCommand) StoragePoolHostDao(com.cloud.storage.dao.StoragePoolHostDao) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VMTemplateDao(com.cloud.storage.dao.VMTemplateDao) DataCenterVO(com.cloud.dc.DataCenterVO) LinkedHashMap(java.util.LinkedHashMap) ClusterDao(com.cloud.dc.dao.ClusterDao) DomainRouterJoinDao(com.cloud.api.query.dao.DomainRouterJoinDao) User(com.cloud.user.User) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StorageAccessException(com.cloud.exception.StorageAccessException) AffinityGroupVMMapDao(org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao) ClusterVO(com.cloud.dc.ClusterVO) UserVm(com.cloud.uservm.UserVm) NicTO(com.cloud.agent.api.to.NicTO) HighAvailabilityManager(com.cloud.ha.HighAvailabilityManager) UserVmDao(com.cloud.vm.dao.UserVmDao) NicDao(com.cloud.vm.dao.NicDao) DB(com.cloud.utils.db.DB) Event(com.cloud.vm.VirtualMachine.Event) Command(com.cloud.agent.api.Command) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) ClusterDetailsDao(com.cloud.dc.ClusterDetailsDao) GlobalLock(com.cloud.utils.db.GlobalLock) StorageManager(com.cloud.storage.StorageManager) GPUDeviceTO(com.cloud.agent.api.to.GPUDeviceTO) AnnotationDao(org.apache.cloudstack.annotation.dao.AnnotationDao) StartCommand(com.cloud.agent.api.StartCommand) Date(java.util.Date) StoragePool(com.cloud.storage.StoragePool) AlertManager(com.cloud.alert.AlertManager) UserVmJoinVO(com.cloud.api.query.vo.UserVmJoinVO) ResourceType(com.cloud.configuration.Resource.ResourceType) Cluster(com.cloud.org.Cluster) StartupCommand(com.cloud.agent.api.StartupCommand) GuestOSCategoryDao(com.cloud.storage.dao.GuestOSCategoryDao) StopAnswer(com.cloud.agent.api.StopAnswer) DeploymentPlan(com.cloud.deploy.DeploymentPlan) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) DeploymentPlanningManager(com.cloud.deploy.DeploymentPlanningManager) UnmanagedVMsManager(org.apache.cloudstack.vm.UnmanagedVMsManager) TransactionCallback(com.cloud.utils.db.TransactionCallback) TimeZone(java.util.TimeZone) EntityExistsException(javax.persistence.EntityExistsException) State(com.cloud.vm.VirtualMachine.State) Collection(java.util.Collection) DeployDestination(com.cloud.deploy.DeployDestination) Commands(com.cloud.agent.manager.Commands) MIGRATE_VM_ACROSS_CLUSTERS(com.cloud.configuration.ConfigurationManagerImpl.MIGRATE_VM_ACROSS_CLUSTERS) UUID(java.util.UUID) Pair(com.cloud.utils.Pair) Collectors(java.util.stream.Collectors) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Entry(java.util.Map.Entry) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) AsyncJobManager(org.apache.cloudstack.framework.jobs.AsyncJobManager) DataStoreManager(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkDetailsDao(com.cloud.network.dao.NetworkDetailsDao) DiskOfferingDao(com.cloud.storage.dao.DiskOfferingDao) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ConfigKey(org.apache.cloudstack.framework.config.ConfigKey) ReflectionUse(com.cloud.utils.ReflectionUse) Listener(com.cloud.agent.Listener) MigrateCommand(com.cloud.agent.api.MigrateCommand) VolumeDao(com.cloud.storage.dao.VolumeDao) ManagementServerNode(org.apache.cloudstack.utils.identity.ManagementServerNode) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) DataCenter(com.cloud.dc.DataCenter) HostVO(com.cloud.host.HostVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) JobInfo(org.apache.cloudstack.jobs.JobInfo) MapUtils(org.apache.commons.collections.MapUtils) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) UserVmDeployAsIsDetailsDao(com.cloud.deployasis.dao.UserVmDeployAsIsDetailsDao) DiskTO(com.cloud.agent.api.to.DiskTO) ApiConstants(org.apache.cloudstack.api.ApiConstants) MigrateVMCmd(org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) NetworkDetailVO(com.cloud.network.dao.NetworkDetailVO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) Comparator(java.util.Comparator) Arrays(java.util.Arrays) UserVmJoinDao(com.cloud.api.query.dao.UserVmJoinDao) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) Transaction(com.cloud.utils.db.Transaction) TransactionCallbackWithExceptionNoReturn(com.cloud.utils.db.TransactionCallbackWithExceptionNoReturn) HostAllocator(com.cloud.agent.manager.allocator.HostAllocator) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AttachOrDettachConfigDriveCommand(com.cloud.agent.api.AttachOrDettachConfigDriveCommand) AgentManager(com.cloud.agent.AgentManager) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) BooleanUtils(org.apache.commons.lang.BooleanUtils) PowerState(com.cloud.vm.VirtualMachine.PowerState) ResultSet(java.sql.ResultSet) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) CapacityManager(com.cloud.capacity.CapacityManager) CallContext(org.apache.cloudstack.context.CallContext) StopCommand(com.cloud.agent.api.StopCommand) ResourceManager(com.cloud.resource.ResourceManager) Set(java.util.Set) ScopeType(com.cloud.storage.ScopeType) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateVolumeCmd(org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd) Executors(java.util.concurrent.Executors) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) VMSnapshotManager(com.cloud.vm.snapshot.VMSnapshotManager) RebootAnswer(com.cloud.agent.api.RebootAnswer) GuestOSDao(com.cloud.storage.dao.GuestOSDao) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO) UsageEventVO(com.cloud.event.UsageEventVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) ArrayList(java.util.ArrayList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) StartAnswer(com.cloud.agent.api.StartAnswer) AsyncJob(org.apache.cloudstack.framework.jobs.AsyncJob) ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) VMInstanceDao(com.cloud.vm.dao.VMInstanceDao) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Journal(com.cloud.utils.Journal) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) JobSerializerHelper(org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) HostPodDao(com.cloud.dc.dao.HostPodDao) Host(com.cloud.host.Host) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ImageFormat(com.cloud.storage.Storage.ImageFormat) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) DpdkTO(com.cloud.agent.api.to.DpdkTO) Certificate(org.apache.cloudstack.framework.ca.Certificate) Networks(com.cloud.network.Networks) Step(com.cloud.vm.ItWorkVO.Step) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Type(com.cloud.storage.Volume.Type) Logger(org.apache.log4j.Logger) ResourceLimitService(com.cloud.user.ResourceLimitService) URI(java.net.URI) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) StringUtils(com.cloud.utils.StringUtils) ManagedContextRunnable(org.apache.cloudstack.managed.context.ManagedContextRunnable) PrimaryDataStoreDao(org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao) MessageDispatcher(org.apache.cloudstack.framework.messagebus.MessageDispatcher) StateMachine2(com.cloud.utils.fsm.StateMachine2) AffinityConflictException(com.cloud.exception.AffinityConflictException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) Account(com.cloud.user.Account) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand) HypervisorGuru(com.cloud.hypervisor.HypervisorGuru) Status(com.cloud.host.Status) VMSnapshotDao(com.cloud.vm.snapshot.dao.VMSnapshotDao) List(java.util.List) MigrateVolumeCmdByAdmin(org.apache.cloudstack.api.command.admin.volume.MigrateVolumeCmdByAdmin) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CAManager(org.apache.cloudstack.ca.CAManager) DataCenterDao(com.cloud.dc.dao.DataCenterDao) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HypervisorGuruBase(com.cloud.hypervisor.HypervisorGuruBase) Predicate(com.cloud.utils.Predicate) EntityManager(com.cloud.utils.db.EntityManager) VolumeApiService(com.cloud.storage.VolumeApiService) RebootCommand(com.cloud.agent.api.RebootCommand) HashMap(java.util.HashMap) ConfigurationException(javax.naming.ConfigurationException) NetworkDao(com.cloud.network.dao.NetworkDao) EventTypes(com.cloud.event.EventTypes) MessageBus(org.apache.cloudstack.framework.messagebus.MessageBus) Outcome(org.apache.cloudstack.framework.jobs.Outcome) CollectionUtils(org.apache.commons.collections.CollectionUtils) UserVmDetailsDao(com.cloud.vm.dao.UserVmDetailsDao) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) NetworkVO(com.cloud.network.dao.NetworkVO) Configurable(org.apache.cloudstack.framework.config.Configurable) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) DomainRouterJoinVO(com.cloud.api.query.vo.DomainRouterJoinVO) DateUtil(com.cloud.utils.DateUtil) OutcomeImpl(org.apache.cloudstack.framework.jobs.impl.OutcomeImpl) TimeUnit(java.util.concurrent.TimeUnit) NetworkOffering(com.cloud.offering.NetworkOffering) HostPodVO(com.cloud.dc.HostPodVO) Ternary(com.cloud.utils.Ternary) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) Volume(com.cloud.storage.Volume) RestoreVMSnapshotCommand(com.cloud.agent.api.RestoreVMSnapshotCommand) Collections(java.util.Collections) VolumeVO(com.cloud.storage.VolumeVO) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) HypervisorGuru(com.cloud.hypervisor.HypervisorGuru) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) ReplugNicCommand(com.cloud.agent.api.ReplugNicCommand) Command(com.cloud.agent.api.Command) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) StartCommand(com.cloud.agent.api.StartCommand) StartupCommand(com.cloud.agent.api.StartupCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) AttachOrDettachConfigDriveCommand(com.cloud.agent.api.AttachOrDettachConfigDriveCommand) StopCommand(com.cloud.agent.api.StopCommand) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand) RebootCommand(com.cloud.agent.api.RebootCommand) RestoreVMSnapshotCommand(com.cloud.agent.api.RestoreVMSnapshotCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) Commands(com.cloud.agent.manager.Commands) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 100 with ResourceUnavailableException

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

the class VirtualMachineManagerImpl method findHostAndMigrate.

@Override
public void findHostAndMigrate(final String vmUuid, final Long newSvcOfferingId, final Map<String, String> customParameters, final ExcludeList excludes) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        throw new CloudRuntimeException("Unable to find " + vmUuid);
    }
    ServiceOfferingVO newServiceOffering = _offeringDao.findById(newSvcOfferingId);
    if (newServiceOffering.isDynamic()) {
        newServiceOffering.setDynamicFlag(true);
        newServiceOffering = _offeringDao.getComputeOffering(newServiceOffering, customParameters);
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, newServiceOffering, null, null);
    final Long srcHostId = vm.getHostId();
    final Long oldSvcOfferingId = vm.getServiceOfferingId();
    if (srcHostId == null) {
        throw new CloudRuntimeException("Unable to scale the vm because it doesn't have a host id");
    }
    final Host host = _hostDao.findById(srcHostId);
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, null, null);
    excludes.addHost(vm.getHostId());
    vm.setServiceOfferingId(newSvcOfferingId);
    DeployDestination dest = null;
    try {
        dest = _dpMgr.planDeployment(profile, plan, excludes, null);
    } catch (final AffinityConflictException e2) {
        String message = String.format("Unable to create deployment, affinity rules associted to the %s conflict.", vm.toString());
        s_logger.warn(message, e2);
        throw new CloudRuntimeException(message);
    }
    if (dest != null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(" Found " + dest + " for scaling the vm to.");
        }
    }
    if (dest == null) {
        throw new InsufficientServerCapacityException("Unable to find a server to scale the vm to.", host.getClusterId());
    }
    excludes.addHost(dest.getHost().getId());
    try {
        migrateForScale(vm.getUuid(), srcHostId, dest, oldSvcOfferingId);
    } catch (ResourceUnavailableException | ConcurrentOperationException e) {
        s_logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e);
        throw e;
    }
}
Also used : DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

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