Search in sources :

Example 6 with DataStoreRole

use of com.cloud.storage.DataStoreRole in project cloudstack by apache.

the class DefaultEndPointSelector method moveBetweenCacheAndImage.

protected boolean moveBetweenCacheAndImage(DataStore srcStore, DataStore destStore) {
    DataStoreRole srcRole = srcStore.getRole();
    DataStoreRole destRole = destStore.getRole();
    if (srcRole == DataStoreRole.Image && destRole == DataStoreRole.ImageCache || srcRole == DataStoreRole.ImageCache && destRole == DataStoreRole.Image) {
        return true;
    } else {
        return false;
    }
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole)

Example 7 with DataStoreRole

use of com.cloud.storage.DataStoreRole in project cloudstack by apache.

the class S3ImageStoreLifeCycleImpl method initialize.

@SuppressWarnings("unchecked")
@Override
public DataStore initialize(Map<String, Object> dsInfos) {
    String url = (String) dsInfos.get("url");
    String name = (String) dsInfos.get("name");
    String providerName = (String) dsInfos.get("providerName");
    ScopeType scope = (ScopeType) dsInfos.get("scope");
    DataStoreRole role = (DataStoreRole) dsInfos.get("role");
    Map<String, String> details = (Map<String, String>) dsInfos.get("details");
    s_logger.info("Trying to add a S3 store with endpoint: " + details.get(ApiConstants.S3_END_POINT));
    Map<String, Object> imageStoreParameters = new HashMap();
    imageStoreParameters.put("name", name);
    imageStoreParameters.put("url", url);
    String protocol = "http";
    String useHttps = details.get(ApiConstants.S3_HTTPS_FLAG);
    if (useHttps != null && Boolean.parseBoolean(useHttps)) {
        protocol = "https";
    }
    imageStoreParameters.put("protocol", protocol);
    if (scope != null) {
        imageStoreParameters.put("scope", scope);
    } else {
        imageStoreParameters.put("scope", ScopeType.REGION);
    }
    imageStoreParameters.put("providerName", providerName);
    imageStoreParameters.put("role", role);
    ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details);
    return imageStoreMgr.getImageStore(ids.getId());
}
Also used : ScopeType(com.cloud.storage.ScopeType) DataStoreRole(com.cloud.storage.DataStoreRole) HashMap(java.util.HashMap) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with DataStoreRole

use of com.cloud.storage.DataStoreRole in project cloudstack by apache.

the class SimulatorImageStoreLifeCycleImpl method initialize.

@Override
public DataStore initialize(Map<String, Object> dsInfos) {
    Long dcId = (Long) dsInfos.get("zoneId");
    String url = (String) dsInfos.get("url");
    String name = (String) dsInfos.get("name");
    if (name == null) {
        name = url;
    }
    String providerName = (String) dsInfos.get("providerName");
    DataStoreRole role = (DataStoreRole) dsInfos.get("role");
    Map<String, String> details = (Map<String, String>) dsInfos.get("details");
    s_logger.info("Trying to add a new data store at " + url + " to data center " + dcId);
    URI uri;
    try {
        uri = new URI(UriUtils.encodeURIComponent(url));
        if (uri.getScheme() == null) {
            throw new InvalidParameterValueException("uri.scheme is null " + url + ", add nfs:// as a prefix");
        } else if (uri.getScheme().equalsIgnoreCase("nfs")) {
            if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
                throw new InvalidParameterValueException("Your host and/or path is wrong.  Make sure it is of the format nfs://hostname/path");
            }
        }
    } catch (URISyntaxException e) {
        throw new InvalidParameterValueException(url + " is not a valid uri");
    }
    if (dcId == null) {
        throw new InvalidParameterValueException("DataCenter id is null, and simulator image store has to be associated with a data center");
    }
    Map<String, Object> imageStoreParameters = new HashMap<String, Object>();
    imageStoreParameters.put("name", name);
    imageStoreParameters.put("zoneId", dcId);
    imageStoreParameters.put("url", url);
    imageStoreParameters.put("protocol", uri.getScheme().toLowerCase());
    imageStoreParameters.put("scope", ScopeType.ZONE);
    imageStoreParameters.put("providerName", providerName);
    imageStoreParameters.put("role", role);
    ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details);
    return imageStoreMgr.getImageStore(ids.getId());
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI)

Example 9 with DataStoreRole

use of com.cloud.storage.DataStoreRole in project cloudstack by apache.

the class VolumeOrchestrator method createVolumeFromSnapshot.

@DB
@Override
public VolumeInfo createVolumeFromSnapshot(Volume volume, Snapshot snapshot, UserVm vm) throws StorageUnavailableException {
    Account account = _entityMgr.findById(Account.class, volume.getAccountId());
    final HashSet<StoragePool> poolsToAvoid = new HashSet<StoragePool>();
    StoragePool pool = null;
    Set<Long> podsToAvoid = new HashSet<Long>();
    Pair<Pod, Long> pod = null;
    DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    DataCenter dc = _entityMgr.findById(DataCenter.class, volume.getDataCenterId());
    DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType());
    String msg = "There are no available storage pools to store the volume in";
    if (vm != null) {
        Pod podofVM = _entityMgr.findById(Pod.class, vm.getPodIdToDeployIn());
        if (podofVM != null) {
            pod = new Pair<Pod, Long>(podofVM, podofVM.getId());
        }
    }
    if (vm != null && pod != null) {
        //if VM is running use the hostId to find the clusterID. If it is stopped, refer the cluster where the ROOT volume of the VM exists.
        Long hostId = null;
        Long clusterId = null;
        if (vm.getState() == State.Running) {
            hostId = vm.getHostId();
            if (hostId != null) {
                Host vmHost = _entityMgr.findById(Host.class, hostId);
                clusterId = vmHost.getClusterId();
            }
        } else {
            List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vm.getId(), 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. Please contact Cloud Support.");
            } else {
                VolumeVO rootVolumeOfVm = rootVolumesOfVm.get(0);
                StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
                clusterId = (rootDiskPool == null ? null : rootDiskPool.getClusterId());
            }
        }
        // Determine what storage pool to store the volume in
        while ((pool = findStoragePool(dskCh, dc, pod.first(), clusterId, hostId, vm, poolsToAvoid)) != null) {
            break;
        }
        if (pool == null) {
            //pool could not be found in the VM's pod/cluster.
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Could not find any storage pool to create Volume in the pod/cluster of the provided VM " + vm.getUuid());
            }
            StringBuilder addDetails = new StringBuilder(msg);
            addDetails.append(", Could not find any storage pool to create Volume in the pod/cluster of the VM ");
            addDetails.append(vm.getUuid());
            msg = addDetails.toString();
        }
    } else {
        // Determine what pod to store the volume in
        while ((pod = findPod(null, null, dc, account.getId(), podsToAvoid)) != null) {
            podsToAvoid.add(pod.first().getId());
            // Determine what storage pool to store the volume in
            while ((pool = findStoragePool(dskCh, dc, pod.first(), null, null, null, poolsToAvoid)) != null) {
                break;
            }
            if (pool != null) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Found a suitable pool for create volume: " + pool.getId());
                }
                break;
            }
        }
    }
    if (pool == null) {
        s_logger.info(msg);
        throw new StorageUnavailableException(msg, -1);
    }
    VolumeInfo vol = volFactory.getVolume(volume.getId());
    DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
    DataStoreRole dataStoreRole = getDataStoreRole(snapshot);
    SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
    if (snapInfo == null && dataStoreRole == DataStoreRole.Image) {
        // snapshot is not backed up to secondary, let's do that now.
        snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
        if (snapInfo == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId());
        }
        // We need to copy the snapshot onto secondary.
        SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP);
        snapshotStrategy.backupSnapshot(snapInfo);
        // Attempt to grab it again.
        snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
        if (snapInfo == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup");
        }
    }
    // don't try to perform a sync if the DataStoreRole of the snapshot is equal to DataStoreRole.Primary
    if (!DataStoreRole.Primary.equals(dataStoreRole)) {
        try {
            // sync snapshot to region store if necessary
            DataStore snapStore = snapInfo.getDataStore();
            long snapVolId = snapInfo.getVolumeId();
            _snapshotSrv.syncVolumeSnapshotsToRegionStore(snapVolId, snapStore);
        } catch (Exception ex) {
            // log but ignore the sync error to avoid any potential S3 down issue, it should be sync next time
            s_logger.warn(ex.getMessage(), ex);
        }
    }
    // create volume on primary from snapshot
    AsyncCallFuture<VolumeApiResult> future = volService.createVolumeFromSnapshot(vol, store, snapInfo);
    try {
        VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to create volume from snapshot:" + result.getResult());
            throw new CloudRuntimeException("Failed to create volume from snapshot:" + result.getResult());
        }
        return result.getVolume();
    } catch (InterruptedException e) {
        s_logger.debug("Failed to create volume from snapshot", e);
        throw new CloudRuntimeException("Failed to create volume from snapshot", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to create volume from snapshot", e);
        throw new CloudRuntimeException("Failed to create volume from snapshot", e);
    }
}
Also used : Account(com.cloud.user.Account) StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) DataStoreRole(com.cloud.storage.DataStoreRole) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ExecutionException(java.util.concurrent.ExecutionException) SnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy) HashSet(java.util.HashSet) Pod(com.cloud.dc.Pod) Host(com.cloud.host.Host) DiskProfile(com.cloud.vm.DiskProfile) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataCenter(com.cloud.dc.DataCenter) DB(com.cloud.utils.db.DB)

Example 10 with DataStoreRole

use of com.cloud.storage.DataStoreRole in project cloudstack by apache.

the class DefaultEndPointSelector method moveBetweenPrimaryImage.

protected boolean moveBetweenPrimaryImage(DataStore srcStore, DataStore destStore) {
    DataStoreRole srcRole = srcStore.getRole();
    DataStoreRole destRole = destStore.getRole();
    if ((srcRole == DataStoreRole.Primary && destRole.isImageStore()) || (srcRole.isImageStore() && destRole == DataStoreRole.Primary)) {
        return true;
    } else {
        return false;
    }
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole)

Aggregations

DataStoreRole (com.cloud.storage.DataStoreRole)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)4 ImageStoreVO (org.apache.cloudstack.storage.datastore.db.ImageStoreVO)4 VolumeVO (com.cloud.storage.VolumeVO)3 DB (com.cloud.utils.db.DB)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 SnapshotStrategy (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy)3 DataCenter (com.cloud.dc.DataCenter)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)2 ScopeType (com.cloud.storage.ScopeType)2 Account (com.cloud.user.Account)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ConfigurationException (javax.naming.ConfigurationException)2 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)2 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)2