Search in sources :

Example 46 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class SharedClusterSnapshotRestoreIT method unrestorableUseCase.

/**
 * Execute the unrestorable test use case *
 */
private void unrestorableUseCase(final String indexName, final Settings createIndexSettings, final Settings repositorySettings, final Settings restoreIndexSettings, final Consumer<UnassignedInfo> checkUnassignedInfo, final Runnable fixUpAction) throws Exception {
    // create a test repository
    final Path repositoryLocation = randomRepoPath();
    createRepository("test-repo", "fs", repositoryLocation);
    // create a test index
    assertAcked(prepareCreate(indexName, Settings.builder().put(createIndexSettings)));
    // index some documents
    final int nbDocs = scaledRandomIntBetween(10, 100);
    indexRandomDocs(indexName, nbDocs);
    // create a snapshot
    final NumShards numShards = getNumShards(indexName);
    final SnapshotInfo snapshotInfo = createSnapshot("test-repo", "test-snap", Collections.singletonList(indexName));
    assertThat(snapshotInfo.successfulShards(), equalTo(numShards.numPrimaries));
    // delete the test index
    assertAcked(client().admin().indices().prepareDelete(indexName));
    // update the test repository
    assertAcked(clusterAdmin().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", repositoryLocation).put(repositorySettings).build()));
    // attempt to restore the snapshot with the given settings
    RestoreSnapshotResponse restoreResponse = clusterAdmin().prepareRestoreSnapshot("test-repo", "test-snap").setIndices(indexName).setIndexSettings(restoreIndexSettings).setWaitForCompletion(true).get();
    // check that all shards failed during restore
    assertThat(restoreResponse.getRestoreInfo().totalShards(), equalTo(numShards.numPrimaries));
    assertThat(restoreResponse.getRestoreInfo().successfulShards(), equalTo(0));
    ClusterStateResponse clusterStateResponse = clusterAdmin().prepareState().setCustoms(true).setRoutingTable(true).get();
    // check that there is no restore in progress
    RestoreInProgress restoreInProgress = clusterStateResponse.getState().custom(RestoreInProgress.TYPE);
    assertNotNull("RestoreInProgress must be not null", restoreInProgress);
    assertTrue("RestoreInProgress must be empty but found entries in " + restoreInProgress, restoreInProgress.isEmpty());
    // check that the shards have been created but are not assigned
    assertThat(clusterStateResponse.getState().getRoutingTable().allShards(indexName), hasSize(numShards.totalNumShards));
    // check that every primary shard is unassigned
    for (ShardRouting shard : clusterStateResponse.getState().getRoutingTable().allShards(indexName)) {
        if (shard.primary()) {
            assertThat(shard.state(), equalTo(ShardRoutingState.UNASSIGNED));
            assertThat(shard.recoverySource().getType(), equalTo(RecoverySource.Type.SNAPSHOT));
            assertThat(shard.unassignedInfo().getLastAllocationStatus(), equalTo(UnassignedInfo.AllocationStatus.DECIDERS_NO));
            checkUnassignedInfo.accept(shard.unassignedInfo());
        }
    }
    // update the test repository in order to make it work
    createRepository("test-repo", "fs", repositoryLocation);
    // execute action to eventually fix the situation
    fixUpAction.run();
    // delete the index and restore again
    assertAcked(client().admin().indices().prepareDelete(indexName));
    restoreResponse = clusterAdmin().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).get();
    assertThat(restoreResponse.getRestoreInfo().totalShards(), equalTo(numShards.numPrimaries));
    assertThat(restoreResponse.getRestoreInfo().successfulShards(), equalTo(numShards.numPrimaries));
    // Wait for the shards to be assigned
    ensureGreen(indexName);
    refresh(indexName);
    assertDocCount(indexName, nbDocs);
}
Also used : Path(java.nio.file.Path) RestoreInProgress(org.opensearch.cluster.RestoreInProgress) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ShardRouting(org.opensearch.cluster.routing.ShardRouting) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 47 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestNodeAttrsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout()));
    parseDeprecatedMasterTimeoutParameter(clusterStateRequest, request, deprecationLogger, getName());
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.timeout(request.param("timeout"));
            nodesInfoRequest.clear().addMetric(NodesInfoRequest.Metric.PROCESS.metricName());
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {

                @Override
                public RestResponse buildResponse(NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) List(java.util.List) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) Map(java.util.Map) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 48 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestNodesAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    if (request.hasParam("local")) {
        deprecationLogger.deprecate("cat_nodes_local_parameter", LOCAL_DEPRECATED_MESSAGE);
    }
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout()));
    parseDeprecatedMasterTimeoutParameter(clusterStateRequest, request, deprecationLogger, getName());
    final boolean fullId = request.paramAsBoolean("full_id", false);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.timeout(request.param("timeout"));
            nodesInfoRequest.clear().addMetrics(NodesInfoRequest.Metric.JVM.metricName(), NodesInfoRequest.Metric.OS.metricName(), NodesInfoRequest.Metric.PROCESS.metricName(), NodesInfoRequest.Metric.HTTP.metricName());
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {

                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.timeout(request.param("timeout"));
                    nodesStatsRequest.clear().indices(true).addMetrics(NodesStatsRequest.Metric.JVM.metricName(), NodesStatsRequest.Metric.OS.metricName(), NodesStatsRequest.Metric.FS.metricName(), NodesStatsRequest.Metric.PROCESS.metricName(), NodesStatsRequest.Metric.SCRIPT.metricName());
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(fullId, request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) FieldDataStats(org.opensearch.index.fielddata.FieldDataStats) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) SearchStats(org.opensearch.index.search.stats.SearchStats) HttpInfo(org.opensearch.http.HttpInfo) Table(org.opensearch.common.Table) RequestCacheStats(org.opensearch.index.cache.request.RequestCacheStats) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) OsStats(org.opensearch.monitor.os.OsStats) MergeStats(org.opensearch.index.merge.MergeStats) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) RefreshStats(org.opensearch.index.refresh.RefreshStats) JvmStats(org.opensearch.monitor.jvm.JvmStats) Locale(java.util.Locale) JvmInfo(org.opensearch.monitor.jvm.JvmInfo) SegmentsStats(org.opensearch.index.engine.SegmentsStats) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NetworkAddress(org.opensearch.common.network.NetworkAddress) CompletionStats(org.opensearch.search.suggest.completion.CompletionStats) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest) ScriptStats(org.opensearch.script.ScriptStats) FlushStats(org.opensearch.index.flush.FlushStats) IndexingStats(org.opensearch.index.shard.IndexingStats) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) NodeIndicesStats(org.opensearch.indices.NodeIndicesStats) Collectors(java.util.stream.Collectors) GetStats(org.opensearch.index.get.GetStats) RestResponse(org.opensearch.rest.RestResponse) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) TransportAddress(org.opensearch.common.transport.TransportAddress) QueryCacheStats(org.opensearch.index.cache.query.QueryCacheStats) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) List(java.util.List) ProcessInfo(org.opensearch.monitor.process.ProcessInfo) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) NodesStatsRequest(org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest) ProcessStats(org.opensearch.monitor.process.ProcessStats) FsInfo(org.opensearch.monitor.fs.FsInfo) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.opensearch.rest.RestResponse) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) NodesStatsRequest(org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 49 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestPluginsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout()));
    parseDeprecatedMasterTimeoutParameter(clusterStateRequest, request, deprecationLogger, getName());
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) throws Exception {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.timeout(request.param("timeout"));
            nodesInfoRequest.clear().addMetric(NodesInfoRequest.Metric.PLUGINS.metricName());
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {

                @Override
                public RestResponse buildResponse(final NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) NodeClient(org.opensearch.client.node.NodeClient) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Table(org.opensearch.common.Table) PluginInfo(org.opensearch.plugins.PluginInfo) RestResponse(org.opensearch.rest.RestResponse) Collections.singletonList(java.util.Collections.singletonList) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) List(java.util.List) NodeInfo(org.opensearch.action.admin.cluster.node.info.NodeInfo) PluginsAndModules(org.opensearch.action.admin.cluster.node.info.PluginsAndModules) RestResponseListener(org.opensearch.rest.action.RestResponseListener) NodesInfoResponse(org.opensearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.opensearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 50 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class RestSegmentsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout()));
    parseDeprecatedMasterTimeoutParameter(clusterStateRequest, request, deprecationLogger, getName());
    clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest();
            indicesSegmentsRequest.indices(indices);
            client.admin().indices().segments(indicesSegmentsRequest, new RestResponseListener<IndicesSegmentResponse>(channel) {

                @Override
                public RestResponse buildResponse(final IndicesSegmentResponse indicesSegmentResponse) throws Exception {
                    final Map<String, IndexSegments> indicesSegments = indicesSegmentResponse.getIndices();
                    Table tab = buildTable(request, clusterStateResponse, indicesSegments);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
Also used : ShardSegments(org.opensearch.action.admin.indices.segments.ShardSegments) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments) RestRequest(org.opensearch.rest.RestRequest) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) IndexShardSegments(org.opensearch.action.admin.indices.segments.IndexShardSegments) Table(org.opensearch.common.Table) RestResponse(org.opensearch.rest.RestResponse) Strings(org.opensearch.common.Strings) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.opensearch.rest.action.RestActionListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Segment(org.opensearch.index.engine.Segment) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) Table(org.opensearch.common.Table) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.opensearch.rest.action.RestResponseListener) ClusterStateRequest(org.opensearch.action.admin.cluster.state.ClusterStateRequest) IndicesSegmentResponse(org.opensearch.action.admin.indices.segments.IndicesSegmentResponse) IndicesSegmentsRequest(org.opensearch.action.admin.indices.segments.IndicesSegmentsRequest) IndexSegments(org.opensearch.action.admin.indices.segments.IndexSegments)

Aggregations

ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)60 Settings (org.opensearch.common.settings.Settings)23 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)20 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)19 List (java.util.List)17 NodeClient (org.opensearch.client.node.NodeClient)13 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)13 DeprecationLogger (org.opensearch.common.logging.DeprecationLogger)12 RestRequest (org.opensearch.rest.RestRequest)12 GET (org.opensearch.rest.RestRequest.Method.GET)12 RestResponse (org.opensearch.rest.RestResponse)12 Table (org.opensearch.common.Table)11 SearchResponse (org.opensearch.action.search.SearchResponse)10 Client (org.opensearch.client.Client)10 ClusterState (org.opensearch.cluster.ClusterState)10 RestResponseListener (org.opensearch.rest.action.RestResponseListener)10 MockTransportService (org.opensearch.test.transport.MockTransportService)10 HashSet (java.util.HashSet)9 ShardRouting (org.opensearch.cluster.routing.ShardRouting)8 Strings (org.opensearch.common.Strings)8