in plugin-solr/src/main/java/org/apache/ranger/services/solr/client/ServiceSolrClient.java [109:345]
public List<String> getResources(ResourceLookupContext context) {
String userInput = context.getUserInput();
String resource = context.getResourceName();
Map<String, List<String>> resourceMap = context.getResources();
List<String> resultList = null;
List<String> collectionList = null;
List<String> fieldList = null;
List<String> configList = null;
List<String> schemaList = null;
RangerSolrConstants.ResourceType lookupResource = RangerSolrConstants.ResourceType.COLLECTION;
LOG.debug("<== getResources() UserInput: \"{}\" resource : {} resourceMap: {}", userInput, resource, resourceMap);
if (userInput != null && resource != null) {
if (resourceMap != null && !resourceMap.isEmpty()) {
collectionList = resourceMap.get(RangerSolrConstants.COLLECTION_KEY);
fieldList = resourceMap.get(RangerSolrConstants.FIELD_KEY);
configList = resourceMap.get(RangerSolrConstants.CONFIG_KEY);
schemaList = resourceMap.get(RangerSolrConstants.SCHEMA_KEY);
}
switch (resource.trim().toLowerCase()) {
case RangerSolrConstants.COLLECTION_KEY:
lookupResource = RangerSolrConstants.ResourceType.COLLECTION;
break;
case RangerSolrConstants.FIELD_KEY:
lookupResource = RangerSolrConstants.ResourceType.FIELD;
break;
case RangerSolrConstants.CONFIG_KEY:
lookupResource = RangerSolrConstants.ResourceType.CONFIG;
break;
case RangerSolrConstants.ADMIN_KEY:
lookupResource = RangerSolrConstants.ResourceType.ADMIN;
break;
case RangerSolrConstants.SCHEMA_KEY:
lookupResource = RangerSolrConstants.ResourceType.SCHEMA;
break;
default:
break;
}
}
if (userInput != null) {
try {
Callable<List<String>> callableObj = null;
final String userInputFinal = userInput;
final List<String> finalCollectionList = collectionList;
final List<String> finalFieldList = fieldList;
final List<String> finalConfigList = configList;
final List<String> finalSchemaList = schemaList;
if (lookupResource == RangerSolrConstants.ResourceType.COLLECTION) {
// get the collection list for given Input
callableObj = () -> {
List<String> retList = new ArrayList<>();
try {
List<String> list;
if (isKerberosAuth) {
list = Subject.doAs(loginSubject, (PrivilegedAction<List<String>>) () -> {
List<String> ret = null;
try {
ret = getCollectionList(finalCollectionList);
} catch (Exception e) {
LOG.error("Unable to get collections, Error : {}", e.getMessage(), new Throwable(e));
}
return ret;
});
} else {
list = getCollectionList(finalCollectionList);
}
if (userInputFinal != null && !userInputFinal.isEmpty()) {
for (String value : list) {
if (value.startsWith(userInputFinal)) {
retList.add(value);
}
}
} else {
retList.addAll(list);
}
} catch (Exception ex) {
LOG.error("Error getting collections.", ex);
}
return retList;
};
} else if (lookupResource == RangerSolrConstants.ResourceType.FIELD) {
callableObj = () -> {
List<String> retList = new ArrayList<>();
try {
List<String> list;
if (isKerberosAuth) {
list = Subject.doAs(loginSubject, (PrivilegedAction<List<String>>) () -> {
List<String> ret = new ArrayList<>();
try {
ret = getFieldList(finalCollectionList, finalFieldList);
} catch (Exception e) {
LOG.error("Unable to get field list, Error : {}", e.getMessage(), new Throwable(e));
}
return ret;
});
} else {
list = getFieldList(finalCollectionList, finalFieldList);
}
if (userInputFinal != null && !userInputFinal.isEmpty()) {
for (String value : list) {
if (value.startsWith(userInputFinal)) {
retList.add(value);
}
}
} else {
retList.addAll(list);
}
} catch (Exception ex) {
LOG.error("Error getting collections.", ex);
}
return retList;
};
} else if (lookupResource == RangerSolrConstants.ResourceType.CONFIG) {
// get the config list for given Input
callableObj = () -> {
List<String> retList = new ArrayList<>();
try {
List<String> list;
if (isKerberosAuth) {
list = Subject.doAs(loginSubject, (PrivilegedAction<List<String>>) () -> {
List<String> ret = null;
try {
ret = getConfigList(finalConfigList);
} catch (Exception e) {
LOG.error("Unable to get Solr configs, Error : {}", e.getMessage(), new Throwable(e));
}
return ret;
});
} else {
list = getConfigList(finalConfigList);
}
if (userInputFinal != null && !userInputFinal.isEmpty()) {
for (String value : list) {
if (value.startsWith(userInputFinal)) {
retList.add(value);
}
}
} else {
retList.addAll(list);
}
} catch (Exception ex) {
LOG.error("Error getting Solr configs: ", ex);
}
return retList;
};
} else if (lookupResource == RangerSolrConstants.ResourceType.ADMIN) {
List<String> retList = new ArrayList<>();
try {
List<String> list = RangerSolrConstants.AdminType.VALUE_LIST;
if (userInputFinal != null && !userInputFinal.isEmpty()) {
for (String value : list) {
if (value.startsWith(userInputFinal)) {
retList.add(value);
}
}
} else {
retList.addAll(list);
}
} catch (Exception ex) {
LOG.error("Error getting Solr admin resources.", ex);
}
resultList = retList;
} else if (lookupResource == RangerSolrConstants.ResourceType.SCHEMA) {
// get the collection list for given Input, since there is no way of getting a list of the available schemas
callableObj = () -> {
List<String> retList = new ArrayList<>();
try {
List<String> list;
if (isKerberosAuth) {
list = Subject.doAs(loginSubject, (PrivilegedAction<List<String>>) () -> {
List<String> ret = null;
try {
ret = getSchemaList(finalSchemaList);
} catch (Exception e) {
LOG.error("Unable to get collections for schema listing, Error : {}", e.getMessage(), new Throwable(e));
}
return ret;
});
} else {
list = getSchemaList(finalSchemaList);
}
if (userInputFinal != null && !userInputFinal.isEmpty()) {
for (String value : list) {
if (value.startsWith(userInputFinal)) {
retList.add(value);
}
}
} else {
retList.addAll(list);
}
} catch (Exception ex) {
LOG.error("Error getting collections for schema listing.", ex);
}
return retList;
};
}
// If we need to do lookup
if (callableObj != null) {
synchronized (this) {
resultList = TimedEventUtil.timedTask(callableObj, RangerSolrConstants.LOOKUP_TIMEOUT_SEC, TimeUnit.SECONDS);
}
}
} catch (Exception e) {
LOG.error("Unable to get Solr resources.", e);
}
}
return resultList;
}