Package com.cloud.storage

Examples of com.cloud.storage.DiskOfferingVO


                newTags.append(token.trim()).append(",");
            }
            newTags.delete(newTags.length() - 1, newTags.length());
            tags = newTags.toString();
        }
        DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, diskSpace, tags, false, null, null, null);
        diskOffering.setUseLocalStorage(local);

        Long bytesReadRate = Long.parseLong(_currentObjectParams.get("bytesReadRate"));
        if (bytesReadRate != null && (bytesReadRate > 0))
            diskOffering.setBytesReadRate(bytesReadRate);
        Long bytesWriteRate = Long.parseLong(_currentObjectParams.get("bytesWriteRate"));
        if (bytesWriteRate != null && (bytesWriteRate > 0))
            diskOffering.setBytesWriteRate(bytesWriteRate);
        Long iopsReadRate = Long.parseLong(_currentObjectParams.get("iopsReadRate"));
        if (iopsReadRate != null && (iopsReadRate > 0))
            diskOffering.setIopsReadRate(iopsReadRate);
        Long iopsWriteRate = Long.parseLong(_currentObjectParams.get("iopsWriteRate"));
        if (iopsWriteRate != null && (iopsWriteRate > 0))
            diskOffering.setIopsWriteRate(iopsWriteRate);

        DiskOfferingDaoImpl offering = ComponentContext.inject(DiskOfferingDaoImpl.class);
        try {
            offering.persist(diskOffering);
        } catch (Exception e) {
View Full Code Here


                // Create an event
                Long templateId = volume.getTemplateId();
                Long diskOfferingId = volume.getDiskOfferingId();
                Long offeringId = null;
                if (diskOfferingId != null) {
                            DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
                            if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) {
                        offeringId = offering.getId();
                    }
                }
                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(),
                        offeringId, templateId, volume.getSize(), Volume.class.getName(), volume.getUuid(), volume.isDisplayVolume());
            }
View Full Code Here

        long size = 0;
        if (tmp != null) {
            size = tmp;
        }
        if (diskOfferingId != null) {
            DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
            if (diskOffering != null && diskOffering.isCustomized()) {
                if (diskSize == null) {
                    throw new InvalidParameterValueException("This disk offering requires a custom size specified");
                }
                Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
                Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
View Full Code Here

        if (svcOffering.getUseLocalStorage()) {
            usesLocalStorage = true;
        } else {
            List<VolumeVO> volumes = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.DATADISK);
            for (VolumeVO vol : volumes) {
                DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
                if (diskOffering.getUseLocalStorage()) {
                    usesLocalStorage = true;
                    break;
                }
            }
        }
View Full Code Here

        // Check if the vm is using any disks on local storage.
        VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm);
        List<VolumeVO> volumes = _volumeDao.findCreatedByInstance(vmProfile.getId());
        boolean usesLocal = false;
        for (VolumeVO volume : volumes) {
            DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
            DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
            if (diskProfile.useLocalStorage()) {
                usesLocal = true;
                break;
            }
View Full Code Here

        return new Ternary<Pair<List<? extends Host>, Integer>, List<? extends Host>, Map<Host, Boolean>>(otherHosts, suitableHosts, requiresStorageMotion);
    }

    private boolean hasSuitablePoolsForVolume(VolumeVO volume, Host host, VirtualMachineProfile vmProfile) {
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
        DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
        DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
        ExcludeList avoid = new ExcludeList();

        for (StoragePoolAllocator allocator : _storagePoolAllocators) {
View Full Code Here

        // Volume stays in the same cluster after migration.
        DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), srcVolumePool.getPodId(), srcVolumePool.getClusterId(), null, null, null);
        VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);

        DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
        DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType());

        // Call the storage pool allocator to find the list of storage pools.
        for (StoragePoolAllocator allocator : _storagePoolAllocators) {
            List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
View Full Code Here

        // If local storage is disabled then attaching a volume with local disk
        // offering not allowed
        DataCenterVO dataCenter = _dcDao.findById(volume.getDataCenterId());
        if (!dataCenter.isLocalStorageEnabled()) {
            DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume
                    .getDiskOfferingId());
            if (diskOffering.getUseLocalStorage()) {
                throw new InvalidParameterValueException(
                        "Zone is not configured to use local storage but volume's disk offering "
                                + diskOffering.getName() + " uses it");
            }
        }

        // permission check
        _accountMgr.checkAccess(caller, null, true, volume, vm);

        // Check if volume is stored on secondary Storage.
        boolean isVolumeOnSec = false;
        VolumeHostVO  volHostVO = _volumeHostDao.findByVolumeId(volume.getId());
        if (volHostVO != null) {
            isVolumeOnSec = true;
            if (!(volHostVO.getDownloadState() == Status.DOWNLOADED)) {
                throw new InvalidParameterValueException(
                        "Volume is not uploaded yet. Please try this operation once the volume is uploaded");
            }
        }

        if (!(Volume.State.Allocated.equals(volume.getState())
                || Volume.State.Ready.equals(volume.getState()) || Volume.State.UploadOp
                .equals(volume.getState()))) {
            throw new InvalidParameterValueException(
                    "Volume state must be in Allocated, Ready or in Uploaded state");
        }

        VolumeVO rootVolumeOfVm = null;
        List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vmId,
                Volume.Type.ROOT);
        if (rootVolumesOfVm.size() != 1) {
            throw new CloudRuntimeException(
                    "The VM "
                            + vm.getHostName()
                            + " has more than one ROOT volume and is in an invalid state.");
        } else {
            rootVolumeOfVm = rootVolumesOfVm.get(0);
        }

        HypervisorType rootDiskHyperType = vm.getHypervisorType();

        HypervisorType dataDiskHyperType = _volsDao.getHypervisorType(volume
                .getId());
        if (dataDiskHyperType != HypervisorType.None
                && rootDiskHyperType != dataDiskHyperType) {
            throw new InvalidParameterValueException(
                    "Can't attach a volume created by: " + dataDiskHyperType
                    + " to a " + rootDiskHyperType + " vm");
        }

        // allocate deviceId
        List<VolumeVO> vols = _volsDao.findByInstance(vmId);
        if (deviceId != null) {
            if (deviceId.longValue() > 15 || deviceId.longValue() == 0
                    || deviceId.longValue() == 3) {
                throw new RuntimeException("deviceId should be 1,2,4-15");
            }
            for (VolumeVO vol : vols) {
                if (vol.getDeviceId().equals(deviceId)) {
                    throw new RuntimeException("deviceId " + deviceId
                            + " is used by VM " + vm.getHostName());
                }
            }
        } else {
            // allocate deviceId here
            List<String> devIds = new ArrayList<String>();
            for (int i = 1; i < 15; i++) {
                devIds.add(String.valueOf(i));
            }
            devIds.remove("3");
            for (VolumeVO vol : vols) {
                devIds.remove(vol.getDeviceId().toString().trim());
            }
            deviceId = Long.parseLong(devIds.iterator().next());
        }

        boolean createVolumeOnBackend = true;
        if (rootVolumeOfVm.getState() == Volume.State.Allocated) {
            createVolumeOnBackend = false;
            if (isVolumeOnSec) {
                throw new CloudRuntimeException(
                        "Cant attach uploaded volume to the vm which is not created. Please start it and then retry");
            }
        }

        // create volume on the backend only when vm's root volume is allocated
        if (createVolumeOnBackend) {
            if (volume.getState().equals(Volume.State.Allocated)
                    || isVolumeOnSec) {
                /* Need to create the volume */
                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();
View Full Code Here

                // Create an event
                Long templateId = volume.getTemplateId();
                Long diskOfferingId = volume.getDiskOfferingId();
                Long offeringId = null;
                if (diskOfferingId != null) {
                    DiskOfferingVO offering = _diskOfferingDao
                            .findById(diskOfferingId);
                    if (offering != null
                            && (offering.getType() == DiskOfferingVO.Type.Disk)) {
                        offeringId = offering.getId();
                    }
                }
                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(),
                        volume.getDataCenterId(), volume.getId(), volume.getName(), offeringId, templateId,
                        volume.getSize(), Volume.class.getName(), volume.getUuid());
View Full Code Here

            usesLocalStorage = true;
        } else {
            List<VolumeVO> volumes = _volsDao.findByInstanceAndType(vm.getId(),
                    Volume.Type.DATADISK);
            for (VolumeVO vol : volumes) {
                DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol
                        .getDiskOfferingId());
                if (diskOffering.getUseLocalStorage()) {
                    usesLocalStorage = true;
                    break;
                }
            }
        }
View Full Code Here

TOP

Related Classes of com.cloud.storage.DiskOfferingVO

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.