Search in sources :

Example 1 with FileSystem

use of org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem in project cloudstack by apache.

the class ElastistorVolumeApiServiceImpl method listElastistorVolume.

@SuppressWarnings("unchecked")
@Override
public ListResponse<ListElastistorVolumeResponse> listElastistorVolume(ListElastistorVolumeCmd cmd) {
    try {
        FileSystem listVolumeResponse = ElastistorUtil.listVolume(cmd.getId());
        List<ListElastistorVolumeResponse> volumeResponses = new ArrayList<ListElastistorVolumeResponse>();
        ListElastistorVolumeResponse volumeResponse;
        volumeResponse = new ListElastistorVolumeResponse();
        volumeResponse.setId(listVolumeResponse.getUuid());
        volumeResponse.setName(listVolumeResponse.getName());
        volumeResponse.setGraceAllowed(listVolumeResponse.getGraceallowed());
        volumeResponse.setDeduplication(listVolumeResponse.getDeduplication());
        volumeResponse.setCompression(listVolumeResponse.getCompression());
        volumeResponse.setSync(listVolumeResponse.getSync());
        // set object name for a better json structure
        volumeResponse.setObjectName("elastistorvolume");
        volumeResponses.add(volumeResponse);
        ListResponse<ListElastistorVolumeResponse> response = new ListResponse<ListElastistorVolumeResponse>();
        response.setResponses(volumeResponses);
        return response;
    } catch (Throwable e) {
        s_logger.error("Unable to list elastistor volume.", e);
        throw new CloudRuntimeException("Unable to list elastistor volume. " + e.getMessage());
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileSystem(org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem) ArrayList(java.util.ArrayList)

Example 2 with FileSystem

use of org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem in project cloudstack by apache.

the class ElastistorPrimaryDataStoreLifeCycle method createElastistorVolume.

private PrimaryDataStoreParameters createElastistorVolume(PrimaryDataStoreParameters parameters, Tsm tsm, String storagePoolName, Long capacityBytes, Long capacityIops, String protocoltype, String mountpoint) {
    try {
        s_logger.info("Creation of elastistor volume started.");
        FileSystem volume = ElastistorUtil.createElastistorVolume(storagePoolName, tsm.getUuid(), capacityBytes, capacityIops, protocoltype, mountpoint);
        if (protocoltype.contentEquals("iscsi")) {
            String accesspath = "/" + volume.getIqn() + "/0";
            parameters.setPath(accesspath);
        }
        s_logger.info("Creation of elastistor volume completed successfully.");
        return parameters;
    } catch (Throwable e) {
        s_logger.error("Failed to create volume in elastistor.", e);
        throw new CloudRuntimeException("Failed to create volume in elastistor. " + e.getMessage());
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileSystem(org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem)

Example 3 with FileSystem

use of org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem 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

CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 FileSystem (org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem)3 Answer (com.cloud.agent.api.Answer)1 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)1 VolumeVO (com.cloud.storage.VolumeVO)1 ArrayList (java.util.ArrayList)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)1 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)1 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1