Search in sources :

Example 1 with IndicesStatsRequest

use of org.opensearch.action.admin.indices.stats.IndicesStatsRequest in project OpenSearch by opensearch-project.

the class IndicesRequestIT method testIndicesStats.

public void testIndicesStats() {
    String indicesStats = IndicesStatsAction.NAME + "[n]";
    interceptTransportActions(indicesStats);
    IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest().indices(randomIndicesOrAliases());
    internalCluster().coordOnlyNodeClient().admin().indices().stats(indicesStatsRequest).actionGet();
    clearInterceptedActions();
    assertSameIndices(indicesStatsRequest, indicesStats);
}
Also used : IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest)

Example 2 with IndicesStatsRequest

use of org.opensearch.action.admin.indices.stats.IndicesStatsRequest in project OpenSearch by opensearch-project.

the class TransportRolloverAction method masterOperation.

@Override
protected void masterOperation(Task task, final RolloverRequest rolloverRequest, final ClusterState state, final ActionListener<RolloverResponse> listener) throws Exception {
    MetadataRolloverService.RolloverResult preResult = rolloverService.rolloverClusterState(state, rolloverRequest.getRolloverTarget(), rolloverRequest.getNewIndexName(), rolloverRequest.getCreateIndexRequest(), Collections.emptyList(), true, true);
    Metadata metadata = state.metadata();
    String sourceIndexName = preResult.sourceIndexName;
    String rolloverIndexName = preResult.rolloverIndexName;
    IndicesStatsRequest statsRequest = new IndicesStatsRequest().indices(rolloverRequest.getRolloverTarget()).clear().indicesOptions(IndicesOptions.fromOptions(true, false, true, true)).docs(true);
    statsRequest.setParentTask(clusterService.localNode().getId(), task.getId());
    client.execute(IndicesStatsAction.INSTANCE, statsRequest, new ActionListener<IndicesStatsResponse>() {

        @Override
        public void onResponse(IndicesStatsResponse statsResponse) {
            final Map<String, Boolean> conditionResults = evaluateConditions(rolloverRequest.getConditions().values(), metadata.index(sourceIndexName), statsResponse);
            if (rolloverRequest.isDryRun()) {
                listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, true, false, false, false));
                return;
            }
            List<Condition<?>> metConditions = rolloverRequest.getConditions().values().stream().filter(condition -> conditionResults.get(condition.toString())).collect(Collectors.toList());
            if (conditionResults.size() == 0 || metConditions.size() > 0) {
                clusterService.submitStateUpdateTask("rollover_index source [" + sourceIndexName + "] to target [" + rolloverIndexName + "]", new ClusterStateUpdateTask() {

                    @Override
                    public ClusterState execute(ClusterState currentState) throws Exception {
                        MetadataRolloverService.RolloverResult rolloverResult = rolloverService.rolloverClusterState(currentState, rolloverRequest.getRolloverTarget(), rolloverRequest.getNewIndexName(), rolloverRequest.getCreateIndexRequest(), metConditions, false, false);
                        if (rolloverResult.sourceIndexName.equals(sourceIndexName) == false) {
                            throw new OpenSearchException("Concurrent modification of alias [{}] during rollover", rolloverRequest.getRolloverTarget());
                        }
                        return rolloverResult.clusterState;
                    }

                    @Override
                    public void onFailure(String source, Exception e) {
                        listener.onFailure(e);
                    }

                    @Override
                    public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
                        if (newState.equals(oldState) == false) {
                            activeShardsObserver.waitForActiveShards(new String[] { rolloverIndexName }, rolloverRequest.getCreateIndexRequest().waitForActiveShards(), rolloverRequest.masterNodeTimeout(), isShardsAcknowledged -> listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, false, true, true, isShardsAcknowledged)), listener::onFailure);
                        }
                    }
                });
            } else {
                // conditions not met
                listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults, false, false, false, false));
            }
        }

        @Override
        public void onFailure(Exception e) {
            listener.onFailure(e);
        }
    });
}
Also used : IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ClusterState(org.opensearch.cluster.ClusterState) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) OpenSearchException(org.opensearch.OpenSearchException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) IOException(java.io.IOException) List(java.util.List) OpenSearchException(org.opensearch.OpenSearchException) Map(java.util.Map) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest)

Example 3 with IndicesStatsRequest

use of org.opensearch.action.admin.indices.stats.IndicesStatsRequest in project OpenSearch by opensearch-project.

the class RetentionLeaseActionsTests method testAddUnderBlock.

public void testAddUnderBlock() throws InterruptedException {
    final Settings settings = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true).build();
    final IndexService indexService = createIndex("index", settings);
    ensureGreen("index");
    final String id = randomAlphaOfLength(8);
    final long retainingSequenceNumber = randomBoolean() ? RETAIN_ALL : randomNonNegativeLong();
    final String source = randomAlphaOfLength(8);
    runActionUnderBlockTest(indexService, (shardId, actionLatch) -> client().execute(RetentionLeaseActions.Add.INSTANCE, new RetentionLeaseActions.AddRequest(shardId, id, retainingSequenceNumber, source), new ActionListener<RetentionLeaseActions.Response>() {

        @Override
        public void onResponse(final RetentionLeaseActions.Response response) {
            actionLatch.countDown();
        }

        @Override
        public void onFailure(final Exception e) {
            fail(e.toString());
        }
    }));
    final IndicesStatsResponse stats = client().execute(IndicesStatsAction.INSTANCE, new IndicesStatsRequest().indices("index")).actionGet();
    assertNotNull(stats.getShards());
    assertThat(stats.getShards(), arrayWithSize(1));
    assertNotNull(stats.getShards()[0].getRetentionLeaseStats());
    assertThat(stats.getShards()[0].getRetentionLeaseStats().retentionLeases().leases(), hasSize(2));
    assertTrue(stats.getShards()[0].getRetentionLeaseStats().retentionLeases().contains(ReplicationTracker.getPeerRecoveryRetentionLeaseId(stats.getShards()[0].getShardRouting())));
    final RetentionLease retentionLease = stats.getShards()[0].getRetentionLeaseStats().retentionLeases().get(id);
    assertThat(retentionLease.id(), equalTo(id));
    assertThat(retentionLease.retainingSequenceNumber(), equalTo(retainingSequenceNumber == RETAIN_ALL ? 0L : retainingSequenceNumber));
    assertThat(retentionLease.source(), equalTo(source));
}
Also used : IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ActionListener(org.opensearch.action.ActionListener) IndexService(org.opensearch.index.IndexService) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest)

Example 4 with IndicesStatsRequest

use of org.opensearch.action.admin.indices.stats.IndicesStatsRequest in project OpenSearch by opensearch-project.

the class RetentionLeaseActionsTests method testRemoveUnderBlock.

public void testRemoveUnderBlock() throws InterruptedException {
    final Settings settings = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true).build();
    final IndexService indexService = createIndex("index", settings);
    ensureGreen("index");
    final String id = randomAlphaOfLength(8);
    final long retainingSequenceNumber = randomBoolean() ? RETAIN_ALL : randomNonNegativeLong();
    final String source = randomAlphaOfLength(8);
    client().execute(RetentionLeaseActions.Add.INSTANCE, new RetentionLeaseActions.AddRequest(indexService.getShard(0).shardId(), id, retainingSequenceNumber, source)).actionGet();
    runActionUnderBlockTest(indexService, (shardId, actionLatch) -> client().execute(RetentionLeaseActions.Remove.INSTANCE, new RetentionLeaseActions.RemoveRequest(shardId, id), new ActionListener<RetentionLeaseActions.Response>() {

        @Override
        public void onResponse(final RetentionLeaseActions.Response response) {
            actionLatch.countDown();
        }

        @Override
        public void onFailure(final Exception e) {
            fail(e.toString());
        }
    }));
    final IndicesStatsResponse stats = client().execute(IndicesStatsAction.INSTANCE, new IndicesStatsRequest().indices("index")).actionGet();
    assertNotNull(stats.getShards());
    assertThat(stats.getShards(), arrayWithSize(1));
    assertNotNull(stats.getShards()[0].getRetentionLeaseStats());
    assertThat(stats.getShards()[0].getRetentionLeaseStats().retentionLeases().leases(), hasSize(1));
    assertTrue(stats.getShards()[0].getRetentionLeaseStats().retentionLeases().contains(ReplicationTracker.getPeerRecoveryRetentionLeaseId(stats.getShards()[0].getShardRouting())));
}
Also used : IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) ActionListener(org.opensearch.action.ActionListener) IndexService(org.opensearch.index.IndexService) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest)

Example 5 with IndicesStatsRequest

use of org.opensearch.action.admin.indices.stats.IndicesStatsRequest in project OpenSearch by opensearch-project.

the class RetentionLeaseActionsTests method testAddAction.

public void testAddAction() {
    final Settings settings = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true).build();
    final IndexService indexService = createIndex("index", settings);
    ensureGreen("index");
    final String id = randomAlphaOfLength(8);
    final long retainingSequenceNumber = randomBoolean() ? RETAIN_ALL : randomNonNegativeLong();
    final String source = randomAlphaOfLength(8);
    client().execute(RetentionLeaseActions.Add.INSTANCE, new RetentionLeaseActions.AddRequest(indexService.getShard(0).shardId(), id, retainingSequenceNumber, source)).actionGet();
    final IndicesStatsResponse stats = client().execute(IndicesStatsAction.INSTANCE, new IndicesStatsRequest().indices("index")).actionGet();
    assertNotNull(stats.getShards());
    assertThat(stats.getShards(), arrayWithSize(1));
    assertNotNull(stats.getShards()[0].getRetentionLeaseStats());
    assertThat(stats.getShards()[0].getRetentionLeaseStats().retentionLeases().leases(), hasSize(2));
    final RetentionLease retentionLease = stats.getShards()[0].getRetentionLeaseStats().retentionLeases().get(id);
    assertThat(retentionLease.id(), equalTo(id));
    assertThat(retentionLease.retainingSequenceNumber(), equalTo(retainingSequenceNumber == RETAIN_ALL ? 0L : retainingSequenceNumber));
    assertThat(retentionLease.source(), equalTo(source));
    assertTrue(stats.getShards()[0].getRetentionLeaseStats().retentionLeases().contains(ReplicationTracker.getPeerRecoveryRetentionLeaseId(stats.getShards()[0].getShardRouting())));
}
Also used : IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) IndexService(org.opensearch.index.IndexService) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) IndicesStatsRequest(org.opensearch.action.admin.indices.stats.IndicesStatsRequest)

Aggregations

IndicesStatsRequest (org.opensearch.action.admin.indices.stats.IndicesStatsRequest)13 IndicesStatsResponse (org.opensearch.action.admin.indices.stats.IndicesStatsResponse)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Matchers.hasToString (org.hamcrest.Matchers.hasToString)6 Settings (org.opensearch.common.settings.Settings)6 IndexService (org.opensearch.index.IndexService)6 IndexSettings (org.opensearch.index.IndexSettings)6 List (java.util.List)4 IOException (java.io.IOException)3 ActionListener (org.opensearch.action.ActionListener)3 TimeValue (org.opensearch.common.unit.TimeValue)3 Arrays.asList (java.util.Arrays.asList)2 Collections.unmodifiableList (java.util.Collections.unmodifiableList)2 Locale (java.util.Locale)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 NodeClient (org.opensearch.client.node.NodeClient)2 Strings (org.opensearch.common.Strings)2 ThreadPool (org.opensearch.threadpool.ThreadPool)2 Instant (java.time.Instant)1