use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.
the class VNXUnityArrayAffinityDiscoverer method isSharedLun.
/**
* Check if a LUN is shared
* @param lun
* @return boolean true if the LUN is shared
*/
private boolean isSharedLun(VNXeLun lun) {
List<BlockHostAccess> accesses = lun.getHostAccess();
int hostCount = 0;
if (accesses != null && !accesses.isEmpty()) {
for (BlockHostAccess access : accesses) {
if (access != null) {
VNXeBase hostId = access.getHost();
if (hostId != null) {
hostCount++;
if (hostCount > 1) {
return true;
}
}
}
}
}
return false;
}
use of com.emc.storageos.vnxe.models.BlockHostAccess in project coprhd-controller by CoprHD.
the class VNXUnityBlockStorageDevice method doDeleteVolumes.
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter completer) throws DeviceControllerException {
logger.info("deleting volumes, array: {}", storageSystem.getSerialNumber());
VNXeApiClient apiClient = getVnxUnityClient(storageSystem);
Map<String, List<String>> cgNameMap = new HashMap<String, List<String>>();
try {
Set<URI> updateStoragePools = new HashSet<URI>();
// Invoke a test failure if testing
for (Volume volume : volumes) {
String lunId = volume.getNativeId();
if (NullColumnValueGetter.isNullValue(lunId)) {
logger.info(String.format("The volume %s does not have native id, do nothing", volume.getLabel()));
continue;
}
updateStoragePools.add(volume.getPool());
if (!apiClient.checkLunExists(lunId)) {
logger.info(String.format("The volume %s does not exist in the array, do nothing", volume.getLabel()));
continue;
}
String cgName = volume.getReplicationGroupInstance();
if (NullColumnValueGetter.isNotNullValue(cgName)) {
List<String> lunIds = cgNameMap.get(cgName);
if (lunIds == null) {
lunIds = new ArrayList<String>();
cgNameMap.put(cgName, lunIds);
}
lunIds.add(volume.getNativeId());
} else {
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
apiClient.deleteLunSync(volume.getNativeId(), false);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
}
}
for (Map.Entry<String, List<String>> entry : cgNameMap.entrySet()) {
String cgName = entry.getKey();
List<String> lunIDs = entry.getValue();
String cgId = apiClient.getConsistencyGroupIdByName(cgName);
boolean isRP = false;
if (cgId != null && !cgId.isEmpty()) {
// Check if the CG has blockHostAccess to a RP host. if the CG is exported to a RP, we could not delete the lun
// directly, we have to remove the volume from the CG first, then delete it.
StorageResource cg = apiClient.getStorageResource(cgId);
List<BlockHostAccess> hosts = cg.getBlockHostAccess();
if (hosts != null && !hosts.isEmpty()) {
for (BlockHostAccess hostAccess : hosts) {
VNXeBase hostId = hostAccess.getHost();
if (hostId != null) {
VNXeHost host = apiClient.getHostById(hostId.getId());
if (host != null) {
if (host.getType() == HostTypeEnum.RPA.getValue()) {
// Remove the luns from the CG
isRP = true;
logger.info(String.format("Removing volumes from CG because the CG %sis exported to RP", cgName));
VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
apiClient.removeLunsFromConsistencyGroup(cgId, lunIDs);
for (String lunId : lunIDs) {
logger.info(String.format("Deleting the volume %s", lunId));
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_035);
apiClient.deleteLunSync(lunId, false);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_036);
}
break;
}
}
}
}
}
}
if (!isRP) {
VNXeUtils.getCGLock(workflowService, storageSystem, cgName, opId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_034);
apiClient.deleteLunsFromConsistencyGroup(cgId, lunIDs);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_037);
}
}
for (URI pool : updateStoragePools) {
VNXeJob.updateStoragePoolCapacity(dbClient, apiClient, pool, null);
}
completer.ready(dbClient);
} catch (VNXeException e) {
logger.error("Delete volumes got the exception", e);
completer.error(dbClient, e);
} catch (Exception ex) {
logger.error("Delete volumes got the exception", ex);
ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteVolumes", ex.getMessage());
completer.error(dbClient, error);
}
}
use of com.emc.storageos.vnxe.models.BlockHostAccess 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.BlockHostAccess 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.BlockHostAccess in project coprhd-controller by CoprHD.
the class VNXUnityUnManagedObjectDiscoverer method createUnManagedVolumeForSnap.
/**
* Creates a new UnManagedVolume with the given arguments for a snap.
*
* @param unManagedVolumeNativeGuid
* @param lun
* @param system
* @param pool
* @param dbClient
* @param hostVolumeMap
* hosts and exported volumes map
* @param snap
* detail of the snap
* @return
*/
private UnManagedVolume createUnManagedVolumeForSnap(UnManagedVolume unManagedVolume, String unManagedVolumeNativeGuid, VNXeLun lun, StorageSystem system, DbClient dbClient, Map<String, List<UnManagedVolume>> hostVolumeMap, Snap snap) {
boolean created = false;
if (null == unManagedVolume) {
unManagedVolume = new UnManagedVolume();
unManagedVolume.setId(URIUtil.createId(UnManagedVolume.class));
unManagedVolume.setNativeGuid(unManagedVolumeNativeGuid);
unManagedVolume.setStorageSystemUri(system.getId());
created = true;
}
unManagedVolume.setLabel(snap.getName());
StringSetMap unManagedVolumeInformation = new StringSetMap();
Map<String, String> unManagedVolumeCharacteristics = new HashMap<String, String>();
Boolean isSnapExported = false;
if (lun.getHostAccess() != null && !lun.getHostAccess().isEmpty()) {
// clear the previous unmanaged export masks, initiators if any. The latest export masks will be updated
// later.
unManagedVolume.getUnmanagedExportMasks().clear();
unManagedVolume.getInitiatorNetworkIds().clear();
unManagedVolume.getInitiatorUris().clear();
for (BlockHostAccess access : lun.getHostAccess()) {
int accessMask = access.getAccessMask();
if (accessMask == BlockHostAccess.HostLUNAccessEnum.BOTH.getValue() || accessMask == BlockHostAccess.HostLUNAccessEnum.SNAPSHOT.getValue()) {
isSnapExported = true;
String hostId = access.getHost().getId();
List<UnManagedVolume> exportedSnaps = hostVolumeMap.get(hostId);
if (exportedSnaps == null) {
exportedSnaps = new ArrayList<UnManagedVolume>();
hostVolumeMap.put(hostId, exportedSnaps);
}
exportedSnaps.add(unManagedVolume);
}
}
}
unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_VOLUME_EXPORTED.toString(), isSnapExported.toString());
StringSet deviceLabel = new StringSet();
deviceLabel.add(snap.getName());
unManagedVolumeInformation.put(SupportedVolumeInformation.DEVICE_LABEL.toString(), deviceLabel);
String snapWWN = snap.getAttachedWWN();
if (snapWWN != null && !snapWWN.isEmpty()) {
String volumeWWN = snapWWN.replaceAll(":", "");
unManagedVolume.setWwn(volumeWWN);
}
StringSet systemTypes = new StringSet();
systemTypes.add(system.getSystemType());
StringSet provCapacity = new StringSet();
provCapacity.add(String.valueOf(snap.getSize()));
unManagedVolumeInformation.put(SupportedVolumeInformation.PROVISIONED_CAPACITY.toString(), provCapacity);
StringSet allocatedCapacity = new StringSet();
allocatedCapacity.add(String.valueOf(snap.getSize()));
unManagedVolumeInformation.put(SupportedVolumeInformation.ALLOCATED_CAPACITY.toString(), allocatedCapacity);
unManagedVolumeInformation.put(SupportedVolumeInformation.SYSTEM_TYPE.toString(), systemTypes);
StringSet nativeId = new StringSet();
nativeId.add(snap.getId());
unManagedVolumeInformation.put(SupportedVolumeInformation.NATIVE_ID.toString(), nativeId);
unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_INGESTABLE.toString(), Boolean.TRUE.toString());
unManagedVolumeCharacteristics.put(SupportedVolumeCharacterstics.IS_THINLY_PROVISIONED.toString(), lun.getIsThinEnabled().toString());
unManagedVolume.setVolumeInformation(unManagedVolumeInformation);
if (unManagedVolume.getVolumeCharacterstics() == null) {
unManagedVolume.setVolumeCharacterstics(new StringMap());
}
unManagedVolume.getVolumeCharacterstics().replace(unManagedVolumeCharacteristics);
if (created) {
unManagedVolumesInsert.add(unManagedVolume);
} else {
unManagedVolumesUpdate.add(unManagedVolume);
}
return unManagedVolume;
}
Aggregations