Search in sources :

Example 1 with RegistrationResponse

use of org.onosproject.kafkaintegration.api.dto.RegistrationResponse 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 RegistrationResponse

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

the class EventSubscriptionManager method registerListener.

@Override
public RegistrationResponse registerListener(String appName) {
    // TODO: Remove it once ONOS provides a mechanism for external apps
    // to register with the core service. See Jira - 4409
    ApplicationId externalAppId = coreService.registerApplication(appName);
    EventSubscriberGroupId id = registeredApps.computeIfAbsent(externalAppId, (key) -> new EventSubscriberGroupId(UUID.randomUUID()));
    RegistrationResponse response = new RegistrationResponse(id, kafkaConfigService.getConfigParams().getIpAddress(), kafkaConfigService.getConfigParams().getPort());
    return response;
}
Also used : EventSubscriberGroupId(org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId) ApplicationId(org.onosproject.core.ApplicationId) RegistrationResponse(org.onosproject.kafkaintegration.api.dto.RegistrationResponse)

Aggregations

RegistrationResponse (org.onosproject.kafkaintegration.api.dto.RegistrationResponse)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ApplicationId (org.onosproject.core.ApplicationId)1 EventSubscriptionService (org.onosproject.kafkaintegration.api.EventSubscriptionService)1 EventSubscriberGroupId (org.onosproject.kafkaintegration.api.dto.EventSubscriberGroupId)1