blob: acc06796dcfb4ea5e4c39815f026e6e33da398f1 [file] [log] [blame]
Jian Li4a3fffa2018-06-10 23:12:40 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
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 */
16package org.onosproject.openstacktelemetry.web;
17
Jian Li7fe7eaf2018-12-31 17:00:33 +090018import org.onosproject.codec.CodecService;
19import org.onosproject.openstacktelemetry.api.FlowInfo;
20import org.onosproject.openstacktelemetry.api.StatsFlowRule;
21import org.onosproject.openstacktelemetry.api.StatsInfo;
22import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
23import org.onosproject.openstacktelemetry.codec.rest.FlowInfoJsonCodec;
24import org.onosproject.openstacktelemetry.codec.rest.StatsFlowRuleJsonCodec;
25import org.onosproject.openstacktelemetry.codec.rest.StatsInfoJsonCodec;
26import org.onosproject.openstacktelemetry.codec.rest.TelemetryConfigJsonCodec;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070027import org.osgi.service.component.annotations.Activate;
28import org.osgi.service.component.annotations.Component;
29import org.osgi.service.component.annotations.Deactivate;
30import org.osgi.service.component.annotations.Reference;
31import org.osgi.service.component.annotations.ReferenceCardinality;
Jian Lida8867f2019-01-31 01:17:36 +090032import org.slf4j.Logger;
Jian Li4a3fffa2018-06-10 23:12:40 +090033
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Implementation of the JSON codec brokering service for OpenstackTelemetry.
38 */
39@Component(immediate = true)
Jian Lida8867f2019-01-31 01:17:36 +090040public class OpenstackRestCodecRegister {
Jian Li4a3fffa2018-06-10 23:12:40 +090041
Jian Lida8867f2019-01-31 01:17:36 +090042 private final Logger log = getLogger(getClass());
Jian Li4a3fffa2018-06-10 23:12:40 +090043
Ray Milkeyd84f89b2018-08-17 14:54:17 -070044 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jian Li4a3fffa2018-06-10 23:12:40 +090045 protected CodecService codecService;
46
47 @Activate
48 protected void activate() {
49 codecService.registerCodec(StatsInfo.class, new StatsInfoJsonCodec());
50 codecService.registerCodec(FlowInfo.class, new FlowInfoJsonCodec());
Boyoung Jeong9e8faec2018-06-17 21:19:23 +090051 codecService.registerCodec(StatsFlowRule.class, new StatsFlowRuleJsonCodec());
Jian Li7fe7eaf2018-12-31 17:00:33 +090052 codecService.registerCodec(TelemetryConfig.class, new TelemetryConfigJsonCodec());
Jian Li4a3fffa2018-06-10 23:12:40 +090053
54 log.info("Started");
55 }
56
57 @Deactivate
58 protected void deactivate() {
59 codecService.unregisterCodec(StatsInfo.class);
60 codecService.unregisterCodec(FlowInfo.class);
Boyoung Jeong9e8faec2018-06-17 21:19:23 +090061 codecService.unregisterCodec(StatsFlowRule.class);
Jian Li7fe7eaf2018-12-31 17:00:33 +090062 codecService.unregisterCodec(TelemetryConfig.class);
Jian Li4a3fffa2018-06-10 23:12:40 +090063
64 log.info("Stopped");
65 }
66}