Search in sources :

Example 6 with VNXeLunSnap

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

the class VNXeSnapshotOperation method deleteSingleVolumeSnapshot.

@Override
public void deleteSingleVolumeSnapshot(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeLunSnap lunSnap = apiClient.getLunSnapshot(snap.getNativeId());
        if (lunSnap != null) {
            VNXeCommandJob job = apiClient.deleteLunSnap(lunSnap.getId());
            if (job != null) {
                ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockDeleteSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
            }
        } else {
            // Perhaps, it's already been deleted or was deleted on the array.
            // In that case, we'll just say all is well, so that this operation
            // is idempotent.
            snap.setInactive(true);
            snap.setIsSyncActive(false);
            _dbClient.updateObject(snap);
            taskCompleter.ready(_dbClient);
        }
    } catch (VNXeException e) {
        _log.error("Delete volume snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (Exception ex) {
        _log.error("Delete volume snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteSnapshot", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeBlockDeleteSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockDeleteSnapshotJob) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 7 with VNXeLunSnap

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

the class VNXeSnapshotOperation 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);
        VNXeLunSnap lunSnap = apiClient.getLunSnapshot(snapshotObj.getNativeId());
        // Error out if the snapshot is attached
        if (lunSnap.getIsAttached()) {
            _log.error("Snapshot {})is attached and cannot be used for restore", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshot.toString());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreLunSnap(lunSnap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (VNXeException e) {
        _log.error("Restore snapshot got the exception", e);
        taskCompleter.error(_dbClient, e);
    } 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) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeBlockRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockRestoreSnapshotJob) VNXeException(com.emc.storageos.vnxe.VNXeException) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 8 with VNXeLunSnap

use of com.emc.storageos.vnxe.models.VNXeLunSnap 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)

Example 9 with VNXeLunSnap

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

the class VNXeApiClient method getSnapWWN.

private String getSnapWWN(String snapId) {
    String wwn = "null";
    if (!isUnityClient()) {
        VNXeLunSnap snap = getLunSnapshot(snapId);
        wwn = snap.getPromotedWWN();
    } else {
        Snap snap = getSnapshot(snapId);
        wwn = snap.getAttachedWWN();
    }
    return wwn;
}
Also used : 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)

Aggregations

VNXeLunSnap (com.emc.storageos.vnxe.models.VNXeLunSnap)9 Snap (com.emc.storageos.vnxe.models.Snap)5 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)4 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)4 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)4 VNXeLun (com.emc.storageos.vnxe.models.VNXeLun)4 VNXeLunGroupSnap (com.emc.storageos.vnxe.models.VNXeLunGroupSnap)4 VNXeFileSystemSnap (com.emc.storageos.vnxe.models.VNXeFileSystemSnap)3 ArrayList (java.util.ArrayList)3 DbClient (com.emc.storageos.db.client.DbClient)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 Volume (com.emc.storageos.db.client.model.Volume)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)2 VNXeException (com.emc.storageos.vnxe.VNXeException)2 BlockHostAccess (com.emc.storageos.vnxe.models.BlockHostAccess)2 HostLunModifyParam (com.emc.storageos.vnxe.models.HostLunModifyParam)2 LunGroupModifyParam (com.emc.storageos.vnxe.models.LunGroupModifyParam)2 LunModifyParam (com.emc.storageos.vnxe.models.LunModifyParam)2 LunParam (com.emc.storageos.vnxe.models.LunParam)2