Search in sources :

Example 1 with ResourceNotFoundRuntimeException

use of org.codelibs.core.exception.ResourceNotFoundRuntimeException in project fess by codelibs.

the class UpgradeUtil method createAlias.

public static boolean createAlias(final IndicesAdminClient indicesClient, final String indexConfigPath, final String indexName, final String aliasName) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final String aliasConfigPath = indexConfigPath + "/" + indexName + "/alias/" + aliasName + ".json";
    try {
        final File aliasConfigFile = org.codelibs.core.io.ResourceUtil.getResourceAsFile(aliasConfigPath);
        if (aliasConfigFile.exists()) {
            final String source = FileUtil.readUTF8(aliasConfigFile);
            final AcknowledgedResponse response = indicesClient.prepareAliases().addAlias(indexName, aliasName, source).execute().actionGet(fessConfig.getIndexIndicesTimeout());
            if (response.isAcknowledged()) {
                logger.info("Created {} alias for {}", aliasName, indexName);
                return true;
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Failed to create {} alias for {}", aliasName, indexName);
            }
        }
    } catch (final ResourceNotFoundRuntimeException e) {
    // ignore
    } catch (final Exception e) {
        logger.warn("{} is not found.", aliasConfigPath, e);
    }
    return false;
}
Also used : AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) File(java.io.File) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException)

Example 2 with ResourceNotFoundRuntimeException

use of org.codelibs.core.exception.ResourceNotFoundRuntimeException in project fess by codelibs.

the class FessEsClient method createAlias.

protected void createAlias(final String index, final String createdIndexName) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    // alias
    final String aliasConfigDirPath = indexConfigPath + "/" + index + "/alias";
    try {
        final File aliasConfigDir = ResourceUtil.getResourceAsFile(aliasConfigDirPath);
        if (aliasConfigDir.isDirectory()) {
            stream(aliasConfigDir.listFiles((dir, name) -> name.endsWith(".json"))).of(stream -> stream.forEach(f -> {
                final String aliasName = f.getName().replaceFirst(".json$", "");
                String source = FileUtil.readUTF8(f);
                if (source.trim().equals("{}")) {
                    source = null;
                }
                final IndicesAliasesResponse response = client.admin().indices().prepareAliases().addAlias(createdIndexName, aliasName, source).execute().actionGet(fessConfig.getIndexIndicesTimeout());
                if (response.isAcknowledged()) {
                    logger.info("Created " + aliasName + " alias for " + createdIndexName);
                } else if (logger.isDebugEnabled()) {
                    logger.debug("Failed to create " + aliasName + " alias for " + createdIndexName);
                }
            }));
        }
    } catch (final ResourceNotFoundRuntimeException e) {
    // ignore
    } catch (final Exception e) {
        logger.warn(aliasConfigDirPath + " is not found.", e);
    }
}
Also used : Arrays(java.util.Arrays) ExplainRequest(org.elasticsearch.action.explain.ExplainRequest) SearchHits(org.elasticsearch.search.SearchHits) Curl(org.codelibs.elasticsearch.runner.net.Curl) InetAddress(java.net.InetAddress) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) QueryContext(org.codelibs.fess.entity.QueryContext) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) UpdateResponse(org.elasticsearch.action.update.UpdateResponse) Map(java.util.Map) TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) RefreshPolicy(org.elasticsearch.action.support.WriteRequest.RefreshPolicy) ActionRequest(org.elasticsearch.action.ActionRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) ResourceUtil(org.codelibs.core.io.ResourceUtil) ExplainResponse(org.elasticsearch.action.explain.ExplainResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) MultiSearchRequestBuilder(org.elasticsearch.action.search.MultiSearchRequestBuilder) StandardCharsets(java.nio.charset.StandardCharsets) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) DocMap(org.codelibs.fess.util.DocMap) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) FileUtil(org.codelibs.core.io.FileUtil) ComponentUtil(org.codelibs.fess.util.ComponentUtil) TermVectorsResponse(org.elasticsearch.action.termvectors.TermVectorsResponse) DocumentHelper(org.codelibs.fess.helper.DocumentHelper) TermVectorsRequestBuilder(org.elasticsearch.action.termvectors.TermVectorsRequestBuilder) ClearScrollRequestBuilder(org.elasticsearch.action.search.ClearScrollRequestBuilder) AdminClient(org.elasticsearch.client.AdminClient) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) ExplainRequestBuilder(org.elasticsearch.action.explain.ExplainRequestBuilder) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) FessSystemException(org.codelibs.fess.exception.FessSystemException) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) GetMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse) TransportClient(org.elasticsearch.client.transport.TransportClient) SimpleDateFormat(java.text.SimpleDateFormat) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) SearchRequest(org.elasticsearch.action.search.SearchRequest) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException) Order(org.elasticsearch.search.aggregations.bucket.terms.Terms.Order) ArrayList(java.util.ArrayList) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder) OpType(org.elasticsearch.action.DocWriteRequest.OpType) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) FacetInfo(org.codelibs.fess.entity.FacetInfo) ActionRequestBuilder(org.elasticsearch.action.ActionRequestBuilder) FlushResponse(org.elasticsearch.action.admin.indices.flush.FlushResponse) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) CollapseBuilder(org.elasticsearch.search.collapse.CollapseBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BaseEncoding(com.google.common.io.BaseEncoding) ActionResponse(org.elasticsearch.action.ActionResponse) Client(org.elasticsearch.client.Client) StringUtil(org.codelibs.core.lang.StringUtil) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) IOException(java.io.IOException) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) UnknownHostException(java.net.UnknownHostException) File(java.io.File) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) ElasticsearchClusterRunner(org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner) GetRequestBuilder(org.elasticsearch.action.get.GetRequestBuilder) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) ActionListener(org.elasticsearch.action.ActionListener) Builder(org.elasticsearch.common.settings.Settings.Builder) ElasticsearchException(org.elasticsearch.ElasticsearchException) Constants(org.codelibs.fess.Constants) GetResponse(org.elasticsearch.action.get.GetResponse) FieldStatsRequest(org.elasticsearch.action.fieldstats.FieldStatsRequest) Date(java.util.Date) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) LoggerFactory(org.slf4j.LoggerFactory) FieldCapabilitiesResponse(org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) GeoInfo(org.codelibs.fess.entity.GeoInfo) PreDestroy(javax.annotation.PreDestroy) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Settings(org.elasticsearch.common.settings.Settings) PingResponse(org.codelibs.fess.entity.PingResponse) QueryHelper(org.codelibs.fess.helper.QueryHelper) SearchResponse(org.elasticsearch.action.search.SearchResponse) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) FieldCapabilitiesRequest(org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Failure(org.elasticsearch.action.bulk.BulkItemResponse.Failure) SearchHit(org.elasticsearch.search.SearchHit) GetRequest(org.elasticsearch.action.get.GetRequest) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) MultiTermVectorsRequestBuilder(org.elasticsearch.action.termvectors.MultiTermVectorsRequestBuilder) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) Collectors(java.util.stream.Collectors) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) ElasticsearchClusterRunner.newConfigs(org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs) List(java.util.List) FieldCapabilitiesRequestBuilder(org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequestBuilder) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) TransportAddress(org.elasticsearch.common.transport.TransportAddress) PostConstruct(javax.annotation.PostConstruct) Pattern(java.util.regex.Pattern) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) BeanUtil(org.codelibs.core.beans.util.BeanUtil) FieldStatsRequestBuilder(org.elasticsearch.action.fieldstats.FieldStatsRequestBuilder) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) UpdateRequestBuilder(org.elasticsearch.action.update.UpdateRequestBuilder) HashMap(java.util.HashMap) ActionFuture(org.elasticsearch.action.ActionFuture) ClearScrollResponse(org.elasticsearch.action.search.ClearScrollResponse) SearchHitField(org.elasticsearch.search.SearchHitField) TimeValue(org.elasticsearch.common.unit.TimeValue) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) IndexResponse(org.elasticsearch.action.index.IndexResponse) Result(org.elasticsearch.action.DocWriteResponse.Result) SearchQueryException(org.codelibs.fess.exception.SearchQueryException) UserMessages(org.lastaflute.core.message.UserMessages) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) OptionalEntity(org.dbflute.optional.OptionalEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Configs(org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.Configs) Action(org.elasticsearch.action.Action) IndicesAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) InnerHitBuilder(org.elasticsearch.index.query.InnerHitBuilder) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Collections(java.util.Collections) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) SearchScrollRequestBuilder(org.elasticsearch.action.search.SearchScrollRequestBuilder) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) File(java.io.File) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchQueryException(org.codelibs.fess.exception.SearchQueryException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException)

Aggregations

File (java.io.File)2 ResourceNotFoundRuntimeException (org.codelibs.core.exception.ResourceNotFoundRuntimeException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BaseEncoding (com.google.common.io.BaseEncoding)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 PostConstruct (javax.annotation.PostConstruct)1