Search in sources :

Example 1 with InsufficientServerCapacityException

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

the class NetworkHelperImpl method startVirtualRouter.

@Override
public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
        return start(router, user, caller, params, null);
    }
    if (router.getState() == State.Running) {
        s_logger.debug("Redundant router " + router.getInstanceName() + " is already running!");
        return router;
    }
    // We will wait until VR is up or fail
    if (router.getState() == State.Starting) {
        return waitRouter(router);
    }
    final DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
    DomainRouterVO result = null;
    assert router.getIsRedundantRouter();
    final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
    DomainRouterVO routerToBeAvoid = null;
    List<DomainRouterVO> routerList = null;
    if (networkIds.size() != 0) {
        routerList = _routerDao.findByNetwork(networkIds.get(0));
    } else if (router.getVpcId() != null) {
        routerList = _routerDao.listByVpcId(router.getVpcId());
    }
    if (routerList != null) {
        for (final DomainRouterVO rrouter : routerList) {
            if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) {
                if (routerToBeAvoid != null) {
                    throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" + ", but there are already two redundant routers with IP " + router.getPublicIpAddress() + ", they are " + rrouter.getInstanceName() + "(" + rrouter.getId() + ") and " + routerToBeAvoid.getInstanceName() + "(" + routerToBeAvoid.getId() + ")", DataCenter.class, rrouter.getDataCenterId());
                }
                routerToBeAvoid = rrouter;
            }
        }
    }
    if (routerToBeAvoid == null) {
        return start(router, user, caller, params, null);
    }
    // We would try best to deploy the router to another place
    final int retryIndex = 5;
    final ExcludeList[] avoids = new ExcludeList[5];
    avoids[0] = new ExcludeList();
    avoids[0].addPod(routerToBeAvoid.getPodIdToDeployIn());
    avoids[1] = new ExcludeList();
    avoids[1].addCluster(_hostDao.findById(routerToBeAvoid.getHostId()).getClusterId());
    avoids[2] = new ExcludeList();
    final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
    if (volumes != null && volumes.size() != 0) {
        avoids[2].addPool(volumes.get(0).getPoolId());
    }
    avoids[2].addHost(routerToBeAvoid.getHostId());
    avoids[3] = new ExcludeList();
    avoids[3].addHost(routerToBeAvoid.getHostId());
    avoids[4] = new ExcludeList();
    for (int i = 0; i < retryIndex; i++) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Try to deploy redundant virtual router:" + router.getHostName() + ", for " + i + " time");
        }
        plan.setAvoids(avoids[i]);
        try {
            result = start(router, user, caller, params, plan);
        } catch (final InsufficientServerCapacityException ex) {
            result = null;
        }
        if (result != null) {
            break;
        }
    }
    return result;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VolumeVO(com.cloud.storage.VolumeVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with InsufficientServerCapacityException

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

the class InternalLoadBalancerVMManagerImpl method getHypervisors.

protected List<HypervisorType> getHypervisors(final DeployDestination dest, final DeploymentPlan plan, final List<HypervisorType> supportedHypervisors) throws InsufficientServerCapacityException {
    List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
    final HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
    if (defaults != HypervisorType.None) {
        hypervisors.add(defaults);
    } else {
        // if there is no default hypervisor, get it from the cluster
        hypervisors = _resourceMgr.getSupportedHypervisorTypes(dest.getDataCenter().getId(), true, plan.getPodId());
    }
    // keep only elements defined in supported hypervisors
    final StringBuilder hTypesStr = new StringBuilder();
    if (supportedHypervisors != null && !supportedHypervisors.isEmpty()) {
        hypervisors.retainAll(supportedHypervisors);
        for (final HypervisorType hType : supportedHypervisors) {
            hTypesStr.append(hType).append(" ");
        }
    }
    if (hypervisors.isEmpty()) {
        throw new InsufficientServerCapacityException("Unable to create internal lb vm, " + "there are no clusters in the zone ", DataCenter.class, dest.getDataCenter().getId());
    }
    return hypervisors;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ArrayList(java.util.ArrayList) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

Example 3 with InsufficientServerCapacityException

use of com.cloud.exception.InsufficientServerCapacityException 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 4 with InsufficientServerCapacityException

use of com.cloud.exception.InsufficientServerCapacityException 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 5 with InsufficientServerCapacityException

use of com.cloud.exception.InsufficientServerCapacityException 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

InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)33 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)21 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 DeployDestination (com.cloud.deploy.DeployDestination)14 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)14 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)12 AffinityConflictException (com.cloud.exception.AffinityConflictException)11 Host (com.cloud.host.Host)8 UserVm (com.cloud.uservm.UserVm)8 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)7 VolumeVO (com.cloud.storage.VolumeVO)7 ExecutionException (com.cloud.utils.exception.ExecutionException)7 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)6 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ServerApiException (com.cloud.api.ServerApiException)4 UserVmResponse (com.cloud.api.response.UserVmResponse)4 ClusterDetailsVO (com.cloud.dc.ClusterDetailsVO)4 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4