use of com.emc.storageos.cinder.model.VolumeShowResponse in project coprhd-controller by CoprHD.
the class AbstractCinderVolumeCreateJob method updateStatus.
/**
* Called to update the job status when the volume create job completes.
* This is common update code for volume create operations.
*
* @param jobContext The job context.
*/
@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());
// If terminal state update storage pool capacity and remove reservation for volumes capacity
// from pool's reserved capacity map.
StoragePool storagePool = null;
if (status == JobStatus.SUCCESS || status == JobStatus.FAILED) {
storagePool = dbClient.queryObject(StoragePool.class, storagePoolUri);
StringMap reservationMap = storagePool.getReservedCapacityMap();
for (URI volumeId : getTaskCompleter().getIds()) {
// remove from reservation map
reservationMap.remove(volumeId.toString());
}
dbClient.persistObject(storagePool);
}
if (status == JobStatus.SUCCESS) {
List<URI> volumes = new ArrayList<URI>();
Calendar now = Calendar.getInstance();
URI volumeId = getTaskCompleter().getId();
volumes.add(volumeId);
for (Map.Entry<String, URI> entry : volumeIds.entrySet()) {
VolumeShowResponse volumeDetails = cinderApi.showVolume(entry.getKey());
processVolume(entry.getValue(), volumeDetails, dbClient, now, logMsgBuilder);
// Adjust the storage pool's capacity
CinderUtils.updateStoragePoolCapacity(dbClient, cinderApi, storagePool, volumeDetails.volume.size, false);
}
} else if (status == JobStatus.FAILED) {
for (URI id : getTaskCompleter().getIds()) {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, id.toString()));
Volume volume = dbClient.queryObject(Volume.class, id);
volume.setInactive(true);
dbClient.persistObject(volume);
}
}
logger.info(logMsgBuilder.toString());
} catch (Exception e) {
logger.error("Caught an exception while trying to updateStatus for CinderCreateVolumeJob", e);
setErrorStatus("Encountered an internal error during volume create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
}
}
use of com.emc.storageos.cinder.model.VolumeShowResponse in project coprhd-controller by CoprHD.
the class CinderApi method getTaskStatus.
/**
* Gets the current status { "creating", "attaching", "deleting", "Error", "Available" }
* of the component ( volume or snapshot ).
*
* @param volumeId
* @return
*/
public String getTaskStatus(String componentId, String componentType) throws Exception {
String status = "";
if (CinderConstants.ComponentType.volume.name().equals(componentType)) {
VolumeShowResponse volumeDetails = showVolume(componentId);
status = volumeDetails.volume.status;
} else if (CinderConstants.ComponentType.snapshot.name().equals(componentType)) {
SnapshotCreateResponse snapshotDetails = showSnapshot(componentId);
status = snapshotDetails.snapshot.status;
}
return status;
}
use of com.emc.storageos.cinder.model.VolumeShowResponse in project coprhd-controller by CoprHD.
the class CinderApi method showVolume.
/**
* Gets the volume information. Its a synchronous operation.
*
* @param volumeId
* @return
*/
public VolumeShowResponse showVolume(String volumeId) throws Exception {
_log.info("CinderApi - start showVolume");
String showVolumeUri = endPoint.getBaseUri() + String.format(CinderConstants.URI_DELETE_VOLUME, new Object[] { endPoint.getCinderTenantId(), volumeId });
ClientResponse js_response = getClient().get(URI.create(showVolumeUri));
_log.debug("uri {} : Response status {}", showVolumeUri, String.valueOf(js_response.getStatus()));
if (js_response.getStatus() == ClientResponse.Status.NOT_FOUND.getStatusCode()) {
throw CinderException.exceptions.volumeNotFound(volumeId);
}
String jsonString = js_response.getEntity(String.class);
VolumeShowResponse volumeDetails = new Gson().fromJson(SecurityUtils.sanitizeJsonString(jsonString), VolumeShowResponse.class);
_log.info("CinderApi - end showVolume");
return volumeDetails;
}
use of com.emc.storageos.cinder.model.VolumeShowResponse in project coprhd-controller by CoprHD.
the class CinderApi method createSnapshot.
/**
* Shows the specified volume attachment details.
*
* @param serverId the server id
* @param volumeAttachmentId the volume attachment id
* @return the volume attachment response
*/
/*
* public VolumeAttachResponse showVolumeAttachment(String serverId, String volumeAttachmentId)
* {
* _log.info("CinderApi - start showVolumeAttachment");
* String showVolumeAttachmentUri = endPoint.getBaseUri()
* + String.format(CinderConstants.URI_LIST_VOLUME_ATTACHMENT,
* new Object[] { endPoint.getCinderTenantId(), serverId, volumeAttachmentId });
* ClientResponse js_response = get_client().get(URI.create(showVolumeAttachmentUri));
* String jsonString = js_response.getEntity(String.class);
*
* VolumeAttachResponse volumeAttachmentDetails = new Gson().fromJson(jsonString, VolumeAttachResponse.class);
* _log.info("CinderApi - end showVolumeAttachment");
* return volumeAttachmentDetails;
* }
*/
/**
* Create Snapshot operation ( It is asynchronous operation )
*
* @param volumeName
* @param volumeTypeId
* @return
* @throws Exception
*/
public String createSnapshot(String volumeId, String snapshotName) throws Exception {
_log.info("CinderApi - start createSnapshot");
Gson gson = new Gson();
VolumeShowResponse volumeDetails = showVolume(volumeId);
String volumeName = volumeDetails.volume.name;
SnapshotCreateRequest request = new SnapshotCreateRequest();
request.snapshot.name = snapshotName;
request.snapshot.description = "Snapshot of volume " + volumeName;
request.snapshot.volume_id = volumeId;
request.snapshot.force = true;
String snapshotCreateUri = endPoint.getBaseUri() + String.format(CinderConstants.URI_CREATE_SNAPSHOT, endPoint.getCinderTenantId());
_log.debug("Creating snapshot with uri : {}", snapshotCreateUri);
String json = gson.toJson(request);
_log.debug("Creating snapshot with body : {}", json);
ClientResponse js_response = getClient().postWithHeader(URI.create(snapshotCreateUri), json);
String s = js_response.getEntity(String.class);
_log.debug("Got the response {}", s);
_log.debug("Response status {}", String.valueOf(js_response.getStatus()));
String snapshotId = "";
if (js_response.getStatus() == ClientResponse.Status.ACCEPTED.getStatusCode()) {
// This means snapshot creation request accepted
SnapshotCreateResponse response = gson.fromJson(SecurityUtils.sanitizeJsonString(s), SnapshotCreateResponse.class);
snapshotId = response.snapshot.id;
} else {
throw CinderException.exceptions.snapshotCreationFailed(s);
}
return snapshotId;
}
Aggregations