Update initialization example in honeycomb archetype
[honeycomb.git] / infra / minimal-distribution / src / main / java / io / fd / honeycomb / infra / distro / cfgattrs / HoneycombConfiguration.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.infra.distro.cfgattrs;
18
19 import com.google.common.base.MoreObjects;
20 import java.util.Optional;
21 import net.jmob.guice.conf.core.BindConfig;
22 import net.jmob.guice.conf.core.InjectConfig;
23 import net.jmob.guice.conf.core.Syntax;
24
25 /**
26  * This is the Java equivalent for honeyconb.json file. We use guice-config library to load all the config attributes
27  * into this class instance.
28  *
29  * The BindConfig annotation tells that honeycomb.json file should be looked up on classpath root.
30  */
31 @BindConfig(value = "honeycomb", syntax = Syntax.JSON)
32 public class HoneycombConfiguration {
33
34     public boolean isRestconfHttpEnabled() {
35         return Boolean.valueOf(restconfHttp);
36     }
37
38     public boolean isRestconfHttpsEnabled() {
39         return Boolean.valueOf(restconfHttps);
40     }
41
42     public boolean isRestconfEnabled() {
43         return isRestconfHttpEnabled() || isRestconfHttpsEnabled();
44     }
45
46     public boolean isNetconfTcpEnabled() {
47         return Boolean.valueOf(netconfTcp);
48     }
49
50     public boolean isNetconfSshEnabled() {
51         return Boolean.valueOf(netconfSsh);
52     }
53
54     public boolean isNetconfEnabled() {
55         return isNetconfTcpEnabled() || isNetconfSshEnabled();
56     }
57
58     public boolean isConfigPersistenceEnabled() {
59         return persistConfig.isPresent() && Boolean.valueOf(persistConfig.get());
60     }
61     public boolean isContextPersistenceEnabled() {
62         return persistContext.isPresent() && Boolean.valueOf(persistContext.get());
63     }
64
65     @InjectConfig("persist-context")
66     public Optional<String> persistContext = Optional.of("true");
67     @InjectConfig("persisted-context-path")
68     public String peristContextPath;
69     @InjectConfig("persisted-context-restoration-type")
70     public String persistedContextRestorationType;
71     @InjectConfig("persist-config")
72     public Optional<String> persistConfig = Optional.of("true");
73     @InjectConfig("persisted-config-path")
74     public String peristConfigPath;
75     @InjectConfig("persisted-config-restoration-type")
76     public String persistedConfigRestorationType;
77     @InjectConfig("notification-service-queue-depth")
78     public int notificationServiceQueueDepth;
79     @InjectConfig("restconf-http-enabled")
80     public String restconfHttp;
81     @InjectConfig("restconf-binding-address")
82     public Optional<String> restconfBindingAddress;
83     @InjectConfig("restconf-port")
84     public Optional<Integer> restconfPort;
85     @InjectConfig("restconf-https-enabled")
86     public String restconfHttps;
87     @InjectConfig("restconf-https-binding-address")
88     public Optional<String> restconfHttpsBindingAddress;
89     @InjectConfig("restconf-https-port")
90     public Optional<Integer> restconfHttpsPort;
91     /**
92      * Restconf keystore file name. It will be loaded from the classpath so must be present in one of the folders
93      * packaged with the distribution e.g. cert/
94      */
95     @InjectConfig("restconf-keystore")
96     public Optional<String> restconfKeystore = Optional.of("/honeycomb-keystore");
97     @InjectConfig("restconf-keystore-password")
98     public Optional<String> keystorePassword;
99     @InjectConfig("restconf-keystore-manager-password")
100     public Optional<String> keystoreManagerPassword;
101     /**
102      * Restconf truststore file name. It will be loaded from the classpath so must be present in one of the folders
103      * packaged with the distribution e.g. cert/
104      */
105     @InjectConfig("restconf-truststore")
106     public Optional<String> restconfTruststore;
107     @InjectConfig("restconf-truststore-password")
108     public Optional<String> truststorePassword;
109     @InjectConfig("restconf-websocket-port")
110     public Optional<Integer> restconfWebsocketPort = Optional.of(7779);
111     @InjectConfig("restconf-root-path")
112     public Optional<String> restconfRootPath = Optional.of("/restconf");
113     @InjectConfig("restconf-pool-max-size")
114     public Optional<Integer> restPoolMaxSize = Optional.of(10);
115     @InjectConfig("restconf-pool-min-size")
116     public Optional<Integer> restPoolMinSize = Optional.of(1);
117     @InjectConfig("restconf-acceptors-size")
118     public Optional<Integer> acceptorsSize = Optional.of(1);
119     @InjectConfig("restconf-selectors-size")
120     public Optional<Integer> selectorsSize = Optional.of(1);
121     @InjectConfig("restconf-https-acceptors-size")
122     public Optional<Integer> httpsAcceptorsSize = Optional.of(1);
123     @InjectConfig("restconf-https-selectors-size")
124     public Optional<Integer> httpsSelectorsSize = Optional.of(1);
125     @InjectConfig("netconf-netty-threads")
126     public Integer netconfNettyThreads;
127     @InjectConfig("netconf-tcp-enabled")
128     public String netconfTcp;
129     @InjectConfig("netconf-tcp-binding-address")
130     public Optional<String> netconfTcpBindingAddress;
131     @InjectConfig("netconf-tcp-binding-port")
132     public Optional<Integer> netconfTcpBindingPort;
133     @InjectConfig("netconf-ssh-enabled")
134     public String netconfSsh;
135     @InjectConfig("netconf-ssh-binding-address")
136     public Optional<String> netconfSshBindingAddress;
137     @InjectConfig("netconf-ssh-binding-port")
138     public Optional<Integer> netconfSshBindingPort;
139     @InjectConfig("netconf-notification-stream-name")
140     public Optional<String> netconfNotificationStreamName = Optional.of("honeycomb");
141     @InjectConfig("username")
142     public String username;
143     @InjectConfig("password")
144     public String password;
145
146     @Override
147     public String toString() {
148         return MoreObjects.toStringHelper(this)
149                 .add("peristContextPath", peristContextPath)
150                 .add("persistedContextRestorationType", persistedContextRestorationType)
151                 .add("peristConfigPath", peristConfigPath)
152                 .add("persistedConfigRestorationType", persistedConfigRestorationType)
153                 .add("notificationServiceQueueDepth", notificationServiceQueueDepth)
154                 .add("restconfHttp", restconfHttp)
155                 .add("restconfBindingAddress", restconfBindingAddress)
156                 .add("restconfPort", restconfPort)
157                 .add("restconfHttps", restconfHttps)
158                 .add("restconfHttpsBindingAddress", restconfHttpsBindingAddress)
159                 .add("restconfHttpsPort", restconfHttpsPort)
160                 .add("restconfKeystore", restconfKeystore)
161                 .add("keystorePassword", keystorePassword)
162                 .add("keystoreManagerPassword", keystoreManagerPassword)
163                 .add("restconfTruststore", restconfTruststore)
164                 .add("truststorePassword", truststorePassword)
165                 .add("restconfWebsocketPort", restconfWebsocketPort)
166                 .add("restconfRootPath", restconfRootPath)
167                 .add("restPoolMaxSize", restPoolMaxSize)
168                 .add("restPoolMinSize", restPoolMinSize)
169                 .add("acceptorsSize", acceptorsSize)
170                 .add("selectorsSize", selectorsSize)
171                 .add("httpsAcceptorsSize", httpsAcceptorsSize)
172                 .add("httpsSelectorsSize", httpsSelectorsSize)
173                 .add("netconfNettyThreads", netconfNettyThreads)
174                 .add("netconfTcp", netconfTcp)
175                 .add("netconfTcpBindingAddress", netconfTcpBindingAddress)
176                 .add("netconfTcpBindingPort", netconfTcpBindingPort)
177                 .add("netconfSsh", netconfSsh)
178                 .add("netconfSshBindingAddress", netconfSshBindingAddress)
179                 .add("netconfSshBindingPort", netconfSshBindingPort)
180                 .add("netconfNotificationStreamName", netconfNotificationStreamName)
181                 .add("username", username)
182                 .add("password", password)
183                 .toString();
184     }
185 }