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);
}
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);
}
});
}
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));
}
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())));
}
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())));
}
Aggregations