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 */
018package org.apache.hadoop.hbase.tool;
019
020import java.io.IOException;
021import java.nio.ByteBuffer;
022import java.util.List;
023import java.util.Map;
024import java.util.stream.Collectors;
025import org.apache.hadoop.conf.Configuration;
026import org.apache.hadoop.fs.Path;
027import org.apache.hadoop.hbase.HBaseConfiguration;
028import org.apache.hadoop.hbase.HBaseInterfaceAudience;
029import org.apache.hadoop.hbase.TableName;
030import org.apache.hadoop.hbase.TableNotFoundException;
031import org.apache.hadoop.util.ToolRunner;
032import org.apache.yetus.audience.InterfaceAudience;
033
034/**
035 * The implementation for {@link BulkLoadHFiles}, and also can be executed from command line as a
036 * tool.
037 */
038@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.TOOLS)
039public class BulkLoadHFilesTool extends LoadIncrementalHFiles implements BulkLoadHFiles {
040
041  public static final String NAME = "completebulkload";
042
043  public BulkLoadHFilesTool(Configuration conf) {
044    super(conf);
045  }
046
047  private Map<BulkLoadHFiles.LoadQueueItem, ByteBuffer>
048    convert(Map<LoadIncrementalHFiles.LoadQueueItem, ByteBuffer> map) {
049    return map.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
050  }
051
052  @Override
053  public Map<BulkLoadHFiles.LoadQueueItem, ByteBuffer> bulkLoad(TableName tableName,
054    Map<byte[], List<Path>> family2Files) throws TableNotFoundException, IOException {
055    return convert(run(family2Files, tableName));
056  }
057
058  @Override
059  public Map<BulkLoadHFiles.LoadQueueItem, ByteBuffer> bulkLoad(TableName tableName, Path dir)
060    throws TableNotFoundException, IOException {
061    return convert(run(dir, tableName));
062  }
063
064  public static void main(String[] args) throws Exception {
065    Configuration conf = HBaseConfiguration.create();
066    int ret = ToolRunner.run(conf, new BulkLoadHFilesTool(conf), args);
067    System.exit(ret);
068  }
069
070}