Search in sources :

Example 11 with StorageUnavailableException

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

the class NetScalerVMManagerImpl method deployNsVpx.

@Override
public Map<String, Object> deployNsVpx(Account owner, DeployDestination dest, DeploymentPlan plan, long svcOffId, long templateId) throws InsufficientCapacityException {
    VMTemplateVO template = _templateDao.findById(templateId);
    long id = _vmDao.getNextInSequence(Long.class, "id");
    Account systemAcct = _accountMgr.getSystemAccount();
    if (template == null) {
        s_logger.error(" Unable to find the NS VPX template");
        throw new CloudRuntimeException("Unable to find the Template" + templateId);
    }
    long dataCenterId = dest.getDataCenter().getId();
    DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId());
    String nxVpxName = VirtualMachineName.getSystemVmName(id, "Vpx", NetScalerLbVmNamePrefix);
    // using 2GB and 2CPU  offering
    ServiceOfferingVO vpxOffering = _serviceOfferingDao.findById(svcOffId);
    if (vpxOffering.getRamSize() < 2048 && vpxOffering.getCpu() < 2) {
        throw new InvalidParameterValueException("Specified Service Offering :" + vpxOffering.getUuid() + " NS Vpx cannot be deployed. Min 2GB Ram and 2 CPU are required");
    }
    long userId = CallContext.current().getCallingUserId();
    // TODO change the os bits from 142  103 to the actual guest of bits
    if (template.getGuestOSId() != 103) {
        throw new InvalidParameterValueException("Specified Template " + template.getUuid() + " not suitable for NS VPX Deployment. Please register the template with guest os type as unknow(64-bit)");
    }
    NetworkVO defaultNetwork = null;
    NetworkVO defaultPublicNetwork = null;
    if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
        List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
        if (networks == null || networks.size() == 0) {
            throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
        }
        defaultNetwork = networks.get(0);
    } else {
        TrafficType defaultTrafficType = TrafficType.Management;
        List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
        TrafficType publicTrafficType = TrafficType.Public;
        List<NetworkVO> publicNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, publicTrafficType);
        // api should never allow this situation to happen
        if (defaultNetworks.size() != 1) {
            throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
        }
        if (publicNetworks.size() != 1) {
            throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
        }
        defaultPublicNetwork = publicNetworks.get(0);
        defaultNetwork = defaultNetworks.get(0);
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(4);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(0);
    networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<NicProfile>());
    NicProfile defaultNic1 = new NicProfile();
    defaultNic1.setDefaultNic(false);
    defaultNic1.setDeviceId(1);
    NicProfile defaultNic2 = new NicProfile();
    defaultNic2.setDefaultNic(false);
    defaultNic2.setDeviceId(2);
    defaultNic2.setIPv4Address("");
    defaultNic2.setIPv4Gateway("");
    defaultNic2.setIPv4Netmask("");
    String macAddress = _networkDao.getNextAvailableMacAddress(defaultPublicNetwork.getId(), null);
    defaultNic2.setMacAddress(macAddress);
    networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findByUniqueName(NetworkOffering.SystemPublicNetwork), plan, null, null, false).get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic2)));
    networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findByUniqueName(NetworkOffering.SystemControlNetwork), plan, null, null, false).get(0), new ArrayList<NicProfile>());
    long physicalNetworkId = _networkModel.findPhysicalNetworkId(dataCenterId, _networkOfferingDao.findById(defaultPublicNetwork.getNetworkOfferingId()).getTags(), TrafficType.Public);
    // Validate physical network
    PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Unable to find physical network with id: " + physicalNetworkId + " and tag: " + _networkOfferingDao.findById(defaultPublicNetwork.getNetworkOfferingId()).getTags());
    }
    String guestvnet = physicalNetwork.getVnetString();
    final List<VlanVO> vlans = _vlanDao.listByZone(dataCenterId);
    List<String> pvlan = new ArrayList<String>();
    for (final VlanVO vlan : vlans) {
        pvlan.add(vlan.getVlanTag());
    }
    long netScalerProvider = getNetScalerLbProviderId(physicalNetworkId);
    DomainRouterVO nsVpx = new DomainRouterVO(id, vpxOffering.getId(), netScalerProvider, nxVpxName, template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, false, false, VirtualMachine.Type.NetScalerVm, null);
    nsVpx.setRole(Role.NETSCALER_VM);
    nsVpx = _routerDao.persist(nsVpx);
    VMInstanceVO vmVO = _vmDao.findVMByHostName(nxVpxName);
    _itMgr.allocate(nxVpxName, template, vpxOffering, networks, plan, template.getHypervisorType());
    Map<Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
    try {
        if (vmVO != null) {
            startNsVpx(vmVO, params);
        } else {
            throw new NullPointerException();
        }
    } catch (StorageUnavailableException e) {
        e.printStackTrace();
    } catch (ConcurrentOperationException e) {
        e.printStackTrace();
    } catch (ResourceUnavailableException e) {
        e.printStackTrace();
    }
    vmVO = _vmDao.findByUuid(nsVpx.getUuid());
    Map<String, Object> deployResponse = new HashMap<String, Object>();
    deployResponse.put("vm", vmVO);
    deployResponse.put("guestvlan", guestvnet);
    deployResponse.put("publicvlan", pvlan);
    return deployResponse;
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) List(java.util.List) ArrayList(java.util.ArrayList) VlanVO(com.cloud.dc.VlanVO) TrafficType(com.cloud.network.Networks.TrafficType) DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) Param(com.cloud.vm.VirtualMachineProfile.Param) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 12 with StorageUnavailableException

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

the class AbstractStoragePoolAllocator method filter.

protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, DeploymentPlan plan) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking if storage pool is suitable, name: " + pool.getName() + " ,poolId: " + pool.getId());
    }
    if (avoid.shouldAvoid(pool)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("StoragePool is in avoid set, skipping this pool");
        }
        return false;
    }
    Long clusterId = pool.getClusterId();
    if (clusterId != null) {
        ClusterVO cluster = clusterDao.findById(clusterId);
        if (!(cluster.getHypervisorType() == dskCh.getHypervisorType())) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool");
            }
            return false;
        }
    } else if (pool.getHypervisor() != null && !pool.getHypervisor().equals(HypervisorType.Any) && !(pool.getHypervisor() == dskCh.getHypervisorType())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("StoragePool does not have required hypervisorType, skipping this pool");
        }
        return false;
    }
    if (!checkDiskProvisioningSupport(dskCh, pool)) {
        return false;
    }
    if (!checkHypervisorCompatibility(dskCh.getHypervisorType(), dskCh.getType(), pool.getPoolType())) {
        return false;
    }
    Volume volume = volumeDao.findById(dskCh.getVolumeId());
    if (!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) {
        return false;
    }
    if (pool.isManaged() && !storageUtil.managedStoragePoolCanScale(pool, plan.getClusterId(), plan.getHostId())) {
        return false;
    }
    // check capacity
    List<Pair<Volume, DiskProfile>> requestVolumeDiskProfilePairs = new ArrayList<>();
    requestVolumeDiskProfilePairs.add(new Pair<>(volume, dskCh));
    if (dskCh.getHypervisorType() == HypervisorType.VMware) {
        // Skip the parent datastore cluster, consider only child storage pools in it
        if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster && storageMgr.isStoragePoolDatastoreClusterParent(pool)) {
            return false;
        }
        // Skip the storage pool whose parent datastore cluster is not in UP state.
        if (pool.getParent() != 0L) {
            StoragePoolVO datastoreCluster = storagePoolDao.findById(pool.getParent());
            if (datastoreCluster == null || (datastoreCluster != null && datastoreCluster.getStatus() != StoragePoolStatus.Up)) {
                return false;
            }
        }
        try {
            boolean isStoragePoolStoragepolicyComplaince = storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool);
            if (!isStoragePoolStoragepolicyComplaince) {
                return false;
            }
        } catch (StorageUnavailableException e) {
            s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage()));
            return false;
        }
    }
    return storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId());
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) Volume(com.cloud.storage.Volume) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) Pair(com.cloud.utils.Pair)

Example 13 with StorageUnavailableException

use of com.cloud.exception.StorageUnavailableException 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 14 with StorageUnavailableException

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

the class CopyTemplateCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        if (destZoneId == null && (destZoneIds == null || destZoneIds.size() == 0))
            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Either destzoneid or destzoneids parameters have to be specified.");
        if (destZoneId != null && destZoneIds != null && destZoneIds.size() != 0)
            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Both destzoneid and destzoneids cannot be specified at the same time.");
        CallContext.current().setEventDetails(getEventDescription());
        VirtualMachineTemplate template = _templateService.copyTemplate(this);
        if (template != null) {
            List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(getResponseView(), template, getDestinationZoneIds(), false);
            TemplateResponse response = new TemplateResponse();
            if (listResponse != null && !listResponse.isEmpty()) {
                response = listResponse.get(0);
            }
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template");
        }
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) TemplateResponse(org.apache.cloudstack.api.response.TemplateResponse)

Example 15 with StorageUnavailableException

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

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

private void orchestrateStorageMigration(final String vmUuid, final Map<Long, Long> volumeToPool) {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    Map<Volume, StoragePool> volumeToPoolMap = prepareVmStorageMigration(vm, volumeToPool);
    try {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(String.format("Offline migration of %s vm %s with volumes", vm.getHypervisorType().toString(), vm.getInstanceName()));
        }
        migrateThroughHypervisorOrStorage(vm, volumeToPoolMap);
    } catch (ConcurrentOperationException | InsufficientCapacityException | StorageUnavailableException e) {
        String msg = String.format("Failed to migrate VM: %s", vmUuid);
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg, e);
    } finally {
        try {
            stateTransitTo(vm, Event.AgentReportStopped, null);
        } catch (final NoTransitionException e) {
            String anotherMEssage = String.format("failed to change vm state of VM: %s", vmUuid);
            s_logger.warn(anotherMEssage, e);
            throw new CloudRuntimeException(anotherMEssage, e);
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Aggregations

StorageUnavailableException (com.cloud.exception.StorageUnavailableException)52 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)21 DB (com.cloud.utils.db.DB)16 ExecutionException (java.util.concurrent.ExecutionException)15 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)14 ArrayList (java.util.ArrayList)13 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 StoragePool (com.cloud.storage.StoragePool)12 Pair (com.cloud.utils.Pair)11 Answer (com.cloud.agent.api.Answer)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)10 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)9 ConfigurationException (javax.naming.ConfigurationException)9 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)8 DiskOffering (com.cloud.offering.DiskOffering)8 VolumeVO (com.cloud.storage.VolumeVO)8 ExecutionException (com.cloud.utils.exception.ExecutionException)8 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)7