blob: 5c90325941f0077af1d261bca15de17d854dc204 [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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.osgi.service.component.annotations.Activate;
20import org.osgi.service.component.annotations.Component;
21import org.osgi.service.component.annotations.Deactivate;
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070022import org.onosproject.event.Event;
23import org.onosproject.kafkaintegration.api.EventConversionService;
24import org.onosproject.kafkaintegration.api.dto.OnosEvent;
25import org.onosproject.kafkaintegration.converter.DeviceEventConverter;
26import org.onosproject.kafkaintegration.converter.EventConverter;
27import org.onosproject.kafkaintegration.converter.LinkEventConverter;
28import org.onosproject.net.device.DeviceEvent;
29import org.onosproject.net.link.LinkEvent;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.DEVICE;
34import static org.onosproject.kafkaintegration.api.dto.OnosEvent.Type.LINK;
35
36/**
37 * Implementation of Event Conversion Service.
38 *
39 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070040@Component(immediate = true, service = EventConversionService.class)
Sanjana Agarwalcb4a3db2016-07-14 11:42:48 -070041public class EventConversionManager implements EventConversionService {
42
43 private final Logger log = LoggerFactory.getLogger(getClass());
44 private EventConverter deviceEventConverter;
45 private EventConverter linkEventConverter;
46
47 @Activate
48 protected void activate() {
49 deviceEventConverter = new DeviceEventConverter();
50 linkEventConverter = new LinkEventConverter();
51
52 log.info("Started");
53 }
54
55 @Deactivate
56 protected void deactivate() {
57 log.info("Stopped");
58 }
59
60 @Override
61 public OnosEvent convertEvent(Event<?, ?> event) {
62 if (event instanceof DeviceEvent) {
63 return new OnosEvent(DEVICE, deviceEventConverter.convertToProtoMessage(event));
64 } else if (event instanceof LinkEvent) {
65 return new OnosEvent(LINK, linkEventConverter.convertToProtoMessage(event));
66 } else {
67 throw new IllegalArgumentException("Unsupported event type");
68 }
69 }
70}