Search in sources :

Example 1 with KubevirtNetworkAdminService

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

the class KubevirtNetworkWebResource method hasNetwork.

/**
 * Checks whether the network exists with given network id.
 *
 * @param id network identifier
 * @return 200 OK with true/false result
 */
@GET
@Path("exist/{id}")
public Response hasNetwork(@PathParam("id") String id) {
    log.trace(String.format(MESSAGE, "QUERY " + id));
    KubevirtNetworkAdminService service = get(KubevirtNetworkAdminService.class);
    ObjectNode root = mapper().createObjectNode();
    KubevirtNetwork network = service.network(id);
    if (network == null) {
        root.put(RESULT, false);
    } else {
        root.put(RESULT, true);
    }
    return Response.ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkAdminService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with KubevirtNetworkAdminService

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

the class KubevirtNetworkWebResource method updateNetwork.

/**
 * Updates the network with the specified identifier.
 *
 * @param id    network identifier
 * @param input network JSON input stream
 * @return 200 OK with the updated network, 400 BAD_REQUEST if the requested
 * network does not exist
 * @onos.rsModel KubevirtNetwork
 */
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNetwork(@PathParam("id") String id, InputStream input) {
    log.trace(String.format(MESSAGE, "UPDATED"));
    KubevirtNetworkAdminService service = get(KubevirtNetworkAdminService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), input);
        JsonNode specifiedNetworkId = jsonTree.get("networkId");
        if (specifiedNetworkId != null && !specifiedNetworkId.asText().equals(id)) {
            throw new IllegalArgumentException(NETWORK_INVALID);
        }
        final KubevirtNetwork network = codec(KubevirtNetwork.class).decode(jsonTree, this);
        service.updateNetwork(network);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return Response.ok().build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkAdminService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 3 with KubevirtNetworkAdminService

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

the class KubevirtNetworkWebResource method getNetworkById.

/**
 * Returns the network with the specified identifier.
 *
 * @param id network identifier
 * @return 200 OK with a network, 404 not found
 * @onos.rsModel KubevirtNetwork
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response getNetworkById(@PathParam("id") String id) {
    KubevirtNetworkAdminService service = get(KubevirtNetworkAdminService.class);
    final KubevirtNetwork network = nullIsNotFound(service.network(id), NETWORK_NOT_FOUND + id);
    return ok(codec(KubevirtNetwork.class).encode(network, this)).build();
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkAdminService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 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)

Example 5 with KubevirtNetworkAdminService

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

the class KubevirtNetworkWebResource method removeNetwork.

/**
 * Removes the network with the given id.
 *
 * @param id network identifier
 * @return 204 NO_CONTENT, 400 BAD_REQUEST if the network does not exist
 */
@DELETE
@Path("{id}")
public Response removeNetwork(@PathParam("id") String id) {
    log.trace(String.format(MESSAGE, "DELETE " + id));
    KubevirtNetworkAdminService service = get(KubevirtNetworkAdminService.class);
    service.removeNetwork(id);
    return Response.noContent().build();
}
Also used : KubevirtNetworkAdminService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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