Search in sources :

Example 1 with VolumeShowResponse

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);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) CinderApi(com.emc.storageos.cinder.api.CinderApi) URI(java.net.URI) VolumeShowResponse(com.emc.storageos.cinder.model.VolumeShowResponse) IOException(java.io.IOException) Volume(com.emc.storageos.db.client.model.Volume) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with VolumeShowResponse

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;
}
Also used : SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) VolumeShowResponse(com.emc.storageos.cinder.model.VolumeShowResponse)

Example 3 with VolumeShowResponse

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Gson(com.google.gson.Gson) VolumeShowResponse(com.emc.storageos.cinder.model.VolumeShowResponse)

Example 4 with VolumeShowResponse

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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) SnapshotCreateRequest(com.emc.storageos.cinder.model.SnapshotCreateRequest) Gson(com.google.gson.Gson) VolumeShowResponse(com.emc.storageos.cinder.model.VolumeShowResponse)

Aggregations

VolumeShowResponse (com.emc.storageos.cinder.model.VolumeShowResponse)4 SnapshotCreateResponse (com.emc.storageos.cinder.model.SnapshotCreateResponse)2 Gson (com.google.gson.Gson)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 CinderApi (com.emc.storageos.cinder.api.CinderApi)1 SnapshotCreateRequest (com.emc.storageos.cinder.model.SnapshotCreateRequest)1 DbClient (com.emc.storageos.db.client.DbClient)1 StoragePool (com.emc.storageos.db.client.model.StoragePool)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 Volume (com.emc.storageos.db.client.model.Volume)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1