• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rackerlabs / blueflood / 2480

pending completion
2480

push

travis-ci

izrik
Merge pull request #648 from izrik/test-module-loader

Test module loader

3 of 3 new or added lines in 1 file covered. (100.0%)

6411 of 8722 relevant lines covered (73.5%)

3.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.42
/blueflood-core/src/main/java/com/rackspacecloud/blueflood/cache/SafetyTtlProvider.java
1
/*
2
 * Copyright 2014 Rackspace
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *        http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16

17
package com.rackspacecloud.blueflood.cache;
18

19
import com.google.common.collect.ImmutableTable;
20
import com.rackspacecloud.blueflood.io.CassandraModel;
21
import com.rackspacecloud.blueflood.io.CassandraModel.MetricColumnFamily;
22
import com.rackspacecloud.blueflood.io.Constants;
23
import com.rackspacecloud.blueflood.rollup.Granularity;
24
import com.rackspacecloud.blueflood.service.Configuration;
25
import com.rackspacecloud.blueflood.service.TtlConfig;
26
import com.rackspacecloud.blueflood.types.RollupType;
27
import com.rackspacecloud.blueflood.utils.TimeValue;
28
import java.util.concurrent.TimeUnit;
29

30
public class SafetyTtlProvider implements TenantTtlProvider {
31
    private final ImmutableTable<Granularity, RollupType, TimeValue> SAFETY_TTLS;
32
    private final TimeValue STRING_TTLS = Constants.STRING_SAFETY_TTL;
6✔
33
    private final TimeValue CONFIG_TTL = new TimeValue(Configuration.getInstance().getIntegerProperty(TtlConfig.TTL_CONFIG_CONST), TimeUnit.DAYS);
6✔
34
    private final boolean ARE_TTLS_FORCED = Configuration.getInstance().getBooleanProperty(TtlConfig.ARE_TTLS_FORCED);
6✔
35

36
    private static final SafetyTtlProvider INSTANCE = new SafetyTtlProvider();
6✔
37

38
    public static SafetyTtlProvider getInstance() {
39
        return INSTANCE;
6✔
40
    }
41

42
    private SafetyTtlProvider() {
6✔
43
        ImmutableTable.Builder<Granularity, RollupType, TimeValue> ttlMapBuilder =
6✔
44
                new ImmutableTable.Builder<Granularity, RollupType, TimeValue>();
45

46
        for (Granularity granularity : Granularity.granularities()) {
6✔
47
            for (RollupType type : RollupType.values()) {
6✔
48
                try {
49
                    MetricColumnFamily metricCF = CassandraModel.getColumnFamily(RollupType.classOf(type, granularity), granularity);
6✔
50
                    TimeValue ttl = new TimeValue(metricCF.getDefaultTTL().getValue() * 5, metricCF.getDefaultTTL().getUnit());
6✔
51
                    ttlMapBuilder.put(granularity, type, ttl);
6✔
52
                } catch (IllegalArgumentException ex) {
6✔
53

54
                }
6✔
55
            }
56
        }
57

58
        this.SAFETY_TTLS = ttlMapBuilder.build();
6✔
59
    }
6✔
60

61
    @Override
62
    public TimeValue getTTL(String tenantId, Granularity gran, RollupType rollupType) throws Exception {
63
        return getSafeTTL(gran, rollupType);
6✔
64
    }
65
    
66
    public TimeValue getSafeTTL(Granularity gran, RollupType rollupType) {
67
        return SAFETY_TTLS.get(gran, rollupType);
6✔
68
    }
69

70
    @Override
71
    public void setTTL(String tenantId, Granularity gran, RollupType rollupType, TimeValue ttlValue) throws Exception {
72
        throw new RuntimeException("Not allowed to override safety ttls. They are auto-derived based on granularity.");
×
73
    }
74

75
    @Override
76
    public TimeValue getTTLForStrings(String tenantId) throws Exception {
77
        return STRING_TTLS;
×
78
    }
79

80
    @Override
81
    public TimeValue getConfigTTLForIngestion() throws Exception {
82
       return CONFIG_TTL;
×
83
    }
84

85
    public long getFinalTTL(String tenantid, Granularity g) {
86
        long ttl;
87
        try {
88
            if (g == Granularity.FULL) {
3✔
89
                if (ARE_TTLS_FORCED) {
3✔
90
                    ttl = getConfigTTLForIngestion().toMillis();
×
91
                }
92
                else {
93
                    ttl = getTTL(tenantid, g, RollupType.BF_BASIC).toMillis();
3✔
94
                }
95
            }
96
            else {
97
                ttl = getTTL(tenantid, g, RollupType.BF_BASIC).toMillis();
3✔
98
            }
99
        } catch (Exception ex) {
×
100
            ttl = getSafeTTL(
×
101
                    g, RollupType.BF_BASIC).toMillis();
×
102
        }
3✔
103
        return ttl;
3✔
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc