Search in sources :

Example 6 with ApiException

use of com.linbit.linstor.api.ApiException in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method cloneResource.

private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolVO storagePoolVO) {
    // get the cached template on this storage
    VMTemplateStoragePoolVO tmplPoolRef = _vmTemplatePoolDao.findByPoolTemplate(storagePoolVO.getId(), csCloneId, null);
    if (tmplPoolRef != null) {
        final String cloneRes = LinstorUtil.RSC_PREFIX + tmplPoolRef.getLocalDownloadPath();
        final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getUuid();
        final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
        try {
            s_logger.debug("Clone resource definition " + cloneRes + " to " + rscName);
            ResourceDefinitionCloneRequest cloneRequest = new ResourceDefinitionCloneRequest();
            cloneRequest.setName(rscName);
            ResourceDefinitionCloneStarted cloneStarted = linstorApi.resourceDefinitionClone(cloneRes, cloneRequest);
            checkLinstorAnswersThrow(cloneStarted.getMessages());
            if (!CloneWaiter.waitFor(linstorApi, cloneStarted)) {
                throw new CloudRuntimeException("Clone for resource " + rscName + " failed.");
            }
            return getDeviceName(linstorApi, rscName);
        } catch (ApiException apiEx) {
            s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
            throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
        }
    } else {
        throw new CloudRuntimeException("Unable to find Linstor resource for the following template data-object ID: " + csCloneId);
    }
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceDefinitionCloneRequest(com.linbit.linstor.api.model.ResourceDefinitionCloneRequest) ResourceDefinitionCloneStarted(com.linbit.linstor.api.model.ResourceDefinitionCloneStarted) ApiException(com.linbit.linstor.api.ApiException)

Example 7 with ApiException

use of com.linbit.linstor.api.ApiException in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method resize.

@Override
public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    final VolumeObject vol = (VolumeObject) data;
    final StoragePool pool = (StoragePool) data.getDataStore();
    final DevelopersApi api = LinstorUtil.getLinstorAPI(pool.getHostAddress());
    final ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
    final String rscName = LinstorUtil.RSC_PREFIX + vol.getPath();
    final long oldSize = vol.getSize();
    String errMsg = null;
    VolumeDefinitionModify dfm = new VolumeDefinitionModify();
    dfm.setSizeKib(resizeParameter.newSize / 1024);
    try {
        ApiCallRcList answers = api.volumeDefinitionModify(rscName, 0, dfm);
        if (answers.hasError()) {
            s_logger.error("Resize error: " + answers.get(0).getMessage());
            errMsg = answers.get(0).getMessage();
        } else {
            s_logger.info(String.format("Successfully resized %s to %d kib", rscName, dfm.getSizeKib()));
            vol.setSize(resizeParameter.newSize);
            vol.update();
        }
    } catch (ApiException apiExc) {
        s_logger.error(apiExc);
        errMsg = apiExc.getBestMessage();
    }
    CreateCmdResult result;
    if (errMsg != null) {
        result = new CreateCmdResult(null, new Answer(null, false, errMsg));
        result.setResult(errMsg);
    } else {
        // notify guests
        result = notifyResize(data, oldSize, resizeParameter);
    }
    callback.complete(result);
}
Also used : ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) StoragePool(com.cloud.storage.StoragePool) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) VolumeDefinitionModify(com.linbit.linstor.api.model.VolumeDefinitionModify) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject) ApiException(com.linbit.linstor.api.ApiException)

Example 8 with ApiException

use of com.linbit.linstor.api.ApiException in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method takeSnapshot.

@Override
public void takeSnapshot(SnapshotInfo snapshotInfo, AsyncCompletionCallback<CreateCmdResult> callback) {
    s_logger.debug("Linstor: takeSnapshot with snapshot: " + snapshotInfo.getUuid());
    final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
    final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    long storagePoolId = volumeVO.getPoolId();
    final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    final DevelopersApi api = LinstorUtil.getLinstorAPI(storagePool.getHostAddress());
    final String rscName = LinstorUtil.RSC_PREFIX + volumeVO.getPath();
    Snapshot snapshot = new Snapshot();
    snapshot.setName(getSnapshotName(snapshotInfo.getUuid()));
    CreateCmdResult result;
    try {
        ApiCallRcList answers = api.resourceSnapshotCreate(rscName, snapshot);
        if (answers.hasError()) {
            final String errMsg = answers.get(0).getMessage();
            s_logger.error("Snapshot error: " + errMsg);
            result = new CreateCmdResult(null, new Answer(null, false, errMsg));
            result.setResult(errMsg);
        } else {
            s_logger.info(String.format("Successfully took snapshot from %s", rscName));
            SnapshotObjectTO snapshotObjectTo = (SnapshotObjectTO) snapshotInfo.getTO();
            snapshotObjectTo.setPath(rscName + "-" + snapshotInfo.getName());
            result = new CreateCmdResult(null, new CreateObjectAnswer(snapshotObjectTo));
            result.setResult(null);
        }
    } catch (ApiException apiExc) {
        s_logger.error(apiExc);
        result = new CreateCmdResult(null, new Answer(null, false, apiExc.getBestMessage()));
        result.setResult(apiExc.getBestMessage());
    }
    callback.complete(result);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) DevelopersApi(com.linbit.linstor.api.DevelopersApi) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) Snapshot(com.linbit.linstor.api.model.Snapshot) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) VolumeVO(com.cloud.storage.VolumeVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ApiException(com.linbit.linstor.api.ApiException)

Example 9 with ApiException

use of com.linbit.linstor.api.ApiException in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method deleteSnapshot.

private void deleteSnapshot(@Nonnull DataStore dataStore, @Nonnull String rscDefName, @Nonnull String snapshotName) {
    StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
    DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePool.getHostAddress());
    try {
        ApiCallRcList answers = linstorApi.resourceSnapshotDelete(rscDefName, snapshotName);
        if (answers.hasError()) {
            for (ApiCallRc answer : answers) {
                s_logger.error(answer.getMessage());
            }
            throw new CloudRuntimeException("Linstor: Unable to delete snapshot: " + rscDefName);
        }
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiCallRc(com.linbit.linstor.api.model.ApiCallRc) ApiException(com.linbit.linstor.api.ApiException)

Example 10 with ApiException

use of com.linbit.linstor.api.ApiException in project cloudstack by apache.

the class LinstorPrimaryDataStoreDriverImpl method createResource.

private String createResource(VolumeInfo vol, StoragePoolVO storagePoolVO) {
    DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(storagePoolVO.getHostAddress());
    final String rscGrp = storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ? storagePoolVO.getUserInfo() : "DfltRscGrp";
    ResourceGroupSpawn rscGrpSpawn = new ResourceGroupSpawn();
    final String rscName = LinstorUtil.RSC_PREFIX + vol.getUuid();
    rscGrpSpawn.setResourceDefinitionName(rscName);
    rscGrpSpawn.addVolumeSizesItem(vol.getSize() / 1024);
    try {
        s_logger.debug("Linstor: Spawn resource " + rscName);
        ApiCallRcList answers = linstorApi.resourceGroupSpawn(rscGrp, rscGrpSpawn);
        checkLinstorAnswersThrow(answers);
        return getDeviceName(linstorApi, rscName);
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
    }
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DevelopersApi(com.linbit.linstor.api.DevelopersApi) ResourceGroupSpawn(com.linbit.linstor.api.model.ResourceGroupSpawn) ApiException(com.linbit.linstor.api.ApiException)

Aggregations

ApiException (com.linbit.linstor.api.ApiException)16 DevelopersApi (com.linbit.linstor.api.DevelopersApi)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)13 ResourceWithVolumes (com.linbit.linstor.api.model.ResourceWithVolumes)6 ResourceDefinition (com.linbit.linstor.api.model.ResourceDefinition)5 ResourceDefinitionModify (com.linbit.linstor.api.model.ResourceDefinitionModify)5 ResourceGroupSpawn (com.linbit.linstor.api.model.ResourceGroupSpawn)5 ApiClient (com.linbit.linstor.api.ApiClient)4 Configuration (com.linbit.linstor.api.Configuration)4 ApiCallRc (com.linbit.linstor.api.model.ApiCallRc)4 Properties (com.linbit.linstor.api.model.Properties)4 ProviderKind (com.linbit.linstor.api.model.ProviderKind)4 ResourceGroup (com.linbit.linstor.api.model.ResourceGroup)4 ResourceMakeAvailable (com.linbit.linstor.api.model.ResourceMakeAvailable)4 StoragePool (com.linbit.linstor.api.model.StoragePool)4 VolumeDefinition (com.linbit.linstor.api.model.VolumeDefinition)4 Collections (java.util.Collections)4 List (java.util.List)4 Logger (org.apache.log4j.Logger)4