Package com.cloud.storage

Examples of com.cloud.storage.StoragePoolVO


        // data disk and host identified from deploying vm (attach volume case)
        if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) {
            List<StoragePoolHostVO> hostPools = _poolHostDao.listByHostId(plan.getHostId());
            for (StoragePoolHostVO hostPool: hostPools) {
                StoragePoolVO pool = _storagePoolDao.findById(hostPool.getPoolId());
                if (pool != null && pool.isLocal()) {
                    s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
                    suitablePools.add(pool);
                }

                if (suitablePools.size() == returnUpTo) {
                    break;
                }
            }
        } else {
            List<StoragePool> availablePool;
            while (!(availablePool = super.allocateToPool(dskCh, vmProfile, plan, myAvoids, 1)).isEmpty()) {
                StoragePool pool = availablePool.get(0);
                myAvoids.addPool(pool.getId());
                List<StoragePoolHostVO> hostsInSPool = _poolHostDao.listByPoolId(pool.getId());
                assert (hostsInSPool.size() == 1) : "Local storage pool should be one host per pool";

                s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
                suitablePools.add(pool);

                if (suitablePools.size() == returnUpTo) {
                    break;
                }
View Full Code Here


                VMTemplateVO rootDiskTmplt = _templateDao.findById(vm
                        .getTemplateId());
                DataCenterVO dcVO = _dcDao.findById(vm
                        .getDataCenterId());
                HostPodVO pod = _podDao.findById(vm.getPodIdToDeployIn());
                StoragePoolVO rootDiskPool = _storagePoolDao
                        .findById(rootVolumeOfVm.getPoolId());
                ServiceOfferingVO svo = _serviceOfferingDao.findById(vm
                        .getServiceOfferingId());
                DiskOfferingVO diskVO = _diskOfferingDao.findById(volume
                        .getDiskOfferingId());
                Long clusterId = (rootDiskPool == null ? null : rootDiskPool
                        .getClusterId());

                if (!isVolumeOnSec) {
                    volume = _storageMgr.createVolume(volume, vm,
                            rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO,
                            new ArrayList<StoragePoolVO>(), volume.getSize(),
                            rootDiskHyperType);
                } else {
                    try {
                        // Format of data disk should be the same as root disk
                        if (!volHostVO
                                .getFormat()
                                .getFileExtension()
                                .equals(_storageMgr
                                        .getSupportedImageFormatForCluster(rootDiskPool
                                                .getClusterId()))) {
                            throw new InvalidParameterValueException(
                                    "Failed to attach volume to VM since volumes format "
                                            + volHostVO.getFormat()
                                            .getFileExtension()
                                            + " is not compatible with the vm hypervisor type");
                        }

                        // Check that there is some shared storage.
                        StoragePoolVO vmRootVolumePool = _storagePoolDao
                                .findById(rootVolumeOfVm.getPoolId());
                        List<StoragePoolVO> sharedVMPools = _storagePoolDao
                                .findPoolsByTags(
                                        vmRootVolumePool.getDataCenterId(),
                                        vmRootVolumePool.getPodId(),
                                        vmRootVolumePool.getClusterId(), null,
                                        true);
                        if (sharedVMPools.size() == 0) {
                            throw new CloudRuntimeException(
                                    "Cannot attach volume since there are no shared storage pools in the VM's cluster to copy the uploaded volume to.");
                        }

                        volume = _storageMgr.copyVolumeFromSecToPrimary(volume,
                                vm, rootDiskTmplt, dcVO, pod,
                                rootDiskPool.getClusterId(), svo, diskVO,
                                new ArrayList<StoragePoolVO>(),
                                volume.getSize(), rootDiskHyperType);
                    } catch (NoTransitionException e) {
                        throw new CloudRuntimeException(
                                "Unable to transition the volume ", e);
                    }
                }

                if (volume == null) {
                    throw new CloudRuntimeException(
                            "Failed to create volume when attaching it to VM: "
                                    + vm.getHostName());
                }
            }

            StoragePoolVO vmRootVolumePool = _storagePoolDao
                    .findById(rootVolumeOfVm.getPoolId());
            DiskOfferingVO volumeDiskOffering = _diskOfferingDao
                    .findById(volume.getDiskOfferingId());
            String[] volumeTags = volumeDiskOffering.getTagsArray();

            boolean isVolumeOnSharedPool = !volumeDiskOffering
                    .getUseLocalStorage();
            StoragePoolVO sourcePool = _storagePoolDao.findById(volume
                    .getPoolId());
            List<StoragePoolVO> matchingVMPools = _storagePoolDao
                    .findPoolsByTags(vmRootVolumePool.getDataCenterId(),
                            vmRootVolumePool.getPodId(),
                            vmRootVolumePool.getClusterId(), volumeTags,
                            isVolumeOnSharedPool);
            boolean moveVolumeNeeded = true;
            if (matchingVMPools.size() == 0) {
                String poolType;
                if (vmRootVolumePool.getClusterId() != null) {
                    poolType = "cluster";
                } else if (vmRootVolumePool.getPodId() != null) {
                    poolType = "pod";
                } else {
                    poolType = "zone";
                }
                throw new CloudRuntimeException(
                        "There are no storage pools in the VM's " + poolType
                        + " with all of the volume's tags ("
                        + volumeDiskOffering.getTags() + ").");
            } else {
                long sourcePoolId = sourcePool.getId();
                Long sourcePoolDcId = sourcePool.getDataCenterId();
                Long sourcePoolPodId = sourcePool.getPodId();
                Long sourcePoolClusterId = sourcePool.getClusterId();
                for (StoragePoolVO vmPool : matchingVMPools) {
                    long vmPoolId = vmPool.getId();
                    Long vmPoolDcId = vmPool.getDataCenterId();
                    Long vmPoolPodId = vmPool.getPodId();
                    Long vmPoolClusterId = vmPool.getClusterId();

                    // Moving a volume is not required if storage pools belongs
                    // to same cluster in case of shared volume or
                    // identical storage pool in case of local
                    if (sourcePoolDcId == vmPoolDcId
                            && sourcePoolPodId == vmPoolPodId
                            && sourcePoolClusterId == vmPoolClusterId
                            && (isVolumeOnSharedPool || sourcePoolId == vmPoolId)) {
                        moveVolumeNeeded = false;
                        break;
                    }
                }
            }

            if (moveVolumeNeeded) {
                if (isVolumeOnSharedPool) {
                    // Move the volume to a storage pool in the VM's zone, pod,
                    // or cluster
                    try {
                        volume = _storageMgr.moveVolume(volume,
                                vmRootVolumePool.getDataCenterId(),
                                vmRootVolumePool.getPodId(),
                                vmRootVolumePool.getClusterId(),
                                dataDiskHyperType);
                    } catch (ConcurrentOperationException e) {
                        throw new CloudRuntimeException(e.toString());
                    }
                } else {
                    throw new CloudRuntimeException(
                            "Failed to attach local data volume "
                                    + volume.getName()
                                    + " to VM "
                                    + vm.getDisplayName()
                                    + " as migration of local data volume is not allowed");
                }
            }
        }

        AsyncJobExecutor asyncExecutor = BaseAsyncJobExecutor
                .getCurrentExecutor();
        if (asyncExecutor != null) {
            AsyncJobVO job = asyncExecutor.getJob();

            if (s_logger.isInfoEnabled()) {
                s_logger.info("Trying to attaching volume " + volumeId
                        + " to vm instance:" + vm.getId()
                        + ", update async job-" + job.getId()
                        + " progress status");
            }

            _asyncMgr.updateAsyncJobAttachment(job.getId(), "volume", volumeId);
            _asyncMgr.updateAsyncJobStatus(job.getId(),
                    BaseCmd.PROGRESS_INSTANCE_CREATED, volumeId);
        }

        String errorMsg = "Failed to attach volume: " + volume.getName()
                + " to VM: " + vm.getHostName();
        boolean sendCommand = (vm.getState() == State.Running);
        AttachVolumeAnswer answer = null;
        Long hostId = vm.getHostId();
        if (hostId == null) {
            hostId = vm.getLastHostId();
            HostVO host = _hostDao.findById(hostId);
            if (host != null
                    && host.getHypervisorType() == HypervisorType.VMware) {
                sendCommand = true;
            }
        }

        if (sendCommand) {
            StoragePoolVO volumePool = _storagePoolDao.findById(volume
                    .getPoolId());
            AttachVolumeCommand cmd = new AttachVolumeCommand(true,
                    vm.getInstanceName(), volume.getPoolType(),
                    volume.getFolder(), volume.getPath(), volume.getName(),
                    deviceId, volume.getChainInfo());
            cmd.setPoolUuid(volumePool.getUuid());

            try {
                answer = (AttachVolumeAnswer) _agentMgr.send(hostId, cmd);
            } catch (Exception e) {
                throw new CloudRuntimeException(errorMsg + " due to: "
View Full Code Here

                    vm.getInstanceName(), volume.getPoolType(),
                    volume.getFolder(), volume.getPath(), volume.getName(),
                    cmmd.getDeviceId() != null ? cmmd.getDeviceId() : volume
                            .getDeviceId(), volume.getChainInfo());

            StoragePoolVO volumePool = _storagePoolDao.findById(volume
                    .getPoolId());
            cmd.setPoolUuid(volumePool.getUuid());

            try {
                answer = _agentMgr.send(vm.getHostId(), cmd);
            } catch (Exception e) {
                throw new CloudRuntimeException(errorMsg + " due to: "
View Full Code Here

        SnapshotCommand cmd = null;
        VMTemplateVO privateTemplate = null;

        String uniqueName = getRandomPrivateTemplateName();

        StoragePoolVO pool = null;
        HostVO secondaryStorageHost = null;
        Long zoneId = null;
        Long accountId = null;
        SnapshotVO snapshot = null;
        String secondaryStorageURL = null;
View Full Code Here

  }


  @Override
  public void updateAvailable(long id, long available) {
    StoragePoolVO pool = createForUpdate(id);
    pool.setAvailableBytes(available);
    update(id, pool);
  }
View Full Code Here

  }


  @Override
  public void updateCapacity(long id, long capacity) {
    StoragePoolVO pool = createForUpdate(id);
    pool.setCapacityBytes(capacity);
    update(id, pool);

  }
View Full Code Here

                        + " upload is in progress. Please wait for some time to schedule another upload for the same");
            }
        }

        long accountId = volume.getAccountId();
        StoragePoolVO srcPool = _poolDao.findById(volume.getPoolId());
        HostVO sserver = _storageMgr.getSecondaryStorageHost(zoneId);
        String secondaryStorageURL = sserver.getStorageUrl();

        List<UploadVO> extractURLList = _uploadDao.listByTypeUploadStatus(volumeId, Upload.Type.VOLUME, UploadVO.Status.DOWNLOAD_URL_CREATED);
View Full Code Here

                                s_logger.debug(vol + " of " + vm + " is READY, but template ids don't match, let the planner reassign a new pool");
                            }
                            continue;
                        }

                        StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
                        if (!pool.isInMaintenance()) {
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("Root volume is ready, need to place VM in volume's cluster");
                            }
                            long rootVolDcId = pool.getDataCenterId();
                            Long rootVolPodId = pool.getPodId();
                            Long rootVolClusterId = pool.getClusterId();
                            if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
                                Long clusterIdSpecified = planToDeploy.getClusterId();
                                if (clusterIdSpecified != null && rootVolClusterId != null) {
                                    if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
                                        // cannot satisfy the plan passed in to the
View Full Code Here

            //If the plan specifies a poolId, it means that this VM's ROOT volume is ready and the pool should be reused.
            //In this case, also check if rest of the volumes are ready and can be reused.
            if(plan.getPoolId() != null){
                s_logger.debug("Volume has pool(" + plan.getPoolId() + ") already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId());
                List<StoragePool> suitablePools = new ArrayList<StoragePool>();
                StoragePoolVO pool;
                if(toBeCreated.getPoolId() != null){
                    s_logger.debug("finding pool by id '" + toBeCreated.getPoolId() + "'");
                    pool = _storagePoolDao.findById(toBeCreated.getPoolId());
                }else{
                    s_logger.debug("finding pool by id '" + plan.getPoolId() + "'");
                    pool = _storagePoolDao.findById(plan.getPoolId());
                }

                if(pool != null){
                    if(!pool.isInMaintenance()){
                        if(!avoid.shouldAvoid(pool)){
                            long exstPoolDcId = pool.getDataCenterId();

                            long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1;
                            long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1;
                            if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){
                                s_logger.debug("Planner need not allocate a pool for this volume since its READY");
                                suitablePools.add(pool);
                                suitableVolumeStoragePools.put(toBeCreated, suitablePools);
                                if (!(toBeCreated.getState() == Volume.State.Allocated || toBeCreated.getState() == Volume.State.Creating)) {
View Full Code Here

        }
       
        List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
        if(!vols.isEmpty()){
            VolumeVO vol = vols.get(0);
            StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
            if (!pool.isInMaintenance()) {
                long rootVolDcId = pool.getDataCenterId();
                Long rootVolPodId = pool.getPodId();
                Long rootVolClusterId = pool.getClusterId();
                if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
                    Long clusterIdSpecified = planToDeploy.getClusterId();
                    if (clusterIdSpecified != null && rootVolClusterId != null) {
                        if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
                            // cannot satisfy the plan passed in to the
View Full Code Here

TOP

Related Classes of com.cloud.storage.StoragePoolVO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.