bf59d2af9576ba3774263f3a7f03bd5a42ccba75
[netconf.git] / apps / 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 package org.opendaylight.netconf.topology.singleton.impl.utils;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorSystem;
13 import io.netty.util.Timer;
14 import java.time.Duration;
15 import java.util.concurrent.Executor;
16 import java.util.concurrent.ScheduledExecutorService;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.mdsal.binding.api.DataBroker;
19 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
20 import org.opendaylight.netconf.client.NetconfClientFactory;
21 import org.opendaylight.netconf.client.mdsal.NetconfDevice;
22 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchemas;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 public final class NetconfTopologySetup {
27     private final ClusterSingletonServiceProvider clusterSingletonServiceProvider;
28     private final DataBroker dataBroker;
29     private final InstanceIdentifier<Node> instanceIdentifier;
30     private final Node node;
31     private final Timer timer;
32     private final ScheduledExecutorService keepaliveExecutor;
33     private final Executor processingExecutor;
34     private final ActorSystem actorSystem;
35     private final NetconfClientFactory netconfClientFactory;
36     private final String topologyId;
37     private final NetconfDevice.SchemaResourcesDTO schemaResourceDTO;
38     private final Duration idleTimeout;
39     private final BaseNetconfSchemas baseSchemas;
40
41     private NetconfTopologySetup(final Builder builder) {
42         clusterSingletonServiceProvider = builder.getClusterSingletonServiceProvider();
43         dataBroker = builder.getDataBroker();
44         instanceIdentifier = builder.getInstanceIdentifier();
45         node = builder.getNode();
46         timer = builder.getTimer();
47         keepaliveExecutor = builder.getKeepaliveExecutor();
48         processingExecutor = builder.getProcessingExecutor();
49         actorSystem = builder.getActorSystem();
50         netconfClientFactory = builder.getNetconfClientFactory();
51         topologyId = builder.getTopologyId();
52         schemaResourceDTO = builder.getSchemaResourceDTO();
53         idleTimeout = builder.getIdleTimeout();
54         baseSchemas = builder.getBaseSchemas();
55     }
56
57     public ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
58         return clusterSingletonServiceProvider;
59     }
60
61     public DataBroker getDataBroker() {
62         return dataBroker;
63     }
64
65     public InstanceIdentifier<Node> getInstanceIdentifier() {
66         return instanceIdentifier;
67     }
68
69     public Node getNode() {
70         return node;
71     }
72
73     public Executor getProcessingExecutor() {
74         return processingExecutor;
75     }
76
77     public ScheduledExecutorService getKeepaliveExecutor() {
78         return keepaliveExecutor;
79     }
80
81     public Timer getTimer() {
82         return timer;
83     }
84
85     public ActorSystem getActorSystem() {
86         return actorSystem;
87     }
88
89     public String getTopologyId() {
90         return topologyId;
91     }
92
93     public NetconfClientFactory getNetconfClientFactory() {
94         return netconfClientFactory;
95     }
96
97     public NetconfDevice.SchemaResourcesDTO getSchemaResourcesDTO() {
98         return schemaResourceDTO;
99     }
100
101     public Duration getIdleTimeout() {
102         return idleTimeout;
103     }
104
105     public BaseNetconfSchemas getBaseSchemas() {
106         return baseSchemas;
107     }
108
109     public static @NonNull Builder builder() {
110         return new Builder();
111     }
112
113     public static final class Builder {
114         private ClusterSingletonServiceProvider clusterSingletonServiceProvider;
115         private DataBroker dataBroker;
116         private InstanceIdentifier<Node> instanceIdentifier;
117         private Node node;
118         private Timer timer;
119         private ScheduledExecutorService keepaliveExecutor;
120         private Executor processingExecutor;
121         private ActorSystem actorSystem;
122         private String topologyId;
123         private NetconfClientFactory netconfClientFactory;
124         private NetconfDevice.SchemaResourcesDTO schemaResourceDTO;
125         private Duration idleTimeout;
126         private BaseNetconfSchemas baseSchemas;
127
128         private Builder() {
129             // Hidden on purpose
130         }
131
132         BaseNetconfSchemas getBaseSchemas() {
133             return requireNonNull(baseSchemas, "BaseSchemas not initialized");
134         }
135
136         public Builder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
137             this.baseSchemas = requireNonNull(baseSchemas);
138             return this;
139         }
140
141         ClusterSingletonServiceProvider getClusterSingletonServiceProvider() {
142             return clusterSingletonServiceProvider;
143         }
144
145         public Builder setClusterSingletonServiceProvider(
146                 final ClusterSingletonServiceProvider clusterSingletonServiceProvider) {
147             this.clusterSingletonServiceProvider = clusterSingletonServiceProvider;
148             return this;
149         }
150
151         DataBroker getDataBroker() {
152             return dataBroker;
153         }
154
155         public Builder setDataBroker(final DataBroker dataBroker) {
156             this.dataBroker = dataBroker;
157             return this;
158         }
159
160         InstanceIdentifier<Node> getInstanceIdentifier() {
161             return instanceIdentifier;
162         }
163
164         public Builder setInstanceIdentifier(final InstanceIdentifier<Node> instanceIdentifier) {
165             this.instanceIdentifier = instanceIdentifier;
166             return this;
167         }
168
169         public Node getNode() {
170             return node;
171         }
172
173         public Builder setNode(final Node node) {
174             this.node = node;
175             return this;
176         }
177
178         public NetconfTopologySetup build() {
179             return new NetconfTopologySetup(this);
180         }
181
182         Timer getTimer() {
183             return timer;
184         }
185
186         public Builder setTimer(final Timer timer) {
187             this.timer = requireNonNull(timer);
188             return this;
189         }
190
191         ScheduledExecutorService getKeepaliveExecutor() {
192             return keepaliveExecutor;
193         }
194
195         public Builder setKeepaliveExecutor(final ScheduledExecutorService keepaliveExecutor) {
196             this.keepaliveExecutor = keepaliveExecutor;
197             return this;
198         }
199
200         Executor getProcessingExecutor() {
201             return processingExecutor;
202         }
203
204         public Builder setProcessingExecutor(final Executor processingExecutor) {
205             this.processingExecutor = processingExecutor;
206             return this;
207         }
208
209         ActorSystem getActorSystem() {
210             return actorSystem;
211         }
212
213         public Builder setActorSystem(final ActorSystem actorSystem) {
214             this.actorSystem = actorSystem;
215             return this;
216         }
217
218         String getTopologyId() {
219             return topologyId;
220         }
221
222         public Builder setTopologyId(final String topologyId) {
223             this.topologyId = topologyId;
224             return this;
225         }
226
227         NetconfClientFactory getNetconfClientFactory() {
228             return netconfClientFactory;
229         }
230
231         public Builder setNetconfClientFactory(final NetconfClientFactory clientFactory) {
232             netconfClientFactory = clientFactory;
233             return this;
234         }
235
236         public Builder setSchemaResourceDTO(
237                 final NetconfDevice.SchemaResourcesDTO schemaResourceDTO) {
238             this.schemaResourceDTO = schemaResourceDTO;
239             return this;
240         }
241
242         NetconfDevice.SchemaResourcesDTO getSchemaResourceDTO() {
243             return schemaResourceDTO;
244         }
245
246         public Builder setIdleTimeout(final Duration idleTimeout) {
247             this.idleTimeout = idleTimeout;
248             return this;
249         }
250
251         Duration getIdleTimeout() {
252             return idleTimeout;
253         }
254     }
255 }