Search in sources :

Example 91 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class HypervStorageMotionStrategy method updateVolumePathsAfterMigration.

private void updateVolumePathsAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        boolean updated = false;
        VolumeInfo volume = entry.getKey();
        StoragePool pool = (StoragePool) entry.getValue();
        for (VolumeObjectTO volumeTo : volumeTos) {
            if (volume.getId() == volumeTo.getId()) {
                VolumeVO volumeVO = volDao.findById(volume.getId());
                Long oldPoolId = volumeVO.getPoolId();
                volumeVO.setPath(volumeTo.getPath());
                volumeVO.setPodId(pool.getPodId());
                volumeVO.setPoolId(pool.getId());
                volumeVO.setLastPoolId(oldPoolId);
                // For SMB, pool credentials are also stored in the uri query string.  We trim the query string
                // part  here to make sure the credentials do not get stored in the db unencrypted.
                String folder = pool.getPath();
                if (pool.getPoolType() == StoragePoolType.SMB && folder != null && folder.contains("?")) {
                    folder = folder.substring(0, folder.indexOf("?"));
                }
                volumeVO.setFolder(folder);
                volDao.update(volume.getId(), volumeVO);
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated.");
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map)

Example 92 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class VmwareManagerImpl method getSecondaryStorageStoreUrlAndId.

@Override
public Pair<String, Long> getSecondaryStorageStoreUrlAndId(long dcId) {
    String secUrl = null;
    Long secId = null;
    DataStore secStore = _dataStoreMgr.getImageStore(dcId);
    if (secStore != null) {
        secUrl = secStore.getUri();
        secId = secStore.getId();
    }
    if (secUrl == null) {
        // we are using non-NFS image store, then use cache storage instead
        s_logger.info("Secondary storage is not NFS, we need to use staging storage");
        DataStore cacheStore = _dataStoreMgr.getImageCacheStore(dcId);
        if (cacheStore != null) {
            secUrl = cacheStore.getUri();
            secId = cacheStore.getId();
        } else {
            s_logger.warn("No staging storage is found when non-NFS secondary storage is used");
        }
    }
    return new Pair<String, Long>(secUrl, secId);
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Pair(com.cloud.utils.Pair)

Example 93 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class UploadMonitorImpl method createVolumeDownloadURL.

@Override
public void createVolumeDownloadURL(Long entityId, String path, Type type, Long dataCenterId, Long uploadId, ImageFormat format) {
    String errorString = "";
    boolean success = false;
    try {
        List<HostVO> storageServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.SecondaryStorage, dataCenterId);
        if (storageServers == null) {
            errorString = "No Storage Server found at the datacenter - " + dataCenterId;
            throw new CloudRuntimeException(errorString);
        }
        // Update DB for state = DOWNLOAD_URL_NOT_CREATED.
        UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
        uploadJob.setUploadState(Status.DOWNLOAD_URL_NOT_CREATED);
        uploadJob.setLastUpdated(new Date());
        _uploadDao.update(uploadJob.getId(), uploadJob);
        // Create Symlink at ssvm
        String uuid = UUID.randomUUID().toString() + "." + format.toString().toLowerCase();
        DataStore secStore = storeMgr.getDataStore(ApiDBUtils.findUploadById(uploadId).getDataStoreId(), DataStoreRole.Image);
        EndPoint ep = _epSelector.select(secStore);
        if (ep == null) {
            errorString = "There is no secondary storage VM for secondary storage host " + secStore.getName();
            throw new CloudRuntimeException(errorString);
        }
        CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand(((ImageStoreEntity) secStore).getMountPoint(), path, uuid, null);
        Answer ans = ep.sendMessage(cmd);
        if (ans == null || !ans.getResult()) {
            errorString = "Unable to create a link for " + type + " id:" + entityId + "," + (ans == null ? "" : ans.getDetails());
            s_logger.warn(errorString);
            throw new CloudRuntimeException(errorString);
        }
        List<SecondaryStorageVmVO> ssVms = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running);
        if (ssVms.size() > 0) {
            SecondaryStorageVmVO ssVm = ssVms.get(0);
            if (ssVm.getPublicIpAddress() == null) {
                errorString = "A running secondary storage vm has a null public ip?";
                s_logger.error(errorString);
                throw new CloudRuntimeException(errorString);
            }
            //Construct actual URL locally now that the symlink exists at SSVM
            String extractURL = generateCopyUrl(ssVm.getPublicIpAddress(), uuid);
            UploadVO vo = _uploadDao.createForUpdate();
            vo.setLastUpdated(new Date());
            vo.setUploadUrl(extractURL);
            vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
            _uploadDao.update(uploadId, vo);
            success = true;
            return;
        }
        errorString = "Couldnt find a running SSVM in the zone" + dataCenterId + ". Couldnt create the extraction URL.";
        throw new CloudRuntimeException(errorString);
    } finally {
        if (!success) {
            UploadVO uploadJob = _uploadDao.createForUpdate(uploadId);
            uploadJob.setLastUpdated(new Date());
            uploadJob.setErrorString(errorString);
            uploadJob.setUploadState(Status.ERROR);
            _uploadDao.update(uploadId, uploadJob);
        }
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UploadVO(com.cloud.storage.UploadVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) Date(java.util.Date) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Example 94 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class TemplateManagerImpl method getAbsoluteIsoPath.

@Override
public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId) {
    TemplateDataStoreVO templateStoreRef = _tmplStoreDao.findByTemplateZoneDownloadStatus(templateId, dataCenterId, VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    if (templateStoreRef == null) {
        throw new CloudRuntimeException("Template " + templateId + " has not been completely downloaded to zone " + dataCenterId);
    }
    DataStore store = _dataStoreMgr.getDataStore(templateStoreRef.getDataStoreId(), DataStoreRole.Image);
    String isoPath = store.getUri() + "/" + templateStoreRef.getInstallPath();
    return new Pair<String, String>(isoPath, store.getUri());
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Pair(com.cloud.utils.Pair)

Example 95 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class TemplateManagerImpl method copyTemplate.

@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_COPY, eventDescription = "copying template", async = true)
public VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException, ResourceAllocationException {
    Long templateId = cmd.getId();
    Long userId = CallContext.current().getCallingUserId();
    Long sourceZoneId = cmd.getSourceZoneId();
    Long destZoneId = cmd.getDestinationZoneId();
    Account caller = CallContext.current().getCallingAccount();
    // Verify parameters
    VMTemplateVO template = _tmpltDao.findById(templateId);
    if (template == null || template.getRemoved() != null) {
        throw new InvalidParameterValueException("Unable to find template with id");
    }
    DataStore srcSecStore = null;
    if (sourceZoneId != null) {
        // template is on zone-wide secondary storage
        srcSecStore = getImageStore(sourceZoneId, templateId);
    } else {
        // template is on region store
        srcSecStore = getImageStore(templateId);
    }
    if (srcSecStore == null) {
        throw new InvalidParameterValueException("There is no template " + templateId + " ready on image store.");
    }
    if (template.isCrossZones()) {
        // sync template from cache store to region store if it is not there, for cases where we are going to migrate existing NFS to S3.
        _tmpltSvr.syncTemplateToRegionStore(templateId, srcSecStore);
        s_logger.debug("Template " + templateId + " is cross-zone, don't need to copy");
        return template;
    }
    if (sourceZoneId != null) {
        if (sourceZoneId.equals(destZoneId)) {
            throw new InvalidParameterValueException("Please specify different source and destination zones.");
        }
        DataCenterVO sourceZone = _dcDao.findById(sourceZoneId);
        if (sourceZone == null) {
            throw new InvalidParameterValueException("Please specify a valid source zone.");
        }
    }
    DataCenterVO dstZone = _dcDao.findById(destZoneId);
    if (dstZone == null) {
        throw new InvalidParameterValueException("Please specify a valid destination zone.");
    }
    DataStore dstSecStore = getImageStore(destZoneId, templateId);
    if (dstSecStore != null) {
        s_logger.debug("There is template " + templateId + " in secondary storage " + dstSecStore.getName() + " in zone " + destZoneId + " , don't need to copy");
        return template;
    }
    _accountMgr.checkAccess(caller, AccessType.OperateEntry, true, template);
    boolean success = copy(userId, template, srcSecStore, dstZone);
    if (success) {
        // increase resource count
        long accountId = template.getAccountId();
        if (template.getSize() != null) {
            _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage, template.getSize());
        }
        return template;
    } else {
        throw new CloudRuntimeException("Failed to copy template");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)158 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)52 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)49 ExecutionException (java.util.concurrent.ExecutionException)37 VolumeVO (com.cloud.storage.VolumeVO)30 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)24 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 VMTemplateVO (com.cloud.storage.VMTemplateVO)22 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)22 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)22 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)18 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)17 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)17 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13