Search in sources :

Example 41 with PermanentBackendException

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);
    }
}
Also used : IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Mapping(org.janusgraph.core.schema.Mapping) IndexMapping(org.janusgraph.diskstorage.es.mapping.IndexMapping) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 42 with PermanentBackendException

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);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 43 with PermanentBackendException

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);
    }
}
Also used : PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) Arrays(java.util.Arrays) DocCollection(org.apache.solr.common.cloud.DocCollection) KerberosScheme(org.apache.http.impl.auth.KerberosScheme) ClusterState(org.apache.solr.common.cloud.ClusterState) Geoshape(org.janusgraph.core.attribute.Geoshape) StringUtils(org.apache.commons.lang3.StringUtils) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Cardinality(org.janusgraph.core.Cardinality) IndexEntry(org.janusgraph.diskstorage.indexing.IndexEntry) KeyInformation(org.janusgraph.diskstorage.indexing.KeyInformation) Map(java.util.Map) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) And(org.janusgraph.graphdb.query.condition.And) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Set(java.util.Set) UncheckedIOException(java.io.UncheckedIOException) IOUtils(org.apache.commons.io.IOUtils) Stream(java.util.stream.Stream) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Joiner(com.google.common.base.Joiner) SolrHttpClientBuilder(org.apache.solr.client.solrj.impl.SolrHttpClientBuilder) SolrInputDocument(org.apache.solr.common.SolrInputDocument) PreInitializeConfigOptions(org.janusgraph.graphdb.configuration.PreInitializeConfigOptions) Not(org.janusgraph.graphdb.query.condition.Not) AttributeUtils(org.janusgraph.graphdb.database.serialize.AttributeUtils) SimpleDateFormat(java.text.SimpleDateFormat) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) Cmp(org.janusgraph.core.attribute.Cmp) HttpClient(org.apache.http.client.HttpClient) CachingTokenFilter(org.apache.lucene.analysis.CachingTokenFilter) StreamSupport(java.util.stream.StreamSupport) JanusGraphElement(org.janusgraph.core.JanusGraphElement) Geo(org.janusgraph.core.attribute.Geo) JanusGraphPredicate(org.janusgraph.graphdb.query.JanusGraphPredicate) Slice(org.apache.solr.common.cloud.Slice) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) IOException(java.io.IOException) DefaultTransaction(org.janusgraph.diskstorage.util.DefaultTransaction) SolrClient(org.apache.solr.client.solrj.SolrClient) CommonParams(org.apache.solr.common.params.CommonParams) SolrDocument(org.apache.solr.common.SolrDocument) StringReader(java.io.StringReader) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) Preconditions(com.google.common.base.Preconditions) INDEX_NS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_NS) IndexMutation(org.janusgraph.diskstorage.indexing.IndexMutation) INDEX_MAX_RESULT_SET_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INDEX_MAX_RESULT_SET_SIZE) GeoToWktConverter(org.janusgraph.diskstorage.solr.transform.GeoToWktConverter) PreemptiveAuth(org.apache.solr.client.solrj.impl.PreemptiveAuth) HttpClientUtil(org.apache.solr.client.solrj.impl.HttpClientUtil) Date(java.util.Date) Spliterators(java.util.Spliterators) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) BaseTransaction(org.janusgraph.diskstorage.BaseTransaction) IndexProvider(org.janusgraph.diskstorage.indexing.IndexProvider) Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder) IndexQuery(org.janusgraph.diskstorage.indexing.IndexQuery) DateFormat(java.text.DateFormat) Mapping(org.janusgraph.core.schema.Mapping) TimeZone(java.util.TimeZone) Collection(java.util.Collection) HttpEntity(org.apache.http.HttpEntity) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Replica(org.apache.solr.common.cloud.Replica) List(java.util.List) Parameter(org.janusgraph.core.schema.Parameter) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Optional(java.util.Optional) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) ClientUtils(org.apache.solr.client.solrj.util.ClientUtils) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) Spliterator(java.util.Spliterator) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Tokenizer(org.apache.lucene.analysis.Tokenizer) ConfigNamespace(org.janusgraph.diskstorage.configuration.ConfigNamespace) Condition(org.janusgraph.graphdb.query.condition.Condition) HashMap(java.util.HashMap) Function(java.util.function.Function) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) HashSet(java.util.HashSet) IndexFeatures(org.janusgraph.diskstorage.indexing.IndexFeatures) Or(org.janusgraph.graphdb.query.condition.Or) SimpleEntry(java.util.AbstractMap.SimpleEntry) TermToBytesRefAttribute(org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) BackendException(org.janusgraph.diskstorage.BackendException) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) Configuration(org.janusgraph.diskstorage.configuration.Configuration) BaseTransactionConfigurable(org.janusgraph.diskstorage.BaseTransactionConfigurable) RawQuery(org.janusgraph.diskstorage.indexing.RawQuery) Order(org.janusgraph.graphdb.internal.Order) Text(org.janusgraph.core.attribute.Text) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) ParameterType(org.janusgraph.graphdb.types.ParameterType) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Collections(java.util.Collections) HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) HttpRequestInterceptor(org.apache.http.HttpRequestInterceptor) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) SolrHttpClientBuilder(org.apache.solr.client.solrj.impl.SolrHttpClientBuilder) KerberosScheme(org.apache.http.impl.auth.KerberosScheme) PreemptiveAuth(org.apache.solr.client.solrj.impl.PreemptiveAuth) Krb5HttpClientBuilder(org.apache.solr.client.solrj.impl.Krb5HttpClientBuilder)

Example 44 with PermanentBackendException

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);
    }
}
Also used : PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 45 with PermanentBackendException

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);
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) BackendException(org.janusgraph.diskstorage.BackendException) KeeperException(org.apache.zookeeper.KeeperException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)53 IOException (java.io.IOException)24 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)16 UncheckedIOException (java.io.UncheckedIOException)12 BackendException (org.janusgraph.diskstorage.BackendException)12 Configuration (org.janusgraph.diskstorage.configuration.Configuration)8 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)7 DatabaseException (com.sleepycat.je.DatabaseException)7 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)7 Duration (java.time.Duration)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)6 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)6 SolrServerException (org.apache.solr.client.solrj.SolrServerException)5 KeeperException (org.apache.zookeeper.KeeperException)5 Transaction (com.sleepycat.je.Transaction)4 HashMap (java.util.HashMap)4 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)4 KeyInformation (org.janusgraph.diskstorage.indexing.KeyInformation)4