View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.backup.master;
20  
21  import java.io.IOException;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.hadoop.hbase.HTableDescriptor;
26  import org.apache.hadoop.hbase.TableExistsException;
27  import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
28  import org.apache.hadoop.hbase.coprocessor.BaseMasterAndRegionObserver;
29  import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;
30  import org.apache.hadoop.hbase.coprocessor.ObserverContext;
31  import org.apache.hadoop.hbase.master.MasterServices;
32  
33  /**
34   * The current implementation checks if the backup system table 
35   * (hbase:backup) exists on HBasae Master startup and if it does not -
36   * it creates it. We need to make sure that backup system table is  
37   * created under HBase user with ADMIN privileges
38   */
39  public class BackupController extends BaseMasterAndRegionObserver {
40    private static final Log LOG = LogFactory.getLog(BackupController.class.getName());
41  
42    @Override
43    public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx)
44        throws IOException {
45      // Need to create the new system table for backups (if does not exist)
46      MasterServices master = ctx.getEnvironment().getMasterServices();
47      HTableDescriptor backupHTD = BackupSystemTable.getSystemTableDescriptor();
48      try{
49        master.createTable(backupHTD, null);
50        LOG.info("Created "+ BackupSystemTable.getTableNameAsString()+" table");
51      } catch(TableExistsException e) {
52        LOG.info("Table "+ BackupSystemTable.getTableNameAsString() +" already exists");
53      } 
54    }
55  }