Search in sources :

Example 6 with StorageVolume

use of com.emc.storageos.storagedriver.model.StorageVolume in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doRemoveFromConsistencyGroup.

@Override
public void doRemoveFromConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockConsistencyGroup consistencyGroup = null;
    try {
        _log.info("{} doRemoveVolumesFromConsistencyGroup START ...", storageSystem.getSerialNumber());
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        List<Volume> volumes = dbClient.queryObject(Volume.class, blockObjects);
        List<StorageVolume> driverVolumes = new ArrayList<>();
        consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
        for (Volume volume : volumes) {
            StorageVolume driverVolume = new StorageVolume();
            driverVolume.setStorageSystemId(storageSystem.getNativeId());
            driverVolume.setNativeId(volume.getNativeId());
            driverVolume.setRequestedCapacity(volume.getCapacity());
            driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
            driverVolume.setConsistencyGroup(consistencyGroup.getNativeId());
            driverVolume.setDisplayName(volume.getLabel());
            // add them to StorageVolumes list
            driverVolumes.add(driverVolume);
        }
        DriverTask task = driver.removeVolumesFromConsistencyGroup(driverVolumes, null);
        _log.info("doRemoveVolumesFromConsistencyGroup -- removing volumes {} from consistency Group: {}", volumes.toString(), consistencyGroupId);
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Volume volume : volumes) {
                volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
            }
            dbClient.updateObject(volumes);
            taskCompleter.ready(dbClient);
        } else {
            _log.error(String.format("Remove volumes from Consistency Group operation failed %s", task.getMessage()));
            taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), task.getMessage()));
        }
        _log.info("{} doRemoveVolumesFromConsistencyGroup END ...", storageSystem.getSerialNumber());
    } catch (Exception e) {
        _log.error(String.format("Remove volumes from Consistency Group operation failed %s", e.getMessage()));
        taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToRemoveMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), e.getMessage()));
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 7 with StorageVolume

use of com.emc.storageos.storagedriver.model.StorageVolume in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doCreateVolumes.

@Override
public void doCreateVolumes(StorageSystem storageSystem, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
    List<StorageVolume> driverVolumes = new ArrayList<>();
    Map<StorageVolume, Volume> driverVolumeToVolumeMap = new HashMap<>();
    Set<URI> consistencyGroups = new HashSet<>();
    StorageCapabilities storageCapabilities = null;
    DriverTask task = null;
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    try {
        for (Volume volume : volumes) {
            if (storageCapabilities == null) {
                // All volumes created in a request will have the same capabilities.
                storageCapabilities = new StorageCapabilities();
                addAutoTieringPolicyCapability(storageCapabilities, volume.getAutoTieringPolicyUri());
                addDeduplicationCapability(storageCapabilities, volume.getIsDeduplicated());
            }
            StorageVolume driverVolume = new StorageVolume();
            driverVolume.setStorageSystemId(storageSystem.getNativeId());
            driverVolume.setStoragePoolId(storagePool.getNativeId());
            driverVolume.setRequestedCapacity(volume.getCapacity());
            driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
            driverVolume.setDisplayName(volume.getLabel());
            if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
                BlockConsistencyGroup cg = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
                driverVolume.setConsistencyGroup(cg.getNativeId());
            }
            driverVolumes.add(driverVolume);
            driverVolumeToVolumeMap.put(driverVolume, volume);
        }
        // Call driver
        task = driver.createVolumes(Collections.unmodifiableList(driverVolumes), storageCapabilities);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY || task.getStatus() == DriverTask.TaskStatus.PARTIALLY_FAILED) {
            updateVolumesWithDriverVolumeInfo(dbClient, driverVolumeToVolumeMap, consistencyGroups);
            dbClient.updateObject(driverVolumeToVolumeMap.values());
            updateConsistencyGroupsWithStorageSystem(consistencyGroups, storageSystem);
            String msg = String.format("doCreateVolumes -- Created volumes: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            // Set volumes to inactive state
            for (Volume volume : volumes) {
                volume.setInactive(true);
            }
            dbClient.updateObject(volumes);
            String errorMsg = String.format("doCreateVolumes -- Failed to create volumes: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createVolumesFailed("doCreateVolumes", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        _log.error("doCreateVolumes -- Failed to create volumes. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.createVolumesFailed("doCreateVolumes", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        try {
            if (task == null || isTaskInTerminalState(task.getStatus())) {
                updateStoragePoolCapacity(storagePool, storageSystem, URIUtil.toUris(volumes), dbClient);
            }
        } catch (Exception ex) {
            _log.error("Failed to update storage pool {} after create volumes operation completion.", storagePool.getId(), ex);
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.StorageCapabilities) CommonStorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) HashSet(java.util.HashSet)

Example 8 with StorageVolume

use of com.emc.storageos.storagedriver.model.StorageVolume in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method doAddToConsistencyGroup.

@Override
public void doAddToConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, String replicationGroupName, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
    BlockConsistencyGroup consistencyGroup = null;
    try {
        _log.info("{} doAddToConsistencyGroup START ...", storageSystem.getSerialNumber());
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        List<Volume> volumes = dbClient.queryObject(Volume.class, blockObjects);
        List<StorageVolume> driverVolumes = new ArrayList<>();
        consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
        for (Volume volume : volumes) {
            StorageVolume driverVolume = new StorageVolume();
            driverVolume.setStorageSystemId(storageSystem.getNativeId());
            driverVolume.setNativeId(volume.getNativeId());
            driverVolume.setRequestedCapacity(volume.getCapacity());
            driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
            driverVolume.setConsistencyGroup(consistencyGroup.getNativeId());
            driverVolume.setDisplayName(volume.getLabel());
            // add them to StorageVolumes list
            driverVolumes.add(driverVolume);
        }
        DriverTask task = driver.addVolumesToConsistencyGroup(driverVolumes, null);
        _log.info("doAddToConsistencyGroup -- added volumes {} to consistency Group: {}", volumes.toString(), consistencyGroupId);
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            for (Volume volume : volumes) {
                volume.setConsistencyGroup(consistencyGroupId);
            }
            dbClient.updateObject(volumes);
            taskCompleter.ready(dbClient);
        } else {
            _log.error(String.format("Add volumes to Consistency Group operation failed %s", task.getMessage()));
            taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), task.getMessage()));
        }
        _log.info("{} doAddVolumesToConsistencyGroup END ...", storageSystem.getSerialNumber());
    } catch (Exception e) {
        _log.error(String.format("Add volumes from Consistency Group operation failed %s", e.getMessage()));
        taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), e.getMessage()));
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 9 with StorageVolume

use of com.emc.storageos.storagedriver.model.StorageVolume in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method updateVolumesWithDriverVolumeInfo.

private void updateVolumesWithDriverVolumeInfo(DbClient dbClient, Map<StorageVolume, Volume> driverVolumesMap, Set<URI> consistencyGroups) throws IOException {
    for (Map.Entry driverVolumeToVolume : driverVolumesMap.entrySet()) {
        StorageVolume driverVolume = (StorageVolume) driverVolumeToVolume.getKey();
        Volume volume = (Volume) driverVolumeToVolume.getValue();
        if (driverVolume.getNativeId() != null && driverVolume.getNativeId().length() > 0) {
            volume.setNativeId(driverVolume.getNativeId());
            volume.setDeviceLabel(driverVolume.getDeviceLabel());
            volume.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(dbClient, volume));
            if (driverVolume.getWwn() == null) {
                volume.setWWN(String.format("%s%s", driverVolume.getStorageSystemId(), driverVolume.getNativeId()));
            } else {
                volume.setWWN(driverVolume.getWwn());
            }
            volume.setProvisionedCapacity(driverVolume.getProvisionedCapacity());
            volume.setAllocatedCapacity(driverVolume.getAllocatedCapacity());
            if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
                consistencyGroups.add(volume.getConsistencyGroup());
            }
        } else {
            volume.setInactive(true);
        }
    }
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with StorageVolume

use of com.emc.storageos.storagedriver.model.StorageVolume in project coprhd-controller by CoprHD.

the class HP3PARExpUnexpHelper method unexportVolumesFromInitiators.

public DriverTask unexportVolumesFromInitiators(List<Initiator> initiators, List<StorageVolume> volumes, DriverTask task, Registry driverRegistry, LockManager driverLockManager) {
    _log.info("3PARDriver:unexportVolumesFromInitiators enter");
    String host = null;
    Boolean fullSuccess = true;
    boolean gotLock = false;
    String exportPath = null;
    if (initiators.isEmpty() || volumes.isEmpty()) {
        String msg = "3PARDriver:unexportVolumesFromInitiators error blank initiator and/or volumes";
        _log.error(msg);
        task.setMessage(msg);
        task.setStatus(DriverTask.TaskStatus.FAILED);
        return task;
    }
    HashMap<String, String> initiatorToHostMap = new HashMap<String, String>();
    // unexport each volume
    for (StorageVolume volume : volumes) {
        try {
            // get Api client for volume specific array
            HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volume.getStorageSystemId(), driverRegistry);
            VirtualLunsList vlunRes = hp3parApi.getVLunsByVolumeName(volume.getNativeId());
            for (Initiator init : initiators) {
                if (initiatorToHostMap.containsKey(init.getPort())) {
                    host = initiatorToHostMap.get(init.getPort());
                } else {
                    ArrayList<Initiator> initList = new ArrayList<>();
                    initList.add(init);
                    HP3PARHostNameResult hostNameResult = get3parHostname(initList, volume.getStorageSystemId(), driverRegistry);
                    if (hostNameResult == null) {
                        fullSuccess = false;
                        String message = String.format("3PARDriver:unexportVolumesFromInitiators host not fond for " + "storage system %s, volume %s initiator %s", volume.getStorageSystemId(), volume.getNativeId(), init.getPort());
                        _log.warn(message);
                        task.setMessage(message);
                        task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
                        continue;
                    } else {
                        host = hostNameResult.getHostName();
                        initiatorToHostMap.put(init.getPort(), host);
                    }
                }
                if (init.getInitiatorType().equals(Type.Host)) {
                    // get vlun and port details on this export
                    Integer lun = -1;
                    Position pos = null;
                    String portId = init.getPort();
                    portId = portId.replace(":", "");
                    Boolean found = false;
                    Integer vlunType = 0;
                    for (VirtualLun vLun : vlunRes.getMembers()) {
                        if (volume.getNativeId().compareTo(vLun.getVolumeName()) != 0 || (!vLun.isActive()) || vLun.getRemoteName() == null || portId.compareToIgnoreCase(vLun.getRemoteName()) != 0 || (vLun.getType() != HP3PARConstants.vLunType.MATCHED_SET.getValue() && vLun.getType() != HP3PARConstants.vLunType.HOST.getValue())) {
                            continue;
                        }
                        lun = vLun.getLun();
                        pos = vLun.getPortPos();
                        vlunType = vLun.getType();
                        found = true;
                        break;
                    }
                    if (found) {
                        String posStr = null;
                        if (vlunType == HP3PARConstants.vLunType.MATCHED_SET.getValue()) {
                            // port details for matched set; null for host-sees
                            posStr = String.format("%s:%s:%s", pos.getNode(), pos.getSlot(), pos.getCardPort());
                        }
                        try {
                            hp3parApi.deleteVlun(volume.getNativeId(), lun.toString(), host, posStr);
                        } catch (Exception e) {
                            if (e.getMessage().contains(HP3PARConstants.VLUN_DOES_NOT_EXIST)) {
                                _log.info("The VLUN(export info) does not exist on the 3PAR " + "array and hence this unexport will be treated as success");
                            } else {
                                throw e;
                            }
                        }
                    }
                    if (!found) {
                        // port could be inactive, remove vlun template
                        for (VirtualLun vLun : vlunRes.getMembers()) {
                            if (volume.getNativeId().compareTo(vLun.getVolumeName()) != 0 || vLun.getHostname() == null || host.compareToIgnoreCase(vLun.getHostname()) != 0 || (vLun.getType() != HP3PARConstants.vLunType.MATCHED_SET.getValue() && vLun.getType() != HP3PARConstants.vLunType.HOST.getValue())) {
                                continue;
                            }
                            lun = vLun.getLun();
                            pos = vLun.getPortPos();
                            vlunType = vLun.getType();
                            found = true;
                            if (found) {
                                String posStr = null;
                                if (vlunType == HP3PARConstants.vLunType.MATCHED_SET.getValue()) {
                                    // port details for matched set; null for host-sees
                                    posStr = String.format("%s:%s:%s", pos.getNode(), pos.getSlot(), pos.getCardPort());
                                }
                                _log.info("3PARDriver:unexportVolumesFromInitiators removing vlun template");
                                posStr = String.format("%s:%s:%s", pos.getNode(), pos.getSlot(), pos.getCardPort());
                                try {
                                    hp3parApi.deleteVlun(volume.getNativeId(), lun.toString(), host, posStr);
                                } catch (Exception e) {
                                    if (e.getMessage().contains(HP3PARConstants.VLUN_DOES_NOT_EXIST)) {
                                        _log.info("The VLUN(export info) does not exist on the 3PAR " + "array and hence this unexport will be treated as success");
                                    } else {
                                        throw e;
                                    }
                                }
                            }
                        // found
                        }
                    // end for all vlun templates
                    }
                } else if (init.getInitiatorType().equals(Type.Cluster)) {
                    // cluster unexport
                    String clusterName = "set:" + initiators.get(0).getClusterName();
                    exportPath = volume.getStorageSystemId() + volume.getNativeId() + clusterName;
                    gotLock = false;
                    if (driverLockManager.acquireLock(exportPath, 10, TimeUnit.MINUTES)) {
                        gotLock = true;
                        Map<String, List<String>> attributes = new HashMap<>();
                        List<String> expValue = new ArrayList<>();
                        List<String> lunValue = new ArrayList<>();
                        boolean regPresent = false;
                        String message = String.format("3PARDriver:unexportVolumesFromInitiators for " + "storage system %s, volume %s Cluster %s", volume.getStorageSystemId(), volume.getNativeId(), clusterName);
                        attributes = driverRegistry.getDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath);
                        if (attributes != null) {
                            expValue = attributes.get("EXPORT_PATH");
                            if (expValue != null && expValue.get(0).compareTo(exportPath) == 0) {
                                lunValue = attributes.get(volume.getNativeId());
                                regPresent = true;
                                _log.info(message);
                                /*
                        			 * below operations are assumed to autonomic
                        			 */
                                hp3parApi.deleteVlun(volume.getNativeId(), lunValue.get(0), clusterName, null);
                                driverRegistry.clearDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, exportPath);
                            }
                        }
                        if (!regPresent) {
                            // gracefully exit, nothing to be done
                            _log.info("3PARDriver: Already unexported, exiting gracefully" + message);
                        }
                        driverLockManager.releaseLock(exportPath);
                        gotLock = false;
                    } else {
                        // lock
                        _log.error("3PARDriver:unexportVolumesFromInitiators error: could not acquire thread lock");
                        throw new HP3PARException("3PARDriver:unexportVolumesFromInitiators error: could not acquire thread lock");
                    }
                }
            // if cluster
            }
        // for each initiator
        } catch (Exception e) {
            String msg = String.format("3PARDriver: Unable to unexport few volumes, error: %s", e);
            _log.error(msg);
            _log.error(CompleteError.getStackTrace(e));
            task.setMessage(msg);
            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
            e.printStackTrace();
            fullSuccess = false;
            if (gotLock && (exportPath != null)) {
                driverLockManager.releaseLock(exportPath);
            }
        }
    }
    if (fullSuccess) {
        task.setStatus(DriverTask.TaskStatus.READY);
    }
    _log.info("3PARDriver:unexportVolumesFromInitiatorss leave");
    return task;
}
Also used : HashMap(java.util.HashMap) Position(com.emc.storageos.hp3par.command.Position) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) List(java.util.List) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) VirtualLun(com.emc.storageos.hp3par.command.VirtualLun) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)38 ArrayList (java.util.ArrayList)17 DriverTask (com.emc.storageos.storagedriver.DriverTask)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)12 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)11 URI (java.net.URI)11 HashMap (java.util.HashMap)11 Volume (com.emc.storageos.db.client.model.Volume)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 Initiator (com.emc.storageos.storagedriver.model.Initiator)7 HashSet (java.util.HashSet)7 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)6 DellSCDriverException (com.emc.storageos.driver.dellsc.DellSCDriverException)6 DellSCDriverTask (com.emc.storageos.driver.dellsc.DellSCDriverTask)6 StorageCenterAPI (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI)6 StorageCenterAPIException (com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException)6 StoragePort (com.emc.storageos.storagedriver.model.StoragePort)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 CommonStorageCapabilities (com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities)5