aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ReindexingContext.java
blob: df37ea7603403577b67f5e10a31e8449f027c22d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.admin.clustercontroller;

import com.yahoo.config.model.api.Reindexing;
import com.yahoo.documentmodel.NewDocumentType;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 * Context required to configure automatic reindexing for a given cluster controller cluster (for a given content cluster).
 *
 * @author bjorncs
 */
public class ReindexingContext {

    private final Object monitor = new Object();
    private final Map<String, Set<NewDocumentType>> documentTypesPerCluster = new HashMap<>();
    private final Reindexing reindexing;

    public ReindexingContext(Reindexing reindexing) {
        this.reindexing = Objects.requireNonNull(reindexing);
    }

    public void addDocumentType(String clusterId, NewDocumentType type) {
        synchronized (monitor) {
            documentTypesPerCluster.computeIfAbsent(clusterId, ignored -> new HashSet<>())
                    .add(type);
        }
    }

    public Collection<String> clusterIds() {
        synchronized (monitor) {
            return new HashSet<>(documentTypesPerCluster.keySet());
        }
    }

    public Collection<NewDocumentType> documentTypesForCluster(String clusterId) {
        synchronized (monitor) {
            return new HashSet<>(documentTypesPerCluster.getOrDefault(clusterId, Set.of()));
        }
    }

    public Reindexing reindexing() { return reindexing; }

}