Search in sources :

Example 1 with DataObject

use of com.cloud.engine.subsystem.api.storage.DataObject in project cosmic by MissionCriticalCloud.

the class VolumeApiServiceImpl method uploadVolume.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume for post upload", async = true)
public GetUploadParamsResponse uploadVolume(final GetUploadParamsForVolumeCmd cmd) throws ResourceAllocationException, MalformedURLException {
    final Account caller = CallContext.current().getCallingAccount();
    final long ownerId = cmd.getEntityOwnerId();
    final Account owner = _entityMgr.findById(Account.class, ownerId);
    final Long zoneId = cmd.getZoneId();
    final String volumeName = cmd.getName();
    final String format = cmd.getFormat();
    final Long diskOfferingId = cmd.getDiskOfferingId();
    final String imageStoreUuid = cmd.getImageStoreUuid();
    final DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
    validateVolume(caller, ownerId, zoneId, volumeName, null, format, diskOfferingId);
    return Transaction.execute(new TransactionCallbackWithException<GetUploadParamsResponse, MalformedURLException>() {

        @Override
        public GetUploadParamsResponse doInTransaction(final TransactionStatus status) throws MalformedURLException {
            final VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(), diskOfferingId, Volume.State.NotUploaded);
            final VolumeInfo vol = volFactory.getVolume(volume.getId());
            final RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(), cmd.getFormat());
            vol.addPayload(payload);
            final Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol, store);
            final EndPoint ep = pair.first();
            final DataObject dataObject = pair.second();
            final GetUploadParamsResponse response = new GetUploadParamsResponse();
            final String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
            final String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(), vol.getUuid());
            response.setPostURL(new URL(url));
            // set the post url, this is used in the monitoring thread to determine the SSVM
            final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(vol.getId());
            assert volumeStore != null : "sincle volume is registered, volumestore cannot be null at this stage";
            volumeStore.setExtractUrl(url);
            _volumeStoreDao.persist(volumeStore);
            response.setId(UUID.fromString(vol.getUuid()));
            final int timeout = ImageStoreUploadMonitorImpl.getUploadOperationTimeout();
            final DateTime currentDateTime = new DateTime(DateTimeZone.UTC);
            final String expires = currentDateTime.plusMinutes(timeout).toString();
            response.setTimeout(expires);
            final String key = _configDao.getValue(Config.SSVMPSK.key());
            /*
                 * encoded metadata using the post upload config key
                 */
            final TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(), cmd.getChecksum(), vol.getType().toString(), vol.getName(), vol.getFormat().toString(), dataObject.getDataStore().getUri(), dataObject.getDataStore().getRole().toString());
            command.setLocalPath(volumeStore.getLocalDownloadPath());
            // using the existing max upload size configuration
            command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
            command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
            command.setAccountId(vol.getAccountId());
            final Gson gson = new GsonBuilder().create();
            final String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
            response.setMetadata(metadata);
            /*
                 * signature calculated on the url, expiry, metadata.
                 */
            response.setSignature(EncryptionUtil.generateSignature(metadata + url + expires, key));
            return response;
        }
    });
}
Also used : Account(com.cloud.user.Account) MalformedURLException(java.net.MalformedURLException) GsonBuilder(com.google.gson.GsonBuilder) TransactionStatus(com.cloud.utils.db.TransactionStatus) Gson(com.google.gson.Gson) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) GetUploadParamsResponse(com.cloud.api.response.GetUploadParamsResponse) URL(java.net.URL) DateTime(org.joda.time.DateTime) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) TemplateOrVolumePostUploadCommand(com.cloud.storage.command.TemplateOrVolumePostUploadCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) Pair(com.cloud.utils.Pair) ActionEvent(com.cloud.event.ActionEvent)

Example 2 with DataObject

use of com.cloud.engine.subsystem.api.storage.DataObject in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method copyAsync.

private AsyncCallFuture<TemplateApiResult> copyAsync(final DataObject source, final TemplateInfo template, final DataStore store) {
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    final DataObject templateOnStore = store.create(template);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
    final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(source, templateOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 3 with DataObject

use of com.cloud.engine.subsystem.api.storage.DataObject in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method copySnapshot.

protected Answer copySnapshot(final DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.BackupSnapshotWait.toString());
    final int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
    DataObject cacheData = null;
    final SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
    final Object payload = snapshotInfo.getPayload();
    Boolean fullSnapshot = true;
    if (payload != null) {
        fullSnapshot = (Boolean) payload;
    }
    final Map<String, String> options = new HashMap<>();
    options.put("fullSnapshot", fullSnapshot.toString());
    Answer answer = null;
    try {
        if (needCacheStorage(srcData, destData)) {
            final Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
            cacheData = cacheMgr.getCacheObject(srcData, selectedScope);
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setCacheTO(cacheData.getTO());
            cmd.setOptions(options);
            final EndPoint ep = selector.select(srcData, destData);
            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);
            }
        } else {
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setOptions(options);
            final EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
            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);
            }
        }
        // clean up cache entry
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    } catch (final Exception e) {
        s_logger.debug("copy snasphot failed: " + e.toString());
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : HashMap(java.util.HashMap) CopyCommand(com.cloud.storage.command.CopyCommand) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) Scope(com.cloud.engine.subsystem.api.storage.Scope) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataObject(com.cloud.engine.subsystem.api.storage.DataObject)

Example 4 with DataObject

use of com.cloud.engine.subsystem.api.storage.DataObject in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method copyObject.

protected Answer copyObject(final DataObject srcData, final DataObject destData, final Host destHost) {
    final String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    Answer answer = null;
    DataObject cacheData = null;
    DataObject srcForCopy = srcData;
    try {
        if (needCacheStorage(srcData, destData)) {
            final Scope destScope = pickCacheScopeForCopy(srcData, destData);
            srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope);
        }
        final CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), destData.getTO(), _primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
        final EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, destData);
        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);
        }
        if (cacheData != null) {
            final Long cacheId = cacheData.getId();
            final String cacheType = cacheData.getType().toString();
            final String cacheUuid = cacheData.getUuid().toString();
            if (srcData.getType() == DataObjectType.VOLUME && (destData.getType() == DataObjectType.VOLUME || destData.getType() == DataObjectType.TEMPLATE)) {
                // volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools
                // Delete cache in order to certainly transfer a latest image.
                s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                cacheMgr.deleteCacheObject(srcForCopy);
            } else {
                // for template, we want to leave it on cache for performance reason
                if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) {
                    // cache object created by this copy, not already there
                    s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.deleteCacheObject(srcForCopy);
                } else {
                    s_logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")");
                    cacheMgr.releaseCacheObject(srcForCopy);
                }
            }
        }
        return answer;
    } catch (final Exception e) {
        s_logger.debug("copy object failed: ", e);
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) Scope(com.cloud.engine.subsystem.api.storage.Scope) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) CopyCommand(com.cloud.storage.command.CopyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with DataObject

use of com.cloud.engine.subsystem.api.storage.DataObject in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method cacheSnapshotChain.

protected DataObject cacheSnapshotChain(SnapshotInfo snapshot, final Scope scope) {
    DataObject leafData = null;
    final DataStore store = cacheMgr.getCacheStorage(snapshot, scope);
    while (snapshot != null) {
        final DataObject cacheData = cacheMgr.createCacheObject(snapshot, store);
        if (leafData == null) {
            leafData = cacheData;
        }
        snapshot = snapshot.getParent();
    }
    return leafData;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Aggregations

DataObject (com.cloud.engine.subsystem.api.storage.DataObject)23 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)9 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)8 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)8 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)8 Answer (com.cloud.agent.api.Answer)6 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)6 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)6 CopyCommand (com.cloud.storage.command.CopyCommand)5 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)4 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)4 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)4 DB (com.cloud.utils.db.DB)4 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)3 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)3 Scope (com.cloud.engine.subsystem.api.storage.Scope)3 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 Date (java.util.Date)3 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2