Search in sources :

Example 1 with VNXeLunSnap

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

the class VNXeExportOperations method setSnapWWN.

/**
 * set snap wwn after export/unexport. if a snap is not exported to any host, its wwn is null
 *
 * @param apiClient
 * @param blockObj
 * @param snapId
 */
private String setSnapWWN(VNXeApiClient apiClient, BlockObject blockObj, String snapId) {
    String wwn = null;
    if (!apiClient.isUnityClient()) {
        VNXeLunSnap snap = apiClient.getLunSnapshot(snapId);
        wwn = snap.getPromotedWWN();
    } else {
        Snap snap = apiClient.getSnapshot(snapId);
        wwn = snap.getAttachedWWN();
    }
    if (wwn == null) {
        wwn = NullColumnValueGetter.getNullStr();
    }
    blockObj.setWWN(wwn);
    _dbClient.updateObject(blockObj);
    return wwn;
}
Also used : VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) Snap(com.emc.storageos.vnxe.models.Snap)

Example 2 with VNXeLunSnap

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

the class VNXeBlockRestoreSnapshotJob 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);
        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();
            if (snapshotObj.getConsistencyGroup() != null) {
                VNXeLunGroupSnap backupSnap = vnxeApiClient.getLunGroupSnapshot(backUpSnapId);
                List<VNXeLun> groupLuns = vnxeApiClient.getLunByStorageResourceId(backupSnap.getStorageResource().getId());
                // Create a snapshot corresponding to the backup snap for each volume in the consistency group
                URI cgID = snapshotObj.getConsistencyGroup();
                List<Volume> cgVolumes = getCGVolumes(cgID.toString(), dbClient);
                final List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
                Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
                for (Volume vol : cgVolumes) {
                    final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
                    newSnap.setOpStatus(new OpStatusMap());
                    snapshotList.add(newSnap);
                    volumeToSnapMap.put(vol.getNativeId(), newSnap);
                }
                // Add vnxe information to the new snapshots
                for (VNXeLun groupLun : groupLuns) {
                    BlockSnapshot snapshot = volumeToSnapMap.get(groupLun.getId());
                    if (snapshot == null) {
                        _logger.info("No snapshot found for the vnxe lun - ", groupLun.getId());
                        continue;
                    }
                    snapshot.setNativeId(backUpSnapId);
                    snapshot.setReplicationGroupInstance(backUpSnapId);
                    processSnapshot(snapshot, storage, groupLun, dbClient);
                }
                dbClient.createObject(snapshotList);
            } else {
                VNXeLunSnap backupSnap = vnxeApiClient.getLunSnapshot(backUpSnapId);
                VNXeLun lun = vnxeApiClient.getLun(backupSnap.getLun().getId());
                Volume vol = dbClient.queryObject(Volume.class, snapshotObj.getParent());
                final BlockSnapshot newSnap = getSnapshotFromVol(vol, backupSnap.getName());
                newSnap.setNativeId(backUpSnapId);
                processSnapshot(newSnap, storage, lun, 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 : VNXeLunGroupSnap(com.emc.storageos.vnxe.models.VNXeLunGroupSnap) 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) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 3 with VNXeLunSnap

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

the class VNXeBlockSnapshotCreateJob 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());
        if (_status == JobStatus.SUCCESS) {
            _logger.info(String.format("Post-processing successful snap creation task:%s. Expected: snapshot.size() = 1; Actual: snapshots.size() = %d", getTaskCompleter().getOpId(), snapshots.size()));
            StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemUri());
            VNXeApiClient vnxeApiClient = getVNXeClient(jobContext);
            VNXeCommandJob vnxeJob = vnxeApiClient.getJob(getJobIds().get(0));
            ParametersOut output = vnxeJob.getParametersOut();
            BlockSnapshot snapshot = snapshots.get(0);
            Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
            snapshot.setNativeId(output.getId());
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
            snapshot.setIsSyncActive(true);
            snapshot.setInactive(false);
            snapshot.setCreationTime(Calendar.getInstance());
            if (vnxeApiClient.isUnityClient()) {
                Snap snap = vnxeApiClient.getSnapshot(output.getId());
                snapshot.setDeviceLabel(snap.getName());
                snapshot.setAllocatedCapacity(snap.getSize());
                snapshot.setProvisionedCapacity(snap.getSize());
            } else {
                VNXeLunSnap vnxeLunSnap = vnxeApiClient.getLunSnapshot(output.getId());
                VNXeLun lun = vnxeApiClient.getLun(vnxeLunSnap.getLun().getId());
                snapshot.setDeviceLabel(vnxeLunSnap.getName());
                snapshot.setAllocatedCapacity(lun.getSnapsSizeAllocated());
                snapshot.setProvisionedCapacity(lun.getSnapsSize());
            }
            _logger.info(String.format("Going to set blocksnapshot %1$s nativeId to %2$s. Associated volume is %3$s (%4$s)", snapshot.getId().toString(), output.getId(), volume.getNativeId(), volume.getLabel()));
            dbClient.updateObject(snapshot);
            getTaskCompleter().ready(dbClient);
        } else if (_status == JobStatus.FAILED) {
            _logger.info("Failed to create snapshot");
            BlockSnapshot snapshot = snapshots.get(0);
            snapshot.setInactive(true);
            dbClient.updateObject(snapshot);
        }
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for VNXeBlockSnapshotCreateJob", e);
        setErrorStatus("Encountered an internal error during volume 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) 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) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) Volume(com.emc.storageos.db.client.model.Volume) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 4 with VNXeLunSnap

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

the class VNXeApiClient method exportSnap.

/**
 * Export a snap for a given host
 *
 * @param host
 *            host
 * @param snapId
 *            snap id
 * @param newhlu
 *            HLU
 * @return
 * @throws VNXeException
 */
public VNXeExportResult exportSnap(VNXeBase host, String snapId, Integer newhlu) throws VNXeException {
    _logger.info("Exporting lun snap: {}", snapId);
    String parentLunId = null;
    VNXeLun parentLun = null;
    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("Attaching the snap: {}", snapId);
            attachLunSnap(snapId);
        }
        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("Attaching the snap: {}", snapId);
            attachSnap(snapId);
        } else if (snapGroup != null && (!snap.isAttached())) {
            String groupId = snapGroup.getId();
            attachSnap(groupId);
        }
    }
    // Get host access info of the parent lun
    parentLun = getLun(parentLunId);
    List<BlockHostAccess> hostAccesses = parentLun.getHostAccess();
    boolean snapHostAccessExists = false;
    if (hostAccesses == null) {
        hostAccesses = new ArrayList<BlockHostAccess>();
    } else {
        // already defined for the given host with a different access mask.
        for (BlockHostAccess hostAccess : hostAccesses) {
            String hostId = hostAccess.getHost().getId();
            if (hostId.equals(host.getId())) {
                if (hostAccess.getAccessMask() == HostLUNAccessEnum.PRODUCTION.getValue()) {
                    hostAccess.setAccessMask(HostLUNAccessEnum.BOTH.getValue());
                    snapHostAccessExists = true;
                    break;
                } else if (hostAccess.getAccessMask() == HostLUNAccessEnum.NOACCESS.getValue()) {
                    hostAccess.setAccessMask(HostLUNAccessEnum.SNAPSHOT.getValue());
                    snapHostAccessExists = true;
                    break;
                }
            }
        }
    }
    if (!snapHostAccessExists) {
        BlockHostAccess access = new BlockHostAccess();
        access.setHost(host);
        access.setAccessMask(BlockHostAccess.HostLUNAccessEnum.SNAPSHOT.getValue());
        hostAccesses.add(access);
    }
    LunParam lunParam = new LunParam();
    lunParam.setHostAccess(hostAccesses);
    LunModifyParam exportParam = new LunModifyParam();
    exportParam.setLunParameters(lunParam);
    int type = parentLun.getType();
    if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
        // if standalone lun
        BlockLunRequests lunReq = new BlockLunRequests(_khClient);
        lunReq.modifyLunSync(exportParam, parentLun.getStorageResource().getId());
    } else {
        // parent lun in a lun group
        exportParam.setLun(new VNXeBase(parentLun.getId()));
        List<LunModifyParam> list = new ArrayList<LunModifyParam>();
        list.add(exportParam);
        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);
        }
    }
    // get hlu
    HostLunRequests hostLunReq = new HostLunRequests(_khClient);
    HostLun hostLun = hostLunReq.getHostLun(parentLun.getId(), host.getId(), HostLunRequests.ID_SEQUENCE_SNAP);
    int hluResult = hostLun.getHlu();
    if (isUnityClient() && newhlu != null && newhlu.intValue() != -1) {
        _logger.info("Modify hlu");
        modifyHostLunHlu(host.getId(), hostLun.getId(), newhlu);
        hluResult = newhlu;
    }
    VNXeExportResult result = new VNXeExportResult();
    result.setHlu(hluResult);
    result.setHostId(host.getId());
    result.setNewAccess(!snapHostAccessExists);
    _logger.info("Done exporting lun snap: {}", snapId);
    return result;
}
Also used : HostLunRequests(com.emc.storageos.vnxe.requests.HostLunRequests) ArrayList(java.util.ArrayList) LunGroupModifyParam(com.emc.storageos.vnxe.models.LunGroupModifyParam) HostLun(com.emc.storageos.vnxe.models.HostLun) 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) VNXeExportResult(com.emc.storageos.vnxe.models.VNXeExportResult) 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 5 with VNXeLunSnap

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

the class LunSnapRequests method getLunSnapByName.

/**
 * Get snapshot details by its name
 *
 * @param name
 * @return
 */
public VNXeLunSnap getLunSnapByName(String name) {
    setFilter(VNXeConstants.NAME_FILTER + name);
    VNXeLunSnap result = null;
    List<VNXeLunSnap> snapList = getDataForObjects(VNXeLunSnap.class);
    // it should just return 1
    if (snapList != null && !snapList.isEmpty()) {
        result = snapList.get(0);
    } else {
        _logger.info("No lun snapshot found using the name: " + name);
    }
    return result;
}
Also used : VNXeLunSnap(com.emc.storageos.vnxe.models.VNXeLunSnap)

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