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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations