Search in sources :

Example 1 with DataStream

use of org.opensearch.cluster.metadata.DataStream in project OpenSearch by opensearch-project.

the class GetDataStreamResponseTests method randomInstance.

private static DataStreamInfo randomInstance() {
    List<Index> indices = randomIndexInstances();
    long generation = indices.size() + randomLongBetween(1, 128);
    String dataStreamName = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
    indices.add(new Index(getDefaultBackingIndexName(dataStreamName, generation), UUIDs.randomBase64UUID(random())));
    DataStream dataStream = new DataStream(dataStreamName, createTimestampField("@timestamp"), indices, generation);
    return new DataStreamInfo(dataStream, ClusterHealthStatus.YELLOW, randomAlphaOfLengthBetween(2, 10));
}
Also used : DataStreamInfo(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Response.DataStreamInfo) DataStream(org.opensearch.cluster.metadata.DataStream) Index(org.opensearch.index.Index)

Example 2 with DataStream

use of org.opensearch.cluster.metadata.DataStream in project OpenSearch by opensearch-project.

the class GetDataStreamResponseTests method assertInstances.

@Override
protected void assertInstances(GetDataStreamAction.Response serverTestInstance, GetDataStreamResponse clientInstance) {
    assertEquals(serverTestInstance.getDataStreams().size(), clientInstance.getDataStreams().size());
    Iterator<DataStreamInfo> serverIt = serverTestInstance.getDataStreams().iterator();
    Iterator<org.opensearch.client.indices.DataStream> clientIt = clientInstance.getDataStreams().iterator();
    while (serverIt.hasNext()) {
        org.opensearch.client.indices.DataStream client = clientIt.next();
        DataStream server = serverIt.next().getDataStream();
        assertEquals(server.getName(), client.getName());
        assertEquals(server.getIndices().stream().map(Index::getName).collect(Collectors.toList()), client.getIndices());
        assertEquals(server.getTimeStampField().getName(), client.getTimeStampField());
        assertEquals(server.getGeneration(), client.getGeneration());
    }
}
Also used : DataStreamInfo(org.opensearch.action.admin.indices.datastream.GetDataStreamAction.Response.DataStreamInfo) DataStream(org.opensearch.cluster.metadata.DataStream) Index(org.opensearch.index.Index)

Example 3 with DataStream

use of org.opensearch.cluster.metadata.DataStream in project OpenSearch by opensearch-project.

the class DataStreamRolloverIT method testDataStreamRollover.

public void testDataStreamRollover() throws Exception {
    createDataStreamIndexTemplate("demo-template", Collections.singletonList("logs-*"));
    createDataStream("logs-demo");
    DataStream dataStream;
    GetDataStreamAction.Response.DataStreamInfo dataStreamInfo;
    GetDataStreamAction.Response response;
    // Data stream before a rollover.
    response = getDataStreams("logs-demo");
    dataStreamInfo = response.getDataStreams().get(0);
    assertThat(dataStreamInfo.getIndexTemplate(), equalTo("demo-template"));
    dataStream = dataStreamInfo.getDataStream();
    assertThat(dataStream.getGeneration(), equalTo(1L));
    assertThat(dataStream.getIndices().size(), equalTo(1));
    assertThat(dataStream.getTimeStampField(), equalTo(new DataStream.TimestampField("@timestamp")));
    assertThat(dataStream.getIndices().stream().map(Index::getName).collect(Collectors.toList()), containsInAnyOrder(".ds-logs-demo-000001"));
    // Perform a rollover.
    RolloverResponse rolloverResponse = rolloverDataStream("logs-demo");
    assertThat(rolloverResponse.getOldIndex(), equalTo(".ds-logs-demo-000001"));
    assertThat(rolloverResponse.getNewIndex(), equalTo(".ds-logs-demo-000002"));
    // Data stream after a rollover.
    response = getDataStreams("logs-demo");
    dataStreamInfo = response.getDataStreams().get(0);
    assertThat(dataStreamInfo.getIndexTemplate(), equalTo("demo-template"));
    dataStream = dataStreamInfo.getDataStream();
    assertThat(dataStream.getGeneration(), equalTo(2L));
    assertThat(dataStream.getIndices().size(), equalTo(2));
    assertThat(dataStream.getTimeStampField(), equalTo(new DataStream.TimestampField("@timestamp")));
    assertThat(dataStream.getIndices().stream().map(Index::getName).collect(Collectors.toList()), containsInAnyOrder(".ds-logs-demo-000001", ".ds-logs-demo-000002"));
}
Also used : RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) DataStream(org.opensearch.cluster.metadata.DataStream) Index(org.opensearch.index.Index) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse)

Example 4 with DataStream

use of org.opensearch.cluster.metadata.DataStream in project OpenSearch by opensearch-project.

the class TransportBulkAction method prohibitAppendWritesInBackingIndices.

static void prohibitAppendWritesInBackingIndices(DocWriteRequest<?> writeRequest, Metadata metadata) {
    IndexAbstraction indexAbstraction = metadata.getIndicesLookup().get(writeRequest.index());
    if (indexAbstraction == null) {
        return;
    }
    if (indexAbstraction.getType() != IndexAbstraction.Type.CONCRETE_INDEX) {
        return;
    }
    if (indexAbstraction.getParentDataStream() == null) {
        return;
    }
    DataStream dataStream = indexAbstraction.getParentDataStream().getDataStream();
    // At this point with write op is targeting a backing index of a data stream directly,
    // so checking if write op is append-only and if so fail.
    // (Updates and deletes are allowed to target a backing index)
    DocWriteRequest.OpType opType = writeRequest.opType();
    // that an engine level change is needed and for now this check is sufficient.)
    if (opType == DocWriteRequest.OpType.CREATE) {
        throw new IllegalArgumentException("index request with op_type=create targeting backing indices is disallowed, " + "target corresponding data stream [" + dataStream.getName() + "] instead");
    }
    if (opType == DocWriteRequest.OpType.INDEX && writeRequest.ifPrimaryTerm() == UNASSIGNED_PRIMARY_TERM && writeRequest.ifSeqNo() == UNASSIGNED_SEQ_NO) {
        throw new IllegalArgumentException("index request with op_type=index and no if_primary_term and if_seq_no set " + "targeting backing indices is disallowed, target corresponding data stream [" + dataStream.getName() + "] instead");
    }
}
Also used : IndexAbstraction(org.opensearch.cluster.metadata.IndexAbstraction) DataStream(org.opensearch.cluster.metadata.DataStream) DocWriteRequest(org.opensearch.action.DocWriteRequest)

Example 5 with DataStream

use of org.opensearch.cluster.metadata.DataStream in project OpenSearch by opensearch-project.

the class SnapshotsService method snapshottingDataStreams.

/**
 * Returns the data streams that are currently being snapshotted (with partial == false) and that are contained in the
 * indices-to-check set.
 */
public static Set<String> snapshottingDataStreams(final ClusterState currentState, final Set<String> dataStreamsToCheck) {
    final SnapshotsInProgress snapshots = currentState.custom(SnapshotsInProgress.TYPE);
    if (snapshots == null) {
        return emptySet();
    }
    Map<String, DataStream> dataStreams = currentState.metadata().dataStreams();
    return snapshots.entries().stream().filter(e -> e.partial() == false).flatMap(e -> e.dataStreams().stream()).filter(ds -> dataStreams.containsKey(ds) && dataStreamsToCheck.contains(ds)).collect(Collectors.toSet());
}
Also used : RepositoryMissingException(org.opensearch.repositories.RepositoryMissingException) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) Collections.unmodifiableList(java.util.Collections.unmodifiableList) DataStream(org.opensearch.cluster.metadata.DataStream) Version(org.opensearch.Version) ClusterStateApplier(org.opensearch.cluster.ClusterStateApplier) Regex(org.opensearch.common.regex.Regex) Strings(org.opensearch.common.Strings) GroupedActionListener(org.opensearch.action.support.GroupedActionListener) Map(java.util.Map) ActionListener(org.opensearch.action.ActionListener) EnumSet(java.util.EnumSet) Repository(org.opensearch.repositories.Repository) TimeValue(org.opensearch.common.unit.TimeValue) Index(org.opensearch.index.Index) ExceptionsHelper(org.opensearch.ExceptionsHelper) Set(java.util.Set) ClusterStateTaskExecutor(org.opensearch.cluster.ClusterStateTaskExecutor) Settings(org.opensearch.common.settings.Settings) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) TransportService(org.opensearch.transport.TransportService) FailedToCommitClusterStateException(org.opensearch.cluster.coordination.FailedToCommitClusterStateException) ActionFilters(org.opensearch.action.support.ActionFilters) AbstractLifecycleComponent(org.opensearch.common.component.AbstractLifecycleComponent) ShardState(org.opensearch.cluster.SnapshotsInProgress.ShardState) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) StepListener(org.opensearch.action.StepListener) State(org.opensearch.cluster.SnapshotsInProgress.State) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RepositoriesService(org.opensearch.repositories.RepositoriesService) ThreadPool(org.opensearch.threadpool.ThreadPool) Priority(org.opensearch.common.Priority) TransportMasterNodeAction(org.opensearch.action.support.master.TransportMasterNodeAction) ArrayList(java.util.ArrayList) ClusterState(org.opensearch.cluster.ClusterState) LegacyESVersion(org.opensearch.LegacyESVersion) ClusterStateTaskConfig(org.opensearch.cluster.ClusterStateTaskConfig) RepositoryCleanupInProgress(org.opensearch.cluster.RepositoryCleanupInProgress) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) Executor(java.util.concurrent.Executor) IOException(java.io.IOException) DeleteSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) ClusterService(org.opensearch.cluster.service.ClusterService) RestoreInProgress(org.opensearch.cluster.RestoreInProgress) RoutingTable(org.opensearch.cluster.routing.RoutingTable) SnapshotsInProgress.completed(org.opensearch.cluster.SnapshotsInProgress.completed) ClusterChangedEvent(org.opensearch.cluster.ClusterChangedEvent) ShardGenerations(org.opensearch.repositories.ShardGenerations) AbstractRunnable(org.opensearch.common.util.concurrent.AbstractRunnable) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) IndexId(org.opensearch.repositories.IndexId) Locale(java.util.Locale) NotMasterException(org.opensearch.cluster.NotMasterException) ShardSnapshotStatus(org.opensearch.cluster.SnapshotsInProgress.ShardSnapshotStatus) RepositoryException(org.opensearch.repositories.RepositoryException) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) Collectors(java.util.stream.Collectors) Nullable(org.opensearch.common.Nullable) Tuple(org.opensearch.common.collect.Tuple) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) ClusterStateTaskListener(org.opensearch.cluster.ClusterStateTaskListener) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) ActionRunnable(org.opensearch.action.ActionRunnable) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) CloneSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest) HashMap(java.util.HashMap) SnapshotDeletionsInProgress(org.opensearch.cluster.SnapshotDeletionsInProgress) Deque(java.util.Deque) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Function(java.util.function.Function) HashSet(java.util.HashSet) IndexRoutingTable(org.opensearch.cluster.routing.IndexRoutingTable) UUIDs(org.opensearch.common.UUIDs) LinkedList(java.util.LinkedList) StreamInput(org.opensearch.common.io.stream.StreamInput) RepositoryData(org.opensearch.repositories.RepositoryData) Setting(org.opensearch.common.settings.Setting) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) RepositoryShardId(org.opensearch.repositories.RepositoryShardId) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) Consumer(java.util.function.Consumer) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) DataStream(org.opensearch.cluster.metadata.DataStream) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress)

Aggregations

DataStream (org.opensearch.cluster.metadata.DataStream)26 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)15 Index (org.opensearch.index.Index)15 Metadata (org.opensearch.cluster.metadata.Metadata)14 ClusterState (org.opensearch.cluster.ClusterState)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 IndexNameExpressionResolver (org.opensearch.cluster.metadata.IndexNameExpressionResolver)7 AliasMetadata (org.opensearch.cluster.metadata.AliasMetadata)6 ArrayList (java.util.ArrayList)5 IndexTemplateMetadata (org.opensearch.cluster.metadata.IndexTemplateMetadata)5 Tuple (org.opensearch.common.collect.Tuple)5 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)4 CreateIndexRequest (org.opensearch.action.admin.indices.create.CreateIndexRequest)4 MetadataCreateIndexService (org.opensearch.cluster.metadata.MetadataCreateIndexService)4 HashMap (java.util.HashMap)3 ClusterName (org.opensearch.cluster.ClusterName)3 MetadataIndexAliasesService (org.opensearch.cluster.metadata.MetadataIndexAliasesService)3 AllocationService (org.opensearch.cluster.routing.allocation.AllocationService)3 ClusterService (org.opensearch.cluster.service.ClusterService)3 ObjectCursor (com.carrotsearch.hppc.cursors.ObjectCursor)2