| /* |
| * Licensed to the Apache Software Foundation (ASF) under one or more |
| * contributor license agreements. See the NOTICE file distributed with |
| * this work for additional information regarding copyright ownership. |
| * The ASF licenses this file to You under the Apache License, Version 2.0 |
| * (the "License"); you may not use this file except in compliance with |
| * the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.apache.sentry.tests.e2e.hive; |
| |
| import java.io.File; |
| import java.util.Map; |
| |
| import org.junit.Assert; |
| |
| import org.apache.commons.io.FileUtils; |
| import org.apache.hadoop.conf.Configuration; |
| import org.apache.hadoop.fs.FileSystem; |
| import org.apache.sentry.tests.e2e.hive.hiveserver.HiveServer; |
| import org.apache.sentry.tests.e2e.hive.hiveserver.HiveServerFactory; |
| import org.junit.AfterClass; |
| import org.slf4j.Logger; |
| import org.slf4j.LoggerFactory; |
| |
| import com.google.common.io.Files; |
| |
| public abstract class AbstractTestWithHiveServer extends RulesForE2ETest { |
| private static final Logger LOGGER = LoggerFactory |
| .getLogger(AbstractTestWithHiveServer.class); |
| protected static File baseDir; |
| protected static File logDir; |
| protected static File confDir; |
| protected static File dataDir; |
| protected static File policyFile; |
| protected static HiveServer hiveServer; |
| protected static FileSystem fileSystem; |
| |
| protected static final String ADMIN1 = StaticUserGroup.ADMIN1, |
| ADMINGROUP = StaticUserGroup.ADMINGROUP, |
| USER1_1 = StaticUserGroup.USER1_1, |
| USER2_1 = StaticUserGroup.USER2_1, |
| USER3_1 = StaticUserGroup.USER3_1, |
| USERGROUP1 = StaticUserGroup.USERGROUP1, |
| USERGROUP2 = StaticUserGroup.USERGROUP2, |
| USERGROUP3 = StaticUserGroup.USERGROUP3; |
| |
| public static Context createContext(Map<String, String> properties) |
| throws Exception { |
| fileSystem = FileSystem.get(new Configuration()); |
| baseDir = Files.createTempDir(); |
| LOGGER.info("BaseDir = " + baseDir); |
| logDir = assertCreateDir(new File(baseDir, "log")); |
| confDir = assertCreateDir(new File(baseDir, "etc")); |
| dataDir = assertCreateDir(new File(baseDir, "data")); |
| policyFile = new File(confDir, HiveServerFactory.AUTHZ_PROVIDER_FILENAME); |
| hiveServer = HiveServerFactory.create(properties, baseDir, confDir, logDir, policyFile.getPath(), fileSystem); |
| hiveServer.start(); |
| return new Context(hiveServer, fileSystem, |
| baseDir, dataDir, policyFile); |
| } |
| |
| protected static File assertCreateDir(File dir) { |
| if(!dir.isDirectory()) { |
| Assert.assertTrue("Failed creating " + dir, dir.mkdirs()); |
| } |
| return dir; |
| } |
| |
| protected FileSystem getFileSystem() { |
| return fileSystem; |
| } |
| |
| @AfterClass |
| public static void tearDownWithHiveServer() throws Exception { |
| if(hiveServer != null) { |
| hiveServer.shutdown(); |
| hiveServer = null; |
| } |
| if(baseDir != null) { |
| if(System.getProperty(HiveServerFactory.KEEP_BASEDIR) == null) { |
| FileUtils.deleteQuietly(baseDir); |
| } |
| baseDir = null; |
| } |
| } |
| } |