Search in sources :

Example 6 with DevelopersApi

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

the class LinstorPrimaryDataStoreDriverImpl method revertSnapshot.

@Override
public void revertSnapshot(SnapshotInfo snapshot, SnapshotInfo snapshotOnPrimaryStore, AsyncCompletionCallback<CommandResult> callback) {
    s_logger.debug("Linstor: revertSnapshot");
    final VolumeInfo volumeInfo = snapshot.getBaseVolume();
    VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    if (volumeVO == null || volumeVO.getRemoved() != null) {
        CommandResult commandResult = new CommandResult();
        commandResult.setResult("The volume that the snapshot belongs to no longer exists.");
        callback.complete(commandResult);
        return;
    }
    String resultMsg;
    try {
        final StoragePool pool = (StoragePool) snapshot.getDataStore();
        final String rscName = LinstorUtil.RSC_PREFIX + volumeInfo.getUuid();
        final String snapName = LinstorUtil.RSC_PREFIX + snapshot.getUuid();
        final DevelopersApi linstorApi = LinstorUtil.getLinstorAPI(pool.getHostAddress());
        ApiCallRcList answers = linstorApi.resourceSnapshotRollback(rscName, snapName);
        resultMsg = checkLinstorAnswers(answers);
    } catch (ApiException apiEx) {
        s_logger.error("Linstor: ApiEx - " + apiEx.getMessage());
        resultMsg = apiEx.getBestMessage();
    }
    if (callback != null) {
        CommandResult result = new CommandResult();
        result.setResult(resultMsg);
        callback.complete(result);
    }
}
Also used : ApiCallRcList(com.linbit.linstor.api.model.ApiCallRcList) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DevelopersApi(com.linbit.linstor.api.DevelopersApi) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ApiException(com.linbit.linstor.api.ApiException)

Example 7 with DevelopersApi

use of com.linbit.linstor.api.DevelopersApi 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 8 with DevelopersApi

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

the class LinstorUtil method getLinstorAPI.

public static DevelopersApi getLinstorAPI(String linstorUrl) {
    ApiClient client = Configuration.getDefaultApiClient();
    client.setBasePath(linstorUrl);
    return new DevelopersApi(client);
}
Also used : DevelopersApi(com.linbit.linstor.api.DevelopersApi) ApiClient(com.linbit.linstor.api.ApiClient)

Example 9 with DevelopersApi

use of com.linbit.linstor.api.DevelopersApi 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 10 with DevelopersApi

use of com.linbit.linstor.api.DevelopersApi 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)

Aggregations

DevelopersApi (com.linbit.linstor.api.DevelopersApi)18 ApiException (com.linbit.linstor.api.ApiException)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)13 ApiCallRcList (com.linbit.linstor.api.model.ApiCallRcList)13 ApiClient (com.linbit.linstor.api.ApiClient)6 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 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