use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportService method processAttachRequest.
private boolean processAttachRequest(Volume vol, VolumeActionRequest.AttachVolume attach, String openstack_tenant_id, String protocol) throws InterruptedException {
_log.info("Attach request");
Map<URI, Integer> volumeMap = new HashMap<URI, Integer>();
List<URI> initiatorURIs = new ArrayList<URI>();
String task = UUID.randomUUID().toString();
// Step 1: get list of host initiators to be added
_log.debug("THE ATTACH.CONNECTOR IS {}", attach.connector.toString());
List<Initiator> newInitiators = getListOfInitiators(attach.connector, openstack_tenant_id, protocol, vol);
ExportGroup exportGroup = findExportGroup(vol);
Set<URI> addedClusters = new HashSet<>();
Set<URI> removedClusters = new HashSet<>();
Set<URI> addedHosts = new HashSet<>();
Set<URI> removedHosts = new HashSet<>();
Set<URI> addedInitiators = new HashSet<>();
Set<URI> removedInitiators = new HashSet<>();
if (exportGroup != null) {
// export group exists, we need to add the initiators to it.
volumeMap = StringMapUtil.stringMapToVolumeMap(exportGroup.getVolumes());
initiatorURIs = StringSetUtil.stringSetToUriList(exportGroup.getInitiators());
for (Initiator initiator : newInitiators) {
URI uri = initiator.getId();
if (!initiatorURIs.contains(uri)) {
addedInitiators.add(uri);
}
}
_log.info("updateExportGroup request is submitted.");
// get block controller
initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.UPDATE_EXPORT_GROUP);
BlockExportController exportController = getController(BlockExportController.class, BlockExportController.EXPORT);
// Now update export group
Map<URI, Integer> noUpdatesVolumeMap = new HashMap<URI, Integer>();
exportController.exportGroupUpdate(exportGroup.getId(), noUpdatesVolumeMap, noUpdatesVolumeMap, addedClusters, removedClusters, addedHosts, removedHosts, addedInitiators, removedInitiators, task);
} else {
// Create a new export group with the given list of initiators
String name = "eg-" + vol.getLabel();
exportGroup = createNewGroup(newInitiators, openstack_tenant_id, name);
exportGroup.setVirtualArray(vol.getVirtualArray());
// put volume map
volumeMap.put(vol.getId(), ExportGroup.LUN_UNASSIGNED);
exportGroup.addVolume(vol.getId(), ExportGroup.LUN_UNASSIGNED);
// put list of initiators
for (Initiator initiator : newInitiators) {
initiatorURIs.add(initiator.getId());
}
exportGroup.setInitiators(StringSetUtil.uriListToStringSet(initiatorURIs));
_dbClient.createObject(exportGroup);
_log.info("createExportGroup request is submitted.");
initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.CREATE_EXPORT_GROUP);
// get block controller
BlockExportController exportController = getController(BlockExportController.class, BlockExportController.EXPORT);
// Now create export group
exportController.exportGroupCreate(exportGroup.getId(), volumeMap, initiatorURIs, task);
}
boolean bTaskComplete = waitForTaskCompletion(exportGroup.getId(), task);
return bTaskComplete;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getBlockObjectInitiatorTargets.
/**
* Returns initiators-to-target-storage-ports pairing for all initiators to which
* the block object (volume or snapshot) was exported.
*
* @param id the URN of a ViPR block object
* @param dbClient dbClient an instance of {@link DbClient}
* @param idEmbeddedInURL
* @return initiators-to-target-storage-ports pairing for all initiators to which
* the block object (volume or snapshot) was exported.
*/
public static ITLRestRepList getBlockObjectInitiatorTargets(URI id, DbClient dbClient, boolean idEmbeddedInURL) {
BlockObject blockObject = getBlockObject(id, dbClient);
ArgValidator.checkEntityNotNull(blockObject, id, idEmbeddedInURL);
ITLRestRepList list = new ITLRestRepList();
Map<ExportMask, List<ExportGroup>> exportMasks = getBlockObjectExportMasks(blockObject, dbClient);
Collection<Initiator> initiators = null;
List<StoragePort> ports = null;
List<StoragePort> initiatorPorts = null;
BlockObject bo = Volume.fetchExportMaskBlockObject(dbClient, blockObject.getId());
if (bo != null) {
Map<StoragePort, List<FCZoneReference>> zoneRefs = null;
for (ExportMask exportMask : exportMasks.keySet()) {
// now process the initiators - Every initiator must see the volume
initiators = getInitiators(exportMask, dbClient);
_log.debug("Found {} initiators in export mask {}", initiators.size(), exportMask.getMaskName());
ports = getStoragePorts(exportMask, dbClient);
_log.debug("Found {} storage ports in export mask {}", ports.size(), exportMask.getMaskName());
String hlu = exportMask.getVolumes().get(bo.getId().toString());
_log.debug("Start pairing initiators and targets in export mask {}.", exportMask.getMaskName());
for (Initiator initiator : initiators) {
initiatorPorts = getInitiatorPorts(exportMask, initiator, ports, dbClient);
zoneRefs = getInitiatorsZoneReferencesForBlockObject(initiator, initiatorPorts, bo, dbClient);
list.getExportList().addAll(getItlsForMaskInitiator(dbClient, exportMasks.get(exportMask), exportMask, initiator, hlu, blockObject, initiatorPorts, zoneRefs));
}
}
}
_log.info("{} ITLs were found for block object {}.", list.getExportList().size(), blockObject.getLabel());
return list;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getInitiators.
/**
* 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
*/
private static Collection<Initiator> getInitiators(ExportMask exportMask, DbClient dbClient) {
Map<String, Initiator> initiators = new HashMap<String, Initiator>();
Initiator initiator = null;
if (exportMask.getInitiators() != null) {
for (String initUri : exportMask.getInitiators()) {
initiator = dbClient.queryObject(Initiator.class, URI.create(initUri));
if (initiator != null && !initiator.getInactive()) {
initiators.put(initiator.getInitiatorPort(), initiator);
}
}
}
if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
for (String initStr : exportMask.getExistingInitiators()) {
if (!initiators.containsKey(initStr)) {
initStr = Initiator.toPortNetworkId(initStr);
Initiator init = getInitiator(initStr, dbClient);
if (init != null) {
initiators.put(initStr, init);
}
}
}
}
return initiators.values();
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method getInitiatorsItls.
/**
* For each initiator in the list, return all the volumes and snapshots that
* have been exported to it together with the target ports and zone name when
* zoning has been performed.
*
* @param networkPorts a list of initiator WWNs or IQNs
* @param dbClient dbClient an instance of {@link DbClient}
* @param permissionsHelper an instance of {@link PermissionsHelper}
* @param user a pointer to the logged in user
* @return all the volumes and snapshots that have been exported to the
* initiators together with the target ports and zone name when
* zoning has been performed.
*/
public static ITLRestRepList getInitiatorsItls(List<String> networkPorts, DbClient dbClient, PermissionsHelper permissionsHelper, StorageOSUser user) throws DatabaseException {
ITLRestRepList list = new ITLRestRepList();
List<String> invalidNetworkPorts = new ArrayList<String>();
Map<String, Initiator> initiators = new HashMap<String, Initiator>();
// get the initiators
for (String networkPort : networkPorts) {
Initiator initiator = null;
if (initiators.containsKey(networkPort)) {
continue;
}
initiator = getInitiator(networkPort, dbClient);
if (initiator == null) {
invalidNetworkPorts.add(networkPort);
} else {
initiators.put(networkPort, initiator);
}
}
// check all the initiators exist and are active
if (!invalidNetworkPorts.isEmpty()) {
_log.warn("Could not find active initiator for the following initiator ports {}", invalidNetworkPorts);
}
for (Initiator initiator : initiators.values()) {
list.getExportList().addAll(getItlsForInitiator(initiator, dbClient, permissionsHelper, user).getExportList());
}
_log.info("{} ITLs were found for the request.", list.getExportList().size());
return list;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class VirtualArrayService method getVarraysForHost.
/**
* Return the Virtual Arrays connected to a given Host
* by checking the connectivity of the Host's Initiators.
*
* @param hostUri URI of a Host
* @return a set of Virtual Array URI strings
*/
private Set<String> getVarraysForHost(URI hostUri) {
_log.info("looking for initiators for host URI: " + hostUri);
Set<String> varrayIds = new HashSet<String>();
Set<String> initiatorList = new HashSet<String>();
List<NamedElementQueryResultList.NamedElement> dataObjects = listChildren(hostUri, Initiator.class, "iniport", "host");
for (NamedElementQueryResultList.NamedElement dataObject : dataObjects) {
initiatorList.add(dataObject.getId().toString());
}
for (String initUri : initiatorList) {
Initiator init = _dbClient.queryObject(Initiator.class, URI.create(initUri));
if (null != init) {
_log.info(" found initiator " + init.getInitiatorPort());
varrayIds.addAll(ConnectivityUtil.getInitiatorVarrays(init.getInitiatorPort(), _dbClient));
_log.info(" connected to varrays: " + varrayIds.toString());
}
}
return varrayIds;
}
Aggregations