Search in sources :

Example 6 with KubevirtNetworkAdminService

use of org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService in project onos by opennetworkinglab.

the class KubevirtNetworkWebResource method createNetwork.

/**
 * Creates a network from the JSON input stream.
 *
 * @param input network JSON input stream
 * @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is invalid or duplicated network already exists
 * @onos.rsModel KubevirtNetwork
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNetwork(InputStream input) {
    log.trace(String.format(MESSAGE, "CREATE"));
    KubevirtNetworkAdminService service = get(KubevirtNetworkAdminService.class);
    URI location;
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), input);
        final KubevirtNetwork network = codec(KubevirtNetwork.class).decode(jsonTree, this);
        service.createNetwork(network);
        location = new URI(network.networkId());
    } catch (IOException | URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
    return Response.created(location).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkAdminService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

KubevirtNetworkAdminService (org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService)6 KubevirtNetwork (org.onosproject.kubevirtnetworking.api.KubevirtNetwork)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 GET (javax.ws.rs.GET)3 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1