use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.
the class NetworkScheduler method selectExistingZoneForInitiatorPort.
/**
* Search the list of existing zones for the initiator-port pair to decide which to use.
* Preference is given to zones according to this priority:
* <ol>
* <li>The zone is in ViPR DB and was created by ViPR</li>
* <li>The zone is in ViPR DB but was not created by ViPR</li>
* <li>The zone follows the single initiator-target pair per zone</li>
* <li>The last zone in the list</li>
* </ol>
* If no zone can be found for the initiator-port pair, null is returned.
*
* @param network the network of the initiator
* @param initiatorWwn the initiator WWN
* @param portWwn the target WWN
* @param existingZones a list of zones found on the network system for the initiator
* @return an instance of Zone if one is found, otherwise null.
*/
public Zone selectExistingZoneForInitiatorPort(NetworkLite network, String initiatorWwn, String portWwn, List<Zone> existingZones) {
// If we did not find zones, we need to create zones even if we have FCZoneReference
if (existingZones == null || existingZones.isEmpty()) {
return null;
}
// initialize variables
boolean existingZone = true;
Zone foundZone = null;
// Find the FCZoneReference in ViPR for the port-initiator key and the network
String key = FCZoneReference.makeEndpointsKey(initiatorWwn, portWwn);
List<FCZoneReference> fcZoneRefs = getFCZoneReferencesForKey(key);
if (!fcZoneRefs.isEmpty()) {
Zone matchedZone = null;
_log.info("Found {} FCZoneReference for key {}", fcZoneRefs.size(), key);
// try to re-use zones known to ViPR as a first preference
for (FCZoneReference fcZoneRef : fcZoneRefs) {
// make sure the FCZoneReference matches the network and its network system a
if (network.getNetworkSystems().contains(fcZoneRef.getNetworkSystemUri().toString()) && network.getNativeId().equals(fcZoneRef.getFabricId())) {
_log.debug("Found an FCZoneReference for zone {}", fcZoneRef.getZoneName());
// do still have the zone on the network system
matchedZone = findZoneByNameAndPort(fcZoneRef.getZoneName(), portWwn, existingZones);
if (matchedZone != null) {
_log.debug("Found the zone for FCZoneReference {} in the initiator existing zones", fcZoneRef.getZoneName());
_log.debug(matchedZone.getLogString());
foundZone = matchedZone;
// if the zone was created by ViPR, the search ended
if (!fcZoneRef.getExistingZone()) {
existingZone = false;
_log.debug("Selected zone {} because it was created by ViPR", foundZone.getName());
break;
}
}
}
}
}
if (foundZone != null) {
_log.debug("Selected existing Zone {} as it is already used by ViPR", foundZone.getName());
} else {
outer: for (Zone curZone : existingZones) {
for (ZoneMember member : curZone.getMembers()) {
if (member.getAddress() != null && member.getAddress().equals(portWwn)) {
foundZone = curZone;
if (curZone.getMembers().size() == 2) {
// if the zone has only 2 members, the search ended
_log.debug("Selected existing Zone {} as it has only 2 members", foundZone.getName());
break outer;
}
}
}
}
}
if (foundZone != null) {
foundZone.setExistingZone(existingZone);
}
return foundZone;
}
use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getZoneAliases.
/**
* Get the zone aliases in the zone.
*
* @param client instance of WBEMClient
* @param path the zone path
* @return the list of aliases by name and WWN (assuming only 1 member in an alias)
*/
public List<ZoneMember> getZoneAliases(WBEMClient client, CIMObjectPath path) {
List<ZoneMember> members = new ArrayList<ZoneMember>();
CloseableIterator<CIMInstance> zoneItr = null;
CIMInstance ins;
try {
String name = getPropertyValueFromInstanceId(path, SmisConstants.CP_NSNAME);
String fabric = getPropertyValueFromInstanceId(path, SmisConstants.CP_FABRIC);
// for some reason, zone aliases can be obtained from inactive zones only
path = getZonePath(name, fabric, false);
zoneItr = client.associatorInstances(path, _Brocade_ZoneAliasInZone, _Brocade_ZoneAlias, null, null, false, null);
while (zoneItr.hasNext()) {
ins = zoneItr.next();
members.addAll(getZoneOrAliasMembers(client, ins.getObjectPath(), true));
}
} catch (Exception ex) {
// Do not fail because of problem getting aliases
_log.info("Failed to get aliases for zone " + path.getObjectName() + " with error: " + ex.getMessage());
} finally {
if (zoneItr != null) {
zoneItr.close();
}
}
return members;
}
use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method getAllZonesForZones.
/**
* For a list of zones requested by clients, check is routing is needed and created
* the required zone to support both use cases: switched and routed endpoints. For
* switched endpoints the same list of zone is returned. For routed endpoints,
* for each zone in the primary fabrics, an identical zone in the target fabrics
* will also be created.
*
* @param zones the zones to be created or deleted.
*
* @return a map of zones to be created grouped by fabric. When the zone members
* are in different fabrics (i.e. routed), there will be a zone to create in each
* member's fabric
*/
private Map<NetworkLite, List<Zone>> getAllZonesForZones(List<Zone> zones, boolean delete, String fabricId, String fabricWwn) {
Map<NetworkLite, List<Zone>> allZones = new HashMap<NetworkLite, List<Zone>>();
// or two networks that are routed to each other
for (Zone zone : zones) {
Map<ZoneMember, NetworkLite> epNetworks = getEndpointNetworks(zone, fabricId, fabricWwn);
if (!epNetworks.isEmpty()) {
Set<NetworkLite> networks = new HashSet<NetworkLite>(epNetworks.values());
if (networks.size() == 2) {
// need to create zone for
// ensure the other members can be routed as well
NetworkLite network = networks.iterator().next();
for (ZoneMember member : epNetworks.keySet()) {
if (network.getId().equals(epNetworks.get(member).getId()) || (network.hasRoutedNetworks(epNetworks.get(member).getId()))) {
_log.info("Verified zone {} endpoints are connected", zone.getName());
} else {
if (!delete) {
// only error on create. For delete, always try.
_log.info("Cannot create zone {} because the member are found to be not connected", zone.getName());
throw NetworkDeviceControllerException.exceptions.zoneEndpointsNotConnected(zone.getName());
}
}
}
// zones, the zone may not be properly named.
if (!delete) {
if (zone.getName() != null && !zone.getName().toLowerCase().startsWith("lsan_")) {
String name = "lsan_" + (zone.getName() == null ? "" : zone.getName());
if (name.length() > ZONE_NAME_MAX_LENGTH) {
name = name.substring(0, ZONE_NAME_MAX_LENGTH - 1);
}
zone.setName(name);
}
}
}
for (NetworkLite network : networks) {
List<Zone> netZones = allZones.get(network);
if (netZones == null) {
netZones = new ArrayList<Zone>();
allZones.put(network, netZones);
}
netZones.add(zone);
}
} else if (delete) {
// if delete zone does not have member or member that are not in end point list
// include them anyway for deletion
NetworkLite networkLite = NetworkUtil.getNetworkLiteByFabricId(fabricId, fabricWwn, _dbClient);
if (networkLite != null) {
List<Zone> zoneList = allZones.get(networkLite);
if (zoneList == null) {
zoneList = new ArrayList<Zone>();
allZones.put(networkLite, zoneList);
}
zoneList.add(zone);
}
}
}
return allZones;
}
use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method checkAndUpdateZone.
/**
* Add and remove members from/to a zone. This function will not fail if
* a member to be removed is not in the zone or if a member that will be
* added is already in the zone.
* <p>
* A member of type alias can be remove using its alias or its WWN.
* <p>
* If the zone already has the WWN of an alias and now the user is trying to add the alias into the zone, the alias will not be added.
* The WWN has to be removed first.
* <p>
* Replacing a WWN with its alias should be possible in a single call by specifying the WWN in the remove list and alias in the add
* list.
* <p>
* Note this function will delete the zone if the zone has no remaining members.
*
* @param client an instance of WBEMClient
* @param zoneServiceIns an instance of ZoneService
* @param fabricId the fabric name or vsan id
* @param fabricWwn the fabric WWN
* @param zonesetPath CIM path of the zoneset
* @param zonesInFabric a map of all zones in the zoneset
* @param zoneUpdate the changes to be made to the zone
* @return true if the update completed successfully.
*/
private boolean checkAndUpdateZone(WBEMClient client, CIMInstance zoneServiceIns, String fabricId, String fabricWwn, CIMObjectPath zonesetPath, Map<String, Zone> zonesInFabric, ZoneUpdate zoneUpdate) {
boolean success = false;
ZoneMember curMember = null;
try {
if (zonesInFabric.containsKey(zoneUpdate.getName())) {
_log.info("Start update zone {}", zoneUpdate.getName());
Zone zone = zonesInFabric.get(zoneUpdate.getName());
Map<String, ZoneMember> members = getZoneMembersMap(client, zone.getName(), (CIMObjectPath) zone.getCimObjectPath());
// handle removed members
if (zoneUpdate.getRemoveZones() != null) {
for (ZoneMember remMember : zoneUpdate.getRemoveZones()) {
curMember = members.containsKey(remMember.getAlias()) ? members.get(remMember.getAlias()) : members.get(remMember.getAddress());
if (curMember != null && curMember.isAliasType() && !StringUtils.isEmpty(remMember.getAlias())) {
_log.info("Removing alia smember {}", remMember.getAlias());
_smisHelper.removeZoneOrAliasMember(client, (CIMObjectPath) curMember.getCimAliasPath(), (CIMObjectPath) zone.getCimObjectPath(), true);
members.remove(curMember.getAlias());
members.remove(curMember.getAddress());
success = true;
} else if (curMember != null && !curMember.isAliasType() && !StringUtils.isEmpty(remMember.getAddress())) {
_log.info("Removing WWN member {}", remMember.getAddress());
_smisHelper.removeZoneOrAliasMember(client, (CIMObjectPath) curMember.getCimObjectPath(), (CIMObjectPath) zone.getCimObjectPath(), false);
members.remove(curMember.getAlias());
members.remove(curMember.getAddress());
success = true;
} else {
_log.warn("Did not remove zone member with alias " + remMember.getAlias() + " and WWN " + remMember.getAddress() + " because it was not found.");
}
}
}
// handle added members
if (zoneUpdate.getAddZones() != null) {
for (ZoneMember addMember : zoneUpdate.getAddZones()) {
curMember = members.containsKey(addMember.getAlias()) ? members.get(addMember.getAlias()) : members.get(addMember.getAddress());
if (curMember == null) {
String name = addMember.hasAlias() ? addMember.getAlias() : addMember.getAddress();
_log.info("Adding zone member {} ", name);
_smisHelper.addZoneOrAliasMember(client, zoneServiceIns, fabricWwn, (CIMObjectPath) zone.getCimObjectPath(), name);
members.put(name, addMember);
success = true;
} else {
_log.warn("Did not add zone member with alias " + addMember.getAlias() + " and WWN " + addMember.getAddress() + " because it already exists.");
}
}
}
// check to see if the zone is now empty
if (members.isEmpty()) {
_log.error("Deleting Zone " + zoneUpdate.getName() + " because it is now empty.");
_smisHelper.removeZone(client, zone);
}
} else {
_log.error("Failed to update zones: " + zoneUpdate.getName() + ". The zone was not found in the active zoneset");
throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailedNotFound(zoneUpdate.getName());
}
} catch (WBEMException ex) {
_log.error("Failed to update zone: " + zoneUpdate.getName() + ". Error message" + ex.getLocalizedMessage(), ex);
throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailed(ex);
}
return success;
}
use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.
the class NetworkSystemService method updateSanZones.
/**
* For given network system's fabric, update zones via add and/or remove their pwwns or aliases.
* This is an asynchronous call.
*
* @param updateSanZones A parameter structure listing the zone(s) to be added and their members.
* @param id the URN of a ViPR network system.
* @param fabricId The name of the VSAN or fabric as returned by /vdc/network-systems/{id}/san-fabrics
* or the VSAN or fabric WWN
* @prereq Updating zones must be exist in network system with given <code>id</code>
* @brief Update SAN zones details for network system VSAN or fabric
* @return A task description structure.
* @throws InternalException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics/{fabricId}/san-zones")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateSanZones(SanZoneUpdateParams updateSanZones, @PathParam("id") URI id, @PathParam("fabricId") String fabricId) throws InternalException {
String task = UUID.randomUUID().toString();
String fabricWwn = null;
if (WWNUtility.isValidWWN(fabricId)) {
fabricWwn = fabricId;
fabricId = fabricId.replaceAll(":", "");
}
ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
NetworkSystem device = queryResource(id);
List<ZoneUpdate> updateZones = new ArrayList<ZoneUpdate>();
for (SanZoneUpdateParam sz : updateSanZones.getUpdateZones()) {
ZoneUpdate updateZone = new ZoneUpdate(sz.getName());
validateZoneName(sz.getName(), device.getSystemType());
for (String szm : sz.getAddMembers()) {
if (StringUtils.isEmpty(szm)) {
continue;
}
ZoneMember member = createZoneMember(szm);
updateZone.getAddZones().add(member);
}
for (String szm : sz.getRemoveMembers()) {
if (StringUtils.isEmpty(szm)) {
continue;
}
ZoneMember member = createZoneMember(szm);
updateZone.getRemoveZones().add(member);
}
updateZones.add(updateZone);
auditOp(OperationTypeEnum.UPDATE_SAN_ZONE, true, AuditLogManager.AUDITOP_BEGIN, updateZone.getName(), device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
}
ArgValidator.checkFieldNotEmpty(updateZones, "zones");
Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.UPDATE_SAN_ZONE);
NetworkController controller = getNetworkController(device.getSystemType());
controller.updateSanZones(device.getId(), fabricId, fabricWwn, updateZones, false, task);
return toTask(device, task, op);
}
Aggregations