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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations