Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.sadis.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.module.SimpleModule; |
| 21 | import org.opencord.sadis.BandwidthProfileInformation; |
| 22 | import org.opencord.sadis.BaseConfig; |
| 23 | import org.slf4j.Logger; |
| 24 | import org.slf4j.LoggerFactory; |
| 25 | |
| 26 | import java.io.IOException; |
| 27 | import java.util.ArrayList; |
| 28 | import 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 Abaka | d46003f | 2021-03-03 10:37:07 +0000 | [diff] [blame^] | 50 | * "gir" : long, |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 51 | * }, ... |
| 52 | * ] |
Gamze Abaka | d46003f | 2021-03-03 10:37:07 +0000 | [diff] [blame^] | 53 | * |
| 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 Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 67 | * } |
| 68 | * </pre> |
| 69 | */ |
| 70 | public 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 | } |