Enable public key based authentication for netconf
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / utils / NetconfTopologySetup.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.topology.singleton.impl.utils;
10
11 import akka.actor.ActorSystem;
12 import io.netty.util.concurrent.EventExecutor;
13 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
14 import org.opendaylight.controller.config.threadpool.ThreadPool;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
17 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
18 import org.opendaylight.netconf.client.NetconfClientDispatcher;
19 import org.opendaylight.netconf.sal.connect.netconf.NetconfDevice;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import scala.concurrent.duration.Duration;
23
24 public class NetconfTopologySetup {
25
26     private final ClusterSingletonServiceProvider clusterSingletonServiceProvider;
27     private final RpcProviderRegistry rpcProviderRegistry;
28     private final DataBroker dataBroker;
29     private final InstanceIdentifier<Node> instanceIdentifier;
30     private final Node node;
31     private final ScheduledThreadPool keepaliveExecutor;
32     private final ThreadPool processingExecutor;
33     private final ActorSystem actorSystem;
34     private final EventExecutor eventExecutor;
35     private final NetconfClientDispatcher netconfClientDispatcher;
36     private final String topologyId;
37     private final NetconfDevice.SchemaResourcesDTO schemaResourceDTO;
38     private final Duration idleTimeout;
39     private final String privateKeyPath;
40     private final String privateKeyPassphrase;
41
42     private NetconfTopologySetup(final NetconfTopologySetupBuilder builder) {
43         this.clusterSingletonServiceProvider = builder.getClusterSingletonServiceProvider();
44         this.rpcProviderRegistry = builder.getRpcProviderRegistry();
45         this.dataBroker = builder.getDataBroker();
46         this.instanceIdentifier = builder.getInstanceIdentifier();
47         this.node = builder.getNode();
48         this.keepaliveExecutor = builder.getKeepaliveExecutor();
49         this.processingExecutor = builder.getProcessingExecutor();
50         this.actorSystem = builder.getActorSystem();
51         this.eventExecutor = builder.getEventExecutor();
52         this.netconfClientDispatcher = builder.getNetconfClientDispatcher();
53         this.topologyId = builder.getTopologyId();
54         this.schemaResourceDTO = builder.getSchemaResourceDTO();
55         this.idleTimeout = builder.getIdleTimeout();
56         this.privateKeyPath = builder.getPrivateKeyPath();
57         this.privateKeyPassphrase = builder.getPrivateKeyPassphrase();
58     }
59
60     public ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
61         return clusterSingletonServiceProvider;
62     }
63
64     public RpcProviderRegistry getRpcProviderRegistry() {
65         return rpcProviderRegistry;
66     }
67
68     public DataBroker getDataBroker() {
69         return dataBroker;
70     }
71
72     public InstanceIdentifier<Node> getInstanceIdentifier() {
73         return instanceIdentifier;
74     }
75
76     public Node getNode() {
77         return node;
78     }
79
80     public ThreadPool getProcessingExecutor() {
81         return processingExecutor;
82     }
83
84     public ScheduledThreadPool getKeepaliveExecutor() {
85         return keepaliveExecutor;
86     }
87
88     public ActorSystem getActorSystem() {
89         return actorSystem;
90     }
91
92     public EventExecutor getEventExecutor() {
93         return eventExecutor;
94     }
95
96     public String getTopologyId() {
97         return topologyId;
98     }
99
100     public NetconfClientDispatcher getNetconfClientDispatcher() {
101         return netconfClientDispatcher;
102     }
103
104     public NetconfDevice.SchemaResourcesDTO getSchemaResourcesDTO() {
105         return schemaResourceDTO;
106     }
107
108     public Duration getIdleTimeout() {
109         return idleTimeout;
110     }
111
112     public String getPrivateKeyPath() {
113         return privateKeyPath;
114     }
115
116     public String getPrivateKeyPassphrase() {
117         return privateKeyPassphrase;
118     }
119
120     public static class NetconfTopologySetupBuilder {
121
122         private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
123         private RpcProviderRegistry rpcProviderRegistry;
124         private DataBroker dataBroker;
125         private InstanceIdentifier<Node> instanceIdentifier;
126         private Node node;
127         private ScheduledThreadPool keepaliveExecutor;
128         private ThreadPool processingExecutor;
129         private ActorSystem actorSystem;
130         private EventExecutor eventExecutor;
131         private String topologyId;
132         private NetconfClientDispatcher netconfClientDispatcher;
133         private NetconfDevice.SchemaResourcesDTO schemaResourceDTO;
134         private Duration idleTimeout;
135         private String privateKeyPath;
136         private String privateKeyPassphrase;
137
138         public NetconfTopologySetupBuilder() {
139         }
140
141         private ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
142             return clusterSingletonServiceProvider;
143         }
144
145         public NetconfTopologySetupBuilder setClusterSingletonServiceProvider(
146                 final ClusterSingletonServiceProvider clusterSingletonServiceProvider) {
147             this.clusterSingletonServiceProvider = clusterSingletonServiceProvider;
148             return this;
149         }
150
151         private RpcProviderRegistry getRpcProviderRegistry() {
152             return rpcProviderRegistry;
153         }
154
155         public NetconfTopologySetupBuilder setRpcProviderRegistry(final RpcProviderRegistry rpcProviderRegistry) {
156             this.rpcProviderRegistry = rpcProviderRegistry;
157             return this;
158         }
159
160         private DataBroker getDataBroker() {
161             return dataBroker;
162         }
163
164         public NetconfTopologySetupBuilder setDataBroker(final DataBroker dataBroker) {
165             this.dataBroker = dataBroker;
166             return this;
167         }
168
169         private InstanceIdentifier<Node> getInstanceIdentifier() {
170             return instanceIdentifier;
171         }
172
173         public NetconfTopologySetupBuilder setInstanceIdentifier(final InstanceIdentifier<Node> instanceIdentifier) {
174             this.instanceIdentifier = instanceIdentifier;
175             return this;
176         }
177
178         public Node getNode() {
179             return node;
180         }
181
182         public NetconfTopologySetupBuilder setNode(final Node node) {
183             this.node = node;
184             return this;
185         }
186
187         public NetconfTopologySetup build() {
188             return new NetconfTopologySetup(this);
189         }
190
191         private ScheduledThreadPool getKeepaliveExecutor() {
192             return keepaliveExecutor;
193         }
194
195         public NetconfTopologySetupBuilder setKeepaliveExecutor(final ScheduledThreadPool keepaliveExecutor) {
196             this.keepaliveExecutor = keepaliveExecutor;
197             return this;
198         }
199
200         private ThreadPool getProcessingExecutor() {
201             return processingExecutor;
202         }
203
204         public NetconfTopologySetupBuilder setProcessingExecutor(final ThreadPool processingExecutor) {
205             this.processingExecutor = processingExecutor;
206             return this;
207         }
208
209         private ActorSystem getActorSystem() {
210             return actorSystem;
211         }
212
213         public NetconfTopologySetupBuilder setActorSystem(final ActorSystem actorSystem) {
214             this.actorSystem = actorSystem;
215             return this;
216         }
217
218         private EventExecutor getEventExecutor() {
219             return eventExecutor;
220         }
221
222         public NetconfTopologySetupBuilder setEventExecutor(final EventExecutor eventExecutor) {
223             this.eventExecutor = eventExecutor;
224             return this;
225         }
226
227         private String getTopologyId() {
228             return topologyId;
229         }
230
231         public NetconfTopologySetupBuilder setTopologyId(final String topologyId) {
232             this.topologyId = topologyId;
233             return this;
234         }
235
236         private NetconfClientDispatcher getNetconfClientDispatcher() {
237             return netconfClientDispatcher;
238         }
239
240         public NetconfTopologySetupBuilder setNetconfClientDispatcher(final NetconfClientDispatcher clientDispatcher) {
241             this.netconfClientDispatcher = clientDispatcher;
242             return this;
243         }
244
245         public NetconfTopologySetupBuilder setSchemaResourceDTO(
246                 final NetconfDevice.SchemaResourcesDTO schemaResourceDTO) {
247             this.schemaResourceDTO = schemaResourceDTO;
248             return this;
249         }
250
251         private NetconfDevice.SchemaResourcesDTO getSchemaResourceDTO() {
252             return schemaResourceDTO;
253         }
254
255         public NetconfTopologySetupBuilder setIdleTimeout(final Duration idleTimeout) {
256             this.idleTimeout = idleTimeout;
257             return this;
258         }
259
260         private Duration getIdleTimeout() {
261             return idleTimeout;
262         }
263
264         public NetconfTopologySetupBuilder setPrivateKeyPath(String privateKeyPath) {
265             this.privateKeyPath = privateKeyPath;
266             return this;
267         }
268
269         public String getPrivateKeyPath() {
270             return this.privateKeyPath;
271         }
272
273         public NetconfTopologySetupBuilder setPrivateKeyPassphrase(String privateKeyPassphrase) {
274             this.privateKeyPassphrase = privateKeyPassphrase;
275             return this;
276         }
277
278         public String getPrivateKeyPassphrase() {
279             return this.privateKeyPassphrase;
280         }
281
282         public static NetconfTopologySetupBuilder create() {
283             return new NetconfTopologySetupBuilder();
284         }
285     }
286
287
288 }