Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame^] | 1 | /* |
| 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 Jampani | afeebbd | 2015-05-19 15:26:01 -0700 | [diff] [blame] | 16 | package org.onosproject.store.cluster.messaging.impl; |
| 17 | |
JunHuy Lam | 39eb429 | 2015-06-26 17:24:23 +0900 | [diff] [blame] | 18 | import com.google.common.base.Strings; |
Madan Jampani | afeebbd | 2015-05-19 15:26:01 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
| 25 | import org.onlab.netty.NettyMessaging; |
| 26 | import org.onosproject.cluster.ClusterDefinitionService; |
| 27 | import org.onosproject.cluster.ControllerNode; |
| 28 | import org.onosproject.store.cluster.messaging.Endpoint; |
| 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
| 32 | /** |
| 33 | * Netty based MessagingService. |
| 34 | */ |
| 35 | @Component(immediate = true, enabled = true) |
| 36 | @Service |
| 37 | public class NettyMessagingManager extends NettyMessaging { |
| 38 | |
| 39 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 40 | |
JunHuy Lam | 39eb429 | 2015-06-26 17:24:23 +0900 | [diff] [blame] | 41 | private static final short MIN_KS_LENGTH = 6; |
| 42 | |
Madan Jampani | afeebbd | 2015-05-19 15:26:01 -0700 | [diff] [blame] | 43 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 44 | protected ClusterDefinitionService clusterDefinitionService; |
| 45 | |
| 46 | @Activate |
| 47 | public void activate() throws Exception { |
| 48 | ControllerNode localNode = clusterDefinitionService.localNode(); |
JunHuy Lam | 39eb429 | 2015-06-26 17:24:23 +0900 | [diff] [blame] | 49 | getTLSParameters(); |
Madan Jampani | afeebbd | 2015-05-19 15:26:01 -0700 | [diff] [blame] | 50 | 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 Lam | 39eb429 | 2015-06-26 17:24:23 +0900 | [diff] [blame] | 59 | |
| 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 | } |