Search in sources :

Example 11 with Snap

use of com.emc.storageos.vnxe.models.Snap in project coprhd-controller by CoprHD.

the class VNXUnityRestoreSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        _logger.info(String.format("Updating status of job %s to %s", opId, _status.name()));
        URI snapId = getTaskCompleter().getId();
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapId);
        URI projectUri = snapshotObj.getProject().getURI();
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS && snapshotObj != null) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            // get the id of the backup snapshot created before restore operation
            String backUpSnapId = output.getBackup().getId();
            Snap backupSnap = vnxeApiClient.getSnapshot(backUpSnapId);
            if (NullColumnValueGetter.isNotNullValue(snapshotObj.getReplicationGroupInstance())) {
                List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshotObj, dbClient);
                // Create a snapshot corresponding to the backup snap for each volume in the consistency group
                final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
                Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
                int count = 1;
                String setLabel = backupSnap.getName();
                for (BlockSnapshot snapshot : snapshots) {
                    BlockObject parent = BlockObject.fetch(dbClient, snapshot.getParent().getURI());
                    String label = String.format("%s-%s", setLabel, count++);
                    final BlockSnapshot newSnap = initSnapshot(parent, label, setLabel, projectUri);
                    newSnap.setOpStatus(new OpStatusMap());
                    snapshotList.add(newSnap);
                    volumeToSnapMap.put(parent.getNativeId(), newSnap);
                }
                List<Snap> snaps = vnxeApiClient.getSnapshotsBySnapGroup(backUpSnapId);
                for (Snap snap : snaps) {
                    String lunId = snap.getLun().getId();
                    BlockSnapshot snapshot = volumeToSnapMap.get(lunId);
                    snapshot.setReplicationGroupInstance(backUpSnapId);
                    createSnapshot(snapshot, snap, storage, dbClient);
                }
            } else {
                Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
                final BlockSnapshot newSnap = initSnapshot(vol, backupSnap.getName(), backupSnap.getName(), projectUri);
                createSnapshot(newSnap, backupSnap, storage, dbClient);
            }
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED && snapshotObj != null) {
            _logger.info(String.format("Task %s failed to restore volume snapshot: %s", opId, snapshotObj.getLabel()));
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockRestoreSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot restore job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Snap(com.emc.storageos.vnxe.models.Snap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) BlockObject(com.emc.storageos.db.client.model.BlockObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 12 with Snap

use of com.emc.storageos.vnxe.models.Snap in project coprhd-controller by CoprHD.

the class VNXUnityCreateCGSnapshotJob method updateStatus.

public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        if (_status == JobStatus.IN_PROGRESS) {
            return;
        }
        BlockSnapshotCreateCompleter completer = (BlockSnapshotCreateCompleter) getTaskCompleter();
        List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, completer.getSnapshotURIs());
        StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
        if (_status == JobStatus.SUCCESS) {
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            String snapGroupId = output.getId();
            List<Snap> snaps = vnxeApiClient.getSnapshotsBySnapGroup(snapGroupId);
            // Create mapping of volume.nativeDeviceId to BlockSnapshot object
            Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
            for (BlockSnapshot snapshot : snapshots) {
                Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
                volumeToSnapMap.put(volume.getNativeId(), snapshot);
            }
            for (Snap snap : snaps) {
                String lunId = snap.getLun().getId();
                BlockSnapshot snapshot = volumeToSnapMap.get(lunId);
                snapshot.setNativeId(snap.getId());
                snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
                snapshot.setDeviceLabel(snap.getName());
                snapshot.setReplicationGroupInstance(snapGroupId);
                snapshot.setIsSyncActive(true);
                snapshot.setInactive(false);
                snapshot.setCreationTime(Calendar.getInstance());
                snapshot.setWWN(snap.getAttachedWWN());
                snapshot.setAllocatedCapacity(snap.getSize());
                snapshot.setProvisionedCapacity(snap.getSize());
                if (readOnly) {
                    snapshot.setIsReadOnly(readOnly);
                }
                _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s (%3$s). Associated lun is %4$s", snapshot.getId().toString(), snap.getId(), snapshot.getLabel(), lunId));
                dbClient.updateObject(snapshot);
            }
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setInactive(true);
            }
            dbClient.updateObject(snapshots);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXUntiyCreateCGSnapshotJob", e);
        setErrorStatus("Encountered an internal error during group snapshot create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ParametersOut(com.emc.storageos.vnxe.models.ParametersOut) BlockSnapshotCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.BlockSnapshotCreateCompleter) Snap(com.emc.storageos.vnxe.models.Snap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 13 with Snap

use of com.emc.storageos.vnxe.models.Snap in project coprhd-controller by CoprHD.

the class VNXUnitySnapshotOperations method restoreSingleVolumeSnapshot.

@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        Snap snap = apiClient.getSnapshot(snapshotObj.getNativeId());
        // Error out if the snapshot is attached
        if (snap.isAttached()) {
            log.error("Snapshot {})is exported and cannot be used for restore, please unexport it first", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshotObj.getLabel());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreSnap(snap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXUnityRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (Exception ex) {
        log.error("Restore snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXUnityRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityRestoreSnapshotJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Snap(com.emc.storageos.vnxe.models.Snap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 14 with Snap

use of com.emc.storageos.vnxe.models.Snap in project coprhd-controller by CoprHD.

the class VNXUnitySnapshotOperations method restoreGroupSnapshots.

@Override
public void restoreGroupSnapshots(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        Snap groupSnap = apiClient.getSnapshot(snapshotObj.getReplicationGroupInstance());
        Snap snap = apiClient.getSnapshot(snapshotObj.getNativeId());
        // Error out if the snapshot is attached
        if (snap.isAttached()) {
            log.error("Snapshot {})is exported and cannot be used for restore", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshotObj.getLabel());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreSnap(groupSnap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXUnityRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (Exception ex) {
        log.error("Restore group snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXUnityRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityRestoreSnapshotJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Snap(com.emc.storageos.vnxe.models.Snap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 15 with Snap

use of com.emc.storageos.vnxe.models.Snap in project coprhd-controller by CoprHD.

the class VNXeApiClient method unexportSnap.

/**
 * Unexport a snapshot
 *
 * @param hostId - The host id
 * @param snapId - The snap id
 */
public void unexportSnap(String hostId, String snapId) {
    _logger.info("Unexporting snap: {}", snapId);
    String parentLunId = null;
    String groupId = null;
    boolean detach = false;
    if (!_khClient.isUnity()) {
        VNXeLunSnap lunSnap = getLunSnapshot(snapId);
        if (lunSnap == null) {
            _logger.info("Could not find lun snap in the vxne: {}", snapId);
            throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun snap: " + snapId);
        }
        if (lunSnap.getIsAttached()) {
            _logger.info("Detaching the snap: {}", snapId);
            detachLunSnap(snapId);
            detach = true;
        }
        parentLunId = lunSnap.getLun().getId();
    } else {
        Snap snap = getSnapshot(snapId);
        if (snap == null) {
            _logger.info("Could not find snap in the vxn unity: {}", snapId);
            throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun snap: " + snapId);
        }
        VNXeBase snapGroup = snap.getSnapGroup();
        parentLunId = snap.getLun().getId();
        if (snapGroup == null && (snap.isAttached())) {
            _logger.info("Detaching the snap: {}", snapId);
            detachSnap(snapId);
            detach = true;
        } else if (snapGroup != null && snap.isAttached()) {
            _logger.info("Detaching the snap: {}", snapId);
            groupId = snapGroup.getId();
            detachSnap(groupId);
            detach = true;
        }
    }
    VNXeLun parentLun = getLun(parentLunId);
    List<BlockHostAccess> hostAccesses = parentLun.getHostAccess();
    if (hostAccesses == null || hostAccesses.isEmpty()) {
        _logger.info("No block host access found for the snap: {}", snapId);
        return;
    }
    List<BlockHostAccess> changedHostAccessList = new ArrayList<BlockHostAccess>();
    /*
         * we have to detach the snap in order to unexport any host. we need to reattach the snap
         * after the unexport if the snap is still exported to any other hosts.
         */
    boolean needReattach = false;
    for (BlockHostAccess hostAccess : hostAccesses) {
        int accessMask = hostAccess.getAccessMask();
        if (hostId.equals(hostAccess.getHost().getId())) {
            if (accessMask == HostLUNAccessEnum.BOTH.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.PRODUCTION.getValue());
            } else if (accessMask == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                hostAccess.setAccessMask(HostLUNAccessEnum.NOACCESS.getValue());
            }
        } else if (detach && !needReattach && (accessMask == HostLUNAccessEnum.BOTH.getValue() || accessMask == HostLUNAccessEnum.SNAPSHOT.getValue())) {
            needReattach = true;
        }
        changedHostAccessList.add(hostAccess);
    }
    if (changedHostAccessList.isEmpty()) {
        // the removing hosts are not exported
        _logger.info("The unexport hosts were not exported.");
        return;
    }
    if (!needReattach && detach && groupId != null) {
        // Check if there are other exported snaps in the snap group
        String cgId = parentLun.getStorageResource().getId();
        if (cgId != null && !cgId.isEmpty()) {
            BlockLunRequests lunReq = new BlockLunRequests(_khClient);
            List<VNXeLun> luns = lunReq.getLunsInLunGroup(cgId);
            for (VNXeLun cgLun : luns) {
                if (cgLun.getId().equals(parentLun.getId())) {
                    continue;
                }
                List<BlockHostAccess> hostAccess = cgLun.getHostAccess();
                if (hostAccess == null) {
                    continue;
                }
                for (BlockHostAccess hostA : hostAccess) {
                    int mask = hostA.getAccessMask();
                    if (mask == HostLUNAccessEnum.BOTH.getValue() || mask == HostLUNAccessEnum.SNAPSHOT.getValue()) {
                        needReattach = true;
                        break;
                    }
                }
                if (needReattach) {
                    break;
                }
            }
        } else {
            _logger.warn(String.format("The storage resource id is empty for the lun ", parentLun.getName()));
        }
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(changedHostAccessList);
    LunModifyParam modifyParam = new LunModifyParam();
    modifyParam.setLunParameters(lunParam);
    int type = parentLun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(modifyParam, parentLun.getStorageResource().getId());
    } else {
        // lun in a lun group
        modifyParam.setLun(new VNXeBase(parentLun.getId()));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(modifyParam);
        LunGroupModifyParam groupParam = new LunGroupModifyParam();
        groupParam.setLunModify(list);
        if (!_khClient.isUnity()) {
            LunGroupRequests lunGroupReq = new LunGroupRequests(_khClient);
            lunGroupReq.modifyLunGroupSync(parentLun.getStorageResource().getId(), groupParam);
        } else {
            ConsistencyGroupRequests cgReq = new ConsistencyGroupRequests(_khClient);
            cgReq.modifyConsistencyGroupSync(parentLun.getStorageResource().getId(), groupParam);
        }
    }
    if (needReattach) {
        if (!_khClient.isUnity()) {
            attachLunSnap(snapId);
        } else {
            if (groupId == null) {
                attachSnap(snapId);
            } else {
                attachSnap(groupId);
            }
        }
    }
    _logger.info("Done unexporting lun: {}", snapId);
}
Also used : ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) ConsistencyGroupRequests(com.emc.storageos.vnxe.requests.ConsistencyGroupRequests) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeFileSystemSnap(com.emc.storageos.vnxe.models.VNXeFileSystemSnap) VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) Snap(com.emc.storageos.vnxe.models.Snap) BlockHostAccess(com.emc.storageos.vnxe.models.BlockHostAccess) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) LunParam(com.emc.storageos.vnxe.models.LunParam) BlockLunRequests(com.emc.storageos.vnxe.requests.BlockLunRequests) LunGroupRequests(com.emc.storageos.vnxe.requests.LunGroupRequests) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) HostLunModifyParam(com.emc.storageos.vnxe.models.HostLunModifyParam) LunModifyParam(com.emc.storageos.vnxe.models.LunModifyParam)

Aggregations

Snap (com.emc.storageos.vnxe.models.Snap)16 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)8 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)8 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)5 VNXeLunSnap (com.emc.storageos.vnxe.models.VNXeLunSnap)5 ArrayList (java.util.ArrayList)5 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)4 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)4 HashMap (java.util.HashMap)4 DbClient (com.emc.storageos.db.client.DbClient)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)3 Volume (com.emc.storageos.db.client.model.Volume)3 ParametersOut (com.emc.storageos.vnxe.models.ParametersOut)3 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)2 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)2