View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase;
19  
20  import java.util.ArrayList;
21  import java.util.Arrays;
22  import java.util.List;
23  
24  import org.apache.hadoop.conf.Configuration;
25  import org.apache.hadoop.hbase.io.hfile.HFile;
26  import org.apache.hadoop.hbase.security.access.AccessController;
27  import org.apache.hadoop.hbase.util.LoadTestTool;
28  import org.apache.hadoop.hbase.util.test.LoadTestDataGeneratorWithACL;
29  import org.apache.hadoop.util.ToolRunner;
30  import org.junit.experimental.categories.Category;
31  /**
32   * /**
33   * An Integration class for tests that does something with the cluster while running
34   * {@link LoadTestTool} to write and verify some data.
35   * Verifies whether cells for users with only WRITE permissions are not read back
36   * and cells with READ permissions are read back. 
37   * Every operation happens in the user's specific context
38   */
39  @Category(IntegrationTests.class)
40  public class IntegrationTestIngestWithACL extends IntegrationTestIngest {
41  
42    private static final char COLON = ':';
43    public static final char HYPHEN = '-';
44    private static final char COMMA = ',';
45    private static final int SPECIAL_PERM_CELL_INSERTION_FACTOR = 100;
46    public static final String[] userNames = { "user1", "user2", "user3", "user4" };
47  
48    @Override
49    public void setUpCluster() throws Exception {
50      util = getTestingUtil(null);
51      Configuration conf = util.getConfiguration();
52      conf.setInt(HFile.FORMAT_VERSION_KEY, 3);
53      conf.set("hbase.coprocessor.master.classes", AccessController.class.getName());
54      conf.set("hbase.coprocessor.region.classes", AccessController.class.getName());
55      // conf.set("hbase.superuser", "admin");
56      super.setUpCluster();
57    }
58  
59    @Override
60    protected String[] getArgsForLoadTestTool(String mode, String modeSpecificArg, long startKey,
61        long numKeys) {
62      String[] args = super.getArgsForLoadTestTool(mode, modeSpecificArg, startKey, numKeys);
63      List<String> tmp = new ArrayList<String>(Arrays.asList(args));
64      tmp.add(HYPHEN + LoadTestTool.OPT_GENERATOR);
65      StringBuilder sb = new StringBuilder(LoadTestDataGeneratorWithACL.class.getName());
66      sb.append(COLON);
67      sb.append(asCommaSeperatedString(userNames));
68      sb.append(COLON);
69      sb.append(Integer.toString(SPECIAL_PERM_CELL_INSERTION_FACTOR));
70      tmp.add(sb.toString());
71      return tmp.toArray(new String[tmp.size()]);
72    }
73  
74    public static void main(String[] args) throws Exception {
75      Configuration conf = HBaseConfiguration.create();
76      IntegrationTestingUtility.setUseDistributedCluster(conf);
77      int ret = ToolRunner.run(conf, new IntegrationTestIngestWithACL(), args);
78      System.exit(ret);
79    }
80  
81    private static String asCommaSeperatedString(String[] list) {
82      StringBuilder sb = new StringBuilder();
83      for (String item : list) {
84        sb.append(item);
85        sb.append(COMMA);
86      }
87      if (sb.length() > 0) {
88        // Remove the trailing ,
89        sb.deleteCharAt(sb.length() - 1);
90      }
91      return sb.toString();
92    }
93  }