blob: 9328817bd57329f38eeb75ca9b21a717aecec9ba [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 Jampaniafeebbd2015-05-19 15:26:01 -070019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onlab.netty.NettyMessaging;
26import org.onosproject.cluster.ClusterDefinitionService;
27import org.onosproject.cluster.ControllerNode;
28import org.onosproject.store.cluster.messaging.Endpoint;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32/**
33 * Netty based MessagingService.
34 */
35@Component(immediate = true, enabled = true)
36@Service
37public class NettyMessagingManager extends NettyMessaging {
38
39 private final Logger log = LoggerFactory.getLogger(getClass());
40
JunHuy Lam39eb4292015-06-26 17:24:23 +090041 private static final short MIN_KS_LENGTH = 6;
42
Madan Jampaniafeebbd2015-05-19 15:26:01 -070043 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected ClusterDefinitionService clusterDefinitionService;
45
46 @Activate
47 public void activate() throws Exception {
48 ControllerNode localNode = clusterDefinitionService.localNode();
JunHuy Lam39eb4292015-06-26 17:24:23 +090049 getTLSParameters();
Madan Jampaniafeebbd2015-05-19 15:26:01 -070050 super.start(new Endpoint(localNode.ip(), localNode.tcpPort()));
51 log.info("Started");
52 }
53
54 @Deactivate
55 public void deactivate() throws Exception {
56 super.stop();
57 log.info("Stopped");
58 }
JunHuy Lam39eb4292015-06-26 17:24:23 +090059
60 private void getTLSParameters() {
61 String tempString = System.getProperty("enableNettyTLS");
62 enableNettyTLS = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString);
63 log.info("enableNettyTLS = {}", enableNettyTLS);
64 if (enableNettyTLS) {
65 ksLocation = System.getProperty("javax.net.ssl.keyStore");
66 if (Strings.isNullOrEmpty(ksLocation)) {
67 enableNettyTLS = TLS_DISABLED;
68 return;
69 }
70 tsLocation = System.getProperty("javax.net.ssl.trustStore");
71 if (Strings.isNullOrEmpty(tsLocation)) {
72 enableNettyTLS = TLS_DISABLED;
73 return;
74 }
75 ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
76 if (MIN_KS_LENGTH > ksPwd.length) {
77 enableNettyTLS = TLS_DISABLED;
78 return;
79 }
80 tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray();
81 if (MIN_KS_LENGTH > tsPwd.length) {
82 enableNettyTLS = TLS_DISABLED;
83 return;
84 }
85 }
86 }
87}