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