Search in sources :

Example 76 with Network

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

the class NetworkService method updateNetwork.

/**
 * Update a network's name, endpoints or varrays.
 * <p>
 * When endpoints are changed, added or removed, and the endpoints match some storage ports, the storage ports associations to the
 * network are updated accordingly. If the endpoints added exist is another network, they are first removed from their current network.
 * Discovered endpoints cannot be removed from their current networks or added to another one.
 * <p>
 * When the storage ports networks are changed, their corresponding storage pools are also update to reflect any change in varray
 * connectivity that may have resulted from the change.
 * <p>
 * For backward compatibility, this function still allows the varray changes to be done using {@link NetworkUpdate#getVarrays()}. The
 * value specified in the parameter will override the existing varrays to maintain the same behavior. Further, only zero or one varray
 * may be specified using this input field.
 *
 * @param id the URN of a ViPR network
 * @param param the update request object
 * @brief Update network
 * @return the details of the updated network
 */
@PUT
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public NetworkRestRep updateNetwork(@PathParam("id") URI id, NetworkUpdate param) {
    _log.info("updateNetwork: started for network {}", id);
    ArgValidator.checkFieldUriType(id, Network.class, "id");
    Network network = queryResource(id);
    ArgValidator.checkEntity(network, id, isIdEmbeddedInURL(id));
    if (param.getName() != null && !network.getLabel().equalsIgnoreCase(param.getName())) {
        // check for active network with same name
        checkDuplicateLabel(Network.class, param.getName());
        _log.info("updateNetwork: changing network {} to {} ", network.getLabel(), param.getName());
        network.setLabel(param.getName());
    }
    if (param.getVarrays() != null && !param.getVarrays().isEmpty() && param.getVarrays().size() != 1) {
        throw APIException.badRequests.networkCanOnlyBeAssociatedWithASingleVirtualArray(network.getId());
    }
    // define variable to hold changes
    List<URI> removedVarrays = null;
    List<URI> addedVarrays = null;
    List<String> removedEps = null;
    List<String> addedEps = null;
    // Update the varray association.
    if (param.getVarrayChanges() != null) {
        VirtualArrayAssignmentChanges varrayChanges = param.getVarrayChanges();
        if (varrayChanges.hasRemoved()) {
            removedVarrays = checkAndFilterRemoveVarrays(network, varrayChanges.getRemove().getVarrays(), varrayChanges.hasAdded() ? varrayChanges.getAdd().getVarrays() : null);
            _log.info("updateNetwork: these varrays will be removed {} ", removedVarrays);
        }
        if (param.getVarrayChanges().hasAdded()) {
            addedVarrays = checkAndFilterAddVarrays(network, varrayChanges.getAdd().getVarrays());
            _log.info("updateNetwork: these varrays will be added {} ", addedVarrays);
        }
    } else if (param.getVarrays() != null) {
        // the user is using the old style - still allow full overwrite of the varrays
        _log.info("updateNetwork: using the old style update for varrays param {}", param.getVarrays());
        if (param.getVarrays().isEmpty()) {
            if (network.getAssignedVirtualArrays() != null) {
                removedVarrays = checkAndFilterRemoveVarrays(network, network.getAssignedVirtualArrays(), null);
                _log.info("updateNetwork: these varrays will be removed {} ", removedVarrays);
            }
        } else {
            addedVarrays = checkAndFilterAddVarrays(network, StringSetUtil.uriListToSet(param.getVarrays()));
            _log.info("updateNetwork: these varrays will be added {} ", addedVarrays);
        }
    }
    // Update the endpoints.
    if (param.getEndpointChanges() != null) {
        if (param.getEndpointChanges().hasRemoved()) {
            removedEps = checkAndFilterRemoveEndPoints(network, param.getEndpointChanges().getRemove());
            _log.info("updateNetwork: these endpoints will be removed {} ", removedEps);
        }
        if (param.getEndpointChanges().hasAdded()) {
            addedEps = checkAndFilterAddEndpoints(network, param.getEndpointChanges().getAdd());
            _log.info("updateNetwork: these endpoints will be added {} ", addedEps);
        }
    }
    if (removedVarrays != null) {
        network.removeAssignedVirtualArrays(StringSetUtil.uriListToSet(removedVarrays));
    }
    if (addedVarrays != null) {
        network.addAssignedVirtualArrays(StringSetUtil.uriListToSet(addedVarrays));
    }
    if (removedEps != null) {
        network.removeEndpoints(removedEps);
    }
    if (addedEps != null) {
        network.addEndpoints(addedEps, false);
    }
    _dbClient.updateAndReindexObject(network);
    recordAndAudit(network, OperationTypeEnum.UPDATE_NETWORK);
    _log.info("updateNetwork: updating ports and pools associations ");
    NetworkAssociationHelper.handleNetworkUpdated(network, addedVarrays, removedVarrays, addedEps, removedEps, _dbClient, _coordinator);
    return MapNetwork.toNetworkRestRep(network, _dbClient);
}
Also used : VirtualArrayAssignmentChanges(com.emc.storageos.model.pools.VirtualArrayAssignmentChanges) Network(com.emc.storageos.db.client.model.Network) MapNetwork(com.emc.storageos.api.mapper.functions.MapNetwork) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 77 with Network

use of com.emc.storageos.db.client.model.Network 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 78 with Network

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

the class NetworkSystemService method reassignZoneNetworkSystem.

/**
 * Reassign the FCZoneReference to another NetworkSystem that manages the
 * zone's fabric
 *
 * @param zone FCZoneReference that will be reassigned to another
 *            NetworkSystem
 */
private void reassignZoneNetworkSystem(FCZoneReference zone) {
    URI networkSystemURI = NullColumnValueGetter.getNullURI();
    List<Network> networkList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Network.class, AlternateIdConstraint.Factory.getConstraint(Network.class, "nativeId", zone.getFabricId()));
    Iterator<Network> networkIter = networkList.iterator();
    while (networkIter.hasNext() && networkSystemURI.equals(NullColumnValueGetter.getNullURI())) {
        Network network = networkIter.next();
        for (String nsURI : network.getNetworkSystems()) {
            if (!nsURI.equals(zone.getNetworkSystemUri().toString())) {
                networkSystemURI = URI.create(nsURI);
                break;
            }
        }
    }
    zone.setNetworkSystemUri(networkSystemURI);
    _dbClient.updateObject(zone);
}
Also used : Network(com.emc.storageos.db.client.model.Network) URI(java.net.URI)

Example 79 with Network

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

the class NetworkSystemService method deregisterNetworkSystem.

/**
 * Deregister a network system.
 *
 * @param id the URN of a ViPR network system.
 *
 * @prereq none
 * @brief Deregister 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}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public NetworkSystemRestRep deregisterNetworkSystem(@PathParam("id") URI id) throws ControllerException {
    // Validate the storage system.
    ArgValidator.checkUri(id);
    NetworkSystem networkSystem = _dbClient.queryObject(NetworkSystem.class, id);
    ArgValidator.checkEntity(networkSystem, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(networkSystem.getRegistrationStatus())) {
        // Deregister 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.UNREGISTERED.toString().equals(network.getRegistrationStatus())) {
                continue;
            }
            List<URI> registeredNetworkSystems = NetworkService.getRegisteredNetworkSystems(network, _dbClient);
            registeredNetworkSystems.remove(networkSystem.getId());
            // Only unregister Network if it is not managed by other registered NetworkSystems
            if (registeredNetworkSystems.isEmpty()) {
                network.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
                _dbClient.updateObject(network);
                auditOp(OperationTypeEnum.DEREGISTER_NETWORK, true, null, id.toString());
            }
        }
        networkSystem.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.updateObject(networkSystem);
        auditOp(OperationTypeEnum.DEREGISTER_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) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 80 with Network

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

the class VirtualArrayService method getNetworkList.

/**
 * List transport zones in VirtualArray
 *
 * @param id the URN of a ViPR VirtualArray
 * @brief List VirtualArray Networks
 * @return List of Networks
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/networks")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public NetworkList getNetworkList(@PathParam("id") URI id) {
    NetworkList networkList = new NetworkList();
    // Verify the passed virtual array id.
    ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
    ArgValidator.checkEntity(varray, id, isIdEmbeddedInURL(id));
    // Get the networks assigned to the virtual array.
    List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, id, Network.class, "connectedVirtualArrays");
    for (Network network : networks) {
        if (network == null || network.getInactive() == true) {
            continue;
        }
        networkList.getNetworks().add(toNamedRelatedResource(ResourceTypeEnum.NETWORK, network.getId(), network.getLabel()));
    }
    return networkList;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) NetworkList(com.emc.storageos.model.varray.NetworkList) Network(com.emc.storageos.db.client.model.Network) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

Network (com.emc.storageos.db.client.model.Network)88 URI (java.net.URI)42 ArrayList (java.util.ArrayList)38 StringSet (com.emc.storageos.db.client.model.StringSet)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)28 StoragePort (com.emc.storageos.db.client.model.StoragePort)25 StringMap (com.emc.storageos.db.client.model.StringMap)23 List (java.util.List)23 StoragePool (com.emc.storageos.db.client.model.StoragePool)22 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)22 Test (org.junit.Test)20 NamedURI (com.emc.storageos.db.client.model.NamedURI)19 Project (com.emc.storageos.db.client.model.Project)19 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)19 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)19 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)17 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)16 Produces (javax.ws.rs.Produces)16 RPProtectionRecommendation (com.emc.storageos.volumecontroller.RPProtectionRecommendation)15