From aeb187784566034251563998930b15a46d2d035c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Thu, 3 Nov 2016 16:25:18 -0400 Subject: [PATCH] Add blueprint wiring for loopback controller-config MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I0bf0664e35f17ba449d71a6555359cc42b61da07 Signed-off-by: Alexis de Talhouët --- features/netconf-connector/pom.xml | 5 - .../src/main/features/features.xml | 2 +- features/netconf/pom.xml | 6 -- netconf/netconf-artifacts/pom.xml | 2 - netconf/netconf-connector-config/pom.xml | 87 ++++++++-------- .../initial/99-netconf-connector.xml | 55 ----------- .../blueprint/netconf-connector.xml | 41 ++++++++ .../blueprint/netconf-topology.xml | 4 + netconf/netconf-topology/pom.xml | 25 ----- .../topology/api/NetconfConnectorFactory.java | 44 +++++++++ .../impl/NetconfConnectorFactoryImpl.java | 99 +++++++++++++++++++ 11 files changed, 237 insertions(+), 133 deletions(-) delete mode 100644 netconf/netconf-connector-config/src/main/resources/initial/99-netconf-connector.xml create mode 100644 netconf/netconf-connector-config/src/main/resources/org/opendaylight/blueprint/netconf-connector.xml create mode 100644 netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/api/NetconfConnectorFactory.java create mode 100644 netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfConnectorFactoryImpl.java diff --git a/features/netconf-connector/pom.xml b/features/netconf-connector/pom.xml index ecd3e5abe6..c3f8d6aa06 100644 --- a/features/netconf-connector/pom.xml +++ b/features/netconf-connector/pom.xml @@ -34,7 +34,6 @@ features.xml etc/opendaylight/karaf 01-netconf.xml - 99-netconf-connector.xml @@ -120,13 +119,9 @@ ${project.groupId} netconf-topology-singleton - ${project.groupId} netconf-connector-config - ${netconf.version} - xml - config diff --git a/features/netconf-connector/src/main/features/features.xml b/features/netconf-connector/src/main/features/features.xml index a911dcf565..cdbe097eb0 100644 --- a/features/netconf-connector/src/main/features/features.xml +++ b/features/netconf-connector/src/main/features/features.xml @@ -43,7 +43,7 @@ odl-netconf-topology - mvn:org.opendaylight.netconf/netconf-connector-config/{{VERSION}}/xml/config + mvn:org.opendaylight.netconf/netconf-connector-config/{{VERSION}} diff --git a/features/netconf/pom.xml b/features/netconf/pom.xml index 502ae76fef..bd68cb8448 100644 --- a/features/netconf/pom.xml +++ b/features/netconf/pom.xml @@ -225,12 +225,6 @@ xml config - - ${project.groupId} - netconf-connector-config - xml - config - ${project.groupId} netconf-monitoring diff --git a/netconf/netconf-artifacts/pom.xml b/netconf/netconf-artifacts/pom.xml index 32bcf637d3..cb03a4d2cf 100644 --- a/netconf/netconf-artifacts/pom.xml +++ b/netconf/netconf-artifacts/pom.xml @@ -75,8 +75,6 @@ ${project.groupId} netconf-connector-config ${project.version} - xml - config ${project.groupId} diff --git a/netconf/netconf-connector-config/pom.xml b/netconf/netconf-connector-config/pom.xml index ff6e0ec177..771a3bea45 100644 --- a/netconf/netconf-connector-config/pom.xml +++ b/netconf/netconf-connector-config/pom.xml @@ -6,46 +6,55 @@ terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html --> - + - 4.0.0 - - org.opendaylight.odlparent - odlparent-lite - 1.8.0-SNAPSHOT - - + 4.0.0 + + org.opendaylight.odlparent + bundle-parent + 1.8.0-SNAPSHOT + + - org.opendaylight.netconf - netconf-connector-config - Configuration files for netconf-connector - 1.2.0-SNAPSHOT - jar + org.opendaylight.netconf + netconf-connector-config + Configuration files for netconf-connector + 1.2.0-SNAPSHOT + bundle - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - attach-artifact - - package - - - - ${project.build.directory}/classes/initial/99-netconf-connector.xml - xml - config - - - - - - - - + + + + org.opendaylight.netconf + netconf-subsystem + ${project.version} + pom + import + + + + + + + ${project.groupId} + netconf-topology + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + netconf-topology + + + + + diff --git a/netconf/netconf-connector-config/src/main/resources/initial/99-netconf-connector.xml b/netconf/netconf-connector-config/src/main/resources/initial/99-netconf-connector.xml deleted file mode 100644 index 62b2c8de44..0000000000 --- a/netconf/netconf-connector-config/src/main/resources/initial/99-netconf-connector.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - prefix:sal-netconf-connector - controller-config -
127.0.0.1
- 1830 - admin - admin - false - true - - prefix:netty-event-executor - global-event-executor - - - prefix:binding-broker-osgi-registry - binding-osgi-broker - - - prefix:dom-broker-osgi-registry - dom-broker - - - prefix:netconf-client-dispatcher - global-netconf-dispatcher - - - prefix:threadpool - global-netconf-processing-executor - - - prefix:scheduled-threadpool - global-netconf-ssh-scheduled-executor - -
-
-
-
- - urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf?module=odl-sal-netconf-connector-cfg&revision=2015-08-03 - -
diff --git a/netconf/netconf-connector-config/src/main/resources/org/opendaylight/blueprint/netconf-connector.xml b/netconf/netconf-connector-config/src/main/resources/org/opendaylight/blueprint/netconf-connector.xml new file mode 100644 index 0000000000..7312471308 --- /dev/null +++ b/netconf/netconf-connector-config/src/main/resources/org/opendaylight/blueprint/netconf-connector.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/netconf/netconf-topology-config/src/main/resources/org/opendaylight/blueprint/netconf-topology.xml b/netconf/netconf-topology-config/src/main/resources/org/opendaylight/blueprint/netconf-topology.xml index cf04017727..62e5046c7b 100755 --- a/netconf/netconf-topology-config/src/main/resources/org/opendaylight/blueprint/netconf-topology.xml +++ b/netconf/netconf-topology-config/src/main/resources/org/opendaylight/blueprint/netconf-topology.xml @@ -48,4 +48,8 @@ + + + \ No newline at end of file diff --git a/netconf/netconf-topology/pom.xml b/netconf/netconf-topology/pom.xml index 5ffd6d8d37..ae7679f62b 100644 --- a/netconf/netconf-topology/pom.xml +++ b/netconf/netconf-topology/pom.xml @@ -70,29 +70,4 @@ yang-model-api
- - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/config; - - - - - - - - diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/api/NetconfConnectorFactory.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/api/NetconfConnectorFactory.java new file mode 100644 index 0000000000..632c2f9e59 --- /dev/null +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/api/NetconfConnectorFactory.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Inocybe Technologies 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.netconf.topology.api; + +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; + +/** + * Created by adetalhouet on 2016-11-03. + */ +public interface NetconfConnectorFactory { + + /** + * Create a new netconf connector with default values. + *

+ * This method will create a {@link Node} and a {@link NetconfNode} that will be added as an augmentation to the + * {@link Node}. Afterward, that {@link Node} will be written in the MDSAL datastore under the {@link NetconfTopology}. + * Listeners of that subtree located within network-topology bundle will setup the session. + * + * @param dataBroker Instance of the {@link DataBroker} + * @param instanceName The name of the node + * @param address The address + * @param port The port + * @param username The username of the netconf session + * @param password The password of the netconf session + * @param tcpOnly Whether to create a TCP or SSH session + * @param reconnectOnSchemaChange Whether to enable ietf-netconf-monitoring and register the NETCONF stream. + * @return The created {@link Node} + */ + Node newInstance(final DataBroker dataBroker, + final String instanceName, + final String address, + final Integer port, + final String username, + final String password, + final Boolean tcpOnly, + final Boolean reconnectOnSchemaChange); +} diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfConnectorFactoryImpl.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfConnectorFactoryImpl.java new file mode 100644 index 0000000000..dc5649f49a --- /dev/null +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/impl/NetconfConnectorFactoryImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016 Inocybe Technologies 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.netconf.topology.impl; + +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import javax.annotation.Nullable; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.netconf.topology.api.NetconfConnectorFactory; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.HostBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Created by adetalhouet on 2016-11-03. + */ +public class NetconfConnectorFactoryImpl implements NetconfConnectorFactory { + + private static final Logger LOG = LoggerFactory.getLogger(NetconfConnectorFactoryImpl.class); + + private static final InstanceIdentifier TOPOLOGY_PATH = InstanceIdentifier.create(NetworkTopology.class) + .child(Topology.class, new TopologyKey(new TopologyId("topology-netconf"))); + + /** + * {@inheritDoc} + */ + @Override + public Node newInstance(final DataBroker dataBroker, + final String instanceName, + final String address, + final Integer port, + final String username, + final String password, + final Boolean tcpOnly, + final Boolean reconnectOnSchemaChange) { + + final NodeId nodeId = new NodeId(instanceName); + final NodeKey nodeKey = new NodeKey(nodeId); + final Credentials credentials = new LoginPasswordBuilder() + .setUsername(username) + .setPassword(password) + .build(); + final Host host = HostBuilder.getDefaultInstance(address); + final PortNumber portNumber = new PortNumber(port); + final NetconfNode netconfNode = new NetconfNodeBuilder() + .setHost(host) + .setPort(portNumber) + .setCredentials(credentials) + .setTcpOnly(tcpOnly) + .setReconnectOnChangedSchema(reconnectOnSchemaChange) + .build(); + final Node node = new NodeBuilder() + .setNodeId(nodeId) + .setKey(nodeKey) + .addAugmentation(NetconfNode.class, netconfNode) + .build(); + + final InstanceIdentifier nodePath = TOPOLOGY_PATH.child(Node.class, nodeKey); + final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + transaction.put(LogicalDatastoreType.CONFIGURATION, nodePath, node); + final CheckedFuture submitFuture = transaction.submit(); + Futures.addCallback(submitFuture, new FutureCallback() { + @Override + public void onSuccess(@Nullable final Void result) { + LOG.debug("Node {} was successfully added to the topology", instanceName); + } + + @Override + public void onFailure(final Throwable t) { + LOG.error("Node {} creation failed: {}", instanceName, t); + } + }); + return node; + } +} \ No newline at end of file -- 2.36.6