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 org.osgi.framework.Bundle;
12 import org.osgi.framework.BundleContext;
13 import org.osgi.framework.Constants;
14 import org.osgi.framework.FrameworkUtil;
15 import org.osgi.service.cm.ConfigurationException;
16 import org.osgi.service.cm.ManagedService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.util.Dictionary;
21 import java.util.Enumeration;
22 import java.util.HashMap;
23 import java.util.Hashtable;
24 import java.util.function.Consumer;
27 * Created by Shakib Ahmed on 4/17/17.
29 public class ConfigurationService implements ManagedService{
30 private static final Logger LOG = LoggerFactory.getLogger(ConfigurationService.class);
32 HashMap<String, Consumer> configMethods;
34 ConfigUtil configUtil = ConfigUtil.getInstance();
36 public ConfigurationService() {
37 Hashtable<String, Object> properties = new Hashtable<>();
38 properties.put(Constants.SERVICE_PID, "org.opendaylight.groupbasedpolicy.renderer.vpp.startup");
39 Bundle bundle = FrameworkUtil.getBundle(this.getClass());
40 BundleContext context = null;
42 context = bundle.getBundleContext();
45 //this function needs to be called before context.registerService() method
48 context.registerService(ManagedService.class.getName(), this, properties);
52 public void updated(Dictionary dictionary) throws ConfigurationException {
53 if (dictionary == null) {
57 Enumeration keys = dictionary.keys();
58 while (keys.hasMoreElements()) {
59 String key = (String) keys.nextElement();
61 if (configMethods.containsKey(key)) {
62 configMethods.get(key).accept(dictionary.get(key));
63 LOG.info("Property {} being updated", key);
65 LOG.debug("Configuration {} = {} being ignored because no consumer for this " +
66 "configuration key has been mapped", keys, dictionary.get(key));
71 private void mapConfigMethods() {
72 configMethods = new HashMap<>();
74 configMethods.put(ConfigUtil.ODL_TENANT_IP,
75 ip -> configUtil.configureOdlTenantIp((String) ip));
76 configMethods.put(ConfigUtil.LISP_MAPREGISTER_ENABLED,
77 mrConfig -> configUtil.configureMapRegister((String) mrConfig));
78 configMethods.put(ConfigUtil.LISP_OVERLAY_ENABLED,
79 overlayConfig -> configUtil.configureLispOverlayEnabled((String) overlayConfig));
80 configMethods.put(ConfigUtil.L3_FLAT_ENABLED,
81 l3FlatConfig -> configUtil.configL3FlatEnabled((String) l3FlatConfig));