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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations