Search in sources :

Example 26 with ElasticException

use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.

the class ElasticClientController method indexDoc.

public void indexDoc(IndexRequest request) throws ElasticException {
    FailableSupplier<IndexResponse> query = () -> client.getClient().index(request, RequestOptions.DEFAULT);
    IndexResponse response = executeElasticQuery(query, "elastic index doc", request.toString());
    if (response.status().getStatus() != 201) {
        String msg = "doc index - bad status response:" + response.status().getStatus();
        throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, msg);
    }
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) GetIndexResponse(org.elasticsearch.client.indices.GetIndexResponse) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse)

Example 27 with ElasticException

use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.

the class ElasticClientController method bulkDelete.

public void bulkDelete(BulkRequest request) throws ElasticException {
    FailableSupplier<BulkResponse> query = () -> client.getClient().bulk(request, RequestOptions.DEFAULT);
    BulkResponse response = executeElasticQuery(query, "elastic bulk delete", request.toString());
    if (response.hasFailures()) {
        String msg = "failures during bulk delete";
        throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, msg);
    }
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Example 28 with ElasticException

use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.

the class ElasticClientController method clusterHealthGet.

public ClusterHealthResponse clusterHealthGet() throws ElasticException {
    ClusterHealthRequest request = new ClusterHealthRequest();
    FailableSupplier<ClusterHealthResponse> query = () -> client.getClient().cluster().health(request, RequestOptions.DEFAULT);
    ClusterHealthResponse response = executeElasticQuery(query, "elastic get cluster health", request.toString());
    if (response.status().equals(RestStatus.OK) || response.status().equals(RestStatus.NOT_FOUND)) {
        return response;
    } else {
        throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, "error during elastic get cluster health");
    }
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 29 with ElasticException

use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.

the class ElasticController method projectSearchHighLevel.

public SearchHit[] projectSearchHighLevel(Integer projectId, String searchTerm) throws ServiceException, ElasticException {
    // check if the index are up and running
    if (!elasticClientCtrl.mngIndexExists(Settings.META_INDEX)) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.ELASTIC_INDEX_NOT_FOUND, Level.SEVERE, "index: " + Settings.META_INDEX);
    }
    SearchResponse response = executeSearchQuery(projectSearchQuery(projectId, searchTerm.toLowerCase()));
    if (response.status().getStatus() == 200) {
        SearchHit[] hits = new SearchHit[0];
        if (response.getHits().getHits().length > 0) {
            hits = response.getHits().getHits();
        }
        projectSearchInSharedDatasets(projectId, searchTerm, hits);
        return hits;
    }
    // elasticsearch rather than a bad query
    throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_QUERY_ERROR, Level.INFO, "Error while executing query, code: " + response.status().getStatus());
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) SearchHit(org.elasticsearch.search.SearchHit) SearchResponse(org.elasticsearch.action.search.SearchResponse) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Example 30 with ElasticException

use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.

the class ElasticClient method shutdownClient.

private void shutdownClient() throws ElasticException {
    if (elasticClient != null) {
        try {
            elasticClient.indices().clearCache(new ClearIndicesCacheRequest(Settings.META_INDEX), RequestOptions.DEFAULT);
            elasticClient.close();
            elasticClient = null;
        } catch (IOException e) {
            throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_INTERNAL_REQ_ERROR, Level.INFO, "Error while shuting down client", e.getMessage(), e);
        }
    }
}
Also used : ElasticException(io.hops.hopsworks.exceptions.ElasticException) ClearIndicesCacheRequest(org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) IOException(java.io.IOException)

Aggregations

ElasticException (io.hops.hopsworks.exceptions.ElasticException)32 ServiceException (io.hops.hopsworks.exceptions.ServiceException)9 SearchResponse (org.elasticsearch.action.search.SearchResponse)8 GenericException (io.hops.hopsworks.exceptions.GenericException)6 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)6 Project (io.hops.hopsworks.persistence.entity.project.Project)6 IOException (java.io.IOException)6 SearchHit (org.elasticsearch.search.SearchHit)6 ArrayList (java.util.ArrayList)5 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)5 Users (io.hops.hopsworks.persistence.entity.user.Users)4 Map (java.util.Map)4 TransactionAttribute (javax.ejb.TransactionAttribute)4 Try (com.lambdista.util.Try)3 ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)3 ElasticController (io.hops.hopsworks.common.elastic.ElasticController)3 ElasticFeaturestoreHit (io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit)3 FeaturestoreDocType (io.hops.hopsworks.common.elastic.FeaturestoreDocType)3 FeaturestoreXAttrsConstants (io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants)3 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)3