blob: b899f56a1c55ba35c168784ab8a7a264198fc36d [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,
50 * "air" : long,
51 * }, ...
52 * ]
53 * }
54 * </pre>
55 */
56public class BandwidthProfileConfig extends BaseConfig<BandwidthProfileInformation> {
57
58 private final Logger log = LoggerFactory.getLogger(this.getClass());
59
60 @Override
61 public List<BandwidthProfileInformation> getEntries() {
62 List<BandwidthProfileInformation> result = new ArrayList<>();
63 ObjectMapper mapper = new ObjectMapper();
64 mapper.registerModule(new SimpleModule());
65 final JsonNode entries = this.object.path(ENTRIES);
66 entries.forEach(entry -> {
67 try {
68 result.add(mapper.readValue(entry.toString(), BandwidthProfileInformation.class));
69 } catch (IOException e) {
70 log.warn("Unable to parse configuration entry, '{}', error: {}", entry, e.getMessage());
71 }
72 });
73
74 return result;
75 }
76}