blob: abd47510e5a87b4ed2fca4f5ed3c7459b21ce61f [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
2 * Copyright 2017-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.opencord.sadis.impl;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.module.SimpleModule;
21import org.opencord.sadis.BandwidthProfileInformation;
22import org.opencord.sadis.BaseConfig;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import java.io.IOException;
27import java.util.ArrayList;
28import java.util.List;
29
30/**
31 * Configuration options for the Bandwidth Profile Information Service.
32 *
33 * <pre>
34 * "bandwidthprofile" : {
35 * "integration" : {
36 * "url" : "http://{hostname}{:port}",
37 * "cache" : {
38 * "enabled" : true or false
39 * "maxsize" : number of entries,
40 * "entryttl" : duration, i.e. 10s or 1m
41 * }
42 * },
43 * "entries" : [
44 * {
45 * "name" : string,
46 * "cir" : long,
47 * "cbs" : Long,
48 * "eir" : long,
49 * "ebs" : Long,
Gamze Abakad46003f2021-03-03 10:37:07 +000050 * "gir" : long,
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000051 * }, ...
52 * ]
Gamze Abakad46003f2021-03-03 10:37:07 +000053 *
54 * OR
55 *
56 * "entries" : [
57 * {
58 * "name" : string,
59 * "pir" : long,
60 * "pbs" : Long,
61 * "cir" : long,
62 * "cbs" : Long,
63 * "gir" : long,
64 * },
65 *
66 * ]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000067 * }
68 * </pre>
69 */
70public class BandwidthProfileConfig extends BaseConfig<BandwidthProfileInformation> {
71
72 private final Logger log = LoggerFactory.getLogger(this.getClass());
73
74 @Override
75 public List<BandwidthProfileInformation> getEntries() {
76 List<BandwidthProfileInformation> result = new ArrayList<>();
77 ObjectMapper mapper = new ObjectMapper();
78 mapper.registerModule(new SimpleModule());
79 final JsonNode entries = this.object.path(ENTRIES);
80 entries.forEach(entry -> {
81 try {
82 result.add(mapper.readValue(entry.toString(), BandwidthProfileInformation.class));
83 } catch (IOException e) {
84 log.warn("Unable to parse configuration entry, '{}', error: {}", entry, e.getMessage());
85 }
86 });
87
88 return result;
89 }
90}