Search in sources :

Example 11 with DataObject

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

the class VolumeServiceImpl method registerVolume.

@Override
public AsyncCallFuture<VolumeApiResult> registerVolume(final VolumeInfo volume, final DataStore store) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final DataObject volumeOnStore = store.create(volume);
    volumeOnStore.processEvent(Event.CreateOnlyRequested);
    try {
        final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().registerVolumeCallback(null, null));
        caller.setContext(context);
        store.getDriver().createAsync(store, volumeOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
        final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
        if (volStoreVO != null) {
            final VolumeInfo volObj = volFactory.getVolume(volume, store);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final VolumeApiResult res = new VolumeApiResult((VolumeObject) volumeOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    return future;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 12 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 13 with DataObject

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

the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.

@DB
protected Void createVolumeFromBaseImageCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
    final DataObject vo = context.vo;
    final DataObject tmplOnPrimary = context.templateOnStore;
    final CopyCommandResult result = callback.getResult();
    final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        vo.processEvent(Event.OperationFailed);
        volResult.setResult(result.getResult());
        // hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
        // template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
        final Answer ans = result.getAnswer();
        if (ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")) {
            if (tmplOnPrimary != null) {
                s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
                VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
                if (templatePoolRef != null) {
                    final long templatePoolRefId = templatePoolRef.getId();
                    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
                    try {
                        if (templatePoolRef == null) {
                            s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
                        } else {
                            templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
                            templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
                            _tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
                        }
                    } finally {
                        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
                    }
                }
            }
        }
    }
    final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(volResult);
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) DB(com.cloud.utils.db.DB)

Example 14 with DataObject

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

the class VolumeServiceImpl method createVolumeAsync.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(final VolumeInfo volume, final DataStore dataStore) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final DataObject volumeOnStore = dataStore.create(volume);
    volumeOnStore.processEvent(Event.CreateOnlyRequested);
    try {
        final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context);
        dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
        final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId());
        if (volStoreVO != null) {
            final VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
        volResult.setResult(ex.getMessage());
        future.complete(volResult);
    }
    return future;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 15 with DataObject

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

the class VolumeServiceImpl method copyBaseImageCallback.

@DB
protected Void copyBaseImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateBaseImageContext<VolumeApiResult> context) {
    final CopyCommandResult result = callback.getResult();
    final VolumeApiResult res = new VolumeApiResult(context.getVolume());
    final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    final DataObject templateOnPrimaryStoreObj = context.destObj;
    if (!result.isSuccess()) {
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
        res.setResult(result.getResult());
        future.complete(res);
        return null;
    }
    templateOnPrimaryStoreObj.processEvent(Event.OperationSuccessed, result.getAnswer());
    createVolumeFromBaseImageAsync(context.volume, templateOnPrimaryStoreObj, context.dataStore, future);
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

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