Search in sources :

Example 36 with CreateCmdResult

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

the class SamplePrimaryDataStoreDriverImpl method createAsync.

/*
     * private class CreateVolumeFromBaseImageContext<T> extends
     * AsyncRpcContext<T> { private final VolumeObject volume;
     *
     * public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T>
     * callback, VolumeObject volume) { super(callback); this.volume = volume; }
     *
     * public VolumeObject getVolume() { return this.volume; }
     *
     * }
     *
     * @Override public void createVolumeFromBaseImageAsync(VolumeObject volume,
     * TemplateInfo template, AsyncCompletionCallback<CommandResult> callback) {
     * VolumeTO vol = this.dataStore.getVolumeTO(volume); List<EndPoint>
     * endPoints = this.dataStore.getEndPoints(); EndPoint ep =
     * endPoints.get(0); String templateUri =
     * template.getDataStore().grantAccess(template, ep);
     * CreateVolumeFromBaseImageCommand cmd = new
     * CreateVolumeFromBaseImageCommand(vol, templateUri);
     *
     * CreateVolumeFromBaseImageContext<CommandResult> context = new
     * CreateVolumeFromBaseImageContext<CommandResult>(callback, volume);
     * AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl, Answer> caller
     * = AsyncCallbackDispatcher.create(this); caller.setContext(context)
     * .setCallback
     * (caller.getTarget().createVolumeFromBaseImageAsyncCallback(null, null));
     *
     * ep.sendMessageAsync(cmd, caller); }
     */
/*
     * public Object
     * createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher
     * <DefaultPrimaryDataStoreDriverImpl, Answer> callback,
     * CreateVolumeFromBaseImageContext<CommandResult> context) {
     * CreateVolumeAnswer answer = (CreateVolumeAnswer)callback.getResult();
     * CommandResult result = new CommandResult(); if (answer == null ||
     * answer.getDetails() != null) { result.setSuccess(false); if (answer !=
     * null) { result.setResult(answer.getDetails()); } } else {
     * result.setSuccess(true); VolumeObject volume = context.getVolume();
     * volume.setPath(answer.getVolumeUuid()); }
     * AsyncCompletionCallback<CommandResult> parentCall =
     * context.getParentCallback(); parentCall.complete(result); return null; }
     */
@Override
public void createAsync(DataStore dataStore, DataObject vol, AsyncCompletionCallback<CreateCmdResult> callback) {
    EndPoint ep = selector.select(vol);
    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);
    }
    CreateObjectCommand createCmd = new CreateObjectCommand(null);
    CreateVolumeContext<CreateCmdResult> context = new CreateVolumeContext<CreateCmdResult>(callback, vol);
    AsyncCallbackDispatcher<SamplePrimaryDataStoreDriverImpl, Answer> caller = AsyncCallbackDispatcher.create(this);
    caller.setContext(context).setCallback(caller.getTarget().createAsyncCallback(null, null));
    ep.sendMessageAsync(createCmd, caller);
}
Also used : Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) CreateObjectCommand(org.apache.cloudstack.storage.command.CreateObjectCommand)

Example 37 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 38 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)

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