package org.opendaylight.openflowplugin.api.openflow.configuration;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
-import org.osgi.framework.BundleContext;
/**
* Factory for creating ConfigurationService instances.
*/
public interface ConfigurationServiceFactory {
- ConfigurationService newInstance(OpenflowProviderConfig providerConfig,
- BundleContext bundleContext);
-}
\ No newline at end of file
+ ConfigurationService newInstance(OpenflowProviderConfig providerConfig);
+}
factory-method="newInstance"
destroy-method="close">
<argument ref="openflowProviderConfig" />
- <argument ref="blueprintBundleContext" />
<cm:managed-properties persistent-id="org.opendaylight.openflowplugin"
update-strategy="component-managed"
update-method="update"/>
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.impl.configuration;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableMap;
-import java.io.IOException;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.function.Function;
import javax.annotation.Nonnull;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationListener;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationServiceFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Override
public ConfigurationService newInstance(
- final OpenflowProviderConfig providerConfig,
- final BundleContext bundleContext) {
- return new ConfigurationServiceImpl(providerConfig, bundleContext);
+ final OpenflowProviderConfig providerConfig) {
+ return new ConfigurationServiceImpl(providerConfig);
}
private static final class ConfigurationServiceImpl implements ConfigurationService {
private final Map<String, String> propertyMap = new HashMap<>();
private final List<ConfigurationListener> listeners = new ArrayList<>();
- ConfigurationServiceImpl(final OpenflowProviderConfig providerConfig, final BundleContext bundleContext) {
+ ConfigurationServiceImpl(final OpenflowProviderConfig providerConfig) {
LOG.info("Loading properties from '{}' YANG file", OpenflowProviderConfig.QNAME);
update(ImmutableMap
.<String, String>builder()
.put(ConfigurationProperty.DEVICE_CONNECTION_RATE_LIMIT_PER_MIN.toString(),
providerConfig.getDeviceConnectionRateLimitPerMin().toString())
.build());
-
- LOG.info("Loading configuration from '{}' configuration file", OFConstants.CONFIG_FILE_ID);
- Optional.ofNullable(bundleContext.getServiceReference(ConfigurationAdmin.class))
- .ifPresent(serviceReference -> {
- final ConfigurationAdmin configurationAdmin = bundleContext.getService(serviceReference);
-
- try {
- final Configuration configuration
- = configurationAdmin.getConfiguration(OFConstants.CONFIG_FILE_ID);
-
- Optional.ofNullable(configuration.getProperties()).ifPresent(properties -> {
- final Enumeration<String> keys = properties.keys();
- final Map<String, String> mapProperties = new HashMap<>(properties.size());
-
- while (keys.hasMoreElements()) {
- final String key = keys.nextElement();
- final String value = properties.get(key).toString();
- mapProperties.put(key, value);
- }
-
- update(mapProperties);
- });
- } catch (IOException e) {
- LOG.debug("Failed to load {} configuration file. Error {}", OFConstants.CONFIG_FILE_ID, e);
- }
- });
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.configuration;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ConfigurationServiceFactoryOsgiImpl extends ConfigurationServiceFactoryImpl {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigurationServiceFactoryOsgiImpl.class);
+
+ private final BundleContext bundleContext;
+
+ public ConfigurationServiceFactoryOsgiImpl(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ @Override
+ public ConfigurationService newInstance(OpenflowProviderConfig providerConfig) {
+ ConfigurationService cs = super.newInstance(providerConfig);
+ update(cs);
+ return cs;
+ }
+
+ private void update(ConfigurationService configurationService) {
+ LOG.info("Loading configuration from '{}' configuration file", OFConstants.CONFIG_FILE_ID);
+ Optional.ofNullable(bundleContext.getServiceReference(ConfigurationAdmin.class)).ifPresent(serviceReference -> {
+ final ConfigurationAdmin configurationAdmin = bundleContext.getService(serviceReference);
+
+ try {
+ final Configuration configuration = configurationAdmin.getConfiguration(OFConstants.CONFIG_FILE_ID);
+
+ Optional.ofNullable(configuration.getProperties()).ifPresent(properties -> {
+ final Enumeration<String> keys = properties.keys();
+ final Map<String, String> mapProperties = new HashMap<>(properties.size());
+
+ while (keys.hasMoreElements()) {
+ final String key = keys.nextElement();
+ final String value = properties.get(key).toString();
+ mapProperties.put(key, value);
+ }
+
+ configurationService.update(mapProperties);
+ });
+ } catch (IOException e) {
+ LOG.debug("Failed to load {} configuration file. Error {}", OFConstants.CONFIG_FILE_ID, e);
+ }
+ });
+ }
+}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.impl.configuration;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
return service.getProperty(ConfigurationProperty.DEVICE_CONNECTION_RATE_LIMIT_PER_MIN.toString(),
Integer::valueOf);
}
-
}
<action class="org.opendaylight.openflowplugin.impl.karaf.ResetSessionStatsComandProvider"/>
</command>
</command-bundle>
-
-
</blueprint>
\ No newline at end of file
<bean id="ofPluginProviderFactory" class="org.opendaylight.openflowplugin.impl.OpenFlowPluginProviderFactoryImpl"/>
<service ref="ofPluginProviderFactory" interface="org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProviderFactory"/>
- <bean id="configurationServiceFactory" class="org.opendaylight.openflowplugin.impl.configuration.ConfigurationServiceFactoryImpl"/>
+ <bean id="configurationServiceFactory" class="org.opendaylight.openflowplugin.impl.configuration.ConfigurationServiceFactoryOsgiImpl">
+ <argument ref="blueprintBundleContext"/>
+ </bean>
<service ref="configurationServiceFactory" interface="org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationServiceFactory"/>
<bean id="mastershipChangeServiceManager" class="org.opendaylight.openflowplugin.impl.mastership.MastershipChangeServiceManagerImpl"/>
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
-import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationListener;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint16Type;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
@RunWith(MockitoJUnitRunner.class)
public class ConfigurationServiceFactoryImplTest {
@Mock
private OpenflowProviderConfig config;
- @Mock
- private BundleContext bundleContext;
-
@Mock
private ConfigurationListener configurationListener;
- @Mock
- private ConfigurationAdmin configurationAdmin;
-
- @Mock
- private ServiceReference<ConfigurationAdmin> serviceReference;
-
- @Mock
- private Configuration configuration;
-
private ConfigurationService configurationService;
@Before
when(config.getThreadPoolTimeout()).thenReturn(THREAD_POOL_TIMEOUT);
when(config.getDeviceConnectionRateLimitPerMin()).thenReturn(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN);
- final Dictionary<String, Object> properties = new Hashtable<>();
- properties.put(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString(), IS_STATISTICS_POLLING_ON);
+ final Map<String, String> properties = new Hashtable<>();
+ properties.put(ConfigurationProperty.IS_STATISTICS_POLLING_ON.toString(),
+ Boolean.toString(IS_STATISTICS_POLLING_ON));
- when(configuration.getProperties()).thenReturn(properties);
- when(configurationAdmin.getConfiguration(OFConstants.CONFIG_FILE_ID)).thenReturn(configuration);
- when(bundleContext.getService(serviceReference)).thenReturn(configurationAdmin);
- when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(serviceReference);
-
- configurationService = new ConfigurationServiceFactoryImpl()
- .newInstance(config, bundleContext);
+ configurationService = new ConfigurationServiceFactoryImpl().newInstance(config);
+ configurationService.update(properties);
}
@Test
configurationService.close();
configurationService.getProperty(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString(), Integer::valueOf);
}
-
-}
\ No newline at end of file
+}