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);
}
}
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);
}
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;
}
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();
}
}
}
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.");
}
}
}
Aggregations