2  * Copyright 2015 Open Networking Laboratory
 
   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
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  16 package org.onosproject.store.cluster.messaging.impl;
 
  18 import com.google.common.base.Strings;
 
  20 import org.apache.felix.scr.annotations.Activate;
 
  21 import org.apache.felix.scr.annotations.Component;
 
  22 import org.apache.felix.scr.annotations.Deactivate;
 
  23 import org.apache.felix.scr.annotations.Reference;
 
  24 import org.apache.felix.scr.annotations.ReferenceCardinality;
 
  25 import org.apache.felix.scr.annotations.Service;
 
  26 import org.onlab.netty.NettyMessaging;
 
  27 import org.onosproject.cluster.ClusterMetadataService;
 
  28 import org.onosproject.cluster.ControllerNode;
 
  29 import org.onosproject.store.cluster.messaging.Endpoint;
 
  30 import org.slf4j.Logger;
 
  31 import org.slf4j.LoggerFactory;
 
  34  * Netty based MessagingService.
 
  36 @Component(immediate = true, enabled = true)
 
  38 public class NettyMessagingManager extends NettyMessaging {
 
  40     private final Logger log = LoggerFactory.getLogger(getClass());
 
  42     private static final short MIN_KS_LENGTH = 6;
 
  44     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
 
  45     protected ClusterMetadataService clusterMetadataService;
 
  48     public void activate() throws Exception {
 
  49         ControllerNode localNode = clusterMetadataService.getLocalNode();
 
  51         super.start(new Endpoint(localNode.ip(), localNode.tcpPort()));
 
  56     public void deactivate() throws Exception {
 
  61     private void getTLSParameters() {
 
  62         String tempString = System.getProperty("enableNettyTLS");
 
  63         enableNettyTLS = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString);
 
  64         log.info("enableNettyTLS = {}", enableNettyTLS);
 
  66             ksLocation = System.getProperty("javax.net.ssl.keyStore");
 
  67             if (Strings.isNullOrEmpty(ksLocation)) {
 
  68                 enableNettyTLS = TLS_DISABLED;
 
  71             tsLocation = System.getProperty("javax.net.ssl.trustStore");
 
  72             if (Strings.isNullOrEmpty(tsLocation)) {
 
  73                 enableNettyTLS = TLS_DISABLED;
 
  76             ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
 
  77             if (MIN_KS_LENGTH > ksPwd.length) {
 
  78                 enableNettyTLS = TLS_DISABLED;
 
  81             tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray();
 
  82             if (MIN_KS_LENGTH > tsPwd.length) {
 
  83                 enableNettyTLS = TLS_DISABLED;