2 * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.config;
11 import java.util.Dictionary;
12 import java.util.Enumeration;
13 import java.util.HashMap;
14 import java.util.Hashtable;
15 import java.util.function.Consumer;
17 import org.osgi.framework.Bundle;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.framework.Constants;
20 import org.osgi.framework.FrameworkUtil;
21 import org.osgi.service.cm.ConfigurationException;
22 import org.osgi.service.cm.ManagedService;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class ConfigurationService implements ManagedService{
27 private static final Logger LOG = LoggerFactory.getLogger(ConfigurationService.class);
29 HashMap<String, Consumer> configMethods;
31 ConfigUtil configUtil = ConfigUtil.getInstance();
33 public ConfigurationService() {
34 Hashtable<String, Object> properties = new Hashtable<>();
35 properties.put(Constants.SERVICE_PID, "org.opendaylight.groupbasedpolicy.renderer.vpp.startup");
36 Bundle bundle = FrameworkUtil.getBundle(this.getClass());
37 BundleContext context = null;
39 context = bundle.getBundleContext();
42 //this function needs to be called before context.registerService() method
45 context.registerService(ManagedService.class.getName(), this, properties);
49 public void updated(Dictionary dictionary) throws ConfigurationException {
50 if (dictionary == null) {
54 Enumeration keys = dictionary.keys();
55 while (keys.hasMoreElements()) {
56 String key = (String) keys.nextElement();
58 if (configMethods.containsKey(key)) {
59 configMethods.get(key).accept(dictionary.get(key));
60 LOG.info("Property {} being updated", key);
62 LOG.debug("Configuration {} = {} being ignored because no consumer for this " +
63 "configuration key has been mapped", key, dictionary.get(key));
68 private void mapConfigMethods() {
69 configMethods = new HashMap<>();
71 configMethods.put(ConfigUtil.ODL_IP,
72 ip -> configUtil.configureOdlIp((String) ip));
73 configMethods.put(ConfigUtil.LISP_MAPREGISTER_ENABLED,
74 mrConfig -> configUtil.configureMapRegister((String) mrConfig));
75 configMethods.put(ConfigUtil.LISP_OVERLAY_ENABLED,
76 overlayConfig -> configUtil.configureLispOverlayEnabled((String) overlayConfig));
77 configMethods.put(ConfigUtil.L3_FLAT_ENABLED,
78 l3FlatConfig -> configUtil.configL3FlatEnabled((String) l3FlatConfig));