use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getExportMaskAllInitiatorPorts.
/**
* Get all initiator ports in mask.
*
* @param exportMask
* @param dbClient
* @return
*/
public static Set<String> getExportMaskAllInitiatorPorts(ExportMask exportMask, DbClient dbClient) {
Set<String> ports = new HashSet<String>();
if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
List<URI> iniUris = StringSetUtil.stringSetToUriList(exportMask.getInitiators());
List<Initiator> initiators = dbClient.queryObject(Initiator.class, iniUris);
for (Initiator ini : initiators) {
if (ini == null || ini.getInitiatorPort() == null) {
continue;
}
ports.add(Initiator.normalizePort(ini.getInitiatorPort()));
}
}
if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
for (String initStr : exportMask.getExistingInitiators()) {
ports.add(initStr);
}
}
return ports;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getAllLUNsForHost.
/**
* Get all LUNs on the array that mapped to a host identified by initiators in the mask
*
* @param dbClient
* @param exportMask
* @return LUNs mapped to the host
*/
public static Set<String> getAllLUNsForHost(DbClient dbClient, ExportMask exportMask) {
Set<String> lunIds = new HashSet<>();
URI storageUri = exportMask.getStorageDevice();
if (NullColumnValueGetter.isNullURI(storageUri)) {
return lunIds;
}
URI hostUri = null;
for (String init : exportMask.getInitiators()) {
Initiator initiator = dbClient.queryObject(Initiator.class, URI.create(init));
if (initiator != null && !initiator.getInactive()) {
hostUri = initiator.getHost();
if (!NullColumnValueGetter.isNullURI(hostUri)) {
break;
}
}
}
// get initiators from host
Map<URI, ExportMask> exportMasks = new HashMap<>();
if (!NullColumnValueGetter.isNullURI(hostUri)) {
URIQueryResultList list = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getContainedObjectsConstraint(hostUri, Initiator.class, "host"), list);
Iterator<URI> uriIter = list.iterator();
while (uriIter.hasNext()) {
URI initiatorId = uriIter.next();
URIQueryResultList egUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiatorId.toString()), egUris);
ExportGroup exportGroup = null;
for (URI egUri : egUris) {
exportGroup = dbClient.queryObject(ExportGroup.class, egUri);
if (exportGroup == null || exportGroup.getInactive() || exportGroup.getExportMasks() == null) {
continue;
}
List<ExportMask> masks = ExportMaskUtils.getExportMasks(dbClient, exportGroup);
for (ExportMask mask : masks) {
if (mask != null && !mask.getInactive() && mask.hasInitiator(initiatorId.toString()) && mask.getVolumes() != null && storageUri.equals(mask.getStorageDevice())) {
exportMasks.put(mask.getId(), mask);
}
}
}
}
}
for (ExportMask mask : exportMasks.values()) {
StringMap volumeMap = mask.getVolumes();
if (volumeMap != null && !volumeMap.isEmpty()) {
for (String strUri : mask.getVolumes().keySet()) {
BlockObject bo = BlockObject.fetch(dbClient, URI.create(strUri));
if (bo != null && !bo.getInactive()) {
lunIds.add(bo.getNativeId());
}
}
}
}
return lunIds;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method cleanStaleExportMasks.
/**
* Method to clean ExportMask stale instances from ViPR db if any stale EM available.
*
* @param storage the storage
* @param maskNamesFromArray Mask Names collected from Array for the set of initiator names
* @param initiatorNames initiator names
* @param dbClient
*/
public static void cleanStaleExportMasks(StorageSystem storage, Set<String> maskNamesFromArray, List<String> initiatorNames, DbClient dbClient) {
Set<Initiator> initiators = ExportUtils.getInitiators(initiatorNames, dbClient);
Set<ExportMask> staleExportMasks = new HashSet<>();
_log.info("Mask Names found in array:{} for the initiators: {}", maskNamesFromArray, initiatorNames);
for (Initiator initiator : initiators) {
URIQueryResultList emUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskInitiatorConstraint(initiator.getId().toString()), emUris);
ExportMask exportMask = null;
for (URI emUri : emUris) {
_log.debug("Export Mask URI :{}", emUri);
exportMask = dbClient.queryObject(ExportMask.class, emUri);
if (exportMask != null && !exportMask.getInactive() && storage.getId().equals(exportMask.getStorageDevice())) {
if (!maskNamesFromArray.contains(exportMask.getMaskName())) {
_log.info("Export Mask {} is not found in array", exportMask.getMaskName());
List<ExportGroup> egList = ExportUtils.getExportGroupsForMask(exportMask.getId(), dbClient);
if (CollectionUtils.isEmpty(egList)) {
_log.info("Found a stale export mask {} - {} and it can be removed from DB", exportMask.getId(), exportMask.getMaskName());
staleExportMasks.add(exportMask);
} else {
_log.info("Export mask is having association with ExportGroup {}", egList);
}
}
}
}
}
if (!CollectionUtils.isEmpty(staleExportMasks)) {
dbClient.markForDeletion(staleExportMasks);
_log.info("Deleted {} stale export masks from DB", staleExportMasks.size());
}
_log.info("Export Mask cleanup activity done");
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getExportMaskAllInitiators.
/**
* Fetches and returns the initiators for an export mask. If the ExportMask's
* existing initiators are set, they will also be returned if an instance can
* be found in ViPR for the given initiator port id.
*
* @param exportMask the export mask
* @param dbClient an instance of {@link DbClient}
* @return a list of active initiators in the export mask
*/
public static List<URI> getExportMaskAllInitiators(ExportMask exportMask, DbClient dbClient) {
List<URI> initiators = new ArrayList<URI>();
if (exportMask.getInitiators() != null && !exportMask.getInitiators().isEmpty()) {
initiators.addAll(StringSetUtil.stringSetToUriList(exportMask.getInitiators()));
}
if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
for (String initStr : exportMask.getExistingInitiators()) {
initStr = Initiator.toPortNetworkId(initStr);
Initiator init = getInitiator(initStr, dbClient);
if (init != null && !initiators.contains(init.getId())) {
initiators.add(init.getId());
}
}
}
return initiators;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getExportMaskExistingInitiators.
/**
* A utility function method to get the user-created initiators from an export mask.
* If an initiator is not found for a given user-created WWN, it is simply
* ignored and no error is raised.
*
* @param exportMask the export mask
* @param dbClient an instance of DbClient
* @return a list of Initiators
*/
public static List<Initiator> getExportMaskExistingInitiators(ExportMask exportMask, DbClient dbClient) {
List<Initiator> initiators = new ArrayList<Initiator>();
Initiator initiator = null;
if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
for (String initStr : exportMask.getExistingInitiators()) {
initStr = Initiator.toPortNetworkId(initStr);
initiator = getInitiator(initStr, dbClient);
if (initiator != null) {
initiators.add(initiator);
}
}
}
return initiators;
}
Aggregations