blob: ca6f9c1c3de030d46e0a6f8018a26660b7b3cd6a [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
Madan Jampaniafeebbd2015-05-19 15:26:01 -070016package org.onosproject.store.cluster.messaging.impl;
17
JunHuy Lam39eb4292015-06-26 17:24:23 +090018import com.google.common.base.Strings;
Madan Jampaniec1df022015-10-13 21:23:03 -070019
Madan Jampaniafeebbd2015-05-19 15:26:01 -070020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
26import org.onlab.netty.NettyMessaging;
Madan Jampaniec1df022015-10-13 21:23:03 -070027import org.onosproject.cluster.ClusterMetadataService;
Madan Jampaniafeebbd2015-05-19 15:26:01 -070028import org.onosproject.cluster.ControllerNode;
29import org.onosproject.store.cluster.messaging.Endpoint;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33/**
34 * Netty based MessagingService.
35 */
36@Component(immediate = true, enabled = true)
37@Service
38public class NettyMessagingManager extends NettyMessaging {
39
40 private final Logger log = LoggerFactory.getLogger(getClass());
41
JunHuy Lam39eb4292015-06-26 17:24:23 +090042 private static final short MIN_KS_LENGTH = 6;
43
Madan Jampaniafeebbd2015-05-19 15:26:01 -070044 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Madan Jampaniec1df022015-10-13 21:23:03 -070045 protected ClusterMetadataService clusterMetadataService;
Madan Jampaniafeebbd2015-05-19 15:26:01 -070046
47 @Activate
48 public void activate() throws Exception {
Madan Jampaniec1df022015-10-13 21:23:03 -070049 ControllerNode localNode = clusterMetadataService.getLocalNode();
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080050 getTlsParameters();
Aaron Kruglikoveb0ae4e2015-11-10 19:16:16 -080051 super.start(clusterMetadataService.getClusterMetadata().getName().hashCode(),
52 new Endpoint(localNode.ip(), localNode.tcpPort()));
Madan Jampaniafeebbd2015-05-19 15:26:01 -070053 log.info("Started");
54 }
55
56 @Deactivate
57 public void deactivate() throws Exception {
58 super.stop();
59 log.info("Stopped");
60 }
JunHuy Lam39eb4292015-06-26 17:24:23 +090061
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080062 private void getTlsParameters() {
JunHuy Lam39eb4292015-06-26 17:24:23 +090063 String tempString = System.getProperty("enableNettyTLS");
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080064 enableNettyTls = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString);
65 log.info("enableNettyTLS = {}", enableNettyTls);
66 if (enableNettyTls) {
JunHuy Lam39eb4292015-06-26 17:24:23 +090067 ksLocation = System.getProperty("javax.net.ssl.keyStore");
68 if (Strings.isNullOrEmpty(ksLocation)) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080069 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090070 return;
71 }
72 tsLocation = System.getProperty("javax.net.ssl.trustStore");
73 if (Strings.isNullOrEmpty(tsLocation)) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080074 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090075 return;
76 }
77 ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
78 if (MIN_KS_LENGTH > ksPwd.length) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080079 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090080 return;
81 }
82 tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray();
83 if (MIN_KS_LENGTH > tsPwd.length) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080084 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090085 return;
86 }
87 }
88 }
89}