aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/JobControlFlags.java
blob: 0632fc0818bf8433dec93f61780170a46c7ef2f3 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.persistence;

import com.yahoo.concurrent.maintenance.JobControlState;
import com.yahoo.transaction.Mutex;
import com.yahoo.vespa.flags.FlagSource;
import com.yahoo.vespa.flags.ListFlag;
import com.yahoo.vespa.flags.PermanentFlags;

import java.util.Set;

/**
 * An implementation of {@link JobControlState} that uses a feature flag to control maintenance jobs.
 *
 * @author mpolden
 */
public class JobControlFlags implements JobControlState {

    private final CuratorDb curator;
    private final ListFlag<String> inactiveJobsFlag;

    public JobControlFlags(CuratorDb curator, FlagSource flagSource) {
        this.curator = curator;
        this.inactiveJobsFlag = PermanentFlags.INACTIVE_MAINTENANCE_JOBS.bindTo(flagSource);
    }

    @Override
    public Set<String> readInactiveJobs() {
        return Set.copyOf(inactiveJobsFlag.value());
    }

    @Override
    public Mutex lockMaintenanceJob(String job) {
        return curator.lockMaintenanceJob(job);
    }

}