Search in sources :

Example 1 with VsphereStoragePolicyVO

use of com.cloud.dc.VsphereStoragePolicyVO in project cloudstack by apache.

the class ServiceOfferingJoinDaoImpl method newServiceOfferingResponse.

@Override
public ServiceOfferingResponse newServiceOfferingResponse(ServiceOfferingJoinVO offering) {
    ServiceOfferingResponse offeringResponse = new ServiceOfferingResponse();
    offeringResponse.setId(offering.getUuid());
    offeringResponse.setName(offering.getName());
    offeringResponse.setIsSystemOffering(offering.isSystemUse());
    offeringResponse.setDefaultUse(offering.isDefaultUse());
    offeringResponse.setSystemVmType(offering.getSystemVmType());
    offeringResponse.setDisplayText(offering.getDisplayText());
    offeringResponse.setProvisioningType(offering.getProvisioningType().toString());
    offeringResponse.setCpuNumber(offering.getCpu());
    offeringResponse.setCpuSpeed(offering.getSpeed());
    offeringResponse.setMemory(offering.getRamSize());
    offeringResponse.setCreated(offering.getCreated());
    offeringResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
    offeringResponse.setOfferHa(offering.isOfferHA());
    offeringResponse.setLimitCpuUse(offering.isLimitCpuUse());
    offeringResponse.setVolatileVm(offering.getVolatileVm());
    offeringResponse.setTags(offering.getTags());
    offeringResponse.setDomain(offering.getDomainName());
    offeringResponse.setDomainId(offering.getDomainUuid());
    offeringResponse.setZone(offering.getZoneName());
    offeringResponse.setZoneId(offering.getZoneUuid());
    offeringResponse.setNetworkRate(offering.getRateMbps());
    offeringResponse.setHostTag(offering.getHostTag());
    offeringResponse.setDeploymentPlanner(offering.getDeploymentPlanner());
    offeringResponse.setCustomizedIops(offering.isCustomizedIops());
    offeringResponse.setMinIops(offering.getMinIops());
    offeringResponse.setMaxIops(offering.getMaxIops());
    offeringResponse.setHypervisorSnapshotReserve(offering.getHypervisorSnapshotReserve());
    offeringResponse.setBytesReadRate(offering.getBytesReadRate());
    offeringResponse.setBytesReadRateMax(offering.getBytesReadRateMax());
    offeringResponse.setBytesReadRateMaxLength(offering.getBytesReadRateMaxLength());
    offeringResponse.setBytesWriteRate(offering.getBytesWriteRate());
    offeringResponse.setBytesWriteRateMax(offering.getBytesWriteRateMax());
    offeringResponse.setBytesWriteRateMaxLength(offering.getBytesWriteRateMaxLength());
    offeringResponse.setIopsReadRate(offering.getIopsReadRate());
    offeringResponse.setIopsReadRateMax(offering.getIopsReadRateMax());
    offeringResponse.setIopsReadRateMaxLength(offering.getIopsReadRateMaxLength());
    offeringResponse.setIopsWriteRate(offering.getIopsWriteRate());
    offeringResponse.setIopsWriteRateMax(offering.getIopsWriteRateMax());
    offeringResponse.setIopsWriteRateMaxLength(offering.getIopsWriteRateMaxLength());
    Map<String, String> offeringDetails = ApiDBUtils.getResourceDetails(offering.getId(), ResourceObjectType.ServiceOffering);
    offeringResponse.setDetails(offeringDetails);
    offeringResponse.setObjectName("serviceoffering");
    offeringResponse.setIscutomized(offering.isDynamic());
    offeringResponse.setCacheMode(offering.getCacheMode());
    offeringResponse.setDynamicScalingEnabled(offering.isDynamicScalingEnabled());
    if (offeringDetails != null && !offeringDetails.isEmpty()) {
        String vsphereStoragePolicyId = offeringDetails.get(ApiConstants.STORAGE_POLICY);
        if (vsphereStoragePolicyId != null) {
            VsphereStoragePolicyVO vsphereStoragePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(vsphereStoragePolicyId));
            if (vsphereStoragePolicyVO != null)
                offeringResponse.setVsphereStoragePolicy(vsphereStoragePolicyVO.getName());
        }
    }
    long rootDiskSizeInGb = (long) offering.getRootDiskSize() / GB_TO_BYTES;
    offeringResponse.setRootDiskSize(rootDiskSizeInGb);
    offeringResponse.setDiskOfferingStrictness(offering.getDiskOfferingStrictness());
    DiskOfferingVO diskOfferingVO = ApiDBUtils.findDiskOfferingById(offering.getDiskOfferingId());
    if (diskOfferingVO != null) {
        offeringResponse.setDiskOfferingId(offering.getDiskOfferingUuid());
        offeringResponse.setDiskOfferingName(offering.getDiskOfferingName());
        offeringResponse.setDiskOfferingDisplayText(offering.getDiskOfferingDisplayText());
    }
    offeringResponse.setHasAnnotation(annotationDao.hasAnnotations(offering.getUuid(), AnnotationService.EntityType.SERVICE_OFFERING.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    return offeringResponse;
}
Also used : ServiceOfferingResponse(org.apache.cloudstack.api.response.ServiceOfferingResponse) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 2 with VsphereStoragePolicyVO

use of com.cloud.dc.VsphereStoragePolicyVO in project cloudstack by apache.

the class VolumeObject method getvSphereStoragePolicyId.

public String getvSphereStoragePolicyId() {
    if (StringUtils.isEmpty(vSphereStoragePolicyId)) {
        String storagePolicyVOid = null;
        if (Volume.Type.ROOT == getVolumeType()) {
            Long vmId = volumeVO.getInstanceId();
            if (vmId != null) {
                VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(vmId);
                storagePolicyVOid = serviceOfferingDetailsDao.getDetail(vm.getServiceOfferingId(), ApiConstants.STORAGE_POLICY);
            }
        } else {
            storagePolicyVOid = diskOfferingDetailsDao.getDetail(volumeVO.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
        }
        if (storagePolicyVOid != null) {
            VsphereStoragePolicyVO vsphereStoragePolicyVO = vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyVOid));
            vSphereStoragePolicyId = vsphereStoragePolicyVO.getPolicyId();
        }
    }
    return vSphereStoragePolicyId;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 3 with VsphereStoragePolicyVO

use of com.cloud.dc.VsphereStoragePolicyVO in project cloudstack by apache.

the class VmwareManagerImpl method listVsphereStoragePolicyCompatibleStoragePools.

@Override
public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd) {
    Long policyId = cmd.getPolicyId();
    VsphereStoragePolicyVO storagePolicy = vsphereStoragePolicyDao.findById(policyId);
    if (storagePolicy == null) {
        throw new CloudRuntimeException("Storage policy with ID = " + policyId + " was not found");
    }
    long zoneId = storagePolicy.getZoneId();
    List<StoragePoolVO> poolsInZone = primaryStorageDao.listByStatusInZone(zoneId, StoragePoolStatus.Up);
    List<StoragePool> compatiblePools = new ArrayList<>();
    for (StoragePoolVO pool : poolsInZone) {
        StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
        List<Long> hostIds = storageManager.getUpHostsInPool(pool.getId());
        if (CollectionUtils.isNullOrEmpty(hostIds)) {
            s_logger.debug("Did not find a suitable host to verify compatibility of the pool " + pool.getName());
            continue;
        }
        Collections.shuffle(hostIds);
        CheckDataStoreStoragePolicyComplainceCommand command = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicy.getPolicyId(), storageFilerTO);
        long targetHostId = hypervisorGuruManager.getGuruProcessedCommandTargetHost(hostIds.get(0), command);
        try {
            Answer answer = _agentMgr.send(targetHostId, command);
            boolean result = answer != null && answer.getResult();
            if (result) {
                compatiblePools.add(pool);
            }
        } catch (AgentUnavailableException | OperationTimedoutException e) {
            s_logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName());
        }
    }
    return compatiblePools;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) StoragePool(com.cloud.storage.StoragePool) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) ArrayList(java.util.ArrayList) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 4 with VsphereStoragePolicyVO

use of com.cloud.dc.VsphereStoragePolicyVO in project cloudstack by apache.

the class DiskOfferingJoinDaoImpl method newDiskOfferingResponse.

@Override
public DiskOfferingResponse newDiskOfferingResponse(DiskOfferingJoinVO offering) {
    DiskOfferingResponse diskOfferingResponse = new DiskOfferingResponse();
    diskOfferingResponse.setId(offering.getUuid());
    diskOfferingResponse.setName(offering.getName());
    diskOfferingResponse.setDisplayText(offering.getDisplayText());
    diskOfferingResponse.setProvisioningType(offering.getProvisioningType().toString());
    diskOfferingResponse.setCreated(offering.getCreated());
    diskOfferingResponse.setDiskSize(offering.getDiskSize() / (1024 * 1024 * 1024));
    diskOfferingResponse.setMinIops(offering.getMinIops());
    diskOfferingResponse.setMaxIops(offering.getMaxIops());
    diskOfferingResponse.setDisplayOffering(offering.isDisplayOffering());
    diskOfferingResponse.setDomainId(offering.getDomainUuid());
    diskOfferingResponse.setDomain(offering.getDomainPath());
    diskOfferingResponse.setZoneId(offering.getZoneUuid());
    diskOfferingResponse.setZone(offering.getZoneName());
    diskOfferingResponse.setHasAnnotation(annotationDao.hasAnnotations(offering.getUuid(), AnnotationService.EntityType.DISK_OFFERING.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    diskOfferingResponse.setTags(offering.getTags());
    diskOfferingResponse.setCustomized(offering.isCustomized());
    diskOfferingResponse.setCustomizedIops(offering.isCustomizedIops());
    diskOfferingResponse.setHypervisorSnapshotReserve(offering.getHypervisorSnapshotReserve());
    diskOfferingResponse.setStorageType(offering.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
    diskOfferingResponse.setBytesReadRate(offering.getBytesReadRate());
    diskOfferingResponse.setBytesReadRateMax(offering.getBytesReadRateMax());
    diskOfferingResponse.setBytesReadRateMaxLength(offering.getBytesReadRateMaxLength());
    diskOfferingResponse.setBytesWriteRate(offering.getBytesWriteRate());
    diskOfferingResponse.setBytesWriteRateMax(offering.getBytesWriteRateMax());
    diskOfferingResponse.setBytesWriteRateMaxLength(offering.getBytesWriteRateMaxLength());
    diskOfferingResponse.setIopsReadRate(offering.getIopsReadRate());
    diskOfferingResponse.setIopsReadRateMax(offering.getIopsReadRateMax());
    diskOfferingResponse.setIopsReadRateMaxLength(offering.getIopsReadRateMaxLength());
    diskOfferingResponse.setIopsWriteRate(offering.getIopsWriteRate());
    diskOfferingResponse.setIopsWriteRateMax(offering.getIopsWriteRateMax());
    diskOfferingResponse.setIopsWriteRateMaxLength(offering.getIopsWriteRateMaxLength());
    diskOfferingResponse.setCacheMode(offering.getCacheMode());
    diskOfferingResponse.setObjectName("diskoffering");
    Map<String, String> offeringDetails = ApiDBUtils.getResourceDetails(offering.getId(), ResourceTag.ResourceObjectType.DiskOffering);
    if (offeringDetails != null && !offeringDetails.isEmpty()) {
        String vsphereStoragePolicyId = offeringDetails.get(ApiConstants.STORAGE_POLICY);
        if (vsphereStoragePolicyId != null) {
            VsphereStoragePolicyVO vsphereStoragePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(vsphereStoragePolicyId));
            if (vsphereStoragePolicyVO != null)
                diskOfferingResponse.setVsphereStoragePolicy(vsphereStoragePolicyVO.getName());
        }
    }
    diskOfferingResponse.setDiskSizeStrictness(offering.getDiskSizeStrictness());
    return diskOfferingResponse;
}
Also used : DiskOfferingResponse(org.apache.cloudstack.api.response.DiskOfferingResponse) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 5 with VsphereStoragePolicyVO

use of com.cloud.dc.VsphereStoragePolicyVO in project cloudstack by apache.

the class StorageManagerImpl method isStoragePoolCompliantWithStoragePolicy.

@Override
public boolean isStoragePoolCompliantWithStoragePolicy(List<Pair<Volume, DiskProfile>> volumes, StoragePool pool) throws StorageUnavailableException {
    if (CollectionUtils.isEmpty(volumes)) {
        return false;
    }
    List<Pair<Volume, Answer>> answers = new ArrayList<Pair<Volume, Answer>>();
    for (Pair<Volume, DiskProfile> volumeDiskProfilePair : volumes) {
        String storagePolicyId = null;
        Volume volume = volumeDiskProfilePair.first();
        DiskProfile diskProfile = volumeDiskProfilePair.second();
        if (volume.getVolumeType() == Type.ROOT) {
            Long vmId = volume.getInstanceId();
            if (vmId != null) {
                VMInstanceVO vm = _vmInstanceDao.findByIdIncludingRemoved(vmId);
                storagePolicyId = _serviceOfferingDetailsDao.getDetail(vm.getServiceOfferingId(), ApiConstants.STORAGE_POLICY);
            }
        } else {
            storagePolicyId = _diskOfferingDetailsDao.getDetail(diskProfile.getDiskOfferingId(), ApiConstants.STORAGE_POLICY);
        }
        if (StringUtils.isNotEmpty(storagePolicyId)) {
            VsphereStoragePolicyVO storagePolicyVO = _vsphereStoragePolicyDao.findById(Long.parseLong(storagePolicyId));
            List<Long> hostIds = getUpHostsInPool(pool.getId());
            Collections.shuffle(hostIds);
            if (hostIds == null || hostIds.isEmpty()) {
                throw new StorageUnavailableException("Unable to send command to the pool " + pool.getName() + " due to there is no enabled hosts up in this cluster", pool.getId());
            }
            try {
                StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
                CheckDataStoreStoragePolicyComplainceCommand cmd = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicyVO.getPolicyId(), storageFilerTO);
                long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostIds.get(0), cmd);
                Answer answer = _agentMgr.send(targetHostId, cmd);
                answers.add(new Pair<>(volume, answer));
            } catch (AgentUnavailableException e) {
                s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostIds.get(0), e);
                throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
            } catch (OperationTimedoutException e) {
                s_logger.debug("Failed to process storage pool command to " + pool + " via " + hostIds.get(0), e);
                throw new StorageUnavailableException("Failed to process storage command to the pool ", pool.getId());
            }
        }
    }
    // check cummilative result for all volumes
    for (Pair<Volume, Answer> answer : answers) {
        if (!answer.second().getResult()) {
            s_logger.debug(String.format("Storage pool %s is not compliance with storage policy for volume %s", pool.getUuid(), answer.first().getName()));
            return false;
        }
    }
    return true;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) DiskProfile(com.cloud.vm.DiskProfile) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) Answer(com.cloud.agent.api.Answer) SyncVolumePathAnswer(org.apache.cloudstack.storage.command.SyncVolumePathAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO) Pair(com.cloud.utils.Pair)

Aggregations

VsphereStoragePolicyVO (com.cloud.dc.VsphereStoragePolicyVO)6 Answer (com.cloud.agent.api.Answer)3 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)3 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)3 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)3 ArrayList (java.util.ArrayList)3 CheckDataStoreStoragePolicyComplainceCommand (org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand)3 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 Pair (com.cloud.utils.Pair)2 CollectionUtils (com.amazonaws.util.CollectionUtils)1 AgentManager (com.cloud.agent.AgentManager)1 Listener (com.cloud.agent.Listener)1 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)1 Command (com.cloud.agent.api.Command)1 GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)1 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)1 GetVolumeStatsAnswer (com.cloud.agent.api.GetVolumeStatsAnswer)1 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)1 StartupCommand (com.cloud.agent.api.StartupCommand)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1