Search in sources :

Example 21 with CreateCmdResult

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

the class CloudStackPrimaryDataStoreDriverImpl method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    String errMsg = null;
    Answer answer = null;
    CreateCmdResult result = new CreateCmdResult(null, null);
    if (data.getType() == DataObjectType.VOLUME) {
        try {
            answer = createVolume((VolumeInfo) data);
            if ((answer == null) || (!answer.getResult())) {
                result.setSuccess(false);
                if (answer != null) {
                    result.setResult(answer.getDetails());
                }
            } else {
                result.setAnswer(answer);
            }
        } catch (StorageUnavailableException e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        } catch (Exception e) {
            s_logger.debug("failed to create volume", e);
            errMsg = e.toString();
        }
    }
    if (errMsg != null) {
        result.setResult(errMsg);
    }
    callback.complete(result);
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) StorageUnavailableException(com.cloud.exception.StorageUnavailableException)

Example 22 with CreateCmdResult

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

the class ElastistorPrimaryDataStoreDriver method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
    String iqn = null;
    String errMsg = null;
    CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
    if (dataObject.getType() == DataObjectType.VOLUME) {
        VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        long storagePoolId = dataStore.getId();
        String volumeName = volumeInfo.getName();
        Long Iops = volumeInfo.getMaxIops();
        // quota size of the cloudbyte volume will be increased with the given HypervisorSnapshotReserve
        Long quotaSize = getDataObjectSizeIncludingHypervisorSnapshotReserve(volumeInfo, _storagePoolDao.findById(storagePoolId));
        StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
        VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
        // calling super(default) that creates a vdi(disk) only.
        if (!(storagePool.isManaged())) {
            super.createAsync(dataStore, dataObject, callback);
            // update the volume property
            volume.setPoolType(storagePool.getPoolType());
            _volumeDao.update(volume.getId(), volume);
            return;
        }
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(volumeInfo.getDiskOfferingId());
        long capacityIops = storagePool.getCapacityIops();
        capacityIops = capacityIops - Iops;
        if (capacityIops < 0) {
            throw new CloudRuntimeException("IOPS not available. [pool:" + storagePool.getName() + "] [availiops:" + capacityIops + "] [requirediops:" + Iops + "]");
        }
        String protocoltype = null;
        StoragePoolVO dataStoreVO = _storagePoolDao.findById(storagePoolId);
        String desc = diskOffering.getDisplayText();
        if (desc.toLowerCase().contains("iscsi")) {
            protocoltype = "iscsi";
        } else if (dataStoreVO.getPoolType().equals(StoragePoolType.NetworkFilesystem) || dataStoreVO.getPoolType().equals(StoragePoolType.Filesystem)) {
            protocoltype = "nfs";
        } else {
            protocoltype = "iscsi";
        }
        FileSystem esvolume = null;
        try {
            esvolume = ElastistorUtil.createElastistorVolume(volumeName, dataStoreVO.getUuid(), quotaSize, Iops, protocoltype, volumeName);
        } catch (Throwable e) {
            s_logger.error(e.toString(), e);
            result.setResult(e.toString());
            callback.complete(result);
            throw new CloudRuntimeException(e.getMessage());
        }
        if (esvolume.getNfsenabled().equalsIgnoreCase("true")) {
            volume.set_iScsiName(esvolume.getPath());
            volume.setPoolType(StoragePoolType.NetworkFilesystem);
        } else {
            iqn = esvolume.getIqn();
            String modifiediqn = "/" + iqn + "/0";
            volume.set_iScsiName(modifiediqn);
            volume.setPoolType(StoragePoolType.IscsiLUN);
        }
        volume.setFolder(String.valueOf(esvolume.getUuid()));
        volume.setPoolId(storagePoolId);
        volume.setUuid(esvolume.getUuid());
        volume.setPath(null);
        _volumeDao.update(volume.getId(), volume);
        // create new volume details for the volume
        //updateVolumeDetails(volume, esvolume);
        long capacityBytes = storagePool.getCapacityBytes();
        long usedBytes = storagePool.getUsedBytes();
        Long inbytes = volume.getSize();
        usedBytes += inbytes;
        storagePool.setCapacityIops(capacityIops);
        storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
        _storagePoolDao.update(storagePoolId, storagePool);
        s_logger.info("Elastistor volume creation complete.");
    } else {
        errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
        s_logger.error(errMsg);
    }
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileSystem(org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 23 with CreateCmdResult

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

the class SwiftImageStoreDriverImpl method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
    VirtualMachineTemplate tmpl = _templateDao.findById(data.getId());
    DataStore cacheStore = cacheManager.getCacheStorage(dataStore.getScope());
    DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO) (data.getTO()), maxTemplateSizeInBytes);
    dcmd.setCacheStore(cacheStore.getTO());
    dcmd.setProxy(getHttpProxy());
    EndPoint ep = _epSelector.select(data);
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
    AsyncCallbackDispatcher<SwiftImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this);
    caller.setContext(context);
    if (data.getType() == DataObjectType.TEMPLATE) {
        caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
    } else if (data.getType() == DataObjectType.VOLUME) {
        caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
    }
    ep.sendMessageAsync(dcmd, caller);
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Example 24 with CreateCmdResult

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

the class SolidFirePrimaryDataStoreDriver method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
    String iqn = null;
    String errMsg = null;
    try {
        if (dataObject.getType() == DataObjectType.VOLUME) {
            iqn = createVolume((VolumeInfo) dataObject, dataStore.getId());
        } else if (dataObject.getType() == DataObjectType.SNAPSHOT) {
            createTempVolume((SnapshotInfo) dataObject, dataStore.getId());
        } else if (dataObject.getType() == DataObjectType.TEMPLATE) {
            iqn = createTemplateVolume((TemplateInfo) dataObject, dataStore.getId());
        } else {
            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
            LOGGER.error(errMsg);
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage();
        LOGGER.error(errMsg);
        if (callback == null) {
            throw ex;
        }
    }
    if (callback != null) {
        // path = iqn
        // size is pulled from DataObject instance, if errMsg is null
        CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 25 with CreateCmdResult

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

the class VolumeServiceImpl method createBaseImageAsync.

@DB
protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStore, TemplateInfo template, AsyncCallFuture<VolumeApiResult> future) {
    DataObject templateOnPrimaryStoreObj = dataStore.create(template);
    VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
    if (templatePoolRef == null) {
        throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId());
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: " + templatePoolRef.getId());
        }
    }
    long templatePoolRefId = templatePoolRef.getId();
    CreateBaseImageContext<CreateCmdResult> context = new CreateBaseImageContext<CreateCmdResult>(null, volume, dataStore, template, future, templateOnPrimaryStoreObj, templatePoolRefId);
    AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context);
    int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds");
    }
    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds);
    if (templatePoolRef == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId);
        }
        templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
        if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
            s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
            createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
            return;
        }
        throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId);
    }
    try {
        if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) {
            s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying");
            createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future);
            return;
        }
        templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested);
        motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller);
    } catch (Throwable e) {
        s_logger.debug("failed to create template on storage", e);
        templateOnPrimaryStoreObj.processEvent(Event.OperationFailed);
        // make sure that template_spool_ref entry is still present so that the second thread can acquire the lock
        dataStore.create(template);
        VolumeApiResult result = new VolumeApiResult(volume);
        result.setResult(e.toString());
        future.complete(result);
    } finally {
        if (s_logger.isDebugEnabled()) {
            s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId);
        }
        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
    }
    return;
}
Also used : CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Aggregations

CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)38 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)12 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)9 Answer (com.cloud.agent.api.Answer)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)7 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)7 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 VolumeVO (com.cloud.storage.VolumeVO)6 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)6 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)6 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)5 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)4 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)4 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)3