Search in sources :

Example 6 with VolumeClone

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

the class ExternalBlockStorageDevice method doCreateGroupClone.

@Override
public void doCreateGroupClone(StorageSystem storageSystem, List<URI> cloneURIs, Boolean createInactive, TaskCompleter taskCompleter) {
    BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
    List<VolumeClone> driverClones = new ArrayList<>();
    Map<VolumeClone, Volume> driverCloneToCloneMap = new HashMap<>();
    Set<URI> consistencyGroups = new HashSet<>();
    List<Volume> clones = null;
    DriverTask task = null;
    try {
        clones = dbClient.queryObject(Volume.class, cloneURIs);
        // We assume here that all volumes belong to the same consistency group
        URI parentUri = clones.get(0).getAssociatedSourceVolume();
        Volume parentVolume = dbClient.queryObject(Volume.class, parentUri);
        BlockConsistencyGroup cg = null;
        if (!NullColumnValueGetter.isNullURI(parentVolume.getConsistencyGroup())) {
            cg = dbClient.queryObject(BlockConsistencyGroup.class, parentVolume.getConsistencyGroup());
        } else {
            String errorMsg = String.format("doCreateGroupClone -- Failed to create group clone, parent volumes do not belong to consistency group." + " Clones: %s .", cloneURIs);
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", errorMsg);
            taskCompleter.error(dbClient, serviceError);
            return;
        }
        // Prepare driver consistency group of parent volume
        VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
        driverCG.setDisplayName(cg.getLabel());
        driverCG.setNativeId(cg.getNativeId());
        driverCG.setStorageSystemId(storageSystem.getNativeId());
        // Prepare driver clones
        for (Volume clone : clones) {
            URI sourceVolumeUri = clone.getAssociatedSourceVolume();
            Volume sourceVolume = dbClient.queryObject(Volume.class, sourceVolumeUri);
            VolumeClone driverClone = new VolumeClone();
            driverClone.setParentId(sourceVolume.getNativeId());
            driverClone.setStorageSystemId(storageSystem.getNativeId());
            driverClone.setDisplayName(clone.getLabel());
            driverClone.setRequestedCapacity(clone.getCapacity());
            driverClone.setThinlyProvisioned(clone.getThinlyProvisioned());
            driverClones.add(driverClone);
            driverCloneToCloneMap.put(driverClone, clone);
        }
        // Call driver to create group snapshot
        task = driver.createConsistencyGroupClone(driverCG, Collections.unmodifiableList(driverClones), null);
        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 clone
            // volume and call the completer as appropriate based on the result of the request.
            CreateGroupCloneExternalDeviceJob job = new CreateGroupCloneExternalDeviceJob(storageSystem.getId(), cloneURIs, parentVolume.getConsistencyGroup(), task.getTaskId(), taskCompleter);
            ControllerServiceImpl.enqueueJob(new QueueJob(job));
        } else if (task.getStatus() == DriverTask.TaskStatus.READY) {
            // Update clone object with driver data
            String msg = String.format("doCreateGroupClone -- Created group clone: %s .", task.getMessage());
            _log.info(msg);
            List<Volume> cloneObjects = new ArrayList<>();
            for (VolumeClone driverCloneResult : driverClones) {
                Volume cloneObject = driverCloneToCloneMap.get(driverCloneResult);
                ExternalDeviceUtils.updateNewlyCreatedGroupClone(cloneObject, driverCloneResult, parentVolume.getConsistencyGroup(), dbClient);
                cloneObjects.add(cloneObject);
            }
            dbClient.updateObject(cloneObjects);
            taskCompleter.ready(dbClient);
        } else {
            // Process failure
            for (Volume cloneObject : clones) {
                cloneObject.setInactive(true);
            }
            dbClient.updateObject(clones);
            String errorMsg = String.format("doCreateGroupClone -- Failed to create group clone: %s .", task.getMessage());
            _log.error(errorMsg);
            ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", errorMsg);
            taskCompleter.error(dbClient, serviceError);
        }
    } catch (Exception e) {
        if (clones != null) {
            // Process failure
            for (Volume cloneObject : clones) {
                cloneObject.setInactive(true);
            }
            dbClient.updateObject(clones);
        }
        _log.error("Failed to create group clone. ", e);
        ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    } finally {
        try {
            if (task == null || isTaskInTerminalState(task.getStatus())) {
                // post process storage pool capacity for clone's pools
                // map clones to their storage pool
                Map<URI, List<URI>> dbPoolToClone = new HashMap<>();
                for (Volume clone : clones) {
                    URI dbPoolUri = clone.getPool();
                    List<URI> poolClones = dbPoolToClone.get(dbPoolUri);
                    if (poolClones == null) {
                        poolClones = new ArrayList<>();
                        dbPoolToClone.put(dbPoolUri, poolClones);
                    }
                    poolClones.add(clone.getId());
                }
                for (URI dbPoolUri : dbPoolToClone.keySet()) {
                    StoragePool dbPool = dbClient.queryObject(StoragePool.class, dbPoolUri);
                    updateStoragePoolCapacity(dbPool, storageSystem, dbPoolToClone.get(dbPoolUri), dbClient);
                }
            }
        } catch (Exception ex) {
            _log.error("Failed to update storage pool after create group clone operation completion.", ex);
        }
    }
}
Also used : VolumeConsistencyGroup(com.emc.storageos.storagedriver.model.VolumeConsistencyGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) 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) CreateGroupCloneExternalDeviceJob(com.emc.storageos.volumecontroller.impl.externaldevice.job.CreateGroupCloneExternalDeviceJob) StorageVolume(com.emc.storageos.storagedriver.model.StorageVolume) Volume(com.emc.storageos.db.client.model.Volume) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockStorageDriver(com.emc.storageos.storagedriver.BlockStorageDriver) HashSet(java.util.HashSet)

Example 7 with VolumeClone

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

the class HP3PARCloneHelper method createVolumeClone.

public DriverTask createVolumeClone(List<VolumeClone> clones, StorageCapabilities capabilities, DriverTask task, Registry driverRegistry) {
    String storageSystemId = null;
    HP3PARApi hp3parApi = null;
    for (VolumeClone clone : clones) {
        try {
            // native id = null ,
            _log.info("3PARDriver: createVolumeClone for storage system native id {}, clone parent name {} , clone name {} - start", clone.toString(), clone.getParentId(), clone.getDisplayName());
            String localStorageSystemId = clone.getStorageSystemId();
            // get Api client
            if (storageSystemId == null || storageSystemId != localStorageSystemId) {
                storageSystemId = localStorageSystemId;
                hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(localStorageSystemId, driverRegistry);
            }
            VolumeDetailsCommandResult volResult = null;
            // Create volume clone
            hp3parApi.createPhysicalCopy(clone.getParentId(), clone.getDisplayName(), clone.getStoragePoolId());
            volResult = hp3parApi.getVolumeDetails(clone.getDisplayName());
            // Actual size of the volume in array
            clone.setProvisionedCapacity(volResult.getSizeMiB() * HP3PARConstants.MEGA_BYTE);
            clone.setWwn(volResult.getWwn());
            // required for volume
            clone.setNativeId(volResult.getName());
            // delete
            clone.setDeviceLabel(clone.getDisplayName());
            clone.setAccessStatus(clone.getAccessStatus());
            clone.setReplicationState(VolumeClone.ReplicationState.SYNCHRONIZED);
            task.setStatus(DriverTask.TaskStatus.READY);
            _log.info("createVolumeClone for storage system native id {}, volume clone name {} - end", clone.getStorageSystemId(), clone.getDisplayName());
        } catch (Exception e) {
            String msg = String.format("3PARDriver: createVolumeClone Unable to create volume clone name %s for parent base volume id %s whose storage system native id is %s; Error: %s.\n", clone.getDisplayName(), clone.getParentId(), clone.getStorageSystemId(), e.getMessage());
            _log.info("createVolumeClone exception message {} ", e.getMessage());
            _log.error(msg);
            task.setMessage(msg);
            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
            e.printStackTrace();
        }
    }
    return task;
}
Also used : VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VolumeDetailsCommandResult(com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)

Example 8 with VolumeClone

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

the class HP3PARCloneHelper method restoreFromClone.

public DriverTask restoreFromClone(List<VolumeClone> clones, Registry driverRegistry, DriverTask task) {
    String storageSystemId = null;
    HP3PARApi hp3parApi = null;
    // 3par system)
    for (VolumeClone clone : clones) {
        try {
            _log.info("3PARDriver: restoreFromClone for storage system system id {}, clone name {} , native id {}  - start", clone.getStorageSystemId(), clone.getDisplayName(), clone.getNativeId());
            String localStorageSystemId = clone.getStorageSystemId();
            // get Api client
            if (storageSystemId == null || storageSystemId != localStorageSystemId) {
                storageSystemId = localStorageSystemId;
                hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(localStorageSystemId, driverRegistry);
            }
            // restore virtual copy
            hp3parApi.restorePhysicalCopy(clone.getNativeId());
            // clone.setReplicationState(VolumeClone.ReplicationState.RESTORED);
            task.setStatus(DriverTask.TaskStatus.READY);
            _log.info("3PARDriver: restoreFromClone successful for storage system  id {}, volume clone native id {} - end", clone.getStorageSystemId(), clone.getNativeId());
        } catch (Exception e) {
            String msg = String.format("3PARDriver:restoreFromClone Unable to restore volume clone display name %s with native id %s for storage system id %s; Error: %s.\n", clone.getDisplayName(), clone.getNativeId(), clone.getStorageSystemId(), e.getMessage());
            _log.error(msg);
            task.setMessage(msg);
            task.setStatus(DriverTask.TaskStatus.PARTIALLY_FAILED);
            e.printStackTrace();
        }
    }
    return task;
}
Also used : VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone)

Example 9 with VolumeClone

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

the class HP3PARIngestHelper method getVolumeClones.

/**
 * Identifying clones of the given parent base volume. NOTE: Intermediate
 * physical copies of 3PAR generated from other snapshots/clone are shown as
 * clone of base volume itself
 */
public List<VolumeClone> getVolumeClones(StorageVolume volume, Registry registry) {
    _log.info("3PARDriver: getVolumeClones Running ");
    List<VolumeClone> clones = new ArrayList<>();
    try {
        Map<String, List<String>> vvolAssociations = registry.getDriverAttributesForKey(HP3PARConstants.DRIVER_NAME, volume.getStorageSystemId() + "____VVOL_ASSOCIATIONS");
        _log.debug("vvolAssociations is {}", vvolAssociations.toString());
        HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(volume.getStorageSystemId(), registry);
        // VolumesCommandResult snapsResult =
        // hp3parApi.getClonesOfVolume(volume.getNativeId());
        ArrayList<String> listOfChildVols = null;
        listOfChildVols = (ArrayList<String>) vvolAssociations.get(volume.getNativeId());
        for (String childName : listOfChildVols) {
            // VolumeDetailsCommandResult is the data structure used for representation of
            // the HP3PAR virtual volume
            VolumeDetailsCommandResult objClone = hp3parApi.getVolumeDetails(childName);
            if (objClone.getCopyType() == copyType.PHYSICAL_COPY.getValue()) {
                // VolumeClone is the CoprHD southbound freamework's data
                // structure
                VolumeClone driverClone = new VolumeClone();
                driverClone.setParentId(volume.getNativeId());
                driverClone.setNativeId(objClone.getName());
                driverClone.setDeviceLabel(objClone.getName());
                driverClone.setStorageSystemId(volume.getStorageSystemId());
                driverClone.setStoragePoolId(volume.getStoragePoolId());
                driverClone.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
                if (volume.getConsistencyGroup() != null) {
                    driverClone.setConsistencyGroup(volume.getConsistencyGroup());
                }
                driverClone.setWwn(objClone.getWwn());
                driverClone.setThinlyProvisioned(volume.getThinlyProvisioned());
                // Allocated capacity is the sum of user, snapshot and admin reserved space
                Long allocatedCapacity = objClone.getUserSpace().getReservedMiB();
                allocatedCapacity += objClone.getSnapshotSpace().getReservedMiB();
                allocatedCapacity += objClone.getAdminSpace().getReservedMiB();
                driverClone.setAllocatedCapacity(allocatedCapacity * HP3PARConstants.MEGA_BYTE);
                driverClone.setProvisionedCapacity(objClone.getSizeMiB() * HP3PARConstants.MEGA_BYTE);
                driverClone.setReplicationState(VolumeClone.ReplicationState.SYNCHRONIZED);
                clones.add(driverClone);
            }
        }
        _log.info("3PARDriver: getVolumeClones Leaving");
        return clones;
    } catch (Exception e) {
        String msg = String.format("3PARDriver: Unable to get clone of volume with storage system %s and volume native id %s; Error: %s.\n", volume.getStorageSystemId(), volume.getNativeId(), e.getMessage());
        _log.error(msg);
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) VirtualLunsList(com.emc.storageos.hp3par.command.VirtualLunsList) List(java.util.List) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) VolumeDetailsCommandResult(com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)

Example 10 with VolumeClone

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

the class DellSCCloning method createVolumeClone.

/**
 * Create a clone of a volume.
 *
 * @param clones The clones to create.
 * @return The clone task.
 */
public DriverTask createVolumeClone(List<VolumeClone> clones) {
    LOG.info("Creating volume clone");
    DellSCDriverTask task = new DellSCDriverTask("createVolumeClone");
    StringBuilder errBuffer = new StringBuilder();
    int createCount = 0;
    for (VolumeClone clone : clones) {
        try {
            StorageCenterAPI api = connectionManager.getConnection(clone.getStorageSystemId());
            ScReplay replay = null;
            // Make sure volume is active for the automated tests that try to
            // create temporary snapshot to create the clone from after immediate volume creation
            api.checkAndInitVolume(clone.getParentId());
            if (clone.getSourceType() == SourceType.SNAPSHOT) {
                replay = api.getReplay(clone.getParentId());
            } else {
                // Create temporary replay to create the clone from
                replay = api.createReplay(clone.getParentId(), 5);
            }
            // Now create a new volume from the snapshot
            ScVolume scVol = api.createViewVolume(clone.getDisplayName(), replay.instanceId);
            clone.setProvisionedCapacity(SizeUtil.sizeStrToBytes(scVol.configuredSize));
            // New volumes don't allocate any space
            clone.setAllocatedCapacity(0L);
            clone.setWwn(scVol.deviceId);
            clone.setNativeId(scVol.instanceId);
            clone.setDeviceLabel(scVol.name);
            clone.setAccessStatus(AccessStatus.READ_WRITE);
            clone.setReplicationState(ReplicationState.SYNCHRONIZED);
            createCount++;
        } catch (DellSCDriverException | StorageCenterAPIException dex) {
            String error = String.format("Error creating clone of volume %s: %s", clone.getParentId(), dex);
            errBuffer.append(String.format("%s%n", error));
        }
    }
    task.setMessage(errBuffer.toString());
    if (createCount == clones.size()) {
        task.setStatus(TaskStatus.READY);
    } else if (createCount == 0) {
        task.setStatus(TaskStatus.FAILED);
    } else {
        task.setStatus(TaskStatus.PARTIALLY_FAILED);
    }
    return task;
}
Also used : ScVolume(com.emc.storageos.driver.dellsc.scapi.objects.ScVolume) StorageCenterAPI(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPI) DellSCDriverException(com.emc.storageos.driver.dellsc.DellSCDriverException) DellSCDriverTask(com.emc.storageos.driver.dellsc.DellSCDriverTask) StorageCenterAPIException(com.emc.storageos.driver.dellsc.scapi.StorageCenterAPIException) VolumeClone(com.emc.storageos.storagedriver.model.VolumeClone) ScReplay(com.emc.storageos.driver.dellsc.scapi.objects.ScReplay)

Aggregations

VolumeClone (com.emc.storageos.storagedriver.model.VolumeClone)27 Volume (com.emc.storageos.db.client.model.Volume)13 StorageVolume (com.emc.storageos.storagedriver.model.StorageVolume)10 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 ArrayList (java.util.ArrayList)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 BlockStorageDriver (com.emc.storageos.storagedriver.BlockStorageDriver)7 DriverTask (com.emc.storageos.storagedriver.DriverTask)7 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)7 IOException (java.io.IOException)7 BlockObject (com.emc.storageos.db.client.model.BlockObject)6 StorageBlockObject (com.emc.storageos.storagedriver.model.StorageBlockObject)6 VolumeDetailsCommandResult (com.emc.storageos.hp3par.command.VolumeDetailsCommandResult)4 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 CreateGroupCloneDriverTask (com.emc.storageos.storagedriver.task.CreateGroupCloneDriverTask)3 RestoreFromCloneDriverTask (com.emc.storageos.storagedriver.task.RestoreFromCloneDriverTask)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2