Search in sources :

Example 1 with MLink

use of org.apache.sqoop.model.MLink in project ranger by apache.

the class RangerSqoopAuthorizerTest method initSqoopAuth.

/**
 * Help function: init sqoop to enable ranger authentication
 */
private static void initSqoopAuth() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    // init sqoop configruation
    String basedir = System.getProperty("basedir");
    if (basedir == null) {
        basedir = new File(".").getCanonicalPath();
    }
    String sqoopConfigDirPath = basedir + "/src/test/resources/";
    System.setProperty(ConfigurationConstants.SYSPROP_CONFIG_DIR, sqoopConfigDirPath);
    SqoopConfiguration.getInstance().initialize();
    // init sqoop authorization
    AuthorizationManager.getInstance().initialize();
    // mock sqoop class for authentication
    RepositoryManager repositoryManager = mock(RepositoryManager.class);
    RepositoryManager.setInstance(repositoryManager);
    Repository repository = mock(Repository.class);
    when(repositoryManager.getRepository()).thenReturn(repository);
    MLink link = mock(MLink.class);
    when(repository.findLink(anyString())).thenReturn(link);
    MJob job = mock(MJob.class);
    when(repository.findJob(anyString())).thenReturn(job);
    // mock user "zhangqiang" as the creator of any link and any job
    when(link.getCreationUser()).thenReturn(ZHANGQIANG);
    when(job.getCreationUser()).thenReturn(ZHANGQIANG);
}
Also used : Repository(org.apache.sqoop.repository.Repository) MJob(org.apache.sqoop.model.MJob) MLink(org.apache.sqoop.model.MLink) RepositoryManager(org.apache.sqoop.repository.RepositoryManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File)

Example 2 with MLink

use of org.apache.sqoop.model.MLink in project testcases by coheigea.

the class SqoopSentryTest method testAliceUser.

// "alice" can create links and read connectors and jobs
@org.junit.Test
public void testAliceUser() throws Exception {
    SqoopClient client = jettySqoopRunner.getSqoopClient("alice");
    assertFalse(client.getConnectors().isEmpty());
    assertEquals(client.getLinks().size(), 2);
    assertEquals(client.getJobs().size(), 1);
    // Update one of the links
    MLink rdbmsLink = client.getLink("JDBC_link1");
    assertNotNull(rdbmsLink);
    rdbmsLink.setName("JDBC_link2");
    client.updateLink(rdbmsLink, "JDBC_link1");
    // Try to read the job
    MJob job1 = client.getJob("HDFS_JDBS_job1");
    assertNotNull(job1);
    job1.setName("HDFS_JDBS_job2");
    try {
        client.updateJob(job1, "HDFS_JDBS_job1");
        fail("Authorization failure expected");
    } catch (SqoopException ex) {
    // expected
    }
}
Also used : MJob(org.apache.sqoop.model.MJob) MLink(org.apache.sqoop.model.MLink) SqoopClient(org.apache.sqoop.client.SqoopClient) SqoopException(org.apache.sqoop.common.SqoopException)

Example 3 with MLink

use of org.apache.sqoop.model.MLink in project testcases by coheigea.

the class SqoopRangerTest method testAliceUser.

// "alice" can create links and read connectors and jobs
@org.junit.Test
public void testAliceUser() throws Exception {
    SqoopClient client = jettySqoopRunner.getSqoopClient("alice");
    assertFalse(client.getConnectors().isEmpty());
    assertEquals(client.getLinks().size(), 2);
    assertEquals(client.getJobs().size(), 1);
    // Update one of the links
    MLink rdbmsLink = client.getLink("JDBC_link1");
    assertNotNull(rdbmsLink);
    rdbmsLink.setName("JDBC_link2");
    client.updateLink(rdbmsLink, "JDBC_link1");
    // Try to read the job
    MJob job1 = client.getJob("HDFS_JDBS_job1");
    assertNotNull(job1);
    job1.setName("HDFS_JDBS_job2");
    try {
        client.updateJob(job1, "HDFS_JDBS_job1");
        fail("Authorization failure expected");
    } catch (SqoopException ex) {
    // expected
    }
}
Also used : MJob(org.apache.sqoop.model.MJob) MLink(org.apache.sqoop.model.MLink) SqoopClient(org.apache.sqoop.client.SqoopClient) SqoopException(org.apache.sqoop.common.SqoopException)

Example 4 with MLink

use of org.apache.sqoop.model.MLink in project testcases by coheigea.

the class SqoopSentryTest method setup.

@org.junit.BeforeClass
public static void setup() throws Exception {
    tempDir = Files.createTempDirectory("sqoop");
    String sentrySitePath = "file:" + SqoopSentryTest.class.getResource("/sentry-site.xml").getPath();
    jettySqoopRunner = new JettySqoopRunner(tempDir.toString(), "sqoopServer1", sentrySitePath, false);
    jettySqoopRunner.start();
    // Create some links, jobs via the admin
    SqoopClient client = jettySqoopRunner.getSqoopClient("admin");
    MLink rdbmsLink = client.createLink("generic-jdbc-connector");
    jettySqoopRunner.fillRdbmsLinkConfig(rdbmsLink);
    rdbmsLink.setName("JDBC_link1");
    jettySqoopRunner.saveLink(client, rdbmsLink);
    MLink hdfsLink = client.createLink("hdfs-connector");
    jettySqoopRunner.fillHdfsLink(hdfsLink);
    hdfsLink.setName("HDFS_link1");
    jettySqoopRunner.saveLink(client, hdfsLink);
    MJob job1 = client.createJob(hdfsLink.getName(), rdbmsLink.getName());
    jettySqoopRunner.fillHdfsFromConfig(job1);
    jettySqoopRunner.fillRdbmsToConfig(job1);
    // create job
    job1.setName("HDFS_JDBS_job1");
    jettySqoopRunner.saveJob(client, job1);
}
Also used : MJob(org.apache.sqoop.model.MJob) MLink(org.apache.sqoop.model.MLink) SqoopClient(org.apache.sqoop.client.SqoopClient)

Example 5 with MLink

use of org.apache.sqoop.model.MLink in project testcases by coheigea.

the class SqoopRangerTest method setup.

@org.junit.BeforeClass
public static void setup() throws Exception {
    tempDir = Files.createTempDirectory("sqoop");
    jettySqoopRunner = new JettySqoopRunner(tempDir.toString(), "sqoopServer1", null, true);
    jettySqoopRunner.start();
    // Create some links, jobs via the admin
    SqoopClient client = jettySqoopRunner.getSqoopClient("admin");
    MLink rdbmsLink = client.createLink("generic-jdbc-connector");
    jettySqoopRunner.fillRdbmsLinkConfig(rdbmsLink);
    rdbmsLink.setName("JDBC_link1");
    jettySqoopRunner.saveLink(client, rdbmsLink);
    MLink hdfsLink = client.createLink("hdfs-connector");
    jettySqoopRunner.fillHdfsLink(hdfsLink);
    hdfsLink.setName("HDFS_link1");
    jettySqoopRunner.saveLink(client, hdfsLink);
    MJob job1 = client.createJob(hdfsLink.getName(), rdbmsLink.getName());
    jettySqoopRunner.fillHdfsFromConfig(job1);
    jettySqoopRunner.fillRdbmsToConfig(job1);
    // create job
    job1.setName("HDFS_JDBS_job1");
    jettySqoopRunner.saveJob(client, job1);
}
Also used : MJob(org.apache.sqoop.model.MJob) MLink(org.apache.sqoop.model.MLink) SqoopClient(org.apache.sqoop.client.SqoopClient)

Aggregations

MJob (org.apache.sqoop.model.MJob)6 MLink (org.apache.sqoop.model.MLink)6 SqoopClient (org.apache.sqoop.client.SqoopClient)5 SqoopException (org.apache.sqoop.common.SqoopException)2 File (java.io.File)1 Repository (org.apache.sqoop.repository.Repository)1 RepositoryManager (org.apache.sqoop.repository.RepositoryManager)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1