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 package org.apache.hadoop.yarn.server.nodemanager.api.impl.pb.client; 19 20 import java.io.Closeable; 21 import java.io.IOException; 22 import java.net.InetSocketAddress; 23 24 import org.apache.hadoop.conf.Configuration; 25 import org.apache.hadoop.ipc.ProtobufRpcEngine; 26 import org.apache.hadoop.ipc.RPC; 27 import org.apache.hadoop.yarn.exceptions.YarnException; 28 import org.apache.hadoop.yarn.ipc.RPCUtil; 29 import org.apache.hadoop.yarn.proto.YarnServerNodemanagerServiceProtos.LocalizerStatusProto; 30 import org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocol; 31 import org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocolPB; 32 import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerHeartbeatResponse; 33 import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.LocalizerStatus; 34 import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.impl.pb.LocalizerHeartbeatResponsePBImpl; 35 import org.apache.hadoop.yarn.server.nodemanager.api.protocolrecords.impl.pb.LocalizerStatusPBImpl; 36 37 import com.google.protobuf.ServiceException; 38 39 public class LocalizationProtocolPBClientImpl implements LocalizationProtocol, 40 Closeable { 41 42 private LocalizationProtocolPB proxy; 43 LocalizationProtocolPBClientImpl(long clientVersion, InetSocketAddress addr, Configuration conf)44 public LocalizationProtocolPBClientImpl(long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException { 45 RPC.setProtocolEngine(conf, LocalizationProtocolPB.class, ProtobufRpcEngine.class); 46 proxy = (LocalizationProtocolPB)RPC.getProxy( 47 LocalizationProtocolPB.class, clientVersion, addr, conf); 48 } 49 50 @Override close()51 public void close() { 52 if (this.proxy != null) { 53 RPC.stopProxy(this.proxy); 54 } 55 } 56 57 @Override heartbeat(LocalizerStatus status)58 public LocalizerHeartbeatResponse heartbeat(LocalizerStatus status) 59 throws YarnException, IOException { 60 LocalizerStatusProto statusProto = ((LocalizerStatusPBImpl)status).getProto(); 61 try { 62 return new LocalizerHeartbeatResponsePBImpl( 63 proxy.heartbeat(null, statusProto)); 64 } catch (ServiceException e) { 65 RPCUtil.unwrapAndThrowException(e); 66 return null; 67 } 68 } 69 70 } 71