use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.
the class NetworkDeviceController method addSanZones.
@Override
public void addSanZones(URI uri, String fabricId, String fabricWwn, List<Zone> zones, boolean activateZones, String taskId) throws ControllerException {
NetworkSystem device = getNetworkSystemObject(uri);
// Lock to prevent concurrent operations on the same VSAN / FABRIC.
InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
try {
// Get the file device reference for the type of file device managed
// by the controller.
NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.addSanZonesFailedNull(device.getSystemType());
}
BiosCommandResult result = networkDevice.addZones(device, zones, fabricId, fabricWwn, activateZones);
setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ADD_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL());
} catch (Exception ex) {
ServiceError serviceError = NetworkDeviceControllerException.errors.addSanZonesFailedExc(device.getSystemType(), ex);
_dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
} finally {
NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
}
}
use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.
the class NetworkDiscoveryWorker method updatePhysicalInventory.
/**
* Update the network system physical inventory and creates/updates the discovered FC transport
* zones as needed. The physical inventory is primarily the FCEndpoints (FCPortConnections),
* which contains a record for each endpoint logged into the Fiber Channel Nameserver database.
* The endpoints per fabric (vsan) constitute an FC transport zone which get created/updated
* based on the FCEndpoints discovered.
*
* @param uri - Device URI
*/
public void updatePhysicalInventory(URI uri) throws ControllerException {
// Retrieve the storage device info from the database.
long start = System.currentTimeMillis();
NetworkSystem networkDev = getDeviceObject(uri);
String msg = "unknown status";
NetworkSystemDevice networkDevice = getDevice();
if (networkDevice == null) {
throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedNull(uri.toString(), networkDev.getSystemType());
}
try {
// === Reconcile the FCEndpoints of this device ===
List<FCEndpoint> currentConnections = new ArrayList<FCEndpoint>();
// IN/OUT parameter to get the routed endpoints map - Fabric-WWN-to-endpoints-WWN
Map<String, Set<String>> routedEndpoints = new HashMap<String, Set<String>>();
try {
currentConnections = networkDevice.getPortConnections(networkDev, routedEndpoints);
msg = MessageFormat.format("Retrieved {0} connections from device {1} at {2}", new Integer(currentConnections.size()), uri, new Date());
_log.info(msg);
} catch (Exception e) {
msg = MessageFormat.format("Discovery failed getting port connections for Network System : {0}", uri.toString());
throw (e);
}
try {
reconcileFCEndpoints(networkDev, currentConnections);
} catch (Exception e) {
msg = MessageFormat.format("Discovery failed reconciling FC endpoints for Network System : {0}", uri.toString());
throw (e);
}
// ==== Reconcile the discovered transport zones ======
try {
reconcileTransportZones(networkDev, routedEndpoints);
} catch (Exception e) {
msg = MessageFormat.format("Discovery failed reconciling networks for Network System : {0}", uri.toString());
throw (e);
}
try {
networkDev.setUptime(networkDevice.getUptime(networkDev));
} catch (Exception e) {
msg = MessageFormat.format("Discovery failed setting version/uptime for Network System : {0}", uri.toString());
throw (e);
}
// discovery succeeds
msg = MessageFormat.format("Discovery completed successfully for Network System : {0}", uri.toString());
} catch (Exception ex) {
Date date = new Date();
throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedExc(uri.toString(), date.toString(), ex);
} finally {
if (networkDev != null) {
try {
// set detailed message
networkDev.setLastDiscoveryStatusMessage(msg);
dbClient.updateObject(networkDev);
_log.info("Discovery took {}", (System.currentTimeMillis() - start));
} catch (DatabaseException ex) {
_log.error("Error while persisting object to DB", ex);
}
}
}
}
use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.
the class NetworkScheduler method getZoningNetworkSystems.
/**
* Finds all the network systems that have access to the initiators and '
* storage port networks. When the initiators and storage port are in
* different networks that are routed to each other, the assumption is that
* there should exist and network system that can be used to managed both
* networks.
*
* @param iniNetwork the initiator network
* @param portNetwork the storage port network
* @return the network systems that can be used to managed the port and initiator
* networks.
*/
List<NetworkSystem> getZoningNetworkSystems(NetworkLite iniNetwork, NetworkLite portNetwork) {
List<NetworkSystem> orderedNetworkSystems = new ArrayList<NetworkSystem>();
List<NetworkSystem> hostNetworkSystems = getOrderedNetworkSystems(iniNetwork);
List<NetworkSystem> arrayNetworkSystems = getOrderedNetworkSystems(portNetwork);
NetworkSystem hostSwitch = null;
if (!hostNetworkSystems.isEmpty()) {
orderedNetworkSystems.add(hostNetworkSystems.get(0));
hostSwitch = hostNetworkSystems.get(0);
_log.info("Host Network System : " + hostSwitch.getNativeGuid());
}
if (!arrayNetworkSystems.isEmpty()) {
for (NetworkSystem arraySwitch : arrayNetworkSystems) {
if (!arraySwitch.getId().equals(hostSwitch.getId())) {
orderedNetworkSystems.add(arraySwitch);
_log.info("Array Network System: " + arraySwitch.getNativeGuid());
break;
}
}
}
return orderedNetworkSystems;
}
use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.
the class NetworkScheduler method getOrderedNetworkSystems.
/**
* Finds all the network systems that have access to the specified network.
*
* @param network the network
* @return the network systems that can be used to manage the specified
* network.
*/
private List<NetworkSystem> getOrderedNetworkSystems(NetworkLite network) {
List<URI> netSysIds = (network == null) ? new ArrayList<URI>() : StringSetUtil.stringSetToUriList(new StringSet(network.getNetworkSystems()));
List<NetworkSystem> idleNetworkSystems = new ArrayList<NetworkSystem>();
List<NetworkSystem> deRegisteredNetworkSystems = new ArrayList<NetworkSystem>();
List<NetworkSystem> orderedNetworkSystems = new ArrayList<NetworkSystem>();
if (!netSysIds.isEmpty()) {
orderedNetworkSystems = _dbClient.queryObject(NetworkSystem.class, netSysIds, true);
if (!orderedNetworkSystems.isEmpty()) {
for (NetworkSystem networkSystem : orderedNetworkSystems) {
if (networkSystem.getRegistrationStatus().equals(RegistrationStatus.UNREGISTERED.toString())) {
_log.info("Network System {} is not used as it is not registered.", networkSystem.getLabel());
deRegisteredNetworkSystems.add(networkSystem);
} else if (networkSystem.getDiscoveryStatus().equals(DataCollectionJobStatus.ERROR.toString()) || networkSystem.getDiscoveryStatus().equals(DataCollectionJobStatus.CREATED.toString())) {
_log.info("Network System {} is moved to the end of Network System list as its discovery is not successful.", networkSystem.getLabel());
idleNetworkSystems.add(networkSystem);
}
}
orderedNetworkSystems.removeAll(deRegisteredNetworkSystems);
orderedNetworkSystems.removeAll(idleNetworkSystems);
Collections.shuffle(orderedNetworkSystems);
Collections.shuffle(idleNetworkSystems);
orderedNetworkSystems.addAll(idleNetworkSystems);
} else {
_log.warn("Could not find any active network systems that can be used to zone.");
}
} else {
_log.warn("Could not find any network systems that can be used to zone.");
}
return orderedNetworkSystems;
}
use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.
the class NetworkScheduler method placeZones.
/**
* Select the network device and VSAN or Brocade Fabric for the host/volume zoning.
*
* The selection is based on the end points (initiator and storage port) and
* the availability of a network device that has ports connections to both
* end points. If a fabric can't be identified with both endpoints, we fall back to
* looking for a fabric with at least the storagePort discovered.
*
* @param exportGroupUri Export Group URI
* @param varrayUri Virtual Array URI
* @param protocol String (FC for this to do anything)
* @param initiatorPort The WWN of the initiator
* @param storagePort The StoragePort object
* @param hostName Used for generating the zone name.
* @param existingZones a list of existing zones for the initiator
* @param checkZones Flag to enable or disable zoning check on a Network System
*
* @return NetworkFabricInfo configured for adding zones
*/
private NetworkFCZoneInfo placeZones(URI exportGroupUri, URI varrayUri, String protocol, String initiatorPort, StoragePort storagePort, String hostName, List<Zone> existingZones, boolean checkZones) throws DeviceControllerException {
initiatorPort = formatWWN(initiatorPort);
String storagePortWwn = formatWWN(storagePort.getPortNetworkId());
if (Transport.FC != StorageProtocol.block2Transport(protocol)) {
return null;
}
_log.info("Placing a zone for initiator {} and port {}", initiatorPort, storagePortWwn);
// do some validation
NetworkLite iniNet = NetworkUtil.getEndpointNetworkLite(initiatorPort, _dbClient);
NetworkLite portNet = getStoragePortNetwork(storagePort);
if (iniNet == null || portNet == null || !NetworkUtil.checkInitiatorAndPortConnected(iniNet, portNet)) {
_log.debug(String.format("Initiator %s could not be paired with port %s", initiatorPort, storagePortWwn));
return null;
}
// False we will use the existing FCZoneReference info
if (!checkZones) {
_log.debug("Check Zones flag is false. Finding FCZoneReference for initiator {} and port {}", initiatorPort, storagePortWwn);
// Find the FCZoneReference in ViPR for the port-initiator key and the network
String key = FCZoneReference.makeEndpointsKey(initiatorPort, storagePortWwn);
List<FCZoneReference> fcZoneRefs = getFCZoneReferencesForKey(key);
FCZoneReference refTemplate = DataObjectUtils.findByProperty(fcZoneRefs, "groupUri", exportGroupUri);
if (refTemplate != null) {
_log.info("Already existing FCZoneReferences for initiator {} and port {} will be replicated for new volumes.", initiatorPort, storagePortWwn);
return createZoneInfoForRef(refTemplate, null, initiatorPort, storagePortWwn, NetworkUtil.getEndpointNetworkLite(initiatorPort, _dbClient), exportGroupUri);
} else {
_log.info("FCZoneReferences doesnt exist for initiator {} and port {} for replication.", initiatorPort, storagePortWwn);
return null;
}
} else {
_log.debug("Check Zones flag is false. Placing a zone for initiator {} and port {}", initiatorPort, storagePortWwn);
// If the zone already exists, just return its reference
NetworkFCZoneInfo zoneInfo = getZoneInfoForExistingZone(iniNet, initiatorPort, storagePort.getPortNetworkId(), existingZones);
if (zoneInfo != null) {
zoneInfo.setExportGroup(exportGroupUri);
_log.info("Already existing zone {} for initiator {} and port {} will be used.", new Object[] { zoneInfo.getZoneName(), initiatorPort, storagePortWwn });
return zoneInfo;
}
_log.debug("Could not find an existing zone for initiator {} and port {} to use." + "A new zone will be created.", new Object[] { initiatorPort, storagePortWwn });
// Create a the list of end points -
List<String> endPoints = Arrays.asList(new String[] { initiatorPort, storagePortWwn });
List<NetworkSystem> networkSystems = getZoningNetworkSystems(iniNet, portNet);
if (networkSystems.isEmpty()) {
_log.info(String.format("Could not find a network system with connection to storage port %s", storagePortWwn));
throw DeviceControllerException.exceptions.cannotFindSwitchConnectionToStoragePort(storagePortWwn);
}
// 2. Select the network system to use
NetworkSystem networkSystem = networkSystems.get(0);
// 3. identify an alternate network device, if any
_log.debug("Network system {} was selected to be the primary network system. " + "Trying to select an alternate network system.", networkSystem.getNativeGuid());
NetworkSystem altNetworkSystem = networkSystem;
for (NetworkSystem system : networkSystems) {
if (altNetworkSystem != system) {
altNetworkSystem = system;
_log.debug("Network system {} was selected to be the alternate network system.", altNetworkSystem.getNativeGuid());
break;
}
}
// 4. create the response
NetworkFCZoneInfo networkFabricInfo = null;
if (networkSystem != null) {
networkFabricInfo = new NetworkFCZoneInfo(networkSystem.getId(), iniNet.getNativeId(), NetworkUtil.getNetworkWwn(iniNet));
networkFabricInfo.getEndPoints().addAll(endPoints);
networkFabricInfo.setAltNetworkDeviceId(URI.create(altNetworkSystem.getId().toString()));
networkFabricInfo.setExportGroup(exportGroupUri);
networkFabricInfo.setCanBeRolledBack(false);
nameZone(networkFabricInfo, networkSystem.getSystemType(), hostName, initiatorPort, storagePort, !portNet.equals(iniNet));
}
return networkFabricInfo;
}
}
Aggregations