8b2cc8e2c31c6a45a8f57ca734ce4588195821eb
[onosfw.git] /
1 package org.onosproject.store.cluster.messaging.impl;
2
3 import com.google.common.base.Strings;
4 import org.apache.felix.scr.annotations.Activate;
5 import org.apache.felix.scr.annotations.Component;
6 import org.apache.felix.scr.annotations.Deactivate;
7 import org.apache.felix.scr.annotations.Reference;
8 import org.apache.felix.scr.annotations.ReferenceCardinality;
9 import org.apache.felix.scr.annotations.Service;
10 import org.onlab.netty.NettyMessaging;
11 import org.onosproject.cluster.ClusterDefinitionService;
12 import org.onosproject.cluster.ControllerNode;
13 import org.onosproject.store.cluster.messaging.Endpoint;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Netty based MessagingService.
19  */
20 @Component(immediate = true, enabled = true)
21 @Service
22 public class NettyMessagingManager extends NettyMessaging {
23
24     private final Logger log = LoggerFactory.getLogger(getClass());
25
26     private static final short MIN_KS_LENGTH = 6;
27
28     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
29     protected ClusterDefinitionService clusterDefinitionService;
30
31     @Activate
32     public void activate() throws Exception {
33         ControllerNode localNode = clusterDefinitionService.localNode();
34         getTLSParameters();
35         super.start(new Endpoint(localNode.ip(), localNode.tcpPort()));
36         log.info("Started");
37     }
38
39     @Deactivate
40     public void deactivate() throws Exception {
41         super.stop();
42         log.info("Stopped");
43     }
44
45     private void getTLSParameters() {
46         String tempString = System.getProperty("enableNettyTLS");
47         enableNettyTLS = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString);
48         log.info("enableNettyTLS = {}", enableNettyTLS);
49         if (enableNettyTLS) {
50             ksLocation = System.getProperty("javax.net.ssl.keyStore");
51             if (Strings.isNullOrEmpty(ksLocation)) {
52                 enableNettyTLS = TLS_DISABLED;
53                 return;
54             }
55             tsLocation = System.getProperty("javax.net.ssl.trustStore");
56             if (Strings.isNullOrEmpty(tsLocation)) {
57                 enableNettyTLS = TLS_DISABLED;
58                 return;
59             }
60             ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
61             if (MIN_KS_LENGTH > ksPwd.length) {
62                 enableNettyTLS = TLS_DISABLED;
63                 return;
64             }
65             tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray();
66             if (MIN_KS_LENGTH > tsPwd.length) {
67                 enableNettyTLS = TLS_DISABLED;
68                 return;
69             }
70         }
71     }
72 }