From: Harshini Date: Mon, 21 Jan 2019 08:40:49 +0000 (+0530) Subject: use annotations instead of XML for Blueprint X-Git-Tag: release/neon~7 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8dc6c29e45b896c0a1a35d272179c15d68b27a77;p=ovsdb.git use annotations instead of XML for Blueprint JIRA: OVSDB-474 Change-Id: Ie40dacf4b4a745d77d83bdc7e1b95fecad4fd276 Signed-off-by: Harshini Signed-off-by: Michael Vorburger --- diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml b/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml index 28b317a9e..9a64d3ee4 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml @@ -42,6 +42,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html org.opendaylight.mdsal mdsal-eos-binding-api + + javax.inject + javax.inject + true + + + org.apache.aries.blueprint + blueprint-maven-plugin-annotation + true + ${project.groupId} @@ -137,11 +147,19 @@ and is available at http://www.eclipse.org/legal/epl-v10.html + + org.apache.aries.blueprint + blueprint-maven-plugin + + org.opendaylight.ovsdb.hwvtepsouthbound + + org.apache.felix maven-bundle-plugin + org.opendaylight.ovsdb.hwvtepsouthbound.TransactionHistoryCmd org.opendaylight.ovsdb.schema.hardwarevtep org.opendaylight.ovsdb.hwvtepsouthbound.*,org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hwvtepsouthbound.impl.rev150901.* diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java index bf6d2707b..1c9af4e5d 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java @@ -12,6 +12,11 @@ import com.google.common.util.concurrent.CheckedFuture; import java.util.Collection; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.aries.blueprint.annotation.service.Reference; import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -41,6 +46,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Singleton public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundProvider.class); @@ -59,11 +65,12 @@ public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener private final AtomicBoolean registered = new AtomicBoolean(false); private ListenerRegistration operTopologyRegistration; - public HwvtepSouthboundProvider(final DataBroker dataBroker, - final EntityOwnershipService entityOwnershipServiceDependency, - final OvsdbConnection ovsdbConnection, - final DOMSchemaService schemaService, - final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) { + @Inject + public HwvtepSouthboundProvider(@Reference final DataBroker dataBroker, + @Reference final EntityOwnershipService entityOwnershipServiceDependency, + @Reference final OvsdbConnection ovsdbConnection, + @Reference final DOMSchemaService schemaService, + @Reference final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer) { this.dataBroker = dataBroker; this.entityOwnershipService = entityOwnershipServiceDependency; registration = null; @@ -76,6 +83,7 @@ public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener /** * Used by blueprint when starting the container. */ + @PostConstruct public void init() { LOG.info("HwvtepSouthboundProvider Session Initiated"); txInvoker = new TransactionInvokerImpl(dataBroker); @@ -105,6 +113,7 @@ public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener } @Override + @PreDestroy @SuppressWarnings("checkstyle:IllegalCatch") public void close() throws Exception { LOG.info("HwvtepSouthboundProvider Closed"); diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml index af0e676dd..b8937d063 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/OSGI-INF/blueprint/hwvtepsouthbound.xml @@ -3,31 +3,10 @@ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" odl:use-default-for-reference-types="true"> - - - - - - - - - - - - - - - + diff --git a/library/impl/pom.xml b/library/impl/pom.xml index 1ba80531e..5b31c90de 100644 --- a/library/impl/pom.xml +++ b/library/impl/pom.xml @@ -30,6 +30,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html + + org.apache.aries.blueprint + blueprint-maven-plugin-annotation + true + com.fasterxml.jackson.core jackson-annotations @@ -105,6 +110,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html + + org.apache.aries.blueprint + blueprint-maven-plugin + + org.opendaylight.ovsdb.lib + + org.apache.felix maven-bundle-plugin diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java index da3f7c30b..6e7a0c95a 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java @@ -50,10 +50,13 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.annotation.Nullable; import javax.inject.Inject; +import javax.inject.Singleton; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult.HandshakeStatus; import javax.net.ssl.SSLPeerUnverifiedException; +import org.apache.aries.blueprint.annotation.service.Reference; +import org.apache.aries.blueprint.annotation.service.Service; import org.opendaylight.aaa.cert.api.ICertificateManager; import org.opendaylight.ovsdb.lib.OvsdbClient; import org.opendaylight.ovsdb.lib.OvsdbConnection; @@ -84,6 +87,8 @@ import org.slf4j.LoggerFactory; * environment. Hence a single instance of the service will be active (via Service Registry in OSGi) * and a Singleton object in a non-OSGi environment. */ +@Singleton +@Service(classes = OvsdbConnection.class) public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection { private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionService.class); private static final int IDLE_READER_TIMEOUT = 30; @@ -118,7 +123,8 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection { private volatile int listenerPort = 6640; @Inject - public OvsdbConnectionService(ICertificateManager certManagerSrv) { + public OvsdbConnectionService(@Reference(filter = "type=default-certificate-manager") + ICertificateManager certManagerSrv) { this.certManagerSrv = certManagerSrv; } diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionServiceConfigurator.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionServiceConfigurator.java new file mode 100644 index 000000000..55835ad5f --- /dev/null +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionServiceConfigurator.java @@ -0,0 +1,63 @@ +/* + * Copyright © 2014, 2017 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.ovsdb.lib.impl; + +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OvsdbConnectionServiceConfigurator { + + private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionServiceConfigurator.class); + + private static final String JSON_RPC_DECODER_MAX_FRAME_LENGTH_PARAM = "json-rpc-decoder-max-frame-length"; + private static final String USE_SSL_PARAM = "use-ssl"; + private static final String OVSDB_RPC_TASK_TIMEOUT_PARAM = "ovsdb-rpc-task-timeout"; + private static final String OVSDB_LISTENER_PORT_PARAM = "ovsdb-listener-port"; + private final OvsdbConnectionService ovsdbconnection; + + public OvsdbConnectionServiceConfigurator(OvsdbConnectionService ovsdbconnection) { + this.ovsdbconnection = ovsdbconnection; + } + + public void setOvsdbRpcTaskTimeout(int timeout) { + ovsdbconnection.setOvsdbRpcTaskTimeout(timeout); + } + + public void setUseSsl(boolean flag) { + ovsdbconnection.setUseSsl(flag); + } + + public void setJsonRpcDecoderMaxFrameLength(int maxFrameLength) { + ovsdbconnection.setJsonRpcDecoderMaxFrameLength(maxFrameLength); + } + + public void setOvsdbListenerIp(String ip) { + ovsdbconnection.setOvsdbListenerIp(ip); + } + + public void setOvsdbListenerPort(int portNumber) { + ovsdbconnection.setOvsdbListenerPort(portNumber); + } + + public void updateConfigParameter(Map configParameters) { + if (configParameters != null && !configParameters.isEmpty()) { + LOG.debug("Config parameters received : {}", configParameters.entrySet()); + for (Map.Entry paramEntry : configParameters.entrySet()) { + if (paramEntry.getKey().equalsIgnoreCase(OVSDB_RPC_TASK_TIMEOUT_PARAM)) { + ovsdbconnection.setOvsdbRpcTaskTimeout(Integer.parseInt((String) paramEntry.getValue())); + } else if (paramEntry.getKey().equalsIgnoreCase(USE_SSL_PARAM)) { + ovsdbconnection.setUseSsl(Boolean.parseBoolean(paramEntry.getValue().toString())); + } + + } + } + } +} + diff --git a/library/impl/src/main/resources/OSGI-INF/blueprint/library.xml b/library/impl/src/main/resources/OSGI-INF/blueprint/library.xml index 5eaf9f033..7d0133d40 100644 --- a/library/impl/src/main/resources/OSGI-INF/blueprint/library.xml +++ b/library/impl/src/main/resources/OSGI-INF/blueprint/library.xml @@ -18,13 +18,9 @@ - - - - + + @@ -35,7 +31,4 @@ - - diff --git a/southbound/southbound-impl/pom.xml b/southbound/southbound-impl/pom.xml index 9c43ff1d0..0e79df9fb 100644 --- a/southbound/southbound-impl/pom.xml +++ b/southbound/southbound-impl/pom.xml @@ -82,13 +82,14 @@ and is available at http://www.eclipse.org/legal/epl-v10.html 1.5.0-SNAPSHOT - org.apache.aries.blueprint - blueprint-maven-plugin-annotation + javax.inject + javax.inject true - javax.inject - javax.inject + org.apache.aries.blueprint + blueprint-maven-plugin-annotation + true org.sonarsource.java @@ -169,6 +170,13 @@ and is available at http://www.eclipse.org/legal/epl-v10.html + + org.apache.aries.blueprint + blueprint-maven-plugin + + org.opendaylight.ovsdb.southbound + + org.apache.felix maven-bundle-plugin diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java index 0365316c4..41f7d075d 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java @@ -11,9 +11,13 @@ import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Collection; -import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; +import org.apache.aries.blueprint.annotation.service.Reference; import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -45,12 +49,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Singleton public class SouthboundProvider implements ClusteredDataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(SouthboundProvider.class); private static final String ENTITY_TYPE = "ovsdb-southbound-provider"; - private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status"; public static DataBroker getDb() { return db; @@ -73,13 +77,14 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener operTopologyRegistration; private final OvsdbDiagStatusProvider ovsdbStatusProvider; - public SouthboundProvider(final DataBroker dataBroker, - final EntityOwnershipService entityOwnershipServiceDependency, - final OvsdbConnection ovsdbConnection, - final DOMSchemaService schemaService, - final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer, - final SystemReadyMonitor systemReadyMonitor, - final DiagStatusService diagStatusService) { + @Inject + public SouthboundProvider(@Reference final DataBroker dataBroker, + @Reference final EntityOwnershipService entityOwnershipServiceDependency, + @Reference final OvsdbConnection ovsdbConnection, + @Reference final DOMSchemaService schemaService, + @Reference final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer, + @Reference final SystemReadyMonitor systemReadyMonitor, + @Reference final DiagStatusService diagStatusService) { this.db = dataBroker; this.entityOwnershipService = entityOwnershipServiceDependency; registration = null; @@ -94,6 +99,7 @@ public class SouthboundProvider implements ClusteredDataTreeChangeListener configParameters) { - if (configParameters != null && !configParameters.isEmpty()) { - LOG.debug("Config parameters received : {}", configParameters.entrySet()); - for (Map.Entry paramEntry : configParameters.entrySet()) { - if (paramEntry.getKey().equalsIgnoreCase(SKIP_MONITORING_MANAGER_STATUS_PARAM)) { - setSkipMonitoringManagerStatus(Boolean.parseBoolean((String)paramEntry.getValue())); - break; - } - } - } - } - public void setSkipMonitoringManagerStatus(boolean flag) { LOG.debug("skipManagerStatus set to {}", flag); if (flag) { diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProviderConfigurator.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProviderConfigurator.java new file mode 100644 index 000000000..6111f19d4 --- /dev/null +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProviderConfigurator.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 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.ovsdb.southbound; + +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper to let Blueprint XML configure {@link SouthboundProvider}. + * + * @author Michael Vorburger.ch + */ +public class SouthboundProviderConfigurator { + + private static final Logger LOG = LoggerFactory.getLogger(SouthboundProviderConfigurator.class); + + private static final String SKIP_MONITORING_MANAGER_STATUS_PARAM = "skip-monitoring-manager-status"; + + private final SouthboundProvider southboundProvider; + + public SouthboundProviderConfigurator(SouthboundProvider southboundProvider) { + this.southboundProvider = southboundProvider; + } + + public void setSkipMonitoringManagerStatus(boolean flag) { + southboundProvider.setSkipMonitoringManagerStatus(flag); + } + + public void updateConfigParameter(Map configParameters) { + if (configParameters != null && !configParameters.isEmpty()) { + LOG.debug("Config parameters received : {}", configParameters.entrySet()); + for (Map.Entry paramEntry : configParameters.entrySet()) { + if (paramEntry.getKey().equalsIgnoreCase(SKIP_MONITORING_MANAGER_STATUS_PARAM)) { + southboundProvider + .setSkipMonitoringManagerStatus(Boolean.parseBoolean((String) paramEntry.getValue())); + break; + } + } + } + } +} diff --git a/southbound/southbound-impl/src/main/resources/OSGI-INF/blueprint/southbound.xml b/southbound/southbound-impl/src/main/resources/OSGI-INF/blueprint/southbound.xml index 9402c7249..2693703f0 100644 --- a/southbound/southbound-impl/src/main/resources/OSGI-INF/blueprint/southbound.xml +++ b/southbound/southbound-impl/src/main/resources/OSGI-INF/blueprint/southbound.xml @@ -4,39 +4,18 @@ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" odl:use-default-for-reference-types="true"> - - - - - - - - - + - - - - - - - +