Coverage Report - org.apache.giraph.job.ClientThriftServer
 
Classes in this File Line Coverage Branch Coverage Complexity
ClientThriftServer
0%
0/17
N/A
2
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.job;
 20  
 
 21  
 import com.facebook.swift.codec.ThriftCodecManager;
 22  
 import com.facebook.swift.service.ThriftEventHandler;
 23  
 import com.facebook.swift.service.ThriftServer;
 24  
 import com.facebook.swift.service.ThriftServerConfig;
 25  
 import com.facebook.swift.service.ThriftServiceProcessor;
 26  
 import org.apache.giraph.conf.GiraphConfiguration;
 27  
 import org.apache.giraph.conf.IntConfOption;
 28  
 import org.apache.giraph.conf.StrConfOption;
 29  
 
 30  
 import java.net.UnknownHostException;
 31  
 import java.util.ArrayList;
 32  
 import java.util.List;
 33  
 
 34  
 import static com.google.common.base.Preconditions.checkNotNull;
 35  
 
 36  
 /**
 37  
  * Manages the life cycle of the Thrift server started on the client.
 38  
  */
 39  
 public class ClientThriftServer {
 40  
   /**
 41  
    * The client can run a Thrift server (e.g. job progress service).
 42  
    * This is the host of the Thrift server.
 43  
    */
 44  0
   public static final StrConfOption CLIENT_THRIFT_SERVER_HOST =
 45  
       new StrConfOption("giraph.client.thrift.server.host", null,
 46  
           "Host on which the client Thrift server runs (if enabled)");
 47  
   /**
 48  
    * The client can run a Thrift server (e.g. job progress service).
 49  
    * This is the port of the Thrift server.
 50  
    */
 51  0
   public static final IntConfOption CLIENT_THRIFT_SERVER_PORT =
 52  
       new IntConfOption("giraph.client.thrift.server.port", -1,
 53  
           "Port on which the client Thrift server runs (if enabled)");
 54  
 
 55  
   /** Thrift server that is intended to run on the client */
 56  
   private final ThriftServer clientThriftServer;
 57  
 
 58  
   /**
 59  
    * Create and start the Thrift server.
 60  
    *
 61  
    * @param conf Giraph conf to set the host and ports for.
 62  
    * @param services Services to start
 63  
    */
 64  
   public ClientThriftServer(GiraphConfiguration conf,
 65  0
                             List<?> services) {
 66  0
     checkNotNull(conf, "conf is null");
 67  0
     checkNotNull(services, "services is null");
 68  
 
 69  0
     ThriftServiceProcessor processor =
 70  
         new ThriftServiceProcessor(new ThriftCodecManager(),
 71  
                                    new ArrayList<ThriftEventHandler>(),
 72  
                                    services);
 73  0
     clientThriftServer =
 74  
         new ThriftServer(processor, new ThriftServerConfig());
 75  0
     clientThriftServer.start();
 76  
     try {
 77  0
       CLIENT_THRIFT_SERVER_HOST.set(
 78  
           conf,
 79  0
           conf.getLocalHostname());
 80  0
     } catch (UnknownHostException e) {
 81  0
       throw new IllegalStateException("Unable to get host information", e);
 82  0
     }
 83  0
     CLIENT_THRIFT_SERVER_PORT.set(conf, clientThriftServer.getPort());
 84  0
   }
 85  
 
 86  
   /**
 87  
    * Stop the Thrift server.
 88  
    */
 89  
   public void stopThriftServer() {
 90  0
     this.clientThriftServer.close();
 91  0
   }
 92  
 }