Java源码示例:org.apache.atlas.ApplicationProperties
示例1
public static Configuration getConfiguration() throws AtlasException {
Configuration configProperties = ApplicationProperties.get();
Configuration titanConfig = ApplicationProperties.getSubsetConfiguration(configProperties, GRAPH_PREFIX);
//add serializers for non-standard property value types that Atlas uses
titanConfig.addProperty("attributes.custom.attribute1.attribute-class", TypeCategory.class.getName());
titanConfig.addProperty("attributes.custom.attribute1.serializer-class",
TypeCategorySerializer.class.getName());
//not ideal, but avoids making large changes to Atlas
titanConfig.addProperty("attributes.custom.attribute2.attribute-class", ArrayList.class.getName());
titanConfig.addProperty("attributes.custom.attribute2.serializer-class", StringListSerializer.class.getName());
titanConfig.addProperty("attributes.custom.attribute3.attribute-class", BigInteger.class.getName());
titanConfig.addProperty("attributes.custom.attribute3.serializer-class", BigIntegerSerializer.class.getName());
titanConfig.addProperty("attributes.custom.attribute4.attribute-class", BigDecimal.class.getName());
titanConfig.addProperty("attributes.custom.attribute4.serializer-class", BigDecimalSerializer.class.getName());
return titanConfig;
}
示例2
@PostConstruct
void setAuthenticationMethod() {
try {
Configuration configuration = ApplicationProperties.get();
this.fileAuthenticationMethodEnabled = configuration.getBoolean(FILE_AUTH_METHOD, true);
this.pamAuthenticationEnabled = configuration.getBoolean(PAM_AUTH_METHOD, false);
this.keycloakAuthenticationEnabled = configuration.getBoolean(KEYCLOAK_AUTH_METHOD, false);
boolean ldapAuthenticationEnabled = configuration.getBoolean(LDAP_AUTH_METHOD, false);
if (ldapAuthenticationEnabled) {
this.ldapType = configuration.getString(LDAP_TYPE, "NONE");
} else {
this.ldapType = "NONE";
}
} catch (Exception e) {
LOG.error("Error while getting atlas.login.method application properties", e);
}
}
示例3
public static String writeConfiguration(final PropertiesConfiguration configuration) throws Exception {
String confLocation = System.getProperty("atlas.conf");
URL url;
if (confLocation == null) {
url = BaseSecurityTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
} else {
url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
}
PropertiesConfiguration configuredProperties = new PropertiesConfiguration();
configuredProperties.load(url);
configuredProperties.copy(configuration);
String persistDir = TestUtils.getTempDirectory();
configuredProperties.setProperty("atlas.authentication.method.file", "true");
configuredProperties.setProperty("atlas.authentication.method.file.filename", persistDir
+ "/users-credentials");
configuredProperties.setProperty("atlas.auth.policy.file",persistDir
+ "/policy-store.txt" );
TestUtils.writeConfiguration(configuredProperties, persistDir + File.separator +
ApplicationProperties.APPLICATION_PROPERTIES);
setupUserCredential(persistDir);
setUpPolicyStore(persistDir);
ApplicationProperties.forceReload();
return persistDir;
}
示例4
@Inject
public NotificationHookConsumer(NotificationInterface notificationInterface, AtlasEntityStore atlasEntityStore,
ServiceState serviceState, AtlasInstanceConverter instanceConverter,
AtlasTypeRegistry typeRegistry) throws AtlasException {
this.notificationInterface = notificationInterface;
this.atlasEntityStore = atlasEntityStore;
this.serviceState = serviceState;
this.instanceConverter = instanceConverter;
this.typeRegistry = typeRegistry;
this.applicationProperties = ApplicationProperties.get();
maxRetries = applicationProperties.getInt(CONSUMER_RETRIES_PROPERTY, 3);
failedMsgCacheSize = applicationProperties.getInt(CONSUMER_FAILEDCACHESIZE_PROPERTY, 20);
consumerRetryInterval = applicationProperties.getInt(CONSUMER_RETRY_INTERVAL, 500);
}
示例5
public void validateType(AtlasBaseTypeDef typeDef) throws AtlasBaseException {
if (!isValidName(typeDef.getName())) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID_FORMAT, typeDef.getName(), typeDef.getCategory().name());
}
try {
final boolean allowReservedKeywords = ApplicationProperties.get().getBoolean(ALLOW_RESERVED_KEYWORDS, true);
if (!allowReservedKeywords && typeDef instanceof AtlasStructDef) {
final List<AtlasStructDef.AtlasAttributeDef> attributeDefs = ((AtlasStructDef) typeDef).getAttributeDefs();
for (AtlasStructDef.AtlasAttributeDef attrDef : attributeDefs) {
if (QueryParser.isKeyword(attrDef.getName())) {
throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_NAME_INVALID, attrDef.getName(), typeDef.getCategory().name());
}
}
}
} catch (AtlasException e) {
LOG.error("Exception while loading configuration ", e);
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "Could not load configuration");
}
}
示例6
@SuppressWarnings("unchecked")
public static Class<? extends GraphDatabase> getGraphDatabaseImpl() {
try {
final Class<? extends GraphDatabase> ret;
Configuration config = ApplicationProperties.get();
String graphDatabaseImpl = config.getString(ApplicationProperties.GRAPHDB_BACKEND_CONF);
if (StringUtils.equals(graphDatabaseImpl, ApplicationProperties.GRAPHBD_BACKEND_JANUS)) {
ret = ApplicationProperties.getClass(JANUS_GRAPH_DATABASE_IMPLEMENTATION_CLASS, GraphDatabase.class);
} else {
ret = ApplicationProperties.getClass(graphDatabaseImpl, GraphDatabase.class);
}
return ret;
} catch (AtlasException e) {
throw new RuntimeException(e);
}
}
示例7
public static int getTypeUpdateLockMaxWaitTimeInSeconds() {
Integer ret = typeUpdateLockMaxWaitTimeInSeconds;
if (ret == null) {
try {
Configuration config = ApplicationProperties.get();
ret = config.getInteger(CONFIG_TYPE_UPDATE_LOCK_MAX_WAIT_TIME_IN_SECONDS, DEFAULT_TYPE_UPDATE_LOCK_MAX_WAIT_TIME_IN_SECONDS);
typeUpdateLockMaxWaitTimeInSeconds = ret;
} catch (AtlasException e) {
// ignore
}
}
return ret == null ? DEFAULT_TYPE_UPDATE_LOCK_MAX_WAIT_TIME_IN_SECONDS : ret;
}
示例8
private static void initialize() {
if (!isInitialized) {
try {
isFreeTextSearchEnabled = ApplicationProperties.get().getBoolean(ApplicationProperties.ENABLE_FREETEXT_SEARCH_CONF, true);
if (isFreeTextSearchEnabled) { // currently free-text is supported only for Solr
isFreeTextSearchEnabled = ApplicationProperties.INDEX_BACKEND_SOLR.equalsIgnoreCase(ApplicationProperties.get().getString(ApplicationProperties.INDEX_BACKEND_CONF));
}
if (isFreeTextSearchEnabled) { // if free-text is enabled, disable full-text - to avoid performance penalty
isFullTextSearchEnabled = false;
} else {
isFullTextSearchEnabled = ApplicationProperties.get().getBoolean(ApplicationProperties.ENABLE_FULLTEXT_SEARCH_CONF, true);
}
isInitialized = true;
} catch (AtlasException excp) {
LOG.error("Failed to initialize. isFullTextSearchEnabled={}, isFreeTextSearchEnabled={}", isFullTextSearchEnabled, isFreeTextSearchEnabled, excp);
}
}
}
示例9
@Override
public void init() {
LOG.info("==> SimpleAtlasAuthorizer.init()");
InputStream inputStream = null;
try {
inputStream = ApplicationProperties.getFileAsInputStream(ApplicationProperties.get(), "atlas.authorizer.simple.authz.policy.file", "atlas-simple-authz-policy.json");
authzPolicy = AtlasJson.fromJson(inputStream, AtlasSimpleAuthzPolicy.class);
} catch (IOException | AtlasException e) {
LOG.error("SimpleAtlasAuthorizer.init(): initialization failed", e);
throw new RuntimeException(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException excp) {
// ignore
}
}
}
LOG.info("<== SimpleAtlasAuthorizer.init()");
}
示例10
@Override
public void publish(SqoopJobDataPublisher.Data data) throws AtlasHookException {
try {
Configuration atlasProperties = ApplicationProperties.get();
String clusterName = atlasProperties.getString(ATLAS_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);
Referenceable dbStoreRef = createDBStoreInstance(data);
Referenceable dbRef = createHiveDatabaseInstance(clusterName, data.getHiveDB());
Referenceable hiveTableRef = createHiveTableInstance(clusterName, dbRef,
data.getHiveTable(), data.getHiveDB());
Referenceable procRef = createSqoopProcessInstance(dbStoreRef, hiveTableRef, data, clusterName);
int maxRetries = atlasProperties.getInt(HOOK_NUM_RETRIES, 3);
HookNotification.HookNotificationMessage message =
new HookNotification.EntityCreateRequest(AtlasHook.getUser(), dbStoreRef, dbRef, hiveTableRef, procRef);
AtlasHook.notifyEntities(Arrays.asList(message), maxRetries);
}
catch(Exception e) {
throw new AtlasHookException("SqoopHook.publish() failed.", e);
}
}
示例11
public static boolean useLocalSolr() {
boolean ret = false;
try {
Configuration conf = ApplicationProperties.get();
Object property = conf.getProperty("atlas.graph.index.search.solr.embedded");
if (property != null && property instanceof String) {
ret = Boolean.valueOf((String) property);
}
} catch (AtlasException ignored) {
throw new SkipException("useLocalSolr: failed! ", ignored);
}
return ret;
}
示例12
private void setPamProperties() {
try {
this.groupsFromUGI = ApplicationProperties.get().getBoolean("atlas.authentication.method.pam.ugi-groups", true);
Properties properties = ConfigurationConverter.getProperties(ApplicationProperties.get()
.subset("atlas.authentication.method.pam"));
for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
options.put(key, value);
}
if (!options.containsKey("service")) {
options.put("service", "atlas-login");
}
} catch (Exception e) {
LOG.error("Exception while setLdapProperties", e);
}
}
示例13
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
try {
Configuration configuration = ApplicationProperties.get();
boolean shouldRunSetup = configuration.getBoolean(ATLAS_SERVER_RUN_SETUP_KEY, false);
if (shouldRunSetup) {
LOG.warn("Running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
return true;
} else {
LOG.info("Not running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY);
}
} catch (AtlasException e) {
LOG.error("Unable to read config to determine if setup is needed. Not running setup.");
}
return false;
}
示例14
private void setLdapProperties() {
try {
Configuration configuration = ApplicationProperties.get();
Properties properties = ConfigurationConverter.getProperties(configuration.subset("atlas.authentication.method.ldap"));
ldapURL = properties.getProperty("url");
ldapUserDNPattern = properties.getProperty("userDNpattern");
ldapGroupSearchBase = properties.getProperty("groupSearchBase");
ldapGroupSearchFilter = properties.getProperty("groupSearchFilter");
ldapGroupRoleAttribute = properties.getProperty("groupRoleAttribute");
ldapBindDN = properties.getProperty("bind.dn");
ldapBindPassword = properties.getProperty("bind.password");
ldapDefaultRole = properties.getProperty("default.role");
ldapUserSearchFilter = properties.getProperty("user.searchfilter");
ldapReferral = properties.getProperty("referral");
ldapBase = properties.getProperty("base.dn");
groupsFromUGI = configuration.getBoolean("atlas.authentication.method.ldap.ugi-groups", true);
if(LOG.isDebugEnabled()) {
LOG.debug("AtlasLdapAuthenticationProvider{" +
"ldapURL='" + ldapURL + '\'' +
", ldapUserDNPattern='" + ldapUserDNPattern + '\'' +
", ldapGroupSearchBase='" + ldapGroupSearchBase + '\'' +
", ldapGroupSearchFilter='" + ldapGroupSearchFilter + '\'' +
", ldapGroupRoleAttribute='" + ldapGroupRoleAttribute + '\'' +
", ldapBindDN='" + ldapBindDN + '\'' +
", ldapDefaultRole='" + ldapDefaultRole + '\'' +
", ldapUserSearchFilter='" + ldapUserSearchFilter + '\'' +
", ldapReferral='" + ldapReferral + '\'' +
", ldapBase='" + ldapBase + '\'' +
", groupsFromUGI=" + groupsFromUGI +
'}');
}
} catch (Exception e) {
LOG.error("Exception while setLdapProperties", e);
}
}
示例15
@SuppressWarnings("unchecked")
public static Class<? extends EntityAuditRepository> getAuditRepositoryImpl() {
try {
Configuration config = ApplicationProperties.get();
return ApplicationProperties.getClass(config,
AUDIT_REPOSITORY_IMPLEMENTATION_PROPERTY, HBaseBasedAuditRepository.class.getName(), EntityAuditRepository.class);
} catch (AtlasException e) {
throw new RuntimeException(e);
}
}
示例16
void loadFileLoginsDetails() {
userLogins.clear();
InputStream inStr = null;
try {
Configuration configuration = ApplicationProperties.get();
v1ValidationEnabled = configuration.getBoolean("atlas.authentication.method.file.v1-validation.enabled", true);
v2ValidationEnabled = configuration.getBoolean("atlas.authentication.method.file.v2-validation.enabled", true);
inStr = ApplicationProperties.getFileAsInputStream(configuration, "atlas.authentication.method.file.filename", DEFAULT_USER_CREDENTIALS_PROPERTIES);
userLogins.load(inStr);
} catch (IOException | AtlasException e) {
LOG.error("Error while reading user.properties file", e);
throw new RuntimeException(e);
} finally {
if (inStr != null) {
try {
inStr.close();
} catch (Exception excp) {
// ignore
}
}
}
}
示例17
private void setUpAltasApplicationProperties(String persistDir) throws Exception {
final PropertiesConfiguration configuration = new PropertiesConfiguration();
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
+ ApplicationProperties.APPLICATION_PROPERTIES);
}
示例18
/**
* Get the configuration property that specifies the size of the compiled query
* cache. This is an optional property. A default is used if it is not
* present.
*
* @return the size to be used when creating the compiled query cache.
*/
public static int getCompiledQueryCacheCapacity() {
try {
return ApplicationProperties.get().getInt(COMPILED_QUERY_CACHE_CAPACITY, DEFAULT_COMPILED_QUERY_CACHE_CAPACITY);
} catch (AtlasException e) {
throw new RuntimeException(e);
}
}
示例19
@Inject
public AtlasKnoxSSOAuthenticationFilter(AtlasAuthenticationProvider authenticationProvider) {
this.authenticationProvider = authenticationProvider;
try {
configuration = ApplicationProperties.get();
} catch (Exception e) {
LOG.error("Error while getting application properties", e);
}
if (configuration != null) {
ssoEnabled = configuration.getBoolean("atlas.sso.knox.enabled", false);
jwtProperties = loadJwtProperties();
}
setJwtProperties();
}
示例20
/**
* Returns the metadata application configuration.
* @return the metadata configuration.
* @throws ConfigurationException
*/
protected org.apache.commons.configuration.Configuration getApplicationConfiguration() {
try {
return ApplicationProperties.get();
} catch (AtlasException e) {
LOG.warn("Error reading application configuration", e);
}
return null;
}
示例21
static String[] getServerUrl(String[] args) throws AtlasException {
if (args.length > 0) {
return args[0].split(",");
}
Configuration configuration = ApplicationProperties.get();
String[] urls = configuration.getStringArray(ATLAS_REST_ADDRESS);
if (ArrayUtils.isEmpty(urls)) {
System.out.println("org.apache.atlas.examples.QuickStartV2 <Atlas REST address <http/https>://<atlas-fqdn>:<atlas-port> like http://localhost:21000>");
System.exit(-1);
}
return urls;
}
示例22
@Inject
EntityDiscoveryService(MetadataRepository metadataRepository, AtlasTypeRegistry typeRegistry,
AtlasGraph graph, GraphBackedSearchIndexer indexer, SearchTracker searchTracker) throws AtlasException {
this.graph = graph;
this.graphPersistenceStrategy = new DefaultGraphPersistenceStrategy(metadataRepository);
this.entityRetriever = new EntityGraphRetriever(typeRegistry);
this.indexer = indexer;
this.searchTracker = searchTracker;
this.gremlinQueryProvider = AtlasGremlinQueryProvider.INSTANCE;
this.typeRegistry = typeRegistry;
this.maxResultSetSize = ApplicationProperties.get().getInt(Constants.INDEX_SEARCH_MAX_RESULT_SET_SIZE, 150);
this.maxTypesLengthInIdxQuery = ApplicationProperties.get().getInt(Constants.INDEX_SEARCH_TYPES_MAX_QUERY_STR_LENGTH, 512);
this.maxTagsLengthInIdxQuery = ApplicationProperties.get().getInt(Constants.INDEX_SEARCH_TAGS_MAX_QUERY_STR_LENGTH, 512);
}
示例23
protected void generateTestProperties(Properties props) throws ConfigurationException, IOException {
PropertiesConfiguration config =
new PropertiesConfiguration(System.getProperty("user.dir") +
"/../src/conf/" + ApplicationProperties.APPLICATION_PROPERTIES);
for (String propName : props.stringPropertyNames()) {
config.setProperty(propName, props.getProperty(propName));
}
File file = new File(System.getProperty("user.dir"), ApplicationProperties.APPLICATION_PROPERTIES);
file.deleteOnExit();
Writer fileWriter = new FileWriter(file);
config.save(fileWriter);
}
示例24
@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));
}
}
示例25
protected void initNotificationService() throws Exception {
Configuration applicationProperties = ApplicationProperties.get();
applicationProperties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));
kafkaNotification = new KafkaNotification(applicationProperties);
notificationInterface = kafkaNotification;
kafkaNotification.start();
Thread.sleep(2000);
}
示例26
/**
* Returns the metadata application configuration.
* @return the metadata configuration.
* @throws ConfigurationException
*/
protected org.apache.commons.configuration.Configuration getApplicationConfiguration() {
try {
return ApplicationProperties.get();
} catch (AtlasException e) {
LOG.warn("Error reading application configuration", e);
}
return null;
}
示例27
@Test
public void testNoConfiguredCredentialProvider() throws Exception {
String originalConf = null;
try {
originalConf = System.getProperty("atlas.conf");
System.clearProperty("atlas.conf");
ApplicationProperties.forceReload();
secureEmbeddedServer = new SecureEmbeddedServer(
EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS, securePort, TestUtils.getWarPath());
secureEmbeddedServer.server.start();
Assert.fail("Should have thrown an exception");
} catch (IOException e) {
Assert.assertEquals(e.getMessage(),
"No credential provider path configured for storage of certificate store passwords");
} finally {
if (secureEmbeddedServer != null) {
secureEmbeddedServer.server.stop();
}
if (originalConf == null) {
System.clearProperty("atlas.conf");
} else {
System.setProperty("atlas.conf", originalConf);
}
}
}
示例28
void initNotificationService() throws AtlasException, InterruptedException {
Configuration applicationProperties = ApplicationProperties.get();
applicationProperties.setProperty("atlas.kafka.data", "target/" + RandomStringUtils.randomAlphanumeric(5));
kafkaServer = new EmbeddedKafkaServer(applicationProperties);
kafkaNotification = new KafkaNotification(applicationProperties);
notificationInterface = kafkaNotification;
kafkaServer.start();
kafkaNotification.start();
Thread.sleep(2000);
}
示例29
private static int getApplicationProperty(String propertyName, int defaultValue) {
try {
return ApplicationProperties.get().getInt(propertyName, defaultValue);
} catch (AtlasException excp) {
// ignore
}
return defaultValue;
}
示例30
private static int getApplicationProperty(String propertyName, int defaultValue) {
try {
return ApplicationProperties.get().getInt(propertyName, defaultValue);
} catch (AtlasException excp) {
// ignore
}
return defaultValue;
}