/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.master;

import alluxio.Constants;
import alluxio.thrift.MasterInfo;
import alluxio.thrift.MasterInfoField;
import alluxio.thrift.MetaMasterClientService;

import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * This class is a Thrift handler for meta master RPCs.
 */
public final class MetaMasterClientServiceHandler implements MetaMasterClientService.Iface {
  private static final Logger LOG = LoggerFactory.getLogger(MetaMasterClientServiceHandler.class);

  private final MasterProcess mMasterProcess;

  /**
   * @param masterProcess the Alluxio master process
   */
  public MetaMasterClientServiceHandler(MasterProcess masterProcess) {
    mMasterProcess = masterProcess;
  }

  @Override
  public long getServiceVersion() {
    return Constants.META_MASTER_CLIENT_SERVICE_VERSION;
  }

  @Override
  public MasterInfo getInfo(Set<MasterInfoField> fields) throws TException {
    if (fields == null) {
      fields = new HashSet<>(Arrays.asList(MasterInfoField.values()));
    }
    MasterInfo info = new alluxio.thrift.MasterInfo();
    for (MasterInfoField field : fields) {
      switch (field) {
        case WEB_PORT:
          info.setWebPort(mMasterProcess.getWebAddress().getPort());
          break;
        default:
          LOG.warn("Unrecognized master info field: " + field);
      }
    }
    return info;
  }
}

@@ -558,16 +558,84 @@
 stants;%0A
+import alluxio.RpcUtils;%0Aimport alluxio.exception.AlluxioException;%0A
 import a
@@ -1547,16 +1547,22 @@
 getInfo(
+final 
 Set%3CMast
@@ -1610,44 +1610,230 @@
     
-if (fields == null) %7B%0A
+return RpcUtils.call(LOG, new RpcUtils.RpcCallable%3CMasterInfo%3E() %7B%0A      @Override%0A      public MasterInfo call() throws AlluxioException %7B%0A        Set%3CMasterInfoField%3E fieldsToQuery =%0A   
       
+   
 fields 
+!
 =
+ null ? fields :
  new
@@ -1885,26 +1885,24 @@
 es()));%0A    
-%7D%0A
     MasterIn
@@ -1944,16 +1944,20 @@
 Info();%0A
+    
     for 
@@ -1987,16 +1987,23 @@
 : fields
+ToQuery
 ) %7B%0A    
@@ -2004,16 +2004,20 @@
 %7B%0A      
+ 
+   
 switch (
@@ -2033,16 +2033,20 @@
         
+   
+ 
 case WEB
@@ -2052,16 +2052,20 @@
 B_PORT:%0A
+    
         
@@ -2135,16 +2135,20 @@
         
+    
 break;%0A 
@@ -2154,16 +2154,20 @@
         
+  
+  
 default:
@@ -2167,16 +2167,20 @@
 efault:%0A
+    
         
@@ -2245,16 +2245,28 @@
     
-%7D%0A
+    %7D%0A   
     
+ 
 %7D%0A
+    
     
@@ -2278,14 +2278,30 @@
 n info;%0A
+      %7D%0A    %7D);%0A
   %7D%0A%7D%0A

Handle RPCs consistently in meta master service