org.elasticsearch.common.xcontent.NamedXContentRegistry Java Examples

The following examples show how to use org.elasticsearch.common.xcontent.NamedXContentRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenDistroSecuritySSLPlugin.java    From deprecated-security-ssl with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
        CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
        NamedXContentRegistry xContentRegistry, NetworkService networkService, Dispatcher dispatcher) {
    
    final Map<String, Supplier<HttpServerTransport>> httpTransports = new HashMap<String, Supplier<HttpServerTransport>>(1);
    if (!client && httpSSLEnabled) {
        
        final ValidatingDispatcher validatingDispatcher = new ValidatingDispatcher(threadPool.getThreadContext(), dispatcher, settings, configPath, NOOP_SSL_EXCEPTION_HANDLER);
        final OpenDistroSecuritySSLNettyHttpServerTransport sgsnht = new OpenDistroSecuritySSLNettyHttpServerTransport(settings, networkService, bigArrays, threadPool, odsks, xContentRegistry, validatingDispatcher, NOOP_SSL_EXCEPTION_HANDLER);
        
        httpTransports.put("com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyHttpServerTransport", () -> sgsnht);
        
    }
    return httpTransports;
}
 
Example #2
Source File: GeoUtils.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the value as a geopoint. The following types of values are supported:
 * <p>
 * Object: has to contain either lat and lon or geohash fields
 * <p>
 * String: expected to be in "latitude, longitude" format or a geohash
 * <p>
 * Array: two or more elements, the first element is longitude, the second is latitude, the rest is ignored if ignoreZValue is true
 */
public static GeoPoint parseGeoPoint(Object value, final boolean ignoreZValue) throws ElasticsearchParseException {
    try {
        XContentBuilder content = JsonXContent.contentBuilder();
        content.startObject();
        content.field("null_value", value);
        content.endObject();

        try (InputStream stream = BytesReference.bytes(content).streamInput();
             XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(
                 NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) {
            parser.nextToken(); // start object
            parser.nextToken(); // field name
            parser.nextToken(); // field value
            return parseGeoPoint(parser, new GeoPoint(), ignoreZValue);
        }

    } catch (IOException ex) {
        throw new ElasticsearchParseException("error parsing geopoint", ex);
    }
}
 
Example #3
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
public static SearchSourceBuilder generatePreviewQuery(
    AnomalyDetector detector,
    List<Entry<Long, Long>> ranges,
    NamedXContentRegistry xContentRegistry
) throws IOException {

    DateRangeAggregationBuilder dateRangeBuilder = dateRange("date_range").field(detector.getTimeField()).format("epoch_millis");
    for (Entry<Long, Long> range : ranges) {
        dateRangeBuilder.addRange(range.getKey(), range.getValue());
    }

    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            dateRangeBuilder.subAggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return new SearchSourceBuilder().query(detector.getFilterQuery()).size(0).aggregation(dateRangeBuilder);
}
 
Example #4
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
public static String generateInternalFeatureQueryTemplate(AnomalyDetector detector, NamedXContentRegistry xContentRegistry)
    throws IOException {
    RangeQueryBuilder rangeQuery = new RangeQueryBuilder(detector.getTimeField())
        .from("{{" + QUERY_PARAM_PERIOD_START + "}}")
        .to("{{" + QUERY_PARAM_PERIOD_END + "}}");

    BoolQueryBuilder internalFilterQuery = QueryBuilders.boolQuery().must(rangeQuery).must(detector.getFilterQuery());

    SearchSourceBuilder internalSearchSourceBuilder = new SearchSourceBuilder().query(internalFilterQuery);
    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            internalSearchSourceBuilder.aggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return internalSearchSourceBuilder.toString();
}
 
Example #5
Source File: MetaDataIndexUpgradeService.java    From crate with Apache License 2.0 6 votes vote down vote up
public MetaDataIndexUpgradeService(Settings settings,
                                   NamedXContentRegistry xContentRegistry,
                                   MapperRegistry mapperRegistry,
                                   IndexScopedSettings indexScopedSettings,
                                   Collection<UnaryOperator<IndexMetaData>> indexMetaDataUpgraders) {
    this.settings = settings;
    this.xContentRegistry = xContentRegistry;
    this.mapperRegistry = mapperRegistry;
    this.indexScopedSettings = indexScopedSettings;
    this.upgraders = indexMetaData -> {
        IndexMetaData newIndexMetaData = indexMetaData;
        for (UnaryOperator<IndexMetaData> upgrader : indexMetaDataUpgraders) {
            newIndexMetaData = upgrader.apply(newIndexMetaData);
        }
        return newIndexMetaData;
    };
}
 
Example #6
Source File: PartitionedTableIntegrationTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
@UseRandomizedSchema(random = false)
public void testAlterTableAddColumnOnPartitionedTableWithoutPartitions() throws Exception {
    execute("create table t (id int primary key, date timestamp with time zone primary key) " +
            "partitioned by (date) " +
            "clustered into 1 shards " +
            "with (number_of_replicas=0)");
    ensureYellow();

    execute("alter table t add column name string");
    execute("alter table t add column ft_name string index using fulltext");
    ensureYellow();

    execute("select * from t");
    assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "ft_name", "id", "name"));

    GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
    IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0);
    String mappingSource = metaData.mappings().get(DEFAULT_MAPPING_TYPE).toString();
    Map mapping = (Map) XContentFactory.xContent(mappingSource)
        .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource)
        .map()
        .get(DEFAULT_MAPPING_TYPE);
    assertNotNull(((Map) mapping.get("properties")).get("name"));
    assertNotNull(((Map) mapping.get("properties")).get("ft_name"));
}
 
Example #7
Source File: Netty4Plugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                                                                    CircuitBreakerService circuitBreakerService,
                                                                    NamedWriteableRegistry namedWriteableRegistry,
                                                                    NamedXContentRegistry xContentRegistry,
                                                                    NetworkService networkService,
                                                                    NodeClient nodeClient) {
    return Collections.singletonMap(
        NETTY_HTTP_TRANSPORT_NAME,
        () -> new Netty4HttpServerTransport(
            settings,
            networkService,
            bigArrays,
            threadPool,
            xContentRegistry,
            pipelineRegistry,
            nodeClient
        )
    );
}
 
Example #8
Source File: LtrQueryParserPlugin.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           ResourceWatcherService resourceWatcherService,
                                           ScriptService scriptService,
                                           NamedXContentRegistry xContentRegistry,
                                           Environment environment,
                                           NodeEnvironment nodeEnvironment,
                                           NamedWriteableRegistry namedWriteableRegistry,
                                           IndexNameExpressionResolver indexNameExpressionResolver) {
    clusterService.addListener(event -> {
        for (Index i : event.indicesDeleted()) {
            if (IndexFeatureStore.isIndexStore(i.getName())) {
                caches.evict(i.getName());
            }
        }
    });
    return asList(caches, parserFactory);
}
 
Example #9
Source File: XGBoostJsonParser.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public NaiveAdditiveDecisionTree parse(FeatureSet set, String model) {
    XGBoostDefinition modelDefinition;
    try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
            LoggingDeprecationHandler.INSTANCE, model)
    ) {
        modelDefinition = XGBoostDefinition.parse(parser, set);
    } catch (IOException e) {
        throw new IllegalArgumentException("Cannot parse model", e);
    }

    Node[] trees = modelDefinition.getTrees(set);
    float[] weights = new float[trees.length];
    // Tree weights are already encoded in outputs
    Arrays.fill(weights, 1F);
    return new NaiveAdditiveDecisionTree(trees, weights, set.size(), modelDefinition.normalizer);
}
 
Example #10
Source File: AzureRepository.java    From crate with Apache License 2.0 6 votes vote down vote up
public AzureRepository(RepositoryMetaData metadata,
                       Environment environment,
                       NamedXContentRegistry namedXContentRegistry,
                       AzureStorageService storageService,
                       ThreadPool threadPool) {
    super(metadata, environment.settings(), namedXContentRegistry, threadPool, buildBasePath(metadata));
    this.chunkSize = Repository.CHUNK_SIZE_SETTING.get(metadata.settings());
    this.storageService = storageService;

    // If the user explicitly did not define a readonly value, we set it by ourselves depending on the location mode setting.
    // For secondary_only setting, the repository should be read only
    final LocationMode locationMode = Repository.LOCATION_MODE_SETTING.get(metadata.settings());
    if (Repository.READONLY_SETTING.exists(metadata.settings())) {
        this.readonly = Repository.READONLY_SETTING.get(metadata.settings());
    } else {
        this.readonly = locationMode == LocationMode.SECONDARY_ONLY;
    }
}
 
Example #11
Source File: MetaDataStateFormat.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to load the latest state from the given data-locations.
 *
 * @param logger        a logger instance.
 * @param dataLocations the data-locations to try.
 * @return tuple of the latest state and generation. (-1, null) if no state is found.
 */
public Tuple<T, Long> loadLatestStateWithGeneration(Logger logger, NamedXContentRegistry namedXContentRegistry, Path... dataLocations)
        throws IOException {
    long generation = findMaxGenerationId(prefix, dataLocations);
    T state = loadGeneration(logger, namedXContentRegistry, generation, dataLocations);

    if (generation > -1 && state == null) {
        throw new IllegalStateException(
            "unable to find state files with generation id " + generation +
            " returned by findMaxGenerationId function, in data folders [" +
            Arrays.stream(dataLocations)
                .map(Path::toAbsolutePath)
                .map(Object::toString)
                .collect(Collectors.joining(", ")) + "], concurrent writes?");
    }
    return Tuple.tuple(state, generation);
}
 
Example #12
Source File: SampleIndexTestCase.java    From elasticsearch-carrot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Roundtrip to/from JSON.
 */
protected static void checkJsonSerialization(ClusteringActionResponse result) throws IOException {
   XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
   builder.startObject();
   result.toXContent(builder, ToXContent.EMPTY_PARAMS);
   builder.endObject();
   String json = Strings.toString(builder);

   try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
       DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json)) {
      Map<String, Object> mapAndClose = parser.map();
      Assertions.assertThat(mapAndClose)
          .as("json-result")
          .containsKey(Fields.CLUSTERS);
   }
}
 
Example #13
Source File: TransportNodesListShardStoreMetaData.java    From crate with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportNodesListShardStoreMetaData(Settings settings,
                                            ThreadPool threadPool,
                                            ClusterService clusterService,
                                            TransportService transportService,
                                            IndicesService indicesService,
                                            NodeEnvironment nodeEnv,
                                            IndexNameExpressionResolver indexNameExpressionResolver,
                                            NamedXContentRegistry namedXContentRegistry) {
    super(ACTION_NAME, threadPool, clusterService, transportService, indexNameExpressionResolver,
        Request::new, NodeRequest::new, ThreadPool.Names.FETCH_SHARD_STORE, NodeStoreFilesMetaData.class);
    this.settings = settings;
    this.indicesService = indicesService;
    this.nodeEnv = nodeEnv;
    this.namedXContentRegistry = namedXContentRegistry;
}
 
Example #14
Source File: JsonXContentGenerator.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException {
    if (mayWriteRawData(contentType) == false) {
        // EMPTY is safe here because we never call namedObject when writing raw data
        try (XContentParser parser = XContentFactory.xContent(contentType)
                // It's okay to pass the throwing deprecation handler
                // because we should not be writing raw fields when
                // generating JSON
                .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, content)) {
            parser.nextToken();
            writeFieldName(name);
            copyCurrentStructure(parser);
        }
    } else {
        writeStartRaw(name);
        flush();
        copyStream(content, os);
        writeEndRaw();
    }
}
 
Example #15
Source File: MapperTestUtils.java    From crate with Apache License 2.0 6 votes vote down vote up
public static MapperService newMapperService(NamedXContentRegistry xContentRegistry, Path tempDir, Settings settings,
                                             IndicesModule indicesModule, String indexName) throws IOException {
    Settings.Builder settingsBuilder = Settings.builder()
        .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
        .put(settings);
    if (settings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) {
        settingsBuilder.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
    }
    Settings finalSettings = settingsBuilder.build();
    MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexName, finalSettings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(indexSettings, finalSettings).indexAnalyzers;
    return new MapperService(indexSettings,
        indexAnalyzers,
        xContentRegistry,
        mapperRegistry,
        () -> null);
}
 
Example #16
Source File: S3RepositoryPlugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Repository.Factory> getRepositories(final Environment env, final NamedXContentRegistry registry, ThreadPool threadPool) {
    return Collections.singletonMap(
        S3Repository.TYPE,
        new Repository.Factory() {

            @Override
            public TypeSettings settings() {
                return new TypeSettings(List.of(), S3Repository.optionalSettings());
            }

            @Override
            public Repository create(RepositoryMetaData metadata) throws Exception {
                return new S3Repository(metadata, env.settings(), registry, service, threadPool);
            }
        }
    );
}
 
Example #17
Source File: AzureDiscoveryPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           NamedXContentRegistry xContentRegistry,
                                           Environment environment,
                                           NodeEnvironment nodeEnvironment,
                                           NamedWriteableRegistry namedWriteableRegistry) {
    if (AzureConfiguration.isDiscoveryReady(settings, logger)) {
        return Collections.singletonList(azureComputeService());
    }
    return Collections.emptyList();
}
 
Example #18
Source File: DlsFlsValveImpl.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
@Override
public void handleSearchContext(SearchContext context, ThreadPool threadPool, NamedXContentRegistry namedXContentRegistry) {
    try {
        final Map<String, Set<String>> queries = (Map<String, Set<String>>) HeaderHelper.deserializeSafeFromHeader(threadPool.getThreadContext(),
                ConfigConstants.OPENDISTRO_SECURITY_DLS_QUERY_HEADER);

        final String dlsEval = OpenDistroSecurityUtils.evalMap(queries, context.indexShard().indexSettings().getIndex().getName());

        if (dlsEval != null) {

            if(context.suggest() != null) {
                return;
            }

            assert context.parsedQuery() != null;

            final Set<String> unparsedDlsQueries = queries.get(dlsEval);
            if (unparsedDlsQueries != null && !unparsedDlsQueries.isEmpty()) {
                final ParsedQuery dlsQuery = DlsQueryParser.parse(unparsedDlsQueries, context.parsedQuery(), context.getQueryShardContext(), namedXContentRegistry);
                context.parsedQuery(dlsQuery);
                context.preProcess(true);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error evaluating dls for a search query: " + e, e);
    }

}
 
Example #19
Source File: S3RepositoryTests.java    From crate with Apache License 2.0 5 votes vote down vote up
private S3Repository createS3Repo(RepositoryMetaData metadata) {
    return new S3Repository(metadata, Settings.EMPTY, NamedXContentRegistry.EMPTY, new DummyS3Service(), mock(ThreadPool.class)) {
        @Override
        protected void assertSnapshotOrGenericThread() {
            // eliminate thread name check as we create repo manually on test/main threads
        }
    };
}
 
Example #20
Source File: Netty4Plugin.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           NamedXContentRegistry xContentRegistry,
                                           Environment environment,
                                           NodeEnvironment nodeEnvironment,
                                           NamedWriteableRegistry namedWriteableRegistry) {
    // pipelineRegistry is returned here so that it's bound in guice and can be injected in other places
    return Collections.singletonList(pipelineRegistry);
}
 
Example #21
Source File: AnomalyDetectorProfileRunner.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public AnomalyDetectorProfileRunner(
    Client client,
    NamedXContentRegistry xContentRegistry,
    DiscoveryNodeFilterer nodeFilter,
    IndexNameExpressionResolver indexNameExpressionResolver,
    ClusterService clusterService,
    Calendar calendar
) {
    this.client = client;
    this.xContentRegistry = xContentRegistry;
    this.nodeFilter = nodeFilter;
    this.indexNameExpressionResolver = indexNameExpressionResolver;
    this.clusterService = clusterService;
    this.calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
}
 
Example #22
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static SearchSourceBuilder generateInternalFeatureQuery(
    AnomalyDetector detector,
    long startTime,
    long endTime,
    NamedXContentRegistry xContentRegistry
) throws IOException {
    RangeQueryBuilder rangeQuery = new RangeQueryBuilder(detector.getTimeField())
        .from(startTime)
        .to(endTime)
        .format("epoch_millis")
        .includeLower(true)
        .includeUpper(false);

    BoolQueryBuilder internalFilterQuery = QueryBuilders.boolQuery().must(rangeQuery).must(detector.getFilterQuery());

    SearchSourceBuilder internalSearchSourceBuilder = new SearchSourceBuilder().query(internalFilterQuery);
    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            internalSearchSourceBuilder.aggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return internalSearchSourceBuilder;
}
 
Example #23
Source File: AnomalyDetectorProfileRunnerTests.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
@Override
protected NamedXContentRegistry xContentRegistry() {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList());
    List<NamedXContentRegistry.Entry> entries = searchModule.getNamedXContents();
    entries.addAll(Arrays.asList(AnomalyDetector.XCONTENT_REGISTRY, AnomalyResult.XCONTENT_REGISTRY));
    return new NamedXContentRegistry(entries);
}
 
Example #24
Source File: MetaDataStateFormat.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Reads the state from a given file and compares the expected version against the actual version of
 * the state.
 */
public final T read(NamedXContentRegistry namedXContentRegistry, Path file) throws IOException {
    try (Directory dir = newDirectory(file.getParent())) {
        try (IndexInput indexInput = dir.openInput(file.getFileName().toString(), IOContext.DEFAULT)) {
            // We checksum the entire file before we even go and parse it. If it's corrupted we barf right here.
            CodecUtil.checksumEntireFile(indexInput);
            CodecUtil.checkHeader(indexInput, STATE_FILE_CODEC, MIN_COMPATIBLE_STATE_FILE_VERSION, STATE_FILE_VERSION);
            final XContentType xContentType = XContentType.values()[indexInput.readInt()];
            if (xContentType != FORMAT) {
                throw new IllegalStateException("expected state in " + file + " to be " + FORMAT + " format but was " + xContentType);
            }
            long filePointer = indexInput.getFilePointer();
            long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
            try (IndexInput slice = indexInput.slice("state_xcontent", filePointer, contentSize)) {
                try (InputStreamIndexInput in = new InputStreamIndexInput(slice, contentSize)) {
                    try (XContentParser parser = XContentFactory.xContent(FORMAT)
                            .createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE,
                                in)) {
                        return fromXContent(parser);
                    }
                }
            }
        } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            // we trick this into a dedicated exception with the original stacktrace
            throw new CorruptStateException(ex);
        }
    }
}
 
Example #25
Source File: EnterpriseUsersExtension.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public List<NamedXContentRegistry.Entry> getNamedXContent() {
    List<NamedXContentRegistry.Entry> entries = new ArrayList<>(2);
    entries.add(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(UsersMetaData.TYPE),
        UsersMetaData::fromXContent
    ));
    entries.add(new NamedXContentRegistry.Entry(
        MetaData.Custom.class,
        new ParseField(UsersPrivilegesMetaData.TYPE),
        UsersPrivilegesMetaData::fromXContent
    ));
    return entries;
}
 
Example #26
Source File: TransportCreatePartitionsAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportCreatePartitionsAction(TransportService transportService,
                                       ClusterService clusterService,
                                       ThreadPool threadPool,
                                       IndicesService indicesService,
                                       AllocationService allocationService,
                                       NamedXContentRegistry xContentRegistry,
                                       IndexNameExpressionResolver indexNameExpressionResolver) {
    super(NAME, transportService, clusterService, threadPool, CreatePartitionsRequest::new, indexNameExpressionResolver);
    this.indicesService = indicesService;
    this.allocationService = allocationService;
    this.xContentRegistry = xContentRegistry;
    this.activeShardsObserver = new ActiveShardsObserver(clusterService, threadPool);
}
 
Example #27
Source File: ShardPath.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * This method walks through the nodes shard paths to find the data and state path for the given shard. If multiple
 * directories with a valid shard state exist the one with the highest version will be used.
 * <b>Note:</b> this method resolves custom data locations for the shard.
 */
public static ShardPath loadShardPath(Logger logger, ShardId shardId, IndexSettings indexSettings, Path[] availableShardPaths,
                                       int nodeLockId, Path sharedDataPath) throws IOException {
    final String indexUUID = indexSettings.getUUID();
    Path loadedPath = null;
    for (Path path : availableShardPaths) {
        // EMPTY is safe here because we never call namedObject
        ShardStateMetaData load = ShardStateMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, path);
        if (load != null) {
            if (load.indexUUID.equals(indexUUID) == false && IndexMetaData.INDEX_UUID_NA_VALUE.equals(load.indexUUID) == false) {
                logger.warn("{} found shard on path: [{}] with a different index UUID - this "
                    + "shard seems to be leftover from a different index with the same name. "
                    + "Remove the leftover shard in order to reuse the path with the current index", shardId, path);
                throw new IllegalStateException(shardId + " index UUID in shard state was: " + load.indexUUID
                    + " expected: " + indexUUID + " on shard path: " + path);
            }
            if (loadedPath == null) {
                loadedPath = path;
            } else {
                throw new IllegalStateException(shardId + " more than one shard state found");
            }
        }

    }
    if (loadedPath == null) {
        return null;
    } else {
        final Path dataPath;
        final Path statePath = loadedPath;
        if (indexSettings.hasCustomDataPath()) {
            dataPath = NodeEnvironment.resolveCustomLocation(indexSettings, shardId, sharedDataPath, nodeLockId);
        } else {
            dataPath = statePath;
        }
        logger.debug("{} loaded data path [{}], state path [{}]", shardId, dataPath, statePath);
        return new ShardPath(indexSettings.hasCustomDataPath(), dataPath, statePath, shardId);
    }
}
 
Example #28
Source File: TestingHelpers.java    From crate with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> jsonMap(String json) {
    try {
        return JsonXContent.JSON_XCONTENT.createParser(
            NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json).map();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #29
Source File: TranslogHandler.java    From crate with Apache License 2.0 5 votes vote down vote up
public TranslogHandler(NamedXContentRegistry xContentRegistry, IndexSettings indexSettings) {
    NamedAnalyzer defaultAnalyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer());
    IndexAnalyzers indexAnalyzers =
            new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, emptyMap(), emptyMap(), emptyMap());
    MapperRegistry mapperRegistry = new IndicesModule(emptyList()).getMapperRegistry();
    mapperService = new MapperService(indexSettings, indexAnalyzers, xContentRegistry, mapperRegistry,
            () -> null);
}
 
Example #30
Source File: DocumentMapperParser.java    From crate with Apache License 2.0 5 votes vote down vote up
public DocumentMapperParser(IndexSettings indexSettings, MapperService mapperService, IndexAnalyzers indexAnalyzers,
                            NamedXContentRegistry xContentRegistry, MapperRegistry mapperRegistry,
                            Supplier<QueryShardContext> queryShardContextSupplier) {
    this.mapperService = mapperService;
    this.indexAnalyzers = indexAnalyzers;
    this.xContentRegistry = xContentRegistry;
    this.queryShardContextSupplier = queryShardContextSupplier;
    this.typeParsers = mapperRegistry.getMapperParsers();
    this.rootTypeParsers = mapperRegistry.getMetadataMapperParsers();
    indexVersionCreated = indexSettings.getIndexVersionCreated();
}