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