aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/content/storagecluster/PersistenceProducer.java
blob: 2d8677143ef394062fe45a9117b01c699b892ba9 (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
51
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.content.storagecluster;

import com.yahoo.vespa.config.content.PersistenceConfig;
import com.yahoo.vespa.model.builder.xml.dom.ModelElement;
import com.yahoo.vespa.model.utils.Duration;

/**
 * Serves engines config for storage clusters.
 */
public class PersistenceProducer implements PersistenceConfig.Producer {

    public static class Builder {
        public PersistenceProducer build(ModelElement element) {
            ModelElement persistence = element.child("engine");
            if (persistence == null) {
                return new PersistenceProducer();
            }

            return new PersistenceProducer(
                    persistence.childAsBoolean("fail-partition-on-error"),
                    persistence.childAsDuration("recovery-time"),
                    persistence.childAsDuration("revert-time"));
        }
    }

    Boolean failOnError;
    Duration recoveryPeriod;
    Duration revertTimePeriod;

    public PersistenceProducer() {}

    public PersistenceProducer(Boolean failOnError, Duration recoveryPeriod, Duration revertTimePeriod) {
        this.failOnError = failOnError;
        this.recoveryPeriod = recoveryPeriod;
        this.revertTimePeriod = revertTimePeriod;
    }

    @Override
    public void getConfig(PersistenceConfig.Builder builder) {
        if (failOnError != null) {
            builder.fail_partition_on_error(failOnError);
        }
        if (recoveryPeriod != null) {
            builder.keep_remove_time_period((int)recoveryPeriod.getSeconds());
        }
        if (revertTimePeriod != null) {
            builder.revert_time_period((int)revertTimePeriod.getSeconds());
        }
    }
}