Search in sources :

Example 91 with QueueJob

use of com.emc.storageos.volumecontroller.impl.job.QueueJob in project coprhd-controller by CoprHD.

the class CinderStorageDevice method doDeleteSnapshot.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.volumecontroller.BlockStorageDevice#doDeleteSnapshot
     * (com.emc.storageos.db.client.model.StorageSystem,
     * java.net.URI, com.emc.storageos.volumecontroller.TaskCompleter)
     */
@Override
public void doDeleteSnapshot(StorageSystem storageSystem, URI snapshotURI, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Snapshot Start - Array:%s", storageSystem.getSerialNumber()));
        log.info(logMsgBuilder.toString());
        BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotURI);
        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);
        try {
            cinderApi.showSnapshot(snapshot.getId().toString());
        } catch (CinderException ce) {
            // This means, the snapshot is not present on the back-end device
            log.info(String.format("Snapshot %s already deleted: ", snapshot.getNativeId()));
            snapshot.setInactive(true);
            dbClient.updateObject(snapshot);
            taskCompleter.ready(dbClient);
        }
        // Now - trigger the delete
        cinderApi.deleteSnapshot(snapshot.getNativeId().toString());
        ControllerServiceImpl.enqueueJob(new QueueJob(new CinderSnapshotDeleteJob(snapshot.getNativeId(), snapshot.getLabel(), storageSystem.getId(), CinderConstants.ComponentType.snapshot.name(), ep, taskCompleter)));
    } catch (Exception e) {
        log.error("Problem in doDeleteVolume: ", e);
        ServiceError error = DeviceControllerErrors.cinder.operationFailed("doDeleteSnapshot", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
}
Also used : CinderException(com.emc.storageos.cinder.errorhandling.CinderException) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CinderApi(com.emc.storageos.cinder.api.CinderApi) CinderSnapshotDeleteJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderSnapshotDeleteJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) 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 92 with QueueJob

use of com.emc.storageos.volumecontroller.impl.job.QueueJob in project coprhd-controller by CoprHD.

the class CinderStorageDevice method doCreateVolumes.

/*
     * (non-Javadoc)
     * 
     * @see com.emc.storageos.volumecontroller.BlockStorageDevice#doCreateVolumes
     * (com.emc.storageos.db.client.model.StorageSystem,
     * com.emc.storageos.db.client.model.StoragePool,
     * java.lang.String, java.util.List,
     * com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper,
     * com.emc.storageos.volumecontroller.TaskCompleter)
     */
@Override
public void doCreateVolumes(StorageSystem storageSystem, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
    String label = null;
    Long capacity = null;
    boolean opCreationFailed = false;
    StringBuilder logMsgBuilder = new StringBuilder(String.format("Create Volume Start - Array:%s, Pool:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid()));
    for (Volume volume : volumes) {
        logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
        String tenantName = "";
        try {
            TenantOrg tenant = dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
            tenantName = tenant.getLabel();
        } catch (DatabaseException e) {
            log.error("Error lookup TenantOrg object", e);
        }
        label = nameGenerator.generate(tenantName, volume.getLabel(), volume.getId().toString(), CinderConstants.CHAR_HYPHEN, SmisConstants.MAX_VOLUME_NAME_LENGTH);
        if (capacity == null) {
            capacity = volume.getCapacity();
        }
    }
    log.info(logMsgBuilder.toString());
    try {
        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 = null;
        Map<String, URI> volumeIds = new HashMap<String, URI>();
        if (volumes.size() == 1) {
            volumeId = cinderApi.createVolume(label, CinderUtils.convertToGB(capacity), storagePool.getNativeId());
            volumeIds.put(volumeId, volumes.get(0).getId());
            log.debug("Creating volume with the id {} on Openstack cinder node", volumeId);
        } else {
            log.debug("Starting to create {} volumes", volumes.size());
            for (int volumeIndex = 0; volumeIndex < volumes.size(); volumeIndex++) {
                volumeId = cinderApi.createVolume(label + CinderConstants.HYPHEN + (volumeIndex + 1), CinderUtils.convertToGB(capacity), storagePool.getNativeId());
                volumeIds.put(volumeId, volumes.get(volumeIndex).getId());
                log.debug("Creating volume with the id {} on Openstack cinder node", volumeId);
            }
        }
        if (!volumeIds.isEmpty()) {
            CinderJob createVolumeJob = (volumes.size() > 1) ? new CinderMultiVolumeCreateJob(volumeId, label, volumes.get(0).getStorageController(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, storagePool.getId(), volumeIds) : new CinderSingleVolumeCreateJob(volumeId, label, volumes.get(0).getStorageController(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, storagePool.getId(), volumeIds);
            ControllerServiceImpl.enqueueJob(new QueueJob(createVolumeJob));
        }
    } catch (final InternalException e) {
        log.error("Problem in doCreateVolumes: ", e);
        opCreationFailed = true;
        taskCompleter.error(dbClient, e);
    } catch (final Exception e) {
        log.error("Problem in doCreateVolumes: ", e);
        opCreationFailed = true;
        ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("doCreateVolumes", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
    if (opCreationFailed) {
        for (Volume vol : volumes) {
            vol.setInactive(true);
            dbClient.persistObject(vol);
        }
    }
    logMsgBuilder = new StringBuilder(String.format("Create Volumes End - Array:%s, Pool:%s", storageSystem.getSerialNumber(), storagePool.getNativeGuid()));
    for (Volume volume : volumes) {
        logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
    }
    log.info(logMsgBuilder.toString());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) CinderApi(com.emc.storageos.cinder.api.CinderApi) CinderSingleVolumeCreateJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderSingleVolumeCreateJob) URI(java.net.URI) 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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Volume(com.emc.storageos.db.client.model.Volume) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) CinderMultiVolumeCreateJob(com.emc.storageos.volumecontroller.impl.cinder.job.CinderMultiVolumeCreateJob) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 93 with QueueJob

use of com.emc.storageos.volumecontroller.impl.job.QueueJob 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 94 with QueueJob

use of com.emc.storageos.volumecontroller.impl.job.QueueJob 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 95 with QueueJob

use of com.emc.storageos.volumecontroller.impl.job.QueueJob in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doExpandVolume.

@Override
public void doExpandVolume(StorageSystem storageSystem, StoragePool storagePool, Volume volume, Long size, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("Volume expand ..... Started");
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = null;
    try {
        // Prepare driver volume
        StorageVolume driverVolume = new StorageVolume();
        driverVolume.setNativeId(volume.getNativeId());
        driverVolume.setDeviceLabel(volume.getDeviceLabel());
        driverVolume.setStorageSystemId(storageSystem.getNativeId());
        driverVolume.setStoragePoolId(storagePool.getNativeId());
        driverVolume.setRequestedCapacity(volume.getCapacity());
        driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
        driverVolume.setDisplayName(volume.getLabel());
        driverVolume.setAllocatedCapacity(volume.getAllocatedCapacity());
        driverVolume.setProvisionedCapacity(volume.getProvisionedCapacity());
        driverVolume.setWwn(volume.getWWN());
        // call driver
        task = driver.expandVolume(driverVolume, size);
        if (!isTaskInTerminalState(task.getStatus())) {
            // If the task is not in a terminal state and will be completed asynchronously
            // create a job to monitor the progress of the request and update the volume and
            // call the completer as appropriate based on the result of the request.
            ExpandVolumeExternalDeviceJob job = new ExpandVolumeExternalDeviceJob(storageSystem.getId(), volume.getId(), task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            String msg = String.format("doExpandVolume -- Expanded volume: %s .", task.getMessage());
            _log.info(msg);
            ExternalDeviceUtils.updateExpandedVolume(volume, driverVolume, dbClient);
            taskCompleter.ready(dbClient);
        } else {
            // operation failed
            String errorMsg = String.format("doExpandVolume -- Failed to expand volume: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.expandVolumeFailed("doExpandVolume", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        _log.error("doExpandVolume -- Failed to expand volume. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.expandVolumeFailed("doExpandVolume", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        try {
            if (task == null || isTaskInTerminalState(task.getStatus())) {
                updateStoragePoolCapacity(storagePool, storageSystem, URIUtil.toUris(Collections.singletonList(volume)), dbClient);
            }
        } catch (Exception ex) {
            _log.error("Failed to update storage pool {} after expand volume operation completion.", storagePool.getId(), ex);
        }
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) ExpandVolumeExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.ExpandVolumeExternalDeviceJob)

Aggregations

DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)109 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)109 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)104 Volume (com.emc.storageos.db.client.model.Volume)51 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)43 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)41 CIMObjectPath (javax.cim.CIMObjectPath)41 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)40 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)40 VNXeException (com.emc.storageos.vnxe.VNXeException)36 WBEMException (javax.wbem.WBEMException)33 ControllerException (com.emc.storageos.volumecontroller.ControllerException)32 CIMArgument (javax.cim.CIMArgument)32 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)25 URI (java.net.URI)23 ArrayList (java.util.ArrayList)23 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)20 Snapshot (com.emc.storageos.db.client.model.Snapshot)18 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)18 FileShare (com.emc.storageos.db.client.model.FileShare)16