blob: c96b81b94ebe8818f816eb4bd743b74d7fc66fa7 [file] [log] [blame]
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -07001/**
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.kafkaintegration.impl;
18
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Service;
23import org.onosproject.event.Event;
24import org.onosproject.kafkaintegration.api.EventConversionService;
25import org.onosproject.kafkaintegration.api.dto.OnosEvent;
26import org.onosproject.kafkaintegration.converter.DeviceEventConverter;
27import org.onosproject.kafkaintegration.converter.EventConverter;
28import org.onosproject.kafkaintegration.converter.LinkEventConverter;
29import org.onosproject.net.device.DeviceEvent;
30import org.onosproject.net.link.LinkEvent;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
35import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
36
37/**
38 * Implementation of Event Conversion Service.
39 *
40 */
41@Component(immediate = true)
42@Service
43public class EventConversionManager implements EventConversionService {
44
45 private final Logger log = LoggerFactory.getLogger(getClass());
46 private EventConverter deviceEventConverter;
47 private EventConverter linkEventConverter;
48
49 @Activate
50 protected void activate() {
51 deviceEventConverter = new DeviceEventConverter();
52 linkEventConverter = new LinkEventConverter();
53
54 log.info("Started");
55 }
56
57 @Deactivate
58 protected void deactivate() {
59 log.info("Stopped");
60 }
61
62 @Override
63 public OnosEvent convertEvent(Event<?, ?> event) {
64 if (event instanceof DeviceEvent) {
65 return new OnosEvent(DEVICE, deviceEventConverter.convertToProtoMessage(event));
66 } else if (event instanceof LinkEvent) {
67 return new OnosEvent(LINK, linkEventConverter.convertToProtoMessage(event));
68 } else {
69 throw new IllegalArgumentException("Unsupported event type");
70 }
71 }
72}