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.backup;
019
020import org.apache.hadoop.conf.Configuration;
021import org.apache.hadoop.hbase.backup.mapreduce.MapReduceBackupCopyJob;
022import org.apache.hadoop.hbase.backup.mapreduce.MapReduceBackupMergeJob;
023import org.apache.hadoop.hbase.backup.mapreduce.MapReduceRestoreJob;
024import org.apache.hadoop.hbase.backup.mapreduce.MapReduceRestoreToOriginalSplitsJob;
025import org.apache.hadoop.util.ReflectionUtils;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * Factory implementation for backup/restore related jobs
030 */
031@InterfaceAudience.Private
032public final class BackupRestoreFactory {
033  public final static String HBASE_INCR_RESTORE_IMPL_CLASS = "hbase.incremental.restore.class";
034  public final static String HBASE_BACKUP_COPY_IMPL_CLASS = "hbase.backup.copy.class";
035  public final static String HBASE_BACKUP_MERGE_IMPL_CLASS = "hbase.backup.merge.class";
036
037  private BackupRestoreFactory() {
038    throw new AssertionError("Instantiating utility class...");
039  }
040
041  /**
042   * Gets backup restore job
043   * @param conf configuration
044   * @return backup restore job instance
045   */
046  public static RestoreJob getRestoreJob(Configuration conf) {
047    Class<? extends RestoreJob> defaultCls =
048      conf.getBoolean(RestoreJob.KEEP_ORIGINAL_SPLITS_KEY, RestoreJob.KEEP_ORIGINAL_SPLITS_DEFAULT)
049        ? MapReduceRestoreToOriginalSplitsJob.class
050        : MapReduceRestoreJob.class;
051
052    Class<? extends RestoreJob> cls =
053      conf.getClass(HBASE_INCR_RESTORE_IMPL_CLASS, defaultCls, RestoreJob.class);
054    RestoreJob service = ReflectionUtils.newInstance(cls, conf);
055    service.setConf(conf);
056    return service;
057  }
058
059  /**
060   * Gets backup copy job
061   * @param conf configuration
062   * @return backup copy job instance
063   */
064  public static BackupCopyJob getBackupCopyJob(Configuration conf) {
065    Class<? extends BackupCopyJob> cls = conf.getClass(HBASE_BACKUP_COPY_IMPL_CLASS,
066      MapReduceBackupCopyJob.class, BackupCopyJob.class);
067    BackupCopyJob service = ReflectionUtils.newInstance(cls, conf);
068    service.setConf(conf);
069    return service;
070  }
071
072  /**
073   * Gets backup merge job
074   * @param conf configuration
075   * @return backup merge job instance
076   */
077  public static BackupMergeJob getBackupMergeJob(Configuration conf) {
078    Class<? extends BackupMergeJob> cls = conf.getClass(HBASE_BACKUP_MERGE_IMPL_CLASS,
079      MapReduceBackupMergeJob.class, BackupMergeJob.class);
080    BackupMergeJob service = ReflectionUtils.newInstance(cls, conf);
081    service.setConf(conf);
082    return service;
083  }
084}