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.snapshot; 019 020import java.util.UUID; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.FileSystem; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.HBaseTestingUtil; 025import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; 026import org.apache.hadoop.hbase.mob.MobConstants; 027import org.apache.hadoop.hbase.security.HadoopSecurityEnabledUserProviderForTesting; 028import org.apache.hadoop.hbase.security.UserProvider; 029import org.apache.hadoop.hbase.security.access.PermissionStorage; 030import org.apache.hadoop.hbase.security.access.SecureTestUtil; 031 032final class ExportSnapshotTestHelpers { 033 034 private ExportSnapshotTestHelpers() { 035 } 036 037 private static void setUpBaseConf(Configuration conf) { 038 conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); 039 conf.setInt("hbase.regionserver.msginterval", 100); 040 // If a single node has enough failures (default 3), resource manager will blacklist it. 041 // With only 2 nodes and tests injecting faults, we don't want that. 042 conf.setInt("mapreduce.job.maxtaskfailures.per.tracker", 100); 043 conf.setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); 044 } 045 046 static void startCluster(HBaseTestingUtil util, boolean useTmpDir) throws Exception { 047 Configuration conf = util.getConfiguration(); 048 setUpBaseConf(conf); 049 if (useTmpDir) { 050 FileSystem localFs = FileSystem.getLocal(conf); 051 Path tmpDir = util.getDataTestDir(UUID.randomUUID().toString()) 052 .makeQualified(localFs.getUri(), localFs.getWorkingDirectory()); 053 conf.set(SnapshotDescriptionUtils.SNAPSHOT_WORKING_DIR, tmpDir.toUri().toString()); 054 } 055 util.startMiniCluster(1); 056 util.startMiniMapReduceCluster(); 057 } 058 059 static void startSecureCluster(HBaseTestingUtil util) throws Exception { 060 setUpBaseConf(util.getConfiguration()); 061 // Setup separate test-data directory for MR cluster and set corresponding configurations. 062 // Otherwise, different test classes running MR cluster can step on each other. 063 util.getDataTestDir(); 064 065 // set the always on security provider 066 UserProvider.setUserProviderForTesting(util.getConfiguration(), 067 HadoopSecurityEnabledUserProviderForTesting.class); 068 069 // setup configuration 070 SecureTestUtil.enableSecurity(util.getConfiguration()); 071 072 util.startMiniCluster(3); 073 util.startMiniMapReduceCluster(); 074 075 // Wait for the ACL table to become available 076 util.waitTableEnabled(PermissionStorage.ACL_TABLE_NAME); 077 } 078 079}