Search in sources :

Example 1 with IntService

use of org.onosproject.inbandtelemetry.api.IntService in project onos by opennetworkinglab.

the class IntWebResource method getIntents.

/**
 * Gets all IntIntents. Returns array of all IntIntents in the system.
 * @return 200 OK with a collection of IntIntents
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntents() {
    ArrayNode intsNode = root.putArray(INTS);
    IntService service = get(IntService.class);
    Map<IntIntentId, IntIntent> intIntents = service.getIntIntents();
    if (!intIntents.isEmpty()) {
        intIntents.entrySet().forEach(intIntentEntry -> {
            intsNode.add(codec(IntIntent.class).encode(intIntentEntry.getValue(), this).put(ID, intIntentEntry.getKey().id()));
        });
    }
    return ok(root).build();
}
Also used : IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntService(org.onosproject.inbandtelemetry.api.IntService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with IntService

use of org.onosproject.inbandtelemetry.api.IntService in project onos by opennetworkinglab.

the class IntWebResource method deleteIntent.

/**
 * Removes the specified IntIntent.
 *
 * @param  id InIntentId
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{id}")
public Response deleteIntent(@PathParam("id") String id) {
    IntService service = get(IntService.class);
    service.removeIntIntent(IntIntentId.valueOf(Long.parseLong(id)));
    return Response.noContent().build();
}
Also used : IntService(org.onosproject.inbandtelemetry.api.IntService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 3 with IntService

use of org.onosproject.inbandtelemetry.api.IntService in project onos by opennetworkinglab.

the class IntWebResource method getIntent.

/**
 * Get an IntIntent. Returns an IntIntent in the system.
 * @param  id IntIntentId
 * @return 200 OK with a IntIntent
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response getIntent(@PathParam("id") String id) {
    ArrayNode intsNode = root.putArray(INT);
    IntService service = get(IntService.class);
    final IntIntent intIntent = nullIsNotFound(service.getIntIntent(IntIntentId.valueOf(Long.parseLong(id))), INT_NOT_FOUND + id);
    intsNode.add(codec(IntIntent.class).encode(intIntent, this));
    return ok(root).build();
}
Also used : IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntService(org.onosproject.inbandtelemetry.api.IntService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with IntService

use of org.onosproject.inbandtelemetry.api.IntService in project onos by opennetworkinglab.

the class IntWebResource method createIntent.

/**
 * Creates new IntIntent. Creates and installs a new IntIntent.
 *
 * @param stream IntIntent JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel Int
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createIntent(InputStream stream) {
    IntService service = get(IntService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        IntIntent intIntent = codec(IntIntent.class).decode(jsonTree, this);
        IntIntentId intIntentId = service.installIntIntent(intIntent);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(INT).path(Long.toString(intIntentId.id()));
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IntIntent(org.onosproject.inbandtelemetry.api.IntIntent) IntIntentId(org.onosproject.inbandtelemetry.api.IntIntentId) IntService(org.onosproject.inbandtelemetry.api.IntService) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

IntService (org.onosproject.inbandtelemetry.api.IntService)4 Produces (javax.ws.rs.Produces)3 IntIntent (org.onosproject.inbandtelemetry.api.IntIntent)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 IntIntentId (org.onosproject.inbandtelemetry.api.IntIntentId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 UriBuilder (javax.ws.rs.core.UriBuilder)1