Search in sources :

Example 1 with NetworkEndpointParam

use of com.emc.storageos.model.varray.NetworkEndpointParam in project coprhd-controller by CoprHD.

the class NetworkService method doUpdateEndpoints.

/**
 * Adds/removes endpoints to/from networks and handles all the related
 * updates needed for:
 * <ul>
 * <li>The storage ports corresponding to the endpoints if they exist</li>
 * <li>The networks, the one the endpoints are added into, and the old one when an endpoint is moving from one network to another</li>
 * <li>The storage pools when this operation results in the pools being implicitly associated with the new network's varray and
 * disassociated from the old ones.</li>
 * </ul>
 * When a port is added:
 * <ul>
 * <li>the port's endpoint is added to the network</li>
 * <li>The port's network is set to the new network</li>
 * <li>The pool-to-varray associations are updated if needed.</li>
 * <li>If the ports exists in another network, its endpoint is removed from the old network and the pool-to-varray associations are also
 * updated</li>
 * </ul>
 * When a port is removed:
 * <ul>
 * <li>the port's endpoint is removed from the network</li>
 * <li>The port network is set null</li>
 * <li>The pool-to-varray associations are updated if needed.</li>
 * </ul>
 *
 * @param id the URN of a ViPR network
 * @param param the request object containing the endpoint to be added or removed
 *            as well as the operation type (add/remove).
 * @return the target networke
 */
public Network doUpdateEndpoints(URI id, NetworkEndpointParam param) {
    // This I am not sure about -
    _log.info("doUpdateEndpoints START...");
    ArgValidator.checkUri(id);
    Network network = _dbClient.queryObject(Network.class, id);
    ArgValidator.checkEntity(network, id, isIdEmbeddedInURL(id));
    NetworkEndpointParam.EndpointOp op = NetworkEndpointParam.EndpointOp.valueOf(param.getOp());
    List<String> updatedEndoints = null;
    // create an update parameter
    if (op.equals(NetworkEndpointParam.EndpointOp.add)) {
        _log.info("doUpdateEndpoints: adding endpoints {} to network {}", param.getEndpoints(), network);
        updatedEndoints = checkAndFilterAddEndpoints(network, param.getEndpoints());
        network.addEndpoints(updatedEndoints, false);
    } else {
        _log.info("doUpdateEndpoints: removing endpoints {} from network {}", param.getEndpoints(), network);
        updatedEndoints = checkAndFilterRemoveEndPoints(network, param.getEndpoints());
        network.removeEndpoints(updatedEndoints);
    }
    _dbClient.updateAndReindexObject(network);
    _log.info("doUpdateEndpoints: update the port and pools associations following {} endpoints operation", op.name());
    updateEndpointsAssociation(network, updatedEndoints, op);
    return network;
}
Also used : NetworkEndpointParam(com.emc.storageos.model.varray.NetworkEndpointParam) Network(com.emc.storageos.db.client.model.Network) MapNetwork(com.emc.storageos.api.mapper.functions.MapNetwork)

Example 2 with NetworkEndpointParam

use of com.emc.storageos.model.varray.NetworkEndpointParam in project coprhd-controller by CoprHD.

the class StoragePortService method updateNetworkEndpoint.

/**
 * Utility method to add/remove storage port endpoints to/from transport
 * zones. The {@link NetworkService#doUpdateEndpoints(URI, NetworkEndpointParam)} handles updating the transport zone as well as the
 * port and pool
 * associations. When a port is added:
 * <ul>
 * <li>the port's endpoint is added to the Network</li>
 * <li>The port Network is set to the new Network</li>
 * <li>The pool-to-varray associations are updated if needed.</li>
 * <li>If the ports exists in another Network, its endpoint is removed from the old Network and the pool-to-varray associations are also
 * updated</li>
 * </ul>
 * When a port is removed:
 * <ul>
 * <li>the port's endpoint is removed from the Network</li>
 * <li>The port Network is set null</li>
 * <li>The pool-to-varray associations are updated if needed.</li>
 * </ul>
 *
 * @param transportZoneURI The URI of the Network.
 * @param endpointNetworkId The network id of the storage port.
 * @param op The operation, add/remove
 */
private void updateNetworkEndpoint(URI transportZoneURI, String endpointNetworkId, NetworkEndpointParam.EndpointOp op) {
    // Set up the parameters to add/remove the storage port endpoint
    NetworkEndpointParam param = new NetworkEndpointParam();
    List<String> endpoints = new ArrayList<String>();
    endpoints.add(endpointNetworkId);
    param.setEndpoints(endpoints);
    param.setOp(op.name());
    // Add/Remove the storage port endpoint to/from the Network.
    Network network = networkSvc.doUpdateEndpoints(transportZoneURI, param);
    _dbClient.updateAndReindexObject(network);
}
Also used : NetworkEndpointParam(com.emc.storageos.model.varray.NetworkEndpointParam) Network(com.emc.storageos.db.client.model.Network) ArrayList(java.util.ArrayList)

Example 3 with NetworkEndpointParam

use of com.emc.storageos.model.varray.NetworkEndpointParam in project coprhd-controller by CoprHD.

the class NetworkUtils method removeEndpoints.

public static NetworkRestRep removeEndpoints(String networkId, Collection<String> endpoints) {
    NetworkEndpointParam param = new NetworkEndpointParam();
    param.setOp("remove");
    param.setEndpoints(Lists.newArrayList(endpoints));
    return getViprClient().networks().updateEndpoints(uri(networkId), param);
}
Also used : NetworkEndpointParam(com.emc.storageos.model.varray.NetworkEndpointParam)

Example 4 with NetworkEndpointParam

use of com.emc.storageos.model.varray.NetworkEndpointParam in project coprhd-controller by CoprHD.

the class NetworkUtils method addEndpoints.

public static NetworkRestRep addEndpoints(String networkId, Collection<String> endpoints) {
    NetworkEndpointParam param = new NetworkEndpointParam();
    param.setOp("add");
    param.setEndpoints(Lists.newArrayList(endpoints));
    return getViprClient().networks().updateEndpoints(uri(networkId), param);
}
Also used : NetworkEndpointParam(com.emc.storageos.model.varray.NetworkEndpointParam)

Example 5 with NetworkEndpointParam

use of com.emc.storageos.model.varray.NetworkEndpointParam in project coprhd-controller by CoprHD.

the class InternalApiTest method testNetworkUsingInternalClient.

@Test
public void testNetworkUsingInternalClient() {
    // first add a new endpoint
    String newEndpoint = "www.networktest-" + System.currentTimeMillis() + ".com";
    NetworkEndpointParam endpointParam = new NetworkEndpointParam();
    endpointParam.setEndpoints(Arrays.asList(newEndpoint));
    endpointParam.setOp(NetworkEndpointParam.EndpointOp.add.name());
    NetworkRestRep network = _internalNetworkClient.updateNetworkEndpoints(_networkId, endpointParam);
    Assert.assertNotNull("update should not return a null response", network);
    Assert.assertTrue("response should contain the new endpoint " + newEndpoint, network.getEndpoints().contains(newEndpoint));
    // then remove it again
    endpointParam.setOp(NetworkEndpointParam.EndpointOp.remove.name());
    network = _internalNetworkClient.updateNetworkEndpoints(_networkId, endpointParam);
    Assert.assertNotNull("update should not return a null response", network);
    Assert.assertFalse("response should not contain the new endpoint " + newEndpoint, network.getEndpoints().contains(newEndpoint));
}
Also used : NetworkEndpointParam(com.emc.storageos.model.varray.NetworkEndpointParam) NetworkRestRep(com.emc.storageos.model.varray.NetworkRestRep) Test(org.junit.Test)

Aggregations

NetworkEndpointParam (com.emc.storageos.model.varray.NetworkEndpointParam)5 Network (com.emc.storageos.db.client.model.Network)2 MapNetwork (com.emc.storageos.api.mapper.functions.MapNetwork)1 NetworkRestRep (com.emc.storageos.model.varray.NetworkRestRep)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1