Search in sources :

Example 1 with EventSubscriber

use of org.onosproject.kafkaintegration.api.dto.EventSubscriber in project onos by opennetworkinglab.

the class EventExporterWebResource method unsubscribe.

/**
 * Deletes subscription from a specific ONOS event.
 *
 * @param input data in JSON format
 * @return 200 OK if successful or 400 BAD REQUEST
 * @onos.rsModel KafkaSubscription
 */
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Path("unsubscribe")
public Response unsubscribe(InputStream input) {
    EventSubscriptionService service = get(EventSubscriptionService.class);
    try {
        EventSubscriber sub = parseSubscriptionData(input);
        service.unsubscribe(sub);
    } catch (Exception e) {
        log.error(e.getMessage());
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
    return ok(EVENT_SUBSCRIPTION_REMOVED).build();
}
Also used : EventSubscriptionService(org.onosproject.kafkaintegration.api.EventSubscriptionService) EventSubscriber(org.onosproject.kafkaintegration.api.dto.EventSubscriber) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 2 with EventSubscriber

use of org.onosproject.kafkaintegration.api.dto.EventSubscriber in project onos by opennetworkinglab.

the class EventExporterWebResource method parseSubscriptionData.

/**
 * Parses JSON Subscription Data from the external application.
 *
 * @param input Subscription Data in JSON format
 * @return parsed DTO object
 * @throws IOException
 */
private EventSubscriber parseSubscriptionData(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = readTreeFromStream(mapper, input);
    checkNotNull(node, JSON_NOT_NULL);
    EventSubscriber codec = codec(EventSubscriber.class).decode(node, this);
    checkNotNull(codec, JSON_NOT_NULL);
    return codec;
}
Also used : EventSubscriber(org.onosproject.kafkaintegration.api.dto.EventSubscriber) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with EventSubscriber

use of org.onosproject.kafkaintegration.api.dto.EventSubscriber in project onos by opennetworkinglab.

the class EventExporterWebResource method subscribe.

/**
 * Creates subscription to a specific ONOS event.
 *
 * @param input Subscription Data in JSON format
 * @return 200 OK if successful or 400 BAD REQUEST
 * @onos.rsModel KafkaSubscription
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("subscribe")
public Response subscribe(InputStream input) {
    EventSubscriptionService service = get(EventSubscriptionService.class);
    try {
        EventSubscriber sub = parseSubscriptionData(input);
        service.subscribe(sub);
    // It will subscribe to all the topics. Not only the one that is sent by the consumer.
    } catch (Exception e) {
        log.error(e.getMessage());
        return Response.status(BAD_REQUEST).entity(e.getMessage()).build();
    }
    return ok(EVENT_SUBSCRIPTION_SUCCESSFUL).build();
}
Also used : EventSubscriptionService(org.onosproject.kafkaintegration.api.EventSubscriptionService) EventSubscriber(org.onosproject.kafkaintegration.api.dto.EventSubscriber) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with EventSubscriber

use of org.onosproject.kafkaintegration.api.dto.EventSubscriber in project onos by opennetworkinglab.

the class SubscriberCodec method decode.

@Override
public EventSubscriber decode(ObjectNode json, CodecContext context) {
    EventSubscriber.Builder resultBuilder = new DefaultEventSubscriber.Builder();
    String appName = json.get(NAME).asText();
    resultBuilder.setAppName(appName);
    String subscriberGroupId = json.get(GROUP_ID).asText();
    resultBuilder.setSubscriberGroupId(new EventSubscriberGroupId(UUID.fromString(subscriberGroupId)));
    String eventType = json.get(EVENT_TYPE).asText();
    resultBuilder.setEventType(Type.valueOf(eventType));
    return resultBuilder.build();
}
Also used : EventSubscriber(org.onosproject.kafkaintegration.api.dto.EventSubscriber) DefaultEventSubscriber(org.onosproject.kafkaintegration.api.dto.DefaultEventSubscriber) EventSubscriberGroupId(org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId)

Aggregations

EventSubscriber (org.onosproject.kafkaintegration.api.dto.EventSubscriber)4 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 EventSubscriptionService (org.onosproject.kafkaintegration.api.EventSubscriptionService)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 DefaultEventSubscriber (org.onosproject.kafkaintegration.api.dto.DefaultEventSubscriber)1 EventSubscriberGroupId (org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId)1