Search in sources :

Example 1 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method doDeleteConsistencyGroup.

@Override
public void doDeleteConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, String replicationGroupName, Boolean keepRGName, Boolean markInactive, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("Delete consistency group: STARTED...");
    BlockConsistencyGroup consistencyGroup = null;
    String groupNativeId = null;
    String groupDisplayName = null;
    boolean isDeleteForBlockCG = true;
    try {
        if (!NullColumnValueGetter.isNullURI(consistencyGroupId)) {
            consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
            groupDisplayName = consistencyGroup != null ? consistencyGroup.getLabel() : replicationGroupName;
            groupNativeId = consistencyGroup != null ? consistencyGroup.getNativeId() : replicationGroupName;
            if (consistencyGroup == null) {
                isDeleteForBlockCG = false;
            }
        } else {
            groupDisplayName = replicationGroupName;
            groupNativeId = replicationGroupName;
            isDeleteForBlockCG = false;
        }
        if (groupNativeId == null || groupNativeId.isEmpty()) {
            String msg = String.format("doDeleteConsistencyGroup -- There is no consistency group or replication group to delete.");
            _log.info(msg);
            taskCompleter.ready(dbClient);
            return;
        }
        if (isDeleteForBlockCG) {
            _log.info("Deleting consistency group: storage system {}, group {}", storageSystem.getNativeId(), groupDisplayName);
        } else {
            _log.info("Deleting system replication group: storage system {}, group {}", storageSystem.getNativeId(), groupDisplayName);
            _log.info("Replication groups are not supported for external devices. Do not call driver.");
            taskCompleter.ready(dbClient);
            return;
        }
        // prepare driver consistency group
        VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
        driverCG.setDisplayName(groupDisplayName);
        driverCG.setNativeId(groupNativeId);
        driverCG.setStorageSystemId(storageSystem.getNativeId());
        // call driver
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.deleteConsistencyGroup(driverCG);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            if (consistencyGroup != null) {
                // I followed xtremio pattern to implement this logic.
                consistencyGroup.removeSystemConsistencyGroup(URIUtil.asString(storageSystem.getId()), groupDisplayName);
                dbClient.updateObject(consistencyGroup);
                // have to read again to get updated systemConsistencyGroup map
                consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
                /*
                     * Verify if the BlockConsistencyGroup references any LOCAL arrays.
                     * If we no longer have any references we can remove the 'LOCAL' type from the BlockConsistencyGroup.
                     */
                List<URI> referencedArrays = BlockConsistencyGroupUtils.getLocalSystems(consistencyGroup, dbClient);
                boolean cgReferenced = referencedArrays != null && !referencedArrays.isEmpty();
                if (!cgReferenced) {
                    // Remove the LOCAL type
                    StringSet cgTypes = consistencyGroup.getTypes();
                    cgTypes.remove(BlockConsistencyGroup.Types.LOCAL.name());
                    consistencyGroup.setTypes(cgTypes);
                    // of storage systems associated with the CG.
                    if (!BlockConsistencyGroupUtils.referencesNonLocalCgs(consistencyGroup, dbClient)) {
                        consistencyGroup.setStorageController(NullColumnValueGetter.getNullURI());
                        // Update the consistency group model
                        consistencyGroup.setInactive(markInactive);
                    }
                } else {
                    _log.info("*** Referenced arrays {}", referencedArrays.toString());
                }
                dbClient.updateObject(consistencyGroup);
            }
            String msg = String.format("doDeleteConsistencyGroup -- Delete consistency group: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("doDeleteConsistencyGroup -- Failed to delete Consistency Group: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.deleteConsistencyGroupFailed("doDeleteConsistencyGroup", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        String errorMsg = String.format("doDeleteConsistencyGroup -- Failed to delete Consistency Group: %s .", e.getMessage());
        _log.error(errorMsg, e);
        ServiceError serviceError = ExternalDeviceException.errors.deleteConsistencyGroupFailed("doDeleteConsistencyGroup", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    } finally {
        _log.info("Delete consistency group: END...");
    }
}
Also used : VolumeConsistencyGroup(com.emc.storageos.storagedriver.model.VolumeConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) 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 2 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method doConnect.

@Override
public void doConnect(StorageSystem storageSystem) {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    if (driver == null) {
        throw DeviceControllerException.exceptions.connectStorageFailedNoDevice(storageSystem.getSystemType());
    }
    _log.info("doConnect to external device {} - start", storageSystem.getId());
    _log.info("doConnect to external device {} - end", storageSystem.getId());
}
Also used : BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 3 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method validateStorageProviderConnection.

public boolean validateStorageProviderConnection(StorageProvider storageProvider) {
    boolean isConnectionValid = false;
    try {
        // call driver to validate provider connection
        // get driver for the provider
        BlockStorageDriver driver = getDriver(storageProvider.getInterfaceType());
        String username = storageProvider.getUserName();
        String password = storageProvider.getPassword();
        String hostName = storageProvider.getIPAddress();
        Integer providerPortNumber = storageProvider.getPortNumber();
        String providerType = storageProvider.getInterfaceType();
        Boolean useSsl = storageProvider.getUseSSL();
        String msg = String.format("Storage provider info: type: %s, host: %s, port: %s, user: %s, useSsl: %s", providerType, hostName, providerPortNumber, username, useSsl);
        _log.info(msg);
        com.emc.storageos.storagedriver.model.StorageProvider driverProvider = new com.emc.storageos.storagedriver.model.StorageProvider();
        // initialize driver provider
        driverProvider.setProviderHost(hostName);
        driverProvider.setPortNumber(providerPortNumber);
        driverProvider.setUsername(username);
        driverProvider.setPassword(password);
        driverProvider.setUseSSL(useSsl);
        driverProvider.setProviderType(providerType);
        isConnectionValid = driver.validateStorageProviderConnection(driverProvider);
    } catch (Exception ex) {
        _log.error("Problem in checking connection of provider {} due to: ", storageProvider.getLabel(), ex);
    }
    return isConnectionValid;
}
Also used : StorageProvider(com.emc.storageos.db.client.model.StorageProvider) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) IOException(java.io.IOException) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 4 with BlockStorageDriver

use of com.emc.storageos.storagedriver.BlockStorageDriver 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 5 with BlockStorageDriver

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

the class ExternalBlockStorageDevice method deleteVolumeSnapshot.

private void deleteVolumeSnapshot(StorageSystem storageSystem, URI snapshot, TaskCompleter taskCompleter) {
    BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
    if (blockSnapshot != null && !blockSnapshot.getInactive() && // state against the BlockSnapshot object can be set.
    !Strings.isNullOrEmpty(blockSnapshot.getNativeId())) {
        _log.info("Deleting snapshot of a volume. Snapshot: {}", snapshot);
        Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
        VolumeSnapshot driverSnapshot = new VolumeSnapshot();
        driverSnapshot.setStorageSystemId(storageSystem.getNativeId());
        driverSnapshot.setNativeId(blockSnapshot.getNativeId());
        driverSnapshot.setParentId(parent.getNativeId());
        driverSnapshot.setConsistencyGroup(blockSnapshot.getReplicationGroupInstance());
        // call driver
        BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
        DriverTask task = driver.deleteVolumeSnapshot(driverSnapshot);
        // todo: need to implement support for async case.
        if (task.getStatus() == DriverTask.TaskStatus.READY) {
            // update snapshots
            blockSnapshot.setInactive(true);
            dbClient.updateObject(blockSnapshot);
            String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", task.getMessage());
            _log.info(msg);
            taskCompleter.ready(dbClient);
        } else {
            String errorMsg = String.format("doDeleteSnapshot -- Failed to delete snapshot: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.deleteSnapshotFailed("doDeleteSnapshot", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } else if (blockSnapshot != null) {
        blockSnapshot.setInactive(true);
        dbClient.updateObject(blockSnapshot);
        String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", blockSnapshot.getId());
        _log.info(msg);
        taskCompleter.ready(dbClient);
    }
}
Also used : DriverTask(com.emc.storageos.storagedriver.DriverTask) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Aggregations

BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)30 DriverTask (com.emc.storageos.storagedriver.DriverTask)26 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)22 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)22 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)22 ArrayList (java.util.ArrayList)18 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 IOException (java.io.IOException)16 Volume (com.emc.storageos.db.client.model.Volume)15 URI (java.net.URI)12 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)9 HashMap (java.util.HashMap)9 VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)7 BlockObject (com.emc.storageos.db.client.model.BlockObject)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 ExportMask (com.emc.storageos.db.client.model.ExportMask)6 Initiator (com.emc.storageos.storagedriver.model.Initiator)6 StorageBlockObject (com.emc.storageos.storagedriver.model.StorageBlockObject)6 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)6