Search in sources :

Example 1 with EventSubscriptionService

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

the class EventExporterWebResource method registerKafkaListener.

/**
 * Registers a listener for ONOS Events.
 *
 * @param appName The application trying to register
 * @return 200 OK with UUID string which should be used as Kafka Consumer
 *         Group Id and Kafka Server, port information.
 * @onos.rsModel KafkaRegistration
 */
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("register")
public Response registerKafkaListener(String appName) {
    EventSubscriptionService service = get(EventSubscriptionService.class);
    RegistrationResponse response = service.registerListener(appName);
    ObjectNode result = mapper().createObjectNode();
    result.put("groupId", response.getGroupId().getId().toString());
    result.put("ipAddress", response.getIpAddress());
    result.put("port", response.getPort());
    log.info("Registered app {}", appName);
    return ok(result.toString()).build();
}
Also used : EventSubscriptionService(org.onosproject.kafkaintegration.api.EventSubscriptionService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RegistrationResponse(org.onosproject.kafkaintegration.api.dto.RegistrationResponse) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 2 with EventSubscriptionService

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

the class EventExporterWebResource method removeKafkaListener.

/**
 * Unregisters a listener for ONOS Events.
 *
 * @param appName The application trying to unregister
 * @return 200 OK
 * @onos.rsModel KafkaRegistration
 */
@DELETE
@Path("unregister")
public Response removeKafkaListener(String appName) {
    EventSubscriptionService service = get(EventSubscriptionService.class);
    service.unregisterListener(appName);
    log.info("Unregistered app {}", appName);
    return ok(DEREGISTRATION_SUCCESSFUL).build();
}
Also used : EventSubscriptionService(org.onosproject.kafkaintegration.api.EventSubscriptionService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 3 with EventSubscriptionService

use of org.onosproject.kafkaintegration.api.EventSubscriptionService 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 4 with EventSubscriptionService

use of org.onosproject.kafkaintegration.api.EventSubscriptionService 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)

Aggregations

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