Search in sources :

Example 1 with AtlasClient

use of org.apache.atlas.AtlasClient in project incubator-atlas by apache.

the class HiveMetaStoreBridge method main.

public static void main(String[] args) throws AtlasHookException {
    try {
        Configuration atlasConf = ApplicationProperties.get();
        String[] atlasEndpoint = atlasConf.getStringArray(ATLAS_ENDPOINT);
        if (atlasEndpoint == null || atlasEndpoint.length == 0) {
            atlasEndpoint = new String[] { DEFAULT_DGI_URL };
        }
        AtlasClient atlasClient;
        if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
            String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
            atlasClient = new AtlasClient(atlasEndpoint, basicAuthUsernamePassword);
        } else {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            atlasClient = new AtlasClient(ugi, ugi.getShortUserName(), atlasEndpoint);
        }
        Options options = new Options();
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);
        boolean failOnError = false;
        if (cmd.hasOption("failOnError")) {
            failOnError = true;
        }
        HiveMetaStoreBridge hiveMetaStoreBridge = new HiveMetaStoreBridge(atlasConf, new HiveConf(), atlasClient);
        hiveMetaStoreBridge.importHiveMetadata(failOnError);
    } catch (Exception e) {
        throw new AtlasHookException("HiveMetaStoreBridge.main() failed.", e);
    }
}
Also used : Options(org.apache.commons.cli.Options) Configuration(org.apache.commons.configuration.Configuration) AtlasServiceException(org.apache.atlas.AtlasServiceException) AtlasHookException(org.apache.atlas.hook.AtlasHookException) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) AtlasHookException(org.apache.atlas.hook.AtlasHookException) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) HiveConf(org.apache.hadoop.hive.conf.HiveConf) AtlasClient(org.apache.atlas.AtlasClient) CommandLineParser(org.apache.commons.cli.CommandLineParser) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 2 with AtlasClient

use of org.apache.atlas.AtlasClient in project incubator-atlas by apache.

the class StormAtlasHookIT method setUp.

@BeforeClass
public void setUp() throws Exception {
    // start a local storm cluster
    stormCluster = StormTestUtil.createLocalStormCluster();
    LOG.info("Created a storm local cluster");
    Configuration configuration = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT), new String[] { "admin", "admin" });
    } else {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasClient(org.apache.atlas.AtlasClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with AtlasClient

use of org.apache.atlas.AtlasClient in project incubator-atlas by apache.

the class SSLTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
    providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri();
    setupCredentials();
    final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl);
    String persistDir = writeConfiguration(configuration);
    persistSSLClientConfiguration(configuration);
    originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);
    originalHomeDir = System.getProperty("atlas.home");
    System.setProperty("atlas.home", TestUtils.getTargetDirectory());
    atlasClient = new AtlasClient(configuration, new String[] { DGI_URL }, new String[] { "admin", "admin" });
    secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) {

        @Override
        public org.apache.commons.configuration.Configuration getConfiguration() {
            return configuration;
        }
    };
    secureEmbeddedServer.getServer().start();
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) AtlasClient(org.apache.atlas.AtlasClient) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with AtlasClient

use of org.apache.atlas.AtlasClient in project incubator-atlas by apache.

the class SSLAndKerberosTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
    providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri();
    String persistDir = TestUtils.getTempDirectory();
    setupKDCAndPrincipals();
    setupCredentials();
    // client will actually only leverage subset of these properties
    final PropertiesConfiguration configuration = getSSLConfiguration(providerUrl);
    persistSSLClientConfiguration(configuration);
    TestUtils.writeConfiguration(configuration, persistDir + File.separator + ApplicationProperties.APPLICATION_PROPERTIES);
    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = SSLAndKerberosTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    configuration.load(url);
    configuration.setProperty(TLS_ENABLED, true);
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.keytab", userKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.principal", "dgi/localhost@" + kdc.getRealm());
    configuration.setProperty("atlas.authentication.method.file", "false");
    configuration.setProperty("atlas.authentication.method.kerberos", "true");
    configuration.setProperty("atlas.authentication.method.kerberos.principal", "HTTP/localhost@" + kdc.getRealm());
    configuration.setProperty("atlas.authentication.method.kerberos.keytab", httpKeytabFile.getAbsolutePath());
    configuration.setProperty("atlas.authentication.method.kerberos.name.rules", "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\nDEFAULT");
    configuration.setProperty("atlas.authentication.method.file", "true");
    configuration.setProperty("atlas.authentication.method.file.filename", persistDir + "/users-credentials");
    configuration.setProperty("atlas.auth.policy.file", persistDir + "/policy-store.txt");
    TestUtils.writeConfiguration(configuration, persistDir + File.separator + "atlas-application.properties");
    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);
    subject = loginTestUser();
    UserGroupInformation.loginUserFromSubject(subject);
    UserGroupInformation proxyUser = UserGroupInformation.createProxyUser("testUser", UserGroupInformation.getLoginUser());
    // save original setting
    originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);
    originalHomeDir = System.getProperty("atlas.home");
    System.setProperty("atlas.home", TestUtils.getTargetDirectory());
    dgiCLient = proxyUser.doAs(new PrivilegedExceptionAction<AtlasClient>() {

        @Override
        public AtlasClient run() throws Exception {
            return new AtlasClient(configuration, DGI_URL);
        }
    });
    secureEmbeddedServer = new TestSecureEmbeddedServer(21443, getWarPath()) {

        @Override
        public PropertiesConfiguration getConfiguration() {
            return configuration;
        }
    };
    secureEmbeddedServer.getServer().start();
}
Also used : Path(org.apache.hadoop.fs.Path) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AtlasClient(org.apache.atlas.AtlasClient) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) File(java.io.File) URL(java.net.URL) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with AtlasClient

use of org.apache.atlas.AtlasClient in project incubator-atlas by apache.

the class EntityJerseyResourceIT method testRequestUser.

@Test
public void testRequestUser() throws Exception {
    Referenceable entity = new Referenceable(DATABASE_TYPE_BUILTIN);
    String dbName = randomString();
    entity.set("name", dbName);
    entity.set(QUALIFIED_NAME, dbName);
    entity.set("clusterName", randomString());
    entity.set("description", randomString());
    entity.set(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, dbName);
    entity.set("owner", "user1");
    entity.set("clusterName", "cl1");
    entity.set("parameters", Collections.EMPTY_MAP);
    entity.set("location", "/tmp");
    String user = "admin";
    AtlasClient localClient = null;
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        localClient = new AtlasClient(atlasUrls, new String[] { "admin", "admin" });
    } else {
        localClient = new AtlasClient(atlasUrls);
    }
    String entityId = localClient.createEntity(entity).get(0);
    List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(entityId, (short) 10);
    assertEquals(events.size(), 1);
    assertEquals(events.get(0).getUser(), user);
}
Also used : EntityAuditEvent(org.apache.atlas.EntityAuditEvent) Referenceable(org.apache.atlas.typesystem.Referenceable) AtlasClient(org.apache.atlas.AtlasClient) Test(org.testng.annotations.Test)

Aggregations

AtlasClient (org.apache.atlas.AtlasClient)9 BeforeClass (org.testng.annotations.BeforeClass)7 Configuration (org.apache.commons.configuration.Configuration)6 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)3 Path (org.apache.hadoop.fs.Path)3 File (java.io.File)2 URL (java.net.URL)2 HiveConf (org.apache.hadoop.hive.conf.HiveConf)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 AtlasClientV2 (org.apache.atlas.AtlasClientV2)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)1 AtlasService (org.apache.atlas.falcon.service.AtlasService)1 HiveMetaStoreBridge (org.apache.atlas.hive.bridge.HiveMetaStoreBridge)1 AtlasHookException (org.apache.atlas.hook.AtlasHookException)1 Referenceable (org.apache.atlas.typesystem.Referenceable)1 BasicParser (org.apache.commons.cli.BasicParser)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1