Repository: sentry
Updated Branches:
  refs/heads/master a001e4455 -> e23fc4ef8


http://git-wip-us.apache.org/repos/asf/sentry/blob/e23fc4ef/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestServerScopeEndToEnd.java
----------------------------------------------------------------------
diff --git 
a/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestServerScopeEndToEnd.java
 
b/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestServerScopeEndToEnd.java
index 85bae92..55213df 100644
--- 
a/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestServerScopeEndToEnd.java
+++ 
b/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestServerScopeEndToEnd.java
@@ -40,30 +40,33 @@ public class TestServerScopeEndToEnd extends 
AbstractSqoopSentryTestBase {
      * ADMIN_USER create two links and one job
      */
     SqoopClient client = sqoopServerRunner.getSqoopClient(ADMIN_USER);
-    MLink rdbmsLink = client.createLink("generic-jdbc-connector");
+    MLink rdbmsLink = client.createLink(JDBC_CONNECTOR_NAME);
     sqoopServerRunner.fillRdbmsLinkConfig(rdbmsLink);
+    rdbmsLink.setName("jdbc-link1");
     sqoopServerRunner.saveLink(client, rdbmsLink);
 
-    MLink hdfsLink = client.createLink("hdfs-connector");
+    MLink hdfsLink = client.createLink(HDFS_CONNECTOR_NAME);
     sqoopServerRunner.fillHdfsLink(hdfsLink);
+    hdfsLink.setName("hdfs-link1");
     sqoopServerRunner.saveLink(client, hdfsLink);
 
-    MJob job1 = client.createJob(hdfsLink.getPersistenceId(), 
rdbmsLink.getPersistenceId());
+    MJob job1 = client.createJob(hdfsLink.getName(), rdbmsLink.getName());
     // set HDFS "FROM" config for the job, since the connector test case base 
class only has utilities for HDFS!
     sqoopServerRunner.fillHdfsFromConfig(job1);
     // set the RDBM "TO" config here
     sqoopServerRunner.fillRdbmsToConfig(job1);
     // create job
+    job1.setName("hdfs-jdbc-job1");
     sqoopServerRunner.saveJob(client, job1);
 
 
-    MResource  sqoopServer1 = new MResource(SQOOP_SERVER_NAME, 
MResource.TYPE.SERVER);
+    MResource sqoopServer1 = new MResource(SQOOP_SERVER_NAME, 
MResource.TYPE.SERVER);
     /**
      * ADMIN_USER grant read privilege on server SQOOP_SERVER_NAME to role1
      */
     MRole role1 = new MRole(ROLE1);
     MPrincipal group1 = new MPrincipal(GROUP1, MPrincipal.TYPE.GROUP);
-    MPrivilege readPrivilege = new 
MPrivilege(sqoopServer1,SqoopActionConstant.READ, false);
+    MPrivilege readPrivilege = new MPrivilege(sqoopServer1, 
SqoopActionConstant.READ, false);
     client.createRole(role1);
     client.grantRole(Lists.newArrayList(role1), Lists.newArrayList(group1));
     client.grantPrivilege(Lists.newArrayList(new MPrincipal(role1.getName(), 
MPrincipal.TYPE.ROLE)),
@@ -71,29 +74,34 @@ public class TestServerScopeEndToEnd extends 
AbstractSqoopSentryTestBase {
 
     /**
      * ADMIN_USER grant write privilege on server SQOOP_SERVER_NAME to role2
-     * ADMIN_USER grant read privilege on connector all to role2 (for update 
link required)
-     * ADMIN_USER grant read privilege on link all to role2 (for update job 
required)
+     * ADMIN_USER grant read privilege on connector HDFS_CONNECTOR_NAME and 
JDBC_CONNECTOR_NAME
+     * to role2 (for update link required)
+     * ADMIN_USER grant read privilege on link "jdbc-link1" and "hdfs-link1" 
to role2 (for update job required)
      */
     MRole role2 = new MRole(ROLE2);
     MPrincipal group2 = new MPrincipal(GROUP2, MPrincipal.TYPE.GROUP);
     MPrivilege writePrivilege = new 
MPrivilege(sqoopServer1,SqoopActionConstant.WRITE, false);
     client.createRole(role2);
 
-    MResource allConnector = new MResource(SqoopActionConstant.ALL, 
MResource.TYPE.CONNECTOR);
-    MResource allLink = new MResource(SqoopActionConstant.ALL, 
MResource.TYPE.LINK);
-    MPrivilege readAllConPriv = new 
MPrivilege(allConnector,SqoopActionConstant.READ, false);
-    MPrivilege readAllLinkPriv = new 
MPrivilege(allLink,SqoopActionConstant.READ, false);
+    MResource hdfsConnector = new MResource(HDFS_CONNECTOR_NAME, 
MResource.TYPE.CONNECTOR);
+    MResource jdbcConnector = new MResource(JDBC_CONNECTOR_NAME, 
MResource.TYPE.CONNECTOR);
+    MResource jdbcLink = new MResource("jdbc-link1", MResource.TYPE.LINK);
+    MResource hdfsLinkResource = new MResource("hdfs-link1", 
MResource.TYPE.LINK);
+    MPrivilege readHdfsConPriv = new MPrivilege(hdfsConnector, 
SqoopActionConstant.READ, false);
+    MPrivilege readJdbcConPriv = new MPrivilege(jdbcConnector, 
SqoopActionConstant.READ, false);
+    MPrivilege readJdbcLinkPriv = new MPrivilege(jdbcLink, 
SqoopActionConstant.READ, false);
+    MPrivilege readHdfsLinkPriv = new MPrivilege(hdfsLinkResource, 
SqoopActionConstant.READ, false);
 
     client.grantRole(Lists.newArrayList(role2), Lists.newArrayList(group2));
     client.grantPrivilege(Lists.newArrayList(new MPrincipal(role2.getName(), 
MPrincipal.TYPE.ROLE)),
-        Lists.newArrayList(writePrivilege, readAllConPriv, readAllLinkPriv));
+        Lists.newArrayList(writePrivilege, readHdfsConPriv, readJdbcConPriv, 
readJdbcLinkPriv, readHdfsLinkPriv));
 
     /**
      * ADMIN_USER grant all privilege on server SQOOP_SERVER_NAME to role3
      */
     MRole role3 = new MRole(ROLE3);
     MPrincipal group3 = new MPrincipal(GROUP3, MPrincipal.TYPE.GROUP);
-    MPrivilege allPrivilege = new 
MPrivilege(sqoopServer1,SqoopActionConstant.ALL_NAME, false);
+    MPrivilege allPrivilege = new MPrivilege(sqoopServer1, 
SqoopActionConstant.ALL_NAME, false);
     client.createRole(role3);
     client.grantRole(Lists.newArrayList(role3), Lists.newArrayList(group3));
     client.grantPrivilege(Lists.newArrayList(new MPrincipal(role3.getName(), 
MPrincipal.TYPE.ROLE)),
@@ -107,15 +115,15 @@ public class TestServerScopeEndToEnd extends 
AbstractSqoopSentryTestBase {
     client = sqoopServerRunner.getSqoopClient(USER1);
     try {
       // show connector
-      assertTrue(client.getConnector("generic-jdbc-connector") != null);
-      assertTrue(client.getConnector("hdfs-connector") != null);
+      assertTrue(client.getConnector(JDBC_CONNECTOR_NAME) != null);
+      assertTrue(client.getConnector(HDFS_CONNECTOR_NAME) != null);
       assertTrue(client.getConnectors().size() > 0);
       // show link
-      assertTrue(client.getLink(hdfsLink.getPersistenceId()) != null);
-      assertTrue(client.getLink(rdbmsLink.getPersistenceId()) != null);
+      assertTrue(client.getLink(hdfsLink.getName()) != null);
+      assertTrue(client.getLink(rdbmsLink.getName()) != null);
       assertTrue(client.getLinks().size() == 2);
       // show job
-      assertTrue(client.getJob(job1.getPersistenceId()) != null);
+      assertTrue(client.getJob(job1.getName()) != null);
       assertTrue(client.getJobs().size() == 1);
     } catch (Exception e) {
       fail("unexpected Authorization exception happend");
@@ -123,18 +131,20 @@ public class TestServerScopeEndToEnd extends 
AbstractSqoopSentryTestBase {
     // user1 can't update link and job
     try {
       hdfsLink.setName("hdfs1_update_user1");
-      client.updateLink(hdfsLink);
+      client.updateLink(hdfsLink, "hdfs-link1");
       fail("expected Authorization exception happend");
     } catch (Exception e) {
       assertCausedMessage(e, SecurityError.AUTH_0014.getMessage());
+      hdfsLink.setName("hdfs-link1");
     }
 
     try {
       job1.setName("job1_update_user1");
-      client.updateJob(job1);
+      client.updateJob(job1, "hdfs-jdbc-job1");
       fail("expected Authorization exception happend");
     } catch (Exception e) {
       assertCausedMessage(e, SecurityError.AUTH_0014.getMessage());
+      job1.setName("hdfs-jdbc-job1");
     }
 
     /**
@@ -146,9 +156,13 @@ public class TestServerScopeEndToEnd extends 
AbstractSqoopSentryTestBase {
     try {
       // update link and job
       hdfsLink.setName("hdfs1_update_user2");
-      client.updateLink(hdfsLink);
+      client.updateLink(hdfsLink, "hdfs-link1");
+      // Now change it back
+      hdfsLink.setName("hdfs-link1");
+      client.updateLink(hdfsLink, "hdfs1_update_user2");
+
       job1.setName("job1_update_user2");
-      client.updateJob(job1);
+      client.updateJob(job1, "hdfs-jdbc-job1");
     } catch (Exception e) {
       fail("unexpected Authorization exception happend");
     }
@@ -162,22 +176,25 @@ public class TestServerScopeEndToEnd extends 
AbstractSqoopSentryTestBase {
     client = sqoopServerRunner.getSqoopClient(USER3);
     try {
       // show connector
-      assertTrue(client.getConnector("generic-jdbc-connector") != null);
-      assertTrue(client.getConnector("hdfs-connector") != null);
+      assertTrue(client.getConnector(JDBC_CONNECTOR_NAME) != null);
+      assertTrue(client.getConnector(HDFS_CONNECTOR_NAME) != null);
       assertTrue(client.getConnectors().size() > 0);
       // show link
-      assertTrue(client.getLink(hdfsLink.getPersistenceId()) != null);
-      assertTrue(client.getLink(rdbmsLink.getPersistenceId()) != null);
+      assertTrue(client.getLink(hdfsLink.getName()) != null);
+      assertTrue(client.getLink(rdbmsLink.getName()) != null);
       assertTrue(client.getLinks().size() == 2);
       // show job
-      assertTrue(client.getJob(job1.getPersistenceId()) != null);
+      assertTrue(client.getJob(job1.getName()) != null);
       assertTrue(client.getJobs().size() == 1);
       // update link
       hdfsLink.setName("hdfs1_update_user3");
-      client.updateLink(hdfsLink);
+      client.updateLink(hdfsLink, "hdfs-link1");
+      // Now change it back
+      hdfsLink.setName("hdfs-link1");
+      client.updateLink(hdfsLink, "hdfs1_update_user3");
       // update job
       job1.setName("job1_update_user3");
-      client.updateJob(job1);
+      client.updateJob(job1, "job1_update_user2");
     } catch (Exception e) {
       fail("unexpected Authorization exception happend");
     }

http://git-wip-us.apache.org/repos/asf/sentry/blob/e23fc4ef/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestShowPrivilege.java
----------------------------------------------------------------------
diff --git 
a/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestShowPrivilege.java
 
b/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestShowPrivilege.java
index 0ccbf5d..8cd8183 100644
--- 
a/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestShowPrivilege.java
+++ 
b/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TestShowPrivilege.java
@@ -36,7 +36,7 @@ public class TestShowPrivilege extends 
AbstractSqoopSentryTestBase {
   public void testNotSupportShowOnUser() throws Exception {
     SqoopClient client = sqoopServerRunner.getSqoopClient(ADMIN_USER);
     MPrincipal user1 = new MPrincipal("not_support_user1", 
MPrincipal.TYPE.USER);
-    MResource resource1 = new MResource("all", MResource.TYPE.CONNECTOR);
+    MResource resource1 = new MResource(HDFS_CONNECTOR_NAME, 
MResource.TYPE.CONNECTOR);
     try {
       client.getPrivilegesByPrincipal(user1, resource1);
       fail("expected not support exception happend");
@@ -49,7 +49,7 @@ public class TestShowPrivilege extends 
AbstractSqoopSentryTestBase {
   public void testNotSupportShowOnGroup() throws Exception {
     SqoopClient client = sqoopServerRunner.getSqoopClient(ADMIN_USER);
     MPrincipal group1 = new MPrincipal("not_support_group1", 
MPrincipal.TYPE.GROUP);
-    MResource resource1 = new MResource("all", MResource.TYPE.CONNECTOR);
+    MResource resource1 = new MResource(HDFS_CONNECTOR_NAME, 
MResource.TYPE.CONNECTOR);
     try {
       client.getPrivilegesByPrincipal(group1, resource1);
       fail("expected not support exception happend");
@@ -63,26 +63,26 @@ public class TestShowPrivilege extends 
AbstractSqoopSentryTestBase {
     /**
      * user1 belongs to group group1
      * admin user grant role role1 to group group1
-     * admin user grant read privilege on connector all to role role1
+     * admin user grant read privilege on connector HDFS_CONNECTOR_NAME to 
role role1
      */
     SqoopClient client = sqoopServerRunner.getSqoopClient(ADMIN_USER);
     MRole role1 = new MRole(ROLE1);
     MPrincipal group1Princ = new MPrincipal(GROUP1, MPrincipal.TYPE.GROUP);
     MPrincipal role1Princ = new MPrincipal(ROLE1, MPrincipal.TYPE.ROLE);
-    MResource allConnector = new MResource(SqoopActionConstant.ALL, 
MResource.TYPE.CONNECTOR);
-    MPrivilege readPriv = new MPrivilege(allConnector, 
SqoopActionConstant.READ, false);
+    MResource hdfsConnector = new MResource(HDFS_CONNECTOR_NAME, 
MResource.TYPE.CONNECTOR);
+    MPrivilege readPriv = new MPrivilege(hdfsConnector, 
SqoopActionConstant.READ, false);
     client.createRole(role1);
     client.grantRole(Lists.newArrayList(role1), 
Lists.newArrayList(group1Princ));
     client.grantPrivilege(Lists.newArrayList(role1Princ), 
Lists.newArrayList(readPriv));
 
     // user1 show privilege on role1
     client = sqoopServerRunner.getSqoopClient(USER1);
-    assertTrue(client.getPrivilegesByPrincipal(role1Princ, 
allConnector).size() == 1);
+    assertTrue(client.getPrivilegesByPrincipal(role1Princ, 
hdfsConnector).size() == 1);
 
     // user2 can't show privilege on role1, because user2 doesn't belong to 
role1
     client = sqoopServerRunner.getSqoopClient(USER2);
     try {
-      client.getPrivilegesByPrincipal(role1Princ, allConnector);
+      client.getPrivilegesByPrincipal(role1Princ, hdfsConnector);
       fail("expected SentryAccessDeniedException happend");
     } catch (Exception e) {
       assertCausedMessage(e, "SentryAccessDeniedException");

http://git-wip-us.apache.org/repos/asf/sentry/blob/e23fc4ef/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TomcatSqoopRunner.java
----------------------------------------------------------------------
diff --git 
a/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TomcatSqoopRunner.java
 
b/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TomcatSqoopRunner.java
deleted file mode 100644
index 0f0496b..0000000
--- 
a/sentry-tests/sentry-tests-sqoop/src/test/java/org/apache/sentry/tests/e2e/sqoop/TomcatSqoopRunner.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * 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.sqoop;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.sqoop.client.SqoopClient;
-import org.apache.sqoop.common.test.db.DatabaseProvider;
-import org.apache.sqoop.common.test.db.DatabaseProviderFactory;
-import org.apache.sqoop.common.test.db.TableName;
-import org.apache.sqoop.common.test.utils.NetworkUtils;
-import org.apache.sqoop.model.MConfigList;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MLink;
-import org.apache.sqoop.model.MPersistableEntity;
-import org.apache.sqoop.test.minicluster.SqoopMiniCluster;
-import org.apache.sqoop.validation.Status;
-import org.codehaus.cargo.container.ContainerType;
-import org.codehaus.cargo.container.InstalledLocalContainer;
-import org.codehaus.cargo.container.configuration.ConfigurationType;
-import org.codehaus.cargo.container.configuration.LocalConfiguration;
-import org.codehaus.cargo.container.deployable.WAR;
-import org.codehaus.cargo.container.installer.Installer;
-import org.codehaus.cargo.container.installer.ZipURLInstaller;
-import org.codehaus.cargo.container.property.ServletPropertySet;
-import org.codehaus.cargo.container.tomcat.TomcatPropertySet;
-import org.codehaus.cargo.generic.DefaultContainerFactory;
-import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory;
-
-import com.google.common.base.Joiner;
-
-public class TomcatSqoopRunner {
-  private static final Logger LOG = Logger.getLogger(TomcatSqoopRunner.class);
-  private SqoopServerEnableSentry server;
-  private DatabaseProvider provider;
-  private String temporaryPath;
-
-  public TomcatSqoopRunner(String temporaryPath, String serverName, String 
sentrySite)
-      throws Exception {
-    this.temporaryPath = temporaryPath;
-    this.server = new SqoopServerEnableSentry(temporaryPath, serverName, 
sentrySite);
-    this.provider = 
DatabaseProviderFactory.getProvider(System.getProperties());
-  }
-
-  public void start() throws Exception {
-    server.start();
-    provider.start();
-  }
-
-  public void stop() throws Exception {
-    server.stop();
-    provider.stop();
-  }
-
-
-  /**
-   * create link.
-   *
-   * With asserts to make sure that it was created correctly.
-   * @param sqoopClient
-   * @param link
-   */
-  public void saveLink(SqoopClient client, MLink link) {
-    assertEquals(Status.OK, client.saveLink(link));
-    assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, 
link.getPersistenceId());
-  }
-
-  /**
-   * create link.
-   *
-   * With asserts to make sure that it was created correctly.
-   * @param sqoopClient
-   * @param link
-   */
-  public void updateLink(SqoopClient client, MLink link) {
-    assertEquals(Status.OK, client.updateLink(link));
-    assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, 
link.getPersistenceId());
-  }
-
-  /**
-   * Create job.
-   *
-   * With asserts to make sure that it was created correctly.
-   *
-   * @param job
-   */
-  public void saveJob(SqoopClient client, MJob job) {
-    assertEquals(Status.OK, client.saveJob(job));
-    assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, 
job.getPersistenceId());
-  }
-
-  /**
-   * fill link.
-   *
-   * With asserts to make sure that it was filled correctly.
-   *
-   * @param link
-   */
-  public void fillHdfsLink(MLink link) {
-    MConfigList configs = link.getConnectorLinkConfig();
-    
configs.getStringInput("linkConfig.confDir").setValue(server.getConfigurationPath());
-  }
-
-  /**
-   * Fill link config based on currently active provider.
-   *
-   * @param link MLink object to fill
-   */
-  public void fillRdbmsLinkConfig(MLink link) {
-    MConfigList configs = link.getConnectorLinkConfig();
-    
configs.getStringInput("linkConfig.jdbcDriver").setValue(provider.getJdbcDriver());
-    
configs.getStringInput("linkConfig.connectionString").setValue(provider.getConnectionUrl());
-    
configs.getStringInput("linkConfig.username").setValue(provider.getConnectionUsername());
-    
configs.getStringInput("linkConfig.password").setValue(provider.getConnectionPassword());
-  }
-
-  public void fillHdfsFromConfig(MJob job) {
-    MConfigList fromConfig = job.getFromJobConfig();
-    
fromConfig.getStringInput("fromJobConfig.inputDirectory").setValue(temporaryPath
 + "/output");
-  }
-
-  public void fillRdbmsToConfig(MJob job) {
-    MConfigList toConfig = job.getToJobConfig();
-    toConfig.getStringInput("toJobConfig.tableName").setValue(provider.
-        escapeTableName(new 
TableName(getClass().getSimpleName()).getTableName()));
-  }
-
-  /**
-   * get a sqoopClient for specific user
-   * @param user
-   */
-  public SqoopClient getSqoopClient(String user) {
-    setAuthenticationUser(user);
-    return new SqoopClient(server.getServerUrl());
-  }
-
-  /**
-   * Set the mock user in the Sqoop simple authentication
-   * @param user
-   */
-  private void setAuthenticationUser(String user) {
-    System.setProperty("user.name", user);
-  }
-
-  private static class SqoopServerEnableSentry extends SqoopMiniCluster {
-    private static final String WAR_PATH = 
"target/thirdparty/sqoop-server.war";
-    private static final String TOMCAT_PATH = "target/thirdparty/tomcat.zip";
-
-    private InstalledLocalContainer container = null;
-    private Integer port;
-    private Integer ajpPort;
-    private String sentrySite;
-    private String serverName;
-
-    SqoopServerEnableSentry(String temporaryPath, String serverName, String 
sentrySite)
-        throws Exception {
-      super(temporaryPath);
-      this.serverName = serverName;
-      this.sentrySite = sentrySite;
-      // Random port
-      this.port = NetworkUtils.findAvailablePort();
-      this.ajpPort = NetworkUtils.findAvailablePort();
-    }
-
-    @Override
-    public Map<String, String> getSecurityConfiguration() {
-      Map<String, String> properties = new HashMap<String, String>();
-      configureAuthentication(properties);
-      configureSentryAuthorization(properties);
-      return properties;
-    }
-
-    private void configureAuthentication(Map<String, String> properties) {
-      /** Simple Authentication */
-      properties.put("org.apache.sqoop.authentication.type", "SIMPLE");
-      properties.put("org.apache.sqoop.authentication.handler",
-          "org.apache.sqoop.security.SimpleAuthenticationHandler");
-    }
-
-    private void configureSentryAuthorization(Map<String, String> properties) {
-      properties.put("org.apache.sqoop.security.authorization.handler",
-          "org.apache.sentry.sqoop.authz.SentryAuthorizationHandler");
-      
properties.put("org.apache.sqoop.security.authorization.access_controller",
-          "org.apache.sentry.sqoop.authz.SentryAccessController");
-      properties.put("org.apache.sqoop.security.authorization.validator",
-          "org.apache.sentry.sqoop.authz.SentryAuthorizationValidator");
-      properties.put("org.apache.sqoop.security.authorization.server_name", 
serverName);
-      properties.put("sentry.sqoop.site.url", sentrySite);
-      /** set Sentry related jars into classpath */
-      List<String> extraClassPath = new LinkedList<String>();
-      for (String jar : System.getProperty("java.class.path").split(":")) {
-        if ((jar.contains("sentry") || jar.contains("shiro-core") || 
jar.contains("libthrift"))
-            && jar.endsWith("jar")) {
-          extraClassPath.add(jar);
-        }
-      }
-      
properties.put("org.apache.sqoop.classpath.extra",Joiner.on(":").join(extraClassPath));
-    }
-
-    @Override
-    public void start() throws Exception {
-      // Container has already been started
-      if (container != null) {
-        return;
-      }
-      prepareTemporaryPath();
-
-      // Source: http://cargo.codehaus.org/Functional+testing
-      String tomcatPath = getTemporaryPath() + "/tomcat";
-      String extractPath = tomcatPath + "/extract";
-      String confPath = tomcatPath + "/conf";
-
-      Installer installer = new ZipURLInstaller(new 
File(TOMCAT_PATH).toURI().toURL(), null, extractPath);
-      installer.install();
-
-      LocalConfiguration configuration = (LocalConfiguration) new 
DefaultConfigurationFactory()
-          .createConfiguration("tomcat7x", ContainerType.INSTALLED, 
ConfigurationType.STANDALONE,
-              confPath);
-      container = (InstalledLocalContainer) new 
DefaultContainerFactory().createContainer("tomcat7x",
-          ContainerType.INSTALLED, configuration);
-
-      // Set home to our installed tomcat instance
-      container.setHome(installer.getHome());
-
-      // Store tomcat logs into file as they are quite handy for debugging
-      container.setOutput(getTemporaryPath() + "/log/tomcat.log");
-
-      // Propagate system properties to the container
-      Map<String, String> map = new HashMap<String, String>((Map) 
System.getProperties());
-      container.setSystemProperties(map);
-
-      // Propagate Hadoop jars to the container classpath
-      // In real world, they would be installed manually by user
-      List<String> extraClassPath = new LinkedList<String>();
-      String[] classpath = System.getProperty("java.class.path").split(":");
-      for (String jar : classpath) {
-        if (jar.contains("hadoop-") || // Hadoop jars
-            jar.contains("hive-") || // Hive jars
-            jar.contains("commons-") || // Apache Commons libraries
-            jar.contains("httpcore-") || // Apache Http Core libraries
-            jar.contains("httpclient-") || // Apache Http Client libraries
-            jar.contains("htrace-") || // htrace-core libraries, new added in
-                                       // Hadoop 2.6.0
-            jar.contains("zookeeper-") || // zookeeper libraries, new added in
-                                          // Hadoop 2.6.0
-            jar.contains("curator-") || // curator libraries, new added in 
Hadoop
-                                        // 2.6.0
-            jar.contains("log4j-") || // Log4j
-            jar.contains("slf4j-") || // Slf4j
-            jar.contains("jackson-") || // Jackson
-            jar.contains("derby") || // Derby drivers
-            jar.contains("avro-") || // Avro
-            jar.contains("parquet-") || // Parquet
-            jar.contains("mysql") || // MySQL JDBC driver
-            jar.contains("postgre") || // PostgreSQL JDBC driver
-            jar.contains("oracle") || // Oracle driver
-            jar.contains("terajdbc") || // Teradata driver
-            jar.contains("tdgs") || // Teradata driver
-            jar.contains("nzjdbc") || // Netezza driver
-            jar.contains("sqljdbc") || // Microsoft SQL Server driver
-            jar.contains("datanucleus-") || // Data nucleus libs
-            jar.contains("google") // Google libraries (guava, ...)
-        ) {
-          extraClassPath.add(jar);
-        }
-      }
-      container.setExtraClasspath(extraClassPath.toArray(new 
String[extraClassPath.size()]));
-
-      // Finally deploy Sqoop server war file
-      configuration.addDeployable(new WAR(WAR_PATH));
-      configuration.setProperty(ServletPropertySet.PORT, port.toString());
-      configuration.setProperty(TomcatPropertySet.AJP_PORT, 
ajpPort.toString());
-      //configuration.setProperty(GeneralPropertySet.JVMARGS, 
"\"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8006\"");
-      LOG.info("Tomcat extract path: " + extractPath);
-      LOG.info("Tomcat home path: " + installer.getHome());
-      LOG.info("Tomcat config home path: " + confPath);
-      LOG.info("Starting tomcat server on port " + port);
-      container.start();
-    }
-
-    @Override
-    public void stop() throws Exception {
-      if (container != null) {
-        container.stop();
-      }
-    }
-
-    /**
-     * Return server URL.
-     */
-    public String getServerUrl() {
-      // We're not doing any changes, so return default URL
-      return "http://localhost:"; + port + "/sqoop/";
-    }
-  }
-}

Reply via email to