All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.elasticsearch.cluster.metadata.ClusterChangedEventUtils Maven / Gradle / Ivy

There is a newer version: 8.16.0
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

package org.elasticsearch.cluster.metadata;

import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterState;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ClusterChangedEventUtils {
    public static List indicesCreated(final ClusterChangedEvent event) {
        if (event.metadataChanged() == false) {
            return Collections.emptyList();
        }
        final ClusterState state = event.state();
        final ClusterState previousState = event.previousState();
        final List created = new ArrayList<>();
        for (Map.Entry cursor : state.metadata().indices().entrySet()) {
            final String index = cursor.getKey();
            if (previousState.metadata().hasIndex(index)) {
                final IndexMetadata currIndexMetadata = cursor.getValue();
                final IndexMetadata prevIndexMetadata = previousState.metadata().index(index);
                if (currIndexMetadata.getIndexUUID().equals(prevIndexMetadata.getIndexUUID()) == false) {
                    created.add(index);
                }
            } else {
                created.add(index);
            }
        }
        return Collections.unmodifiableList(created);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy