Search in sources :

Example 56 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockDeviceController method rollBackCreateVolumes.

/**
 * {@inheritDoc} NOTE: The signature here MUST match the Workflow.Method rollbackCreateVolumesMethod just above
 * (except opId).
 */
@Override
public void rollBackCreateVolumes(URI systemURI, List<URI> volumeURIs, String opId) throws ControllerException {
    MultiVolumeTaskCompleter completer = new MultiVolumeTaskCompleter(volumeURIs, opId);
    List<Volume> volumes = new ArrayList<>(volumeURIs.size());
    completer.setRollingBack(true);
    try {
        String logMsg = String.format("rollbackCreateVolume start - Array:%s, Volume:%s", systemURI.toString(), Joiner.on(',').join(volumeURIs));
        _log.info(logMsg.toString());
        WorkflowStepCompleter.stepExecuting(opId);
        volumes.addAll(_dbClient.queryObject(Volume.class, volumeURIs));
        for (Volume volume : volumes) {
            // CTRL-5597 clean volumes which have failed only in a multi-volume request
            if (null != volume.getNativeGuid()) {
                StorageSystem system = _dbClient.queryObject(StorageSystem.class, volume.getStorageController());
                if (Type.xtremio.toString().equalsIgnoreCase(system.getSystemType())) {
                    continue;
                }
            }
            // then we need to clear srdfTargets and personality fields for source
            if (null != volume.getSrdfTargets()) {
                _log.info("Clearing targets for existing source");
                volume.getSrdfTargets().clear();
                _dbClient.updateObject(volume);
                // Clearing Source CG
                URI sourceCgUri = volume.getConsistencyGroup();
                if (null != sourceCgUri) {
                    BlockConsistencyGroup sourceCG = _dbClient.queryObject(BlockConsistencyGroup.class, sourceCgUri);
                    if (null != sourceCG && (null == sourceCG.getTypes() || NullColumnValueGetter.isNullURI(sourceCG.getStorageController()))) {
                        sourceCG.getRequestedTypes().remove(Types.SRDF.name());
                        _dbClient.updateObject(sourceCG);
                    }
                }
            }
            // for change Virtual Pool, if failed, clear targets and personality field for source and also
            if (!NullColumnValueGetter.isNullNamedURI(volume.getSrdfParent())) {
                URI sourceUri = volume.getSrdfParent().getURI();
                Volume sourceVolume = _dbClient.queryObject(Volume.class, sourceUri);
                sourceVolume.setPersonality(NullColumnValueGetter.getNullStr());
                if (null != sourceVolume.getSrdfTargets()) {
                    sourceVolume.getSrdfTargets().clear();
                    _dbClient.updateObject(sourceVolume);
                }
                // Clearing target CG
                URI cgUri = volume.getConsistencyGroup();
                if (null != cgUri) {
                    BlockConsistencyGroup targetCG = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
                    if (null != targetCG && (null == targetCG.getTypes() || NullColumnValueGetter.isNullURI(targetCG.getStorageController()))) {
                        _log.info("Set target CG {} inactive", targetCG.getLabel());
                        targetCG.setInactive(true);
                        _dbClient.updateObject(targetCG);
                    }
                    // clear association between target volume and target cg
                    volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
                    _dbClient.updateAndReindexObject(volume);
                }
            }
            // Check for loose export groups associated with this rolled-back volume
            URIQueryResultList exportGroupURIs = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeExportGroupConstraint(volume.getId()), exportGroupURIs);
            while (exportGroupURIs.iterator().hasNext()) {
                URI exportGroupURI = exportGroupURIs.iterator().next();
                ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
                if (!exportGroup.getInactive()) {
                    exportGroup.removeVolume(volume.getId());
                    boolean canRemoveGroup = false;
                    List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup);
                    // Make sure the volume is not in an export mask
                    for (ExportMask exportMask : exportMasks) {
                        exportMask.removeVolume(volume.getId());
                        exportMask.removeFromUserCreatedVolumes(volume);
                        exportMask.removeFromExistingVolumes(volume);
                        if (!exportMask.getCreatedBySystem() && !exportMask.hasAnyVolumes() && exportMask.emptyVolumes()) {
                            canRemoveGroup = true;
                            _dbClient.removeObject(exportMask);
                        } else {
                            _dbClient.updateObject(exportMask);
                        }
                    }
                    // If we didn't find that volume in a mask, it's OK to remove it.
                    if (canRemoveGroup && exportMasks.size() == 1 && exportGroup.getVolumes().isEmpty()) {
                        _dbClient.removeObject(exportGroup);
                    } else {
                        _dbClient.updateObject(exportGroup);
                    }
                }
            }
        }
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_013);
        deleteVolumesWithCompleter(systemURI, volumeURIs, completer);
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_014);
        logMsg = String.format("rollbackCreateVolume end - Array:%s, Volume:%s", systemURI.toString(), Joiner.on(',').join(volumeURIs));
        _log.info(logMsg.toString());
    } catch (Exception e) {
        _log.error(String.format("rollbackCreateVolume Failed - Array:%s, Volume:%s", systemURI.toString(), Joiner.on(',').join(volumeURIs)));
        handleException(e, completer);
    }
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) NamedURI(com.emc.storageos.db.client.model.NamedURI) FCTN_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 57 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockDeviceController method createConsistencyGroup.

@Override
public void createConsistencyGroup(URI storage, URI consistencyGroup, String opId) throws ControllerException {
    TaskCompleter completer = new BlockConsistencyGroupCreateCompleter(consistencyGroup, opId);
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        // Lock the CG for the step duration.
        List<String> lockKeys = new ArrayList<String>();
        lockKeys.add(ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, consistencyGroup, storage));
        _workflowService.acquireWorkflowStepLocks(opId, lockKeys, LockTimeoutValue.get(LockType.ARRAY_CG));
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        // Check if already created, if not create, if so just complete.
        BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroup);
        String groupName = ControllerUtils.generateReplicationGroupName(storageObj, cg, null, _dbClient);
        if (!cg.created(storage, groupName)) {
            getDevice(storageObj.getSystemType()).doCreateConsistencyGroup(storageObj, consistencyGroup, groupName, completer);
        } else {
            _log.info(String.format("Consistency group %s (%s) already created", cg.getLabel(), cg.getId()));
            completer.ready(_dbClient);
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(_dbClient, serviceError);
        throw DeviceControllerException.exceptions.createConsistencyGroupFailed(e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockConsistencyGroupCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockConsistencyGroupCreateCompleter) ArrayList(java.util.ArrayList) ScanTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.ScanTaskCompleter) BlockSnapshotEstablishGroupTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter) BlockMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) ApplicationTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 58 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class BlockDeviceController method deleteConsistencyGroup.

@Override
public void deleteConsistencyGroup(URI storage, URI consistencyGroup, Boolean markInactive, String opId) throws ControllerException {
    _log.info("START delete consistency group");
    TaskCompleter wfCompleter = null;
    try {
        Workflow workflow = _workflowService.getNewWorkflow(this, "deleteReplicationGroupInConsistencyGroup", true, opId);
        wfCompleter = new SimpleTaskCompleter(BlockConsistencyGroup.class, consistencyGroup, opId);
        StorageSystem system = _dbClient.queryObject(StorageSystem.class, storage);
        BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroup);
        Set<String> groupNames = BlockConsistencyGroupUtils.getGroupNamesForSystemCG(cg, system);
        String stepId = null;
        for (String groupName : groupNames) {
            Workflow.Method deleteStep = new Workflow.Method("deleteReplicationGroupInConsistencyGroup", storage, consistencyGroup, groupName, false, markInactive, true);
            stepId = workflow.createStep("DeleteReplicationGroup", "Deleting replication group", stepId, storage, system.getSystemType(), this.getClass(), deleteStep, rollbackMethodNullMethod(), null);
        }
        String successMsg = String.format("Successfully deleted replication groups %s", Joiner.on(',').join(groupNames));
        workflow.executePlan(wfCompleter, successMsg);
    } catch (Exception e) {
        if (wfCompleter != null) {
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
            wfCompleter.error(_dbClient, serviceError);
        }
        throw DeviceControllerException.exceptions.deleteConsistencyGroupFailed(e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Workflow(com.emc.storageos.workflow.Workflow) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) ScanTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.ScanTaskCompleter) BlockSnapshotEstablishGroupTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotEstablishGroupTaskCompleter) BlockMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockMirrorTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) ApplicationTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ApplicationTaskCompleter) SimpleTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.SimpleTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) MultiVolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.MultiVolumeTaskCompleter) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 59 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class ExternalBlockStorageDevice method createGroupSnapshots.

private void createGroupSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
    _log.info("Creating snapshot of consistency group .....");
    List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
    Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
    URI cgUri = snapshots.get(0).getConsistencyGroup();
    BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
    // Prepare driver snapshots
    String storageSystemNativeId = storageSystem.getNativeId();
    for (BlockSnapshot snapshot : snapshots) {
        Volume parent = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
        VolumeSnapshot driverSnapshot = new VolumeSnapshot();
        driverSnapshot.setParentId(parent.getNativeId());
        driverSnapshot.setStorageSystemId(storageSystemNativeId);
        driverSnapshot.setDisplayName(snapshot.getLabel());
        if (readOnly) {
            driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
        } else {
            driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_WRITE);
        }
        driverSnapshotToSnapshotMap.put(driverSnapshot, snapshot);
        driverSnapshots.add(driverSnapshot);
    }
    // Prepare driver consistency group of the parent volume
    VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
    driverCG.setNativeId(consistencyGroup.getNativeId());
    driverCG.setDisplayName(consistencyGroup.getLabel());
    driverCG.setStorageSystemId(storageSystem.getNativeId());
    // call driver
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    DriverTask task = driver.createConsistencyGroupSnapshot(driverCG, Collections.unmodifiableList(driverSnapshots), null);
    // todo: need to implement support for async case.
    if (task.getStatus() == DriverTask.TaskStatus.READY) {
        // update snapshots
        for (VolumeSnapshot driverSnapshot : driverSnapshotToSnapshotMap.keySet()) {
            BlockSnapshot snapshot = driverSnapshotToSnapshotMap.get(driverSnapshot);
            snapshot.setNativeId(driverSnapshot.getNativeId());
            snapshot.setDeviceLabel(driverSnapshot.getDeviceLabel());
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
            snapshot.setIsSyncActive(true);
            // we use driver snapshot consistency group id as replication group label for group snapshots
            snapshot.setReplicationGroupInstance(driverSnapshot.getConsistencyGroup());
            if (driverSnapshot.getProvisionedCapacity() > 0) {
                snapshot.setProvisionedCapacity(driverSnapshot.getProvisionedCapacity());
            }
            if (driverSnapshot.getAllocatedCapacity() > 0) {
                snapshot.setAllocatedCapacity(driverSnapshot.getAllocatedCapacity());
            }
        }
        dbClient.updateObject(driverSnapshotToSnapshotMap.values());
        String msg = String.format("createGroupSnapshots -- Created snapshots: %s .", task.getMessage());
        _log.info(msg);
        taskCompleter.ready(dbClient);
    } else {
        for (BlockSnapshot snapshot : snapshots) {
            snapshot.setInactive(true);
        }
        dbClient.updateObject(snapshots);
        String errorMsg = String.format("doCreateSnapshot -- Failed to create snapshots: %s .", task.getMessage());
        _log.error(errorMsg);
        ServiceError serviceError = ExternalDeviceException.errors.createSnapshotsFailed("doCreateSnapshot", errorMsg);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : VolumeConsistencyGroup(com.emc.storageos.storagedriver.model.VolumeConsistencyGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) DriverTask(com.emc.storageos.storagedriver.DriverTask) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) VolumeSnapshot(com.emc.storageos.storagedriver.model.VolumeSnapshot) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver)

Example 60 with BlockConsistencyGroup

use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.

the class ExternalDeviceExportOperations method createDriverVolume.

/**
 * Create driver block object
 *
 * @param storage
 * @param volume
 * @return
 */
private StorageVolume createDriverVolume(StorageSystem storage, BlockObject volume) {
    StorageVolume driverVolume = new StorageVolume();
    driverVolume.setStorageSystemId(storage.getNativeId());
    driverVolume.setNativeId(volume.getNativeId());
    driverVolume.setDeviceLabel(volume.getDeviceLabel());
    if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
        BlockConsistencyGroup cg = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
        driverVolume.setConsistencyGroup(cg.getLabel());
    }
    return driverVolume;
}
Also used : StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Aggregations

BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)253 Volume (com.emc.storageos.db.client.model.Volume)134 URI (java.net.URI)134 ArrayList (java.util.ArrayList)102 NamedURI (com.emc.storageos.db.client.model.NamedURI)88 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)71 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)71 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)49 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)46 StringSet (com.emc.storageos.db.client.model.StringSet)45 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 ControllerException (com.emc.storageos.volumecontroller.ControllerException)43 BlockObject (com.emc.storageos.db.client.model.BlockObject)37 Project (com.emc.storageos.db.client.model.Project)33 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)31 HashMap (java.util.HashMap)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)29 List (java.util.List)29 HashSet (java.util.HashSet)28 Produces (javax.ws.rs.Produces)28