001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.hbase.rsgroup; 020 021import java.util.ArrayList; 022import java.util.List; 023 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.net.Address; 026import org.apache.hadoop.hbase.protobuf.ProtobufUtil; 027import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; 028import org.apache.hadoop.hbase.protobuf.generated.RSGroupProtos; 029import org.apache.hadoop.hbase.protobuf.generated.TableProtos; 030import org.apache.yetus.audience.InterfaceAudience; 031 032@InterfaceAudience.Private 033final class RSGroupProtobufUtil { 034 private RSGroupProtobufUtil() { 035 } 036 037 static RSGroupInfo toGroupInfo(RSGroupProtos.RSGroupInfo proto) { 038 RSGroupInfo RSGroupInfo = new RSGroupInfo(proto.getName()); 039 for(HBaseProtos.ServerName el: proto.getServersList()) { 040 RSGroupInfo.addServer(Address.fromParts(el.getHostName(), el.getPort())); 041 } 042 for(TableProtos.TableName pTableName: proto.getTablesList()) { 043 RSGroupInfo.addTable(ProtobufUtil.toTableName(pTableName)); 044 } 045 return RSGroupInfo; 046 } 047 048 static RSGroupProtos.RSGroupInfo toProtoGroupInfo(RSGroupInfo pojo) { 049 List<TableProtos.TableName> tables = new ArrayList<>(pojo.getTables().size()); 050 for(TableName arg: pojo.getTables()) { 051 tables.add(ProtobufUtil.toProtoTableName(arg)); 052 } 053 List<HBaseProtos.ServerName> hostports = new ArrayList<>(pojo.getServers().size()); 054 for(Address el: pojo.getServers()) { 055 hostports.add(HBaseProtos.ServerName.newBuilder() 056 .setHostName(el.getHostname()) 057 .setPort(el.getPort()) 058 .build()); 059 } 060 return RSGroupProtos.RSGroupInfo.newBuilder().setName(pojo.getName()) 061 .addAllServers(hostports) 062 .addAllTables(tables).build(); 063 } 064}