Search in sources :

Example 51 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreImpl method getScope.

@Override
public Scope getScope() {
    final StoragePoolVO vo = dataStoreDao.findById(pdsv.getId());
    if (vo.getScope() == ScopeType.CLUSTER) {
        return new ClusterScope(vo.getClusterId(), vo.getPodId(), vo.getDataCenterId());
    } else if (vo.getScope() == ScopeType.ZONE) {
        return new ZoneScope(vo.getDataCenterId());
    } else if (vo.getScope() == ScopeType.HOST) {
        final List<StoragePoolHostVO> poolHosts = poolHostDao.listByPoolId(vo.getId());
        if (poolHosts.size() > 0) {
            return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId());
        }
        s_logger.debug("can't find a local storage in pool host table: " + vo.getId());
    }
    return null;
}
Also used : ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) HostScope(com.cloud.engine.subsystem.api.storage.HostScope)

Example 52 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class ApiDBUtils method getHypervisorTypeFromFormat.

public static HypervisorType getHypervisorTypeFromFormat(final long dcId, final ImageFormat format) {
    HypervisorType type = s_storageMgr.getHypervisorTypeFromFormat(format);
    if (format == ImageFormat.RAW) {
        // Currently, KVM only suppoorts RBD images of type RAW.
        // This results in a weird collision with OVM volumes which
        // can only be raw, thus making KVM RBD volumes show up as OVM
        // rather than RBD. This block of code can (hopefuly) by checking to
        // see if the pool is using either RBD or NFS. However, it isn't
        // quite clear what to do if both storage types are used. If the image
        // format is RAW, it narrows the hypervisor choice down to OVM and KVM / RBD or KVM / CLVM
        // This would be better implemented at a cluster level.
        final List<StoragePoolVO> pools = s_storagePoolDao.listByDataCenterId(dcId);
        final ListIterator<StoragePoolVO> itr = pools.listIterator();
        while (itr.hasNext()) {
            final StoragePoolVO pool = itr.next();
            if (pool.getPoolType() == StoragePoolType.RBD || pool.getPoolType() == StoragePoolType.CLVM) {
                // This case will note the presence of non-qcow2 primary stores, suggesting KVM without NFS. Otherwse,
                // If this check is not passed, the hypervisor type will remain OVM.
                type = HypervisorType.KVM;
                break;
            }
        }
    }
    return type;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 53 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method copyAsync.

@Override
public void copyAsync(final DataObject srcdata, final DataObject destData, final AsyncCompletionCallback<CopyCommandResult> callback) {
    final DataStore store = destData.getDataStore();
    if (store.getRole() == DataStoreRole.Primary) {
        if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
            // For CLVM, we need to copy template to primary storage at all, just fake the copy result.
            final TemplateObjectTO templateObjectTO = new TemplateObjectTO();
            templateObjectTO.setPath(UUID.randomUUID().toString());
            templateObjectTO.setSize(srcdata.getSize());
            templateObjectTO.setPhysicalSize(srcdata.getSize());
            templateObjectTO.setFormat(Storage.ImageFormat.RAW);
            final CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
            final CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        } else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
            // For CLVM, we need to pass template on secondary storage to hypervisor
            final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
            final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
            final StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
            final DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
            final DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
            final EndPoint ep = epSelector.select(srcData, destData);
            Answer answer = null;
            if (ep == null) {
                final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                s_logger.error(errMsg);
                answer = new Answer(cmd, false, errMsg);
            } else {
                answer = ep.sendMessage(cmd);
            }
            final CopyCommandResult result = new CopyCommandResult("", answer);
            callback.complete(result);
        }
    }
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 54 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreLifeCycleImpl method initialize.

@Override
public DataStore initialize(final Map<String, Object> dsInfos) {
    final Long clusterId = (Long) dsInfos.get("clusterId");
    final Long podId = (Long) dsInfos.get("podId");
    final Long zoneId = (Long) dsInfos.get("zoneId");
    final String url = (String) dsInfos.get("url");
    final String providerName = (String) dsInfos.get("providerName");
    if (clusterId != null && podId == null) {
        throw new InvalidParameterValueException("Cluster id requires pod id");
    }
    final PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
    URI uri = null;
    try {
        uri = new URI(UriUtils.encodeURIComponent(url));
        if (uri.getScheme() == null) {
            throw new InvalidParameterValueException("scheme is null " + url + ", add nfs:// (or cifs://) as a prefix");
        } else if (uri.getScheme().equalsIgnoreCase("nfs")) {
            final String uriHost = uri.getHost();
            final String uriPath = uri.getPath();
            if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
                throw new InvalidParameterValueException("host or path is null, should be nfs://hostname/path");
            }
        } else if (uri.getScheme().equalsIgnoreCase("cifs")) {
            // Don't validate against a URI encoded URI.
            final URI cifsUri = new URI(url);
            final String warnMsg = UriUtils.getCifsUriParametersProblems(cifsUri);
            if (warnMsg != null) {
                throw new InvalidParameterValueException(warnMsg);
            }
        } else if (uri.getScheme().equalsIgnoreCase("sharedMountPoint")) {
            final String uriPath = uri.getPath();
            if (uriPath == null) {
                throw new InvalidParameterValueException("host or path is null, should be sharedmountpoint://localhost/path");
            }
        } else if (uri.getScheme().equalsIgnoreCase("rbd")) {
            final String uriPath = uri.getPath();
            if (uriPath == null) {
                throw new InvalidParameterValueException("host or path is null, should be rbd://hostname/pool");
            }
        } else if (uri.getScheme().equalsIgnoreCase("gluster")) {
            final String uriHost = uri.getHost();
            final String uriPath = uri.getPath();
            if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
                throw new InvalidParameterValueException("host or path is null, should be gluster://hostname/volume");
            }
        }
    } catch (final URISyntaxException e) {
        throw new InvalidParameterValueException(url + " is not a valid uri");
    }
    final String tags = (String) dsInfos.get("tags");
    final Map<String, String> details = (Map<String, String>) dsInfos.get("details");
    parameters.setTags(tags);
    parameters.setDetails(details);
    final String scheme = uri.getScheme();
    final String storageHost = uri.getHost();
    String hostPath = null;
    try {
        hostPath = URLDecoder.decode(uri.getPath(), "UTF-8");
    } catch (final UnsupportedEncodingException e) {
        s_logger.error("[ignored] we are on a platform not supporting \"UTF-8\"!?!", e);
    }
    if (hostPath == null) {
        // if decoding fails, use getPath() anyway
        hostPath = uri.getPath();
    }
    final Object localStorage = dsInfos.get("localStorage");
    if (localStorage != null) {
        hostPath = hostPath.replaceFirst("/", "");
        hostPath = hostPath.replace("+", " ");
    }
    final String userInfo = uri.getUserInfo();
    int port = uri.getPort();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("createPool Params @ scheme - " + scheme + " storageHost - " + storageHost + " hostPath - " + hostPath + " port - " + port);
    }
    if (scheme.equalsIgnoreCase("nfs")) {
        if (port == -1) {
            port = 2049;
        }
        parameters.setType(StoragePoolType.NetworkFilesystem);
        parameters.setHost(storageHost);
        parameters.setPort(port);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("cifs")) {
        if (port == -1) {
            port = 445;
        }
        parameters.setType(StoragePoolType.SMB);
        parameters.setHost(storageHost);
        parameters.setPort(port);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("file")) {
        if (port == -1) {
            port = 0;
        }
        parameters.setType(StoragePoolType.Filesystem);
        parameters.setHost("localhost");
        parameters.setPort(0);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("sharedMountPoint")) {
        parameters.setType(StoragePoolType.SharedMountPoint);
        parameters.setHost(storageHost);
        parameters.setPort(0);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("clvm")) {
        parameters.setType(StoragePoolType.CLVM);
        parameters.setHost(storageHost);
        parameters.setPort(0);
        parameters.setPath(hostPath.replaceFirst("/", ""));
    } else if (scheme.equalsIgnoreCase("rbd")) {
        if (port == -1) {
            port = 6789;
        }
        parameters.setType(StoragePoolType.RBD);
        parameters.setHost(storageHost);
        parameters.setPort(port);
        parameters.setPath(hostPath.replaceFirst("/", ""));
        parameters.setUserInfo(userInfo);
    } else if (scheme.equalsIgnoreCase("PreSetup")) {
        parameters.setType(StoragePoolType.PreSetup);
        parameters.setHost(storageHost);
        parameters.setPort(0);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("iscsi")) {
        final String[] tokens = hostPath.split("/");
        final int lun = NumbersUtil.parseInt(tokens[tokens.length - 1], -1);
        if (port == -1) {
            port = 3260;
        }
        if (lun != -1) {
            if (clusterId == null) {
                throw new IllegalArgumentException("IscsiLUN need to have clusters specified");
            }
            parameters.setType(StoragePoolType.IscsiLUN);
            parameters.setHost(storageHost);
            parameters.setPort(port);
            parameters.setPath(hostPath);
        } else {
            throw new IllegalArgumentException("iSCSI needs to have LUN number");
        }
    } else if (scheme.equalsIgnoreCase("iso")) {
        if (port == -1) {
            port = 2049;
        }
        parameters.setType(StoragePoolType.ISO);
        parameters.setHost(storageHost);
        parameters.setPort(port);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("ocfs2")) {
        port = 7777;
        parameters.setType(StoragePoolType.OCFS2);
        parameters.setHost("clustered");
        parameters.setPort(port);
        parameters.setPath(hostPath);
    } else if (scheme.equalsIgnoreCase("gluster")) {
        if (port == -1) {
            port = 24007;
        }
        parameters.setType(StoragePoolType.Gluster);
        parameters.setHost(storageHost);
        parameters.setPort(port);
        parameters.setPath(hostPath);
    } else {
        final StoragePoolType type = Enum.valueOf(StoragePoolType.class, scheme);
        if (type != null) {
            parameters.setType(type);
            parameters.setHost(storageHost);
            parameters.setPort(0);
            parameters.setPath(hostPath);
        } else {
            s_logger.warn("Unable to figure out the scheme for URI: " + uri);
            throw new IllegalArgumentException("Unable to figure out the scheme for URI: " + uri);
        }
    }
    if (localStorage == null) {
        final List<StoragePoolVO> pools = primaryDataStoreDao.listPoolByHostPath(storageHost, hostPath);
        if (!pools.isEmpty() && !scheme.equalsIgnoreCase("sharedmountpoint")) {
            final Long oldPodId = pools.get(0).getPodId();
            throw new CloudRuntimeException("Storage pool " + uri + " already in use by another pod (id=" + oldPodId + ")");
        }
    }
    final Object existingUuid = dsInfos.get("uuid");
    String uuid = null;
    if (existingUuid != null) {
        uuid = (String) existingUuid;
    } else if (scheme.equalsIgnoreCase("sharedmountpoint") || scheme.equalsIgnoreCase("clvm")) {
        uuid = UUID.randomUUID().toString();
    } else if (scheme.equalsIgnoreCase("PreSetup")) {
        uuid = hostPath.replace("/", "");
    } else {
        uuid = UUID.nameUUIDFromBytes((storageHost + hostPath).getBytes()).toString();
    }
    final List<StoragePoolVO> spHandles = primaryDataStoreDao.findIfDuplicatePoolsExistByUUID(uuid);
    if (spHandles != null && spHandles.size() > 0) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Another active pool with the same uuid already exists");
        }
        throw new CloudRuntimeException("Another active pool with the same uuid already exists");
    }
    final String poolName = (String) dsInfos.get("name");
    parameters.setUuid(uuid);
    parameters.setZoneId(zoneId);
    parameters.setPodId(podId);
    parameters.setName(poolName);
    parameters.setClusterId(clusterId);
    parameters.setProviderName(providerName);
    return dataStoreHelper.createPrimaryDataStore(parameters);
}
Also used : StoragePoolType(com.cloud.storage.Storage.StoragePoolType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PrimaryDataStoreParameters(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreParameters) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) Map(java.util.Map)

Example 55 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class AlertManagerImpl method recalculateCapacity.

@Override
public void recalculateCapacity() {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("recalculating system capacity");
        s_logger.debug("Executing cpu/ram capacity update");
    }
    // Calculate CPU and RAM capacities
    // get all hosts...even if they are not in 'UP' state
    final List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
    if (hosts != null) {
        for (final HostVO host : hosts) {
            _capacityMgr.updateCapacityForHost(host);
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Done executing cpu/ram capacity update");
        s_logger.debug("Executing storage capacity update");
    }
    // Calculate storage pool capacity
    final List<StoragePoolVO> storagePools = _storagePoolDao.listAll();
    for (final StoragePoolVO pool : storagePools) {
        final long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
        if (pool.isShared()) {
            _storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
        } else {
            _storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Done executing storage capacity update");
        s_logger.debug("Executing capacity updates for public ip and Vlans");
    }
    final List<Zone> zones = zoneRepository.findByRemovedIsNull();
    for (final Zone zone : zones) {
        final long zoneId = zone.getId();
        // Calculate new Public IP capacity for Virtual Network
        if (zone.getNetworkType() == NetworkType.Advanced) {
            createOrUpdateIpCapacity(zoneId, null, Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, zone.getAllocationState());
        }
        // Calculate new Public IP capacity for Direct Attached Network
        createOrUpdateIpCapacity(zoneId, null, Capacity.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP, zone.getAllocationState());
        if (zone.getNetworkType() == NetworkType.Advanced) {
            // Calculate VLAN's capacity
            createOrUpdateVlanCapacity(zoneId, zone.getAllocationState());
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Done capacity updates for public ip and Vlans");
        s_logger.debug("Executing capacity updates for private ip");
    }
    // Calculate new Private IP capacity
    final List<HostPodVO> pods = _podDao.listAll();
    for (final HostPodVO pod : pods) {
        final long podId = pod.getId();
        final long dcId = pod.getDataCenterId();
        createOrUpdateIpCapacity(dcId, podId, Capacity.CAPACITY_TYPE_PRIVATE_IP, _configMgr.findPodAllocationState(pod));
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Done executing capacity updates for private ip");
        s_logger.debug("Done recalculating system capacity");
    }
}
Also used : Zone(com.cloud.db.model.Zone) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8