Search in sources :

Example 41 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkScheduler method unexportVolumes.

/**
 * Called from the unexportVolume call. and others. This method builds the NetworkFabricInfo to be passed to the
 * NetworkDeviceController for automatic unzoning.
 *
 * @param volUris Collection of URIs for volumes whose references are to be deleted
 * @param exportGroupUris List of URIs of all the export groups being processed that might contain the volumes.
 * @param storagePortUri the URI of the StoragePort
 * @param initiatorPort String WWPN with colons
 * @param hasExistingVolumes If true, will not mark a zone as last reference, keeping them from being deleted
 * @return List<NetworkFCZoneInfo> detailing zones to be removed or at least unreferenced
 * @throws IOException
 */
public List<NetworkFCZoneInfo> unexportVolumes(URI varrayURI, Collection<URI> volUris, List<URI> exportGroupUris, URI storagePortUri, String initiatorPort, boolean hasExistingVolumes) {
    List<NetworkFCZoneInfo> ourReferences = new ArrayList<NetworkFCZoneInfo>();
    VirtualArray virtualArray = _dbClient.queryObject(VirtualArray.class, varrayURI);
    if (virtualArray != null && virtualArray.getAutoSanZoning() == false) {
        _log.info("Automatic SAN zoning is disabled in virtual array: " + virtualArray.getLabel());
        return null;
    }
    initiatorPort = formatWWN(initiatorPort);
    // Get the StoragePort
    StoragePort port = null;
    try {
        port = _dbClient.queryObject(StoragePort.class, storagePortUri);
        if (port == null) {
            return null;
        }
    } catch (DatabaseException ex) {
        return null;
    }
    // See if we can find our zone references
    List<String> endPoints = new ArrayList<String>();
    endPoints.add(initiatorPort);
    endPoints.add(formatWWN(port.getPortNetworkId()));
    // Make the key for our endPoints
    String key = null;
    {
        NetworkFCZoneInfo fabricInfo = new NetworkFCZoneInfo();
        fabricInfo.setEndPoints(endPoints);
        key = fabricInfo.makeEndpointsKey();
    }
    // Create a map of the references keyed by volUri concatenated with export group URI.
    // This allows for multiple export groups to export the same volume, and the zone will not
    // be deleted until the volume's references are removed from all export groups.
    // Then we can tell if other volumes are using this.
    Map<String, FCZoneReference> volRefMap = makeExportToReferenceMap(key);
    // If there were no references at all, we don't do anything.
    if (volRefMap.isEmpty()) {
        return null;
    } else {
        // Do this for each of the Export Groups being processed.
        for (URI volUri : volUris) {
            for (URI exportGroupUri : exportGroupUris) {
                FCZoneReference ourReference = volRefMap.get(make2UriKey(volUri, exportGroupUri));
                if (ourReference == null) {
                    continue;
                }
                // We need a fabricInfo for each,
                // so as to remove the FCZoneReference that is keyed on volume/exportGroup.
                NetworkFCZoneInfo fabricInfo = createZoneInfoForRef(ourReference, volUri, initiatorPort, port.getPortNetworkId(), null, exportGroupUri);
                ourReferences.add(fabricInfo);
                volRefMap.remove(make2UriKey(volUri, exportGroupUri));
            }
        }
        // See if all the remaining entries have been marked for deletion.
        boolean live = false;
        for (FCZoneReference ref : volRefMap.values()) {
            if (ref.getInactive() == false) {
                // Here is an apparent live reference; look up the volume and make
                // sure it's still active too.
                BlockObject vol = BlockObject.fetch(_dbClient, ref.getVolumeUri());
                ExportGroup group = _dbClient.queryObject(ExportGroup.class, ref.getGroupUri());
                if (vol != null && vol.getInactive() == false && group != null && group.getInactive() == false) {
                    live = true;
                } else {
                    // mark the errant reference inactive
                    _dbClient.markForDeletion(ref);
                }
            }
        }
        // sets existingZone which will prohibit deletion.
        for (NetworkFCZoneInfo fabricInfo : ourReferences) {
            fabricInfo.setLastReference(!live);
            if (hasExistingVolumes) {
                fabricInfo.setExistingZone(true);
            }
            // Pick an alternate device, just in case
            NetworkLite portNet = getStoragePortNetwork(port);
            NetworkLite iniNet = BlockStorageScheduler.lookupNetworkLite(_dbClient, StorageProtocol.block2Transport("FC"), initiatorPort);
            List<NetworkSystem> networkSystems = getZoningNetworkSystems(iniNet, portNet);
            for (NetworkSystem ns : networkSystems) {
                if (!ns.getId().equals(fabricInfo.getNetworkDeviceId())) {
                    fabricInfo.setAltNetworkDeviceId(ns.getId());
                    break;
                }
            }
        }
        return ourReferences;
    }
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) NetworkLite(com.emc.storageos.util.NetworkLite) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 42 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkScheduler method nameZone.

/**
 * Generates a zoneName from the input parameters according to the CustomConfig handler.
 * @param arrayURI -- URI of StorageSystem
 * @param networkSystemURI -- URI of network system
 * @param initiatorPort -- Initiator port address
 * @param portNetworkAddress -- Port network address
 * @param fabricId -- Fabric id
 * @param lsanZone -- true if LSAN zone
 * @return -- zone name
 */
public String nameZone(URI arrayURI, URI networkSystemURI, String initiatorPort, String portNetworkAddress, String fabricId, boolean lsanZone) {
    StorageSystem array = _dbClient.queryObject(StorageSystem.class, arrayURI);
    NetworkSystem networkSystem = _dbClient.queryObject(NetworkSystem.class, networkSystemURI);
    Initiator initiator = NetworkUtil.findInitiatorInDB(initiatorPort, _dbClient);
    StoragePort port = NetworkUtil.getStoragePort(portNetworkAddress, _dbClient);
    String hostName = initiator.getHostName();
    if (array == null || initiator == null || hostName == null) {
        throw DeviceControllerException.exceptions.unexpectedCondition("Cannot generate zone name because array, initiator, or hostName were null");
    }
    DataSource dataSource = dataSourceFactory.createZoneNameDataSource(hostName, initiator, port, fabricId, array);
    if (array.getSystemType().equals(DiscoveredDataObject.Type.vplex.name())) {
        dataSource.addProperty(CustomConfigConstants.ARRAY_PORT_NAME, getVPlexPortName(port));
        dataSource.addProperty(CustomConfigConstants.ARRAY_SERIAL_NUMBER, getVPlexClusterSerialNumber(port));
    }
    String systemType = networkSystem.getSystemType();
    String resolvedZoneName = customConfigHandler.resolve(CustomConfigConstants.ZONE_MASK_NAME, systemType, dataSource);
    validateZoneNameLength(resolvedZoneName, lsanZone, systemType);
    String zoneName = customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.ZONE_MASK_NAME, systemType, dataSource);
    if (lsanZone && DiscoveredDataObject.Type.brocade.name().equals(systemType)) {
        zoneName = LSAN + zoneName;
    }
    return zoneName;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) DataSource(com.emc.storageos.customconfigcontroller.DataSource)

Example 43 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method activateSanZones.

/**
 * Activate current active zoneset of the given fabric specified on a network system.
 * This is an asynchronous call.
 *
 * @param sanZones 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 WWN of the VSAN or fabric
 * @prereq none
 * @brief Activate all zoning changes made since the last activation
 * @return A task description structure.
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics/{fabricId}/san-zones/activate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep activateSanZones(@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);
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.ACTIVATE_SAN_ZONE);
    auditOp(OperationTypeEnum.ACTIVATE_SAN_ZONE, true, AuditLogManager.AUDITOP_BEGIN, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
    NetworkController controller = getNetworkController(device.getSystemType());
    controller.activateSanZones(device.getId(), fabricId, fabricWwn, task);
    return toTask(device, task, op);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) Operation(com.emc.storageos.db.client.model.Operation) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 44 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method registerNetworkSystem.

/**
 * Register a network system.
 *
 * @param id the URN of a ViPR network system.
 *
 * @prereq none
 * @brief Register network system
 * @return A NetworkSystemRestRep reference specifying the data for the
 *         updated network system.
 * @throws ControllerException
 *
 * @throws IllegalArgumentException When the network system is already
 *             registered.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/register")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public NetworkSystemRestRep registerNetworkSystem(@PathParam("id") URI id) throws ControllerException {
    // Validate the network system.
    ArgValidator.checkUri(id);
    NetworkSystem networkSystem = _dbClient.queryObject(NetworkSystem.class, id);
    ArgValidator.checkEntity(networkSystem, id, isIdEmbeddedInURL(id));
    // If not already registered, register it now.
    if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(networkSystem.getRegistrationStatus())) {
        // Register all Networks for this system.
        List<Network> networkList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Network.class, AlternateIdConstraint.Factory.getConstraint(Network.class, "networkSystems", networkSystem.getId().toString()));
        for (Network network : networkList) {
            if (network.getInactive() || DiscoveredDataObject.RegistrationStatus.REGISTERED.toString().equals(network.getRegistrationStatus())) {
                continue;
            }
            network.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
            _dbClient.updateObject(network);
            auditOp(OperationTypeEnum.REGISTER_NETWORK, true, null, network.getId().toString());
        }
        networkSystem.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
        _dbClient.updateObject(networkSystem);
        auditOp(OperationTypeEnum.REGISTER_NETWORK_SYSTEM, true, null, networkSystem.getId().toString(), networkSystem.getLabel(), networkSystem.getPortNumber(), networkSystem.getUsername(), networkSystem.getSmisProviderIP(), networkSystem.getSmisPortNumber(), networkSystem.getSmisUserName(), networkSystem.getSmisUseSSL());
    }
    return map(networkSystem);
}
Also used : Network(com.emc.storageos.db.client.model.Network) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 45 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem in project coprhd-controller by CoprHD.

the class NetworkSystemService method getFCEndpointsByFabric.

/**
 * This returns the cached fiber channel connectivity information of a given fabric id
 * between the network system and external systems, such as host initiators or storage array ports.
 * If fabric id is not specified, get all connections of the network system.
 * The connectivity information is periodically updated, or can be refreshed on demand
 * using a POST /vdc/network-systems/{id}/refresh.
 *
 * @prereq none
 * @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
 * @brief List network system fiber channel connectivity
 * @return A list of FCEndpoint structures, each containing information about one connection.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/fc-endpoints/")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public FCEndpoints getFCEndpointsByFabric(@PathParam("id") URI id, @QueryParam("fabric-id") String fabricId) {
    FCEndpoints connections = new FCEndpoints();
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    if (WWNUtility.isValidWWN(fabricId)) {
        fabricId = fabricId.replaceAll(":", "");
    }
    NetworkSystem device = queryResource(id);
    List<URI> uriList = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(device.getId()));
    connections.setConnections(getFCEndPointRestReps(uriList, fabricId));
    return connections;
}
Also used : FCEndpoints(com.emc.storageos.model.network.FCEndpoints) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)54 MapNetworkSystem (com.emc.storageos.api.mapper.functions.MapNetworkSystem)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)20 Produces (javax.ws.rs.Produces)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)18 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)16 ControllerException (com.emc.storageos.volumecontroller.ControllerException)16 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 URI (java.net.URI)13 NetworkController (com.emc.storageos.networkcontroller.NetworkController)11 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)10 Consumes (javax.ws.rs.Consumes)10 POST (javax.ws.rs.POST)10 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 Operation (com.emc.storageos.db.client.model.Operation)8 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)8 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7