Search in sources :

Example 11 with CinderApi

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());
}
Also used : CinderSnapshotCreateJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderSnapshotCreateJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CinderApi(com.emc.storageos.cinder.api.CinderApi) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) CinderJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderJob) CinderException(com.emc.storageos.cinder.errorhandling.CinderException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 12 with CinderApi

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);
    }
}
Also used : CinderException(com.emc.storageos.cinder.errorhandling.CinderException) CinderVolumeExpandJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderVolumeExpandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) CinderApi(com.emc.storageos.cinder.api.CinderApi) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) CinderJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderJob) CinderException(com.emc.storageos.cinder.errorhandling.CinderException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 13 with CinderApi

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);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) CinderApi(com.emc.storageos.cinder.api.CinderApi) URI(java.net.URI) CinderException(com.emc.storageos.cinder.errorhandling.CinderException) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Example 14 with CinderApi

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);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CinderApi(com.emc.storageos.cinder.api.CinderApi) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

CinderApi (com.emc.storageos.cinder.api.CinderApi)14 CinderEndPointInfo (com.emc.storageos.cinder.CinderEndPointInfo)9 Volume (com.emc.storageos.db.client.model.Volume)9 URI (java.net.URI)7 CinderException (com.emc.storageos.cinder.errorhandling.CinderException)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)6 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)6 ArrayList (java.util.ArrayList)6 StoragePool (com.emc.storageos.db.client.model.StoragePool)5 DbClient (com.emc.storageos.db.client.DbClient)4 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)4 StringMap (com.emc.storageos.db.client.model.StringMap)3 CinderJob (com.emc.storageos.volumecontroller.impl.cinder.job.CinderJob)3 Initiator (com.emc.storageos.db.client.model.Initiator)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 CinderSingleVolumeCreateJob (com.emc.storageos.volumecontroller.impl.cinder.job.CinderSingleVolumeCreateJob)2