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 java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.hbase.backup.impl.FullTableBackupClient; 023import org.apache.hadoop.hbase.backup.impl.IncrementalTableBackupClient; 024import org.apache.hadoop.hbase.backup.impl.TableBackupClient; 025import org.apache.hadoop.hbase.client.Connection; 026import org.apache.yetus.audience.InterfaceAudience; 027 028@InterfaceAudience.Private 029public final class BackupClientFactory { 030 private BackupClientFactory() { 031 } 032 033 public static TableBackupClient create(Connection conn, String backupId, BackupRequest request) 034 throws IOException { 035 Configuration conf = conn.getConfiguration(); 036 try { 037 String clsName = conf.get(TableBackupClient.BACKUP_CLIENT_IMPL_CLASS); 038 if (clsName != null) { 039 Class<? extends TableBackupClient> clientImpl; 040 clientImpl = Class.forName(clsName).asSubclass(TableBackupClient.class); 041 TableBackupClient client = clientImpl.getDeclaredConstructor().newInstance(); 042 client.init(conn, backupId, request); 043 return client; 044 } 045 } catch (Exception e) { 046 throw new IOException(e); 047 } 048 049 BackupType type = request.getBackupType(); 050 if (type == BackupType.FULL) { 051 return new FullTableBackupClient(conn, backupId, request); 052 } else { 053 return new IncrementalTableBackupClient(conn, backupId, request); 054 } 055 } 056}