use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderStorageDevice method doCreateSnapshot.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doCreateSnapshot
* (com.emc.storageos.db.client.model.StorageSystem,
* java.util.List,
* java.lang.Boolean,
* java.lang.Boolean,
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doCreateSnapshot(StorageSystem storage, List<URI> snapshotList, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
log.debug("In CinderStorageDevice.doCreateSnapshot method.");
boolean operationFailed = false;
StringBuilder logMsgBuilder = new StringBuilder(String.format("Create Snapshot Start - Array:%s, ", storage.getSerialNumber()));
BlockSnapshot snapshot = null;
try {
snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotList.get(0));
Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
logMsgBuilder.append(String.format("%nSnapshot:%s for Volume %s", snapshot.getLabel(), volume.getLabel()));
log.info(logMsgBuilder.toString());
CinderEndPointInfo endPoint = CinderUtils.getCinderEndPoint(storage.getActiveProviderURI(), dbClient);
CinderApi cinderApi = cinderApiFactory.getApi(storage.getActiveProviderURI(), endPoint);
String snapshotID = cinderApi.createSnapshot(volume.getNativeId(), snapshot.getLabel());
if (snapshotID != null) {
CinderJob createSnapshotJob = new CinderSnapshotCreateJob(snapshotID, snapshot.getLabel(), volume.getStorageController(), CinderConstants.ComponentType.snapshot.name(), endPoint, taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(createSnapshotJob));
}
} catch (Exception e) {
String message = String.format("Exception when trying to create snapshot(s) on array %s", storage.getSerialNumber());
log.error(message, e);
ServiceError error = DeviceControllerErrors.cinder.operationFailed("doCreateSnapshot", e.getMessage());
taskCompleter.error(dbClient, error);
operationFailed = true;
}
if (operationFailed && null != snapshot) {
snapshot.setInactive(true);
dbClient.persistObject(snapshot);
}
logMsgBuilder = new StringBuilder(String.format("Create Snapshot End - Array:%s, ", storage.getSerialNumber()));
log.info(logMsgBuilder.toString());
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderStorageDevice method doExpandVolume.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doExpandVolume
* (com.emc.storageos.db.client.model.StorageSystem,
* com.emc.storageos.db.client.model.StoragePool,
* com.emc.storageos.db.client.model.Volume,
* java.lang.Long,
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doExpandVolume(StorageSystem storageSystem, StoragePool storagePool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
log.info(String.format("Expand Volume Start - Array:%s, Pool:%s, Volume:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid(), volume.getId()));
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
log.info("Getting the cinder APi for the provider with id " + storageSystem.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
String volumeId = volume.getNativeId();
if (null != volumeId) {
log.info("Expanding volume with the id " + volumeId + " on Openstack cinder node");
cinderApi.expandVolume(volumeId, CinderUtils.convertToGB(size));
CinderJob expandVolumeJob = new CinderVolumeExpandJob(volumeId, volume.getLabel(), volume.getStorageController(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, storagePool.getId());
ControllerServiceImpl.enqueueJob(new QueueJob(expandVolumeJob));
}
log.info(String.format("Expand Volume End - Array:%s, Pool:%s, Volume:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid(), volume.getId()));
} catch (CinderException ce) {
String message = String.format("Exception when trying to expand volume on Array %s, Pool:%s, Volume:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid(), volume.getId());
log.error(message, ce);
ServiceError error = DeviceControllerErrors.cinder.operationFailed("doExpandVolume", ce.getMessage());
taskCompleter.error(dbClient, error);
} catch (final Exception e) {
log.error("Problem in doExpandVolume: ", e);
ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("doExpandVolume", e.getMessage());
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderDeleteVolumeJob method updateStatus.
/**
* Called to update the job status when the volume delete job completes. *
*
* @param jobContext The job context.
*/
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
if (status == JobStatus.IN_PROGRESS) {
return;
}
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
CinderApi cinderApi = jobContext.getCinderApiFactory().getApi(storageSystem.getActiveProviderURI(), getEndPointInfo());
// Get list of volumes; get set of storage pool ids to which they belong.
List<Volume> volumes = new ArrayList<Volume>();
Set<URI> poolURIs = new HashSet<URI>();
long deletedVolumesTotCapacity = 0L;
for (URI id : getTaskCompleter().getIds()) {
Volume volume = dbClient.queryObject(Volume.class, id);
volumes.add(volume);
poolURIs.add(volume.getPool());
deletedVolumesTotCapacity += volume.getCapacity();
}
// If terminal state update storage pool capacity
if (status == JobStatus.SUCCESS) {
// Update capacity of storage pools.
for (URI poolURI : poolURIs) {
StoragePool storagePool = dbClient.queryObject(StoragePool.class, poolURI);
CinderUtils.updateStoragePoolCapacity(dbClient, cinderApi, storagePool, String.valueOf(deletedVolumesTotCapacity / CinderConstants.BYTES_TO_GB), true);
}
}
StringBuilder logMsgBuilder = new StringBuilder();
if (status == JobStatus.SUCCESS) {
for (Volume volume : volumes) {
volume.setInactive(true);
dbClient.persistObject(volume);
dbClient.ready(Volume.class, volume.getId(), getTaskCompleter().getOpId());
if (logMsgBuilder.length() != 0) {
logMsgBuilder.append("\n");
}
logMsgBuilder.append(String.format("Successfully deleted volume %s", volume.getId()));
}
} else if (status == JobStatus.FAILED) {
for (URI id : getTaskCompleter().getIds()) {
if (logMsgBuilder.length() != 0) {
logMsgBuilder.append("\n");
}
logMsgBuilder.append(String.format("Failed to delete volume: %s", id));
}
}
if (logMsgBuilder.length() > 0) {
logger.info(logMsgBuilder.toString());
}
} catch (Exception e) {
setErrorStatus("Encountered an internal error during delete volume job status processing: " + e.getMessage());
logger.error("Caught exception while handling updateStatus for delete volume job.", e);
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.cinder.api.CinderApi in project coprhd-controller by CoprHD.
the class CinderSnapshotCreateJob method updateStatus.
@Override
public void updateStatus(JobContext jobContext) throws Exception {
DbClient dbClient = jobContext.getDbClient();
try {
// Do nothing if the job is not completed yet
if (status == JobStatus.IN_PROGRESS) {
return;
}
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, status.name()));
StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
CinderApi cinderApi = jobContext.getCinderApiFactory().getApi(storageSystem.getActiveProviderURI(), getEndPointInfo());
URI snapshotId = getTaskCompleter().getId(0);
if (status == JobStatus.SUCCESS) {
SnapshotCreateResponse snapshotDetails = cinderApi.showSnapshot(getJobId());
BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
snapshot.setNativeId(snapshotDetails.snapshot.id);
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
snapshot.setInactive(false);
snapshot.setCreationTime(Calendar.getInstance());
dbClient.persistObject(snapshot);
if (logMsgBuilder.length() != 0) {
logMsgBuilder.append("\n");
}
logMsgBuilder.append(String.format("Created Snapshot successfully .. NativeId: %s, URI: %s", snapshot.getNativeId(), getTaskCompleter().getId()));
} else if (status == JobStatus.FAILED) {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, getTaskCompleter().getId().toString()));
Snapshot snapshot = dbClient.queryObject(Snapshot.class, snapshotId);
snapshot.setInactive(true);
dbClient.persistObject(snapshot);
}
_logger.info(logMsgBuilder.toString());
} catch (Exception e) {
_logger.error("Caught an exception while trying to updateStatus for CinderCreateSnapshotJob", e);
setErrorStatus("Encountered an internal error during snapshot create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
Aggregations