use of com.emc.storageos.vnxe.models.VNXeExportResult in project coprhd-controller by CoprHD.
the class VNXeExportOperations method addVolumes.
@Override
public void addVolumes(StorageSystem storage, URI exportMaskUri, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
_logger.info("{} addVolume START...", storage.getSerialNumber());
List<URI> mappedVolumes = new ArrayList<URI>();
ExportMask exportMask = null;
try {
_logger.info("addVolumes: Export mask id: {}", exportMaskUri);
_logger.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
if (initiatorList != null) {
_logger.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
}
ExportOperationContext context = new VNXeExportOperationContext();
taskCompleter.updateWorkflowStepContext(context);
VNXeApiClient apiClient = getVnxeClient(storage);
exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
if (exportMask == null || exportMask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
}
List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
Collection<VNXeHostInitiator> vnxeInitiators = prepareInitiators(initiators).values();
VNXeBase host = apiClient.prepareHostsForExport(vnxeInitiators);
String opId = taskCompleter.getOpId();
Set<String> processedCGs = new HashSet<String>();
for (VolumeURIHLU volURIHLU : volumeURIHLUs) {
URI volUri = volURIHLU.getVolumeURI();
String hlu = volURIHLU.getHLU();
_logger.info(String.format("hlu %s", hlu));
BlockObject blockObject = BlockObject.fetch(_dbClient, volUri);
VNXeExportResult result = null;
Integer newhlu = -1;
if (hlu != null && !hlu.isEmpty() && !hlu.equals(ExportGroup.LUN_UNASSIGNED_STR)) {
newhlu = Integer.valueOf(hlu);
}
// COP-25254 this method could be called when create vplex volumes from snapshot. in this case
// the volume passed in is an internal volume, representing the snapshot. we need to find the snapshot
// with the same nativeGUID, then export the snapshot.
BlockObject snapshot = findSnapshotByInternalVolume(blockObject);
boolean isVplexVolumeFromSnap = false;
URI vplexBackendVol = null;
if (snapshot != null) {
blockObject = snapshot;
exportMask.addVolume(volUri, newhlu);
isVplexVolumeFromSnap = true;
vplexBackendVol = volUri;
volUri = blockObject.getId();
}
String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
if (cgName != null && !processedCGs.contains(cgName)) {
processedCGs.add(cgName);
VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
}
String nativeId = blockObject.getNativeId();
if (URIUtil.isType(volUri, Volume.class)) {
result = apiClient.exportLun(host, nativeId, newhlu);
exportMask.addVolume(volUri, result.getHlu());
if (result.isNewAccess()) {
mappedVolumes.add(volUri);
}
} else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
result = apiClient.exportSnap(host, nativeId, newhlu);
exportMask.addVolume(volUri, result.getHlu());
if (result.isNewAccess()) {
mappedVolumes.add(volUri);
}
String snapWWN = setSnapWWN(apiClient, blockObject, nativeId);
if (isVplexVolumeFromSnap) {
Volume backendVol = _dbClient.queryObject(Volume.class, vplexBackendVol);
backendVol.setWWN(snapWWN);
_dbClient.updateObject(backendVol);
}
}
}
ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT, mappedVolumes);
_dbClient.updateObject(exportMask);
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_002);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_logger.error("Add volumes error: ", e);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addVolume", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_logger.info("{} addVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.vnxe.models.VNXeExportResult 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.VNXeExportResult in project coprhd-controller by CoprHD.
the class VNXeApiClient method exportLun.
/**
* Export a lun for a given host
*
* @param host
* host
* @param lunId
* lun id
* @param newhlu
* HLU
* @return
* @throws VNXeException
*/
public VNXeExportResult exportLun(VNXeBase host, String lunId, Integer newhlu) throws VNXeException {
_logger.info("Exporting lun: {}", lunId);
VNXeLun lun = getLun(lunId);
if (lun == null) {
_logger.info("Could not find lun in the vxne: {}", lunId);
throw VNXeException.exceptions.vnxeCommandFailed("Could not find lun : " + lunId);
}
List<BlockHostAccess> hostAccesses = lun.getHostAccess();
boolean lunHostAccessExists = 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.SNAPSHOT.getValue()) {
hostAccess.setAccessMask(HostLUNAccessEnum.BOTH.getValue());
lunHostAccessExists = true;
break;
} else if (hostAccess.getAccessMask() == HostLUNAccessEnum.NOACCESS.getValue()) {
hostAccess.setAccessMask(HostLUNAccessEnum.PRODUCTION.getValue());
lunHostAccessExists = true;
break;
}
}
}
}
if (!lunHostAccessExists) {
BlockHostAccess access = new BlockHostAccess();
access.setHost(host);
access.setAccessMask(BlockHostAccess.HostLUNAccessEnum.PRODUCTION.getValue());
hostAccesses.add(access);
}
LunParam lunParam = new LunParam();
lunParam.setHostAccess(hostAccesses);
LunModifyParam exportParam = new LunModifyParam();
exportParam.setLunParameters(lunParam);
int type = lun.getType();
if (type == VNXeLun.LUNTypeEnum.Standalone.getValue()) {
// if standalone lun
BlockLunRequests lunReq = new BlockLunRequests(_khClient);
lunReq.modifyLunSync(exportParam, lun.getStorageResource().getId());
} else {
// lun in a lun group
exportParam.setLun(new VNXeBase(lunId));
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(lun.getStorageResource().getId(), groupParam);
} else {
ConsistencyGroupRequests cgReq = new ConsistencyGroupRequests(_khClient);
cgReq.modifyConsistencyGroupSync(lun.getStorageResource().getId(), groupParam);
}
}
// get hlu
HostLunRequests hostLunReq = new HostLunRequests(_khClient);
HostLun hostLun = hostLunReq.getHostLun(lunId, host.getId(), HostLunRequests.ID_SEQUENCE_LUN);
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.setLunId(lunId);
result.setHostId(host.getId());
result.setNewAccess(!lunHostAccessExists);
_logger.info("Done exporting lun: {}", lunId);
return result;
}
use of com.emc.storageos.vnxe.models.VNXeExportResult in project coprhd-controller by CoprHD.
the class ApiClientTest method exportLun.
// @Test
public void exportLun() {
String lunId = "sv_1";
VNXeHostInitiator init = new VNXeHostInitiator();
init.setChapUserName("iqn.1998-01.com.vmware:lgly6193-7ae20d76");
init.setType(HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI);
init.setName("lgly6193.lss.emc.com");
List<VNXeHostInitiator> inits = new ArrayList<VNXeHostInitiator>();
inits.add(init);
VNXeBase vnxehost = apiClient.prepareHostsForExport(inits);
VNXeExportResult result = apiClient.exportLun(vnxehost, lunId, null);
System.out.println(result.getHlu());
}
use of com.emc.storageos.vnxe.models.VNXeExportResult in project coprhd-controller by CoprHD.
the class VNXeExportOperations method createExportMask.
@Override
public void createExportMask(StorageSystem storage, URI exportMask, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
_logger.info("{} createExportMask START...", storage.getSerialNumber());
VNXeApiClient apiClient = getVnxeClient(storage);
List<URI> mappedVolumes = new ArrayList<URI>();
ExportMask mask = null;
try {
_logger.info("createExportMask: Export mask id: {}", exportMask);
_logger.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
_logger.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
_logger.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
ExportOperationContext context = new VNXeExportOperationContext();
taskCompleter.updateWorkflowStepContext(context);
mask = _dbClient.queryObject(ExportMask.class, exportMask);
if (mask == null || mask.getInactive()) {
throw new DeviceControllerException("Invalid ExportMask URI: " + exportMask);
}
Set<String> processedCGs = new HashSet<String>();
Collection<VNXeHostInitiator> initiators = prepareInitiators(initiatorList).values();
VNXeBase host = apiClient.prepareHostsForExport(initiators);
validateInitiators(_dbClient, initiatorList, apiClient, host.getId());
String opId = taskCompleter.getOpId();
for (VolumeURIHLU volURIHLU : volumeURIHLUs) {
URI volUri = volURIHLU.getVolumeURI();
String hlu = volURIHLU.getHLU();
_logger.info(String.format("hlu %s", hlu));
BlockObject blockObject = BlockObject.fetch(_dbClient, volUri);
String nativeId = blockObject.getNativeId();
VNXeExportResult result = null;
Integer newhlu = -1;
if (hlu != null && !hlu.isEmpty() && !hlu.equals(ExportGroup.LUN_UNASSIGNED_STR)) {
newhlu = Integer.valueOf(hlu);
}
String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
if (cgName != null && !processedCGs.contains(cgName)) {
processedCGs.add(cgName);
VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
}
if (URIUtil.isType(volUri, Volume.class)) {
result = apiClient.exportLun(host, nativeId, newhlu);
mask.addVolume(volUri, result.getHlu());
if (result.isNewAccess()) {
mappedVolumes.add(volUri);
}
} else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
if (BlockObject.checkForRP(_dbClient, volUri)) {
_logger.info(String.format("BlockObject %s is a RecoverPoint bookmark. Exporting associated lun %s instead of snap.", volUri, nativeId));
result = apiClient.exportLun(host, nativeId, newhlu);
} else {
result = apiClient.exportSnap(host, nativeId, newhlu);
setSnapWWN(apiClient, blockObject, nativeId);
}
mask.addVolume(volUri, result.getHlu());
if (result.isNewAccess()) {
mappedVolumes.add(volUri);
}
}
}
ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT, mappedVolumes);
mask.setNativeId(host.getId());
_dbClient.updateObject(mask);
taskCompleter.ready(_dbClient);
} catch (Exception e) {
_logger.error("Unexpected error: createExportMask failed.", e);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createExportMask", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_logger.info("{} createExportMask END...", storage.getSerialNumber());
}
Aggregations