Search in sources :

Example 1 with ClusterName

use of org.opensearch.cluster.ClusterName in project OpenSearch by opensearch-project.

the class MainResponseTests method createServerTestInstance.

@Override
protected org.opensearch.action.main.MainResponse createServerTestInstance(XContentType xContentType) {
    String clusterUuid = randomAlphaOfLength(10);
    ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
    String nodeName = randomAlphaOfLength(10);
    final String date = new Date(randomNonNegativeLong()).toString();
    Version version = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, Version.CURRENT);
    Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString(), version.before(Version.V_1_0_0) ? null : "opensearch");
    return new org.opensearch.action.main.MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
Also used : LegacyESVersion(org.opensearch.LegacyESVersion) Version(org.opensearch.Version) Build(org.opensearch.Build) ClusterName(org.opensearch.cluster.ClusterName) Date(java.util.Date)

Example 2 with ClusterName

use of org.opensearch.cluster.ClusterName in project OpenSearch by opensearch-project.

the class CrossClusterSearchUnavailableClusterIT method startTransport.

private static MockTransportService startTransport(final String id, final List<DiscoveryNode> knownNodes, final Version version, final ThreadPool threadPool) {
    boolean success = false;
    final Settings s = Settings.builder().put("node.name", id).build();
    ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(s);
    MockTransportService newService = MockTransportService.createNewService(s, version, threadPool, null);
    try {
        newService.registerRequestHandler(ClusterSearchShardsAction.NAME, ThreadPool.Names.SAME, ClusterSearchShardsRequest::new, (request, channel, task) -> {
            channel.sendResponse(new ClusterSearchShardsResponse(new ClusterSearchShardsGroup[0], knownNodes.toArray(new DiscoveryNode[0]), Collections.emptyMap()));
        });
        newService.registerRequestHandler(SearchAction.NAME, ThreadPool.Names.SAME, SearchRequest::new, (request, channel, task) -> {
            InternalSearchResponse response = new InternalSearchResponse(new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), Float.NaN), InternalAggregations.EMPTY, null, null, false, null, 1);
            SearchResponse searchResponse = new SearchResponse(response, null, 1, 1, 0, 100, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY);
            channel.sendResponse(searchResponse);
        });
        newService.registerRequestHandler(ClusterStateAction.NAME, ThreadPool.Names.SAME, ClusterStateRequest::new, (request, channel, task) -> {
            DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
            for (DiscoveryNode node : knownNodes) {
                builder.add(node);
            }
            ClusterState build = ClusterState.builder(clusterName).nodes(builder.build()).build();
            channel.sendResponse(new ClusterStateResponse(clusterName, build, false));
        });
        newService.start();
        newService.acceptIncomingRequests();
        success = true;
        return newService;
    } finally {
        if (success == false) {
            newService.close();
        }
    }
}
Also used : ClusterSearchShardsResponse(org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse) TotalHits(org.apache.lucene.search.TotalHits) SearchRequest(org.opensearch.action.search.SearchRequest) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransportService(org.opensearch.test.transport.MockTransportService) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) ClusterSearchShardsGroup(org.opensearch.action.admin.cluster.shards.ClusterSearchShardsGroup) SearchResponse(org.opensearch.action.search.SearchResponse) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse) ClusterSearchShardsRequest(org.opensearch.action.admin.cluster.shards.ClusterSearchShardsRequest) ClusterName(org.opensearch.cluster.ClusterName) Settings(org.opensearch.common.settings.Settings) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse)

Example 3 with ClusterName

use of org.opensearch.cluster.ClusterName in project OpenSearch by opensearch-project.

the class SearchIndexNameMatcherTests method setUpMatchers.

@Before
public void setUpMatchers() {
    Metadata.Builder metadataBuilder = Metadata.builder().put(indexBuilder("index1").putAlias(AliasMetadata.builder("alias"))).put(indexBuilder("index2").putAlias(AliasMetadata.builder("alias"))).put(indexBuilder("index3"));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(metadataBuilder).build();
    ClusterService clusterService = mock(ClusterService.class);
    when(clusterService.state()).thenReturn(state);
    matcher = new SearchIndexNameMatcher("index1", "", clusterService, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
    remoteMatcher = new SearchIndexNameMatcher("index1", "cluster", clusterService, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterService(org.opensearch.cluster.service.ClusterService) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterName(org.opensearch.cluster.ClusterName) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before)

Example 4 with ClusterName

use of org.opensearch.cluster.ClusterName in project OpenSearch by opensearch-project.

the class ClusterStateResponseTests method createTestInstance.

@Override
protected ClusterStateResponse createTestInstance() {
    ClusterName clusterName = new ClusterName(randomAlphaOfLength(4));
    ClusterState clusterState = null;
    if (randomBoolean()) {
        ClusterState.Builder clusterStateBuilder = ClusterState.builder(clusterName).version(randomNonNegativeLong());
        if (randomBoolean()) {
            clusterStateBuilder.nodes(DiscoveryNodes.builder().masterNodeId(randomAlphaOfLength(4)).build());
        }
        clusterState = clusterStateBuilder.build();
    }
    return new ClusterStateResponse(clusterName, clusterState, randomBoolean());
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterName(org.opensearch.cluster.ClusterName)

Example 5 with ClusterName

use of org.opensearch.cluster.ClusterName in project OpenSearch by opensearch-project.

the class DeleteDataStreamRequestTests method getClusterStateWithDataStreams.

/**
 * Constructs {@code ClusterState} with the specified data streams and indices.
 *
 * @param dataStreams The names of the data streams to create with their respective number of backing indices
 * @param indexNames  The names of indices to create that do not back any data streams
 */
public static ClusterState getClusterStateWithDataStreams(List<Tuple<String, Integer>> dataStreams, List<String> indexNames) {
    Metadata.Builder builder = Metadata.builder();
    List<IndexMetadata> allIndices = new ArrayList<>();
    for (Tuple<String, Integer> dsTuple : dataStreams) {
        List<IndexMetadata> backingIndices = new ArrayList<>();
        for (int backingIndexNumber = 1; backingIndexNumber <= dsTuple.v2(); backingIndexNumber++) {
            backingIndices.add(createIndexMetadata(DataStream.getDefaultBackingIndexName(dsTuple.v1(), backingIndexNumber), true));
        }
        allIndices.addAll(backingIndices);
        DataStream ds = new DataStream(dsTuple.v1(), createTimestampField("@timestamp"), backingIndices.stream().map(IndexMetadata::getIndex).collect(Collectors.toList()), dsTuple.v2());
        builder.put(ds);
    }
    for (String indexName : indexNames) {
        allIndices.add(createIndexMetadata(indexName, false));
    }
    for (IndexMetadata index : allIndices) {
        builder.put(index, false);
    }
    return ClusterState.builder(new ClusterName("_name")).metadata(builder).build();
}
Also used : DataStream(org.opensearch.cluster.metadata.DataStream) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ArrayList(java.util.ArrayList) ClusterName(org.opensearch.cluster.ClusterName) Matchers.containsString(org.hamcrest.Matchers.containsString) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Aggregations

ClusterName (org.opensearch.cluster.ClusterName)185 ClusterState (org.opensearch.cluster.ClusterState)164 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)58 Matchers.containsString (org.hamcrest.Matchers.containsString)56 Settings (org.opensearch.common.settings.Settings)46 Metadata (org.opensearch.cluster.metadata.Metadata)44 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)40 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)32 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)31 ClusterChangedEvent (org.opensearch.cluster.ClusterChangedEvent)30 Version (org.opensearch.Version)29 ClusterService (org.opensearch.cluster.service.ClusterService)27 ClusterSettings (org.opensearch.common.settings.ClusterSettings)26 Index (org.opensearch.index.Index)26 HashMap (java.util.HashMap)24 BytesArray (org.opensearch.common.bytes.BytesArray)24 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)24 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 ThreadPool (org.opensearch.threadpool.ThreadPool)23 Mockito.anyString (org.mockito.Mockito.anyString)22