Package coprocessor

Source Code of coprocessor.MasterObserverExample

package coprocessor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.coprocessor.BaseMasterObserver;
import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.master.MasterFileSystem;
import org.apache.hadoop.hbase.master.MasterServices;
import org.apache.hadoop.hbase.regionserver.HRegion;

import java.io.IOException;

// cc MasterObserverExample Example master observer that creates a separate directory on the file system when a table is created.
// vv MasterObserverExample
public class MasterObserverExample extends BaseMasterObserver {
  // ^^ MasterObserverExample
  public static final Log LOG = LogFactory.getLog(HRegion.class);
  // vv MasterObserverExample

  @Override
  public void postCreateTable(
    ObserverContext<MasterCoprocessorEnvironment> env,
    HRegionInfo[] regions, boolean sync)
  throws IOException {
    // ^^ MasterObserverExample
    LOG.debug("Got postCreateTable callback");
    // vv MasterObserverExample
    String tableName = regions[0].getTableDesc().getNameAsString(); // co MasterObserverExample-1-GetName Get the new table's name from the table descriptor.

    // ^^ MasterObserverExample
    LOG.debug("Created table: " + tableName + ", region count: " + regions.length);
    // vv MasterObserverExample
    MasterServices services = env.getEnvironment().getMasterServices();
    MasterFileSystem masterFileSystem = services.getMasterFileSystem(); // co MasterObserverExample-2-Services Get the available services and retrieve a reference to the actual file system.
    FileSystem fileSystem = masterFileSystem.getFileSystem();

    Path blobPath = new Path(tableName + "-blobs"); // co MasterObserverExample-3-Path Create a new directory that will store binary data from the client application.
    fileSystem.mkdirs(blobPath);

    // ^^ MasterObserverExample
    LOG.debug("Created " + blobPath + ": " + fileSystem.exists(blobPath));
    // vv MasterObserverExample
  }
}
// ^^ MasterObserverExample
TOP

Related Classes of coprocessor.MasterObserverExample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.