Search in sources :

Example 61 with Configuration

use of org.apache.commons.configuration.Configuration 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 62 with Configuration

use of org.apache.commons.configuration.Configuration in project incubator-atlas by apache.

the class AtlasTopicCreator method main.

public static void main(String[] args) throws AtlasException {
    Configuration configuration = ApplicationProperties.get();
    AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator();
    atlasTopicCreator.createAtlasTopic(configuration, args);
}
Also used : Configuration(org.apache.commons.configuration.Configuration)

Example 63 with Configuration

use of org.apache.commons.configuration.Configuration in project incubator-atlas by apache.

the class OnAtlasPropertyCondition method matches.

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
    boolean matches = false;
    String propertyName = (String) metadata.getAnnotationAttributes(ConditionalOnAtlasProperty.class.getName()).get("property");
    boolean isDefault = (Boolean) metadata.getAnnotationAttributes(ConditionalOnAtlasProperty.class.getName()).get("isDefault");
    String className = ((AnnotationMetadataReadingVisitor) metadata).getClassName();
    try {
        Configuration configuration = ApplicationProperties.get();
        String configuredProperty = configuration.getString(propertyName);
        if (StringUtils.isNotEmpty(configuredProperty)) {
            matches = configuredProperty.equals(className);
        } else if (isDefault)
            matches = true;
    } catch (AtlasException e) {
        LOG.error("Unable to load atlas properties. Dependent bean configuration may fail");
    }
    return matches;
}
Also used : ConditionalOnAtlasProperty(org.apache.atlas.annotation.ConditionalOnAtlasProperty) Configuration(org.apache.commons.configuration.Configuration) AnnotationMetadataReadingVisitor(org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor) AtlasException(org.apache.atlas.AtlasException)

Example 64 with Configuration

use of org.apache.commons.configuration.Configuration in project incubator-atlas by apache.

the class ApplicationPropertiesTest method testGetFileAsInputStream.

@Test
public void testGetFileAsInputStream() throws Exception {
    Configuration props = ApplicationProperties.get("test.properties");
    InputStream inStr = null;
    // configured file as class loader resource
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
        assertNotNull(inStr);
    } finally {
        if (inStr != null) {
            inStr.close();
        }
    }
    // configured file from file system path
    props.setProperty("jaas.properties.file", "src/test/resources/atlas-jaas.properties");
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
        assertNotNull(inStr);
    } finally {
        if (inStr != null) {
            inStr.close();
        }
    }
    // default file as class loader resource
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
        assertNotNull(inStr);
    } finally {
        if (inStr != null) {
            inStr.close();
        }
    }
    // default file relative to working directory
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "src/test/resources/atlas-jaas.properties");
        assertNotNull(inStr);
    } finally {
        if (inStr != null) {
            inStr.close();
        }
    }
    // default file relative to atlas configuration directory
    String originalConfDirSetting = System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, "src/test/resources");
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", "atlas-jaas.properties");
        assertNotNull(inStr);
    } finally {
        if (inStr != null) {
            inStr.close();
        }
        if (originalConfDirSetting != null) {
            System.setProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY, originalConfDirSetting);
        } else {
            System.clearProperty(ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY);
        }
    }
    // non-existent property and no default file
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "property.not.specified.in.config", null);
        fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
    } catch (AtlasException e) {
    // good
    } finally {
        if (inStr != null) {
            inStr.close();
        }
    }
    // configured file not found in file system or classpath
    props.setProperty("jaas.properties.file", "does_not_exist.txt");
    try {
        inStr = ApplicationProperties.getFileAsInputStream(props, "jaas.properties.file", null);
        fail("Expected " + AtlasException.class.getSimpleName() + " but none thrown");
    } catch (AtlasException e) {
    // good
    } finally {
        if (inStr != null) {
            inStr.close();
        }
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) InputStream(java.io.InputStream) Test(org.testng.annotations.Test)

Example 65 with Configuration

use of org.apache.commons.configuration.Configuration in project incubator-atlas by apache.

the class TaxonomyResourceProvider method createDefaultTaxonomyIfNeeded.

// must be called from within class monitor
private void createDefaultTaxonomyIfNeeded() {
    if (!autoInitializationChecked()) {
        try {
            LOG.info("Checking if default taxonomy needs to be created.");
            // see if any taxonomy exists.
            if (doGetResources(new CollectionRequest(null, null)).getPropertyMaps().isEmpty()) {
                LOG.info("No taxonomies found - going to create default taxonomy.");
                Map<String, Object> requestProperties = new HashMap<>();
                String defaultTaxonomyName = DEFAULT_TAXONOMY_NAME;
                try {
                    Configuration configuration = ApplicationProperties.get();
                    defaultTaxonomyName = configuration.getString("atlas.taxonomy.default.name", defaultTaxonomyName);
                } catch (AtlasException e) {
                    LOG.warn("Unable to read Atlas configuration, will use {} as default taxonomy name", defaultTaxonomyName, e);
                }
                requestProperties.put("name", defaultTaxonomyName);
                requestProperties.put("description", DEFAULT_TAXONOMY_DESCRIPTION);
                doCreateResource(new InstanceRequest(requestProperties));
                LOG.info("Successfully created default taxonomy {}.", defaultTaxonomyName);
            } else {
                taxonomyAutoInitializationChecked = true;
                LOG.info("Some taxonomy exists, not creating default taxonomy");
            }
        } catch (InvalidQueryException | ResourceNotFoundException e) {
            LOG.error("Unable to query for existing taxonomies due to internal error.", e);
        } catch (ResourceAlreadyExistsException e) {
            LOG.info("Attempted to create default taxonomy and it already exists.");
        }
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) AtlasException(org.apache.atlas.AtlasException)

Aggregations

Configuration (org.apache.commons.configuration.Configuration)185 Test (org.junit.Test)51 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)44 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)23 Test (org.testng.annotations.Test)22 File (java.io.File)14 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)13 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)11 Properties (java.util.Properties)10 HashMap (java.util.HashMap)9 AtlasException (org.apache.atlas.AtlasException)9 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)9 ArrayList (java.util.ArrayList)8 ZkUtils (kafka.utils.ZkUtils)8 ConfigurationException (org.apache.commons.configuration.ConfigurationException)8 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)7 AtlasClient (org.apache.atlas.AtlasClient)6 BeforeClass (org.testng.annotations.BeforeClass)6 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)5 IOException (java.io.IOException)5