use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class ElasticSearchIndex method register.
@Override
public void register(String store, String key, KeyInformation information, BaseTransaction tx) throws BackendException {
final Class<?> dataType = information.getDataType();
final Mapping map = Mapping.getMapping(information);
Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtils.isString(dataType) || (map == Mapping.PREFIX_TREE && AttributeUtils.isGeo(dataType)), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
final String indexStoreName = getIndexStoreName(store);
if (useExternalMappings) {
try {
// We check if the externalMapping have the property 'key'
final IndexMapping mappings = client.getMapping(indexStoreName, store);
if (mappings == null || (!mappings.isDynamic() && !mappings.getProperties().containsKey(key))) {
// Error if it is not dynamic and have not the property 'key'
throw new PermanentBackendException("The external mapping for index '" + indexStoreName + "' and type '" + store + "' do not have property '" + key + "'");
} else if (allowMappingUpdate && mappings.isDynamic()) {
// If it is dynamic, we push the unknown property 'key'
this.pushMapping(store, key, information);
}
} catch (final IOException e) {
throw new PermanentBackendException(e);
}
} else {
try {
checkForOrCreateIndex(indexStoreName);
} catch (final IOException e) {
throw new PermanentBackendException(e);
}
this.pushMapping(store, key, information);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class ElasticSearchIndex method runCommonQuery.
private ElasticSearchResponse runCommonQuery(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx, int size, boolean useScroll) throws BackendException {
final ElasticSearchRequest sr = new ElasticSearchRequest();
sr.setQuery(compat.queryString(query.getQuery()));
if (!query.getOrders().isEmpty()) {
addOrderToQuery(informations, sr, query.getOrders(), query.getStore());
}
sr.setFrom(0);
sr.setSize(size);
sr.setDisableSourceRetrieval(true);
try {
Map<String, Object> requestBody = compat.createRequestBody(sr, query.getParameters());
if (!useScroll) {
if (requestBody == null) {
requestBody = TRACK_TOTAL_HITS_DISABLED_REQUEST_BODY;
} else {
requestBody.put(TRACK_TOTAL_HITS_PARAMETER, false);
}
}
return client.search(getIndexStoreName(query.getStore()), requestBody, useScroll);
} catch (final IOException | UncheckedIOException e) {
throw new PermanentBackendException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class SolrIndex method configureSolrClientsForKerberos.
private void configureSolrClientsForKerberos() throws PermanentBackendException {
String kerberosConfig = System.getProperty("java.security.auth.login.config");
if (kerberosConfig == null) {
throw new PermanentBackendException("Unable to configure kerberos for solr client. System property 'java.security.auth.login.config' is not set.");
}
logger.debug("Using kerberos configuration file located at '{}'.", kerberosConfig);
try (Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder()) {
SolrHttpClientBuilder kb = krbBuild.getBuilder();
HttpClientUtil.setHttpClientBuilder(kb);
HttpRequestInterceptor bufferedEntityInterceptor = (request, context) -> {
if (request instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest enclosingRequest = ((HttpEntityEnclosingRequest) request);
HttpEntity requestEntity = enclosingRequest.getEntity();
enclosingRequest.setEntity(new BufferedHttpEntity(requestEntity));
}
};
HttpClientUtil.addRequestInterceptor(bufferedEntityInterceptor);
HttpRequestInterceptor preemptiveAuth = new PreemptiveAuth(new KerberosScheme());
HttpClientUtil.addRequestInterceptor(preemptiveAuth);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class SolrIndex method totals.
@Override
public Long totals(RawQuery query, KeyInformation.IndexRetriever information, BaseTransaction tx) throws BackendException {
try {
final String collection = query.getStore();
final String keyIdField = getKeyFieldId(collection);
final QueryResponse response = solrClient.query(collection, runCommonQuery(query, information, tx, collection, keyIdField));
logger.debug("Executed query [{}] in {} ms", query.getQuery(), response.getElapsedTime());
return response.getResults().getNumFound();
} catch (final IOException e) {
logger.error("Query did not complete : ", e);
throw new PermanentBackendException(e);
} catch (final SolrServerException e) {
logger.error("Unable to query Solr index.", e);
throw new PermanentBackendException(e);
}
}
use of org.janusgraph.diskstorage.PermanentBackendException in project janusgraph by JanusGraph.
the class SolrIndex method clearStorage.
@Override
public void clearStorage() throws BackendException {
try {
if (mode != Mode.CLOUD) {
logger.error("Operation only supported for SolrCloud. Cores must be deleted manually through the Solr API when using HTTP mode.");
return;
}
logger.debug("Clearing storage from Solr: {}", solrClient);
final ZkStateReader zkStateReader = ((CloudSolrClient) solrClient).getZkStateReader();
zkStateReader.forciblyRefreshAllClusterStateSlow();
final ClusterState clusterState = zkStateReader.getClusterState();
for (final String collection : clusterState.getCollectionsMap().keySet()) {
logger.debug("Clearing collection [{}] in Solr", collection);
// Collection is not dropped because it may have been created externally
final UpdateRequest deleteAll = newUpdateRequest();
deleteAll.deleteByQuery("*:*");
solrClient.request(deleteAll, collection);
}
} catch (final SolrServerException e) {
logger.error("Unable to clear storage from index due to server error on Solr.", e);
throw new PermanentBackendException(e);
} catch (final IOException e) {
logger.error("Unable to clear storage from index due to low-level I/O error.", e);
throw new PermanentBackendException(e);
} catch (final Exception e) {
logger.error("Unable to clear storage from index due to general error.", e);
throw new PermanentBackendException(e);
}
}
Aggregations