Search in sources :

Example 56 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class DateTieredCompactionStrategyOptions method validateOptions.

public static Map<String, String> validateOptions(Map<String, String> options, Map<String, String> uncheckedOptions) throws ConfigurationException {
    String optionValue = options.get(TIMESTAMP_RESOLUTION_KEY);
    try {
        if (optionValue != null)
            TimeUnit.valueOf(optionValue);
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException(String.format("timestamp_resolution %s is not valid", optionValue));
    }
    optionValue = options.get(MAX_SSTABLE_AGE_KEY);
    try {
        double maxSStableAge = optionValue == null ? DEFAULT_MAX_SSTABLE_AGE_DAYS : Double.parseDouble(optionValue);
        if (maxSStableAge < 0) {
            throw new ConfigurationException(String.format("%s must be non-negative: %.2f", MAX_SSTABLE_AGE_KEY, maxSStableAge));
        }
    } catch (NumberFormatException e) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, MAX_SSTABLE_AGE_KEY), e);
    }
    optionValue = options.get(BASE_TIME_KEY);
    try {
        long baseTime = optionValue == null ? DEFAULT_BASE_TIME_SECONDS : Long.parseLong(optionValue);
        if (baseTime <= 0) {
            throw new ConfigurationException(String.format("%s must be greater than 0, but was %d", BASE_TIME_KEY, baseTime));
        }
    } catch (NumberFormatException e) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, BASE_TIME_KEY), e);
    }
    optionValue = options.get(EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY);
    try {
        long expiredCheckFrequency = optionValue == null ? DEFAULT_EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS : Long.parseLong(optionValue);
        if (expiredCheckFrequency < 0) {
            throw new ConfigurationException(String.format("%s must not be negative, but was %d", EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY, expiredCheckFrequency));
        }
    } catch (NumberFormatException e) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY), e);
    }
    optionValue = options.get(MAX_WINDOW_SIZE_KEY);
    try {
        long maxWindowSize = optionValue == null ? DEFAULT_MAX_WINDOW_SIZE_SECONDS : Long.parseLong(optionValue);
        if (maxWindowSize < 0) {
            throw new ConfigurationException(String.format("%s must not be negative, but was %d", MAX_WINDOW_SIZE_KEY, maxWindowSize));
        }
    } catch (NumberFormatException e) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, MAX_WINDOW_SIZE_KEY), e);
    }
    uncheckedOptions.remove(MAX_SSTABLE_AGE_KEY);
    uncheckedOptions.remove(BASE_TIME_KEY);
    uncheckedOptions.remove(TIMESTAMP_RESOLUTION_KEY);
    uncheckedOptions.remove(EXPIRED_SSTABLE_CHECK_FREQUENCY_SECONDS_KEY);
    uncheckedOptions.remove(MAX_WINDOW_SIZE_KEY);
    return uncheckedOptions;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 57 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class SizeTieredCompactionStrategyOptions method validateOptions.

public static Map<String, String> validateOptions(Map<String, String> options, Map<String, String> uncheckedOptions) throws ConfigurationException {
    String optionValue = options.get(MIN_SSTABLE_SIZE_KEY);
    try {
        long minSSTableSize = optionValue == null ? DEFAULT_MIN_SSTABLE_SIZE : Long.parseLong(optionValue);
        if (minSSTableSize < 0) {
            throw new ConfigurationException(String.format("%s must be non negative: %d", MIN_SSTABLE_SIZE_KEY, minSSTableSize));
        }
    } catch (NumberFormatException e) {
        throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", optionValue, MIN_SSTABLE_SIZE_KEY), e);
    }
    double bucketLow = parseDouble(options, BUCKET_LOW_KEY, DEFAULT_BUCKET_LOW);
    double bucketHigh = parseDouble(options, BUCKET_HIGH_KEY, DEFAULT_BUCKET_HIGH);
    if (bucketHigh <= bucketLow) {
        throw new ConfigurationException(String.format("%s value (%s) is less than or equal to the %s value (%s)", BUCKET_HIGH_KEY, bucketHigh, BUCKET_LOW_KEY, bucketLow));
    }
    uncheckedOptions.remove(MIN_SSTABLE_SIZE_KEY);
    uncheckedOptions.remove(BUCKET_LOW_KEY);
    uncheckedOptions.remove(BUCKET_HIGH_KEY);
    return uncheckedOptions;
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 58 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class TimeWindowCompactionStrategyTest method testOptionsValidation.

@Test
public void testOptionsValidation() throws ConfigurationException {
    Map<String, String> options = new HashMap<>();
    options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_SIZE_KEY, "30");
    options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_UNIT_KEY, "MINUTES");
    Map<String, String> unvalidated = validateOptions(options);
    assertTrue(unvalidated.isEmpty());
    try {
        options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_SIZE_KEY, "0");
        validateOptions(options);
        fail(String.format("%s == 0 should be rejected", TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_SIZE_KEY));
    } catch (ConfigurationException e) {
    // expected exception
    }
    try {
        options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_SIZE_KEY, "-1337");
        validateOptions(options);
        fail(String.format("Negative %s should be rejected", TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_SIZE_KEY));
    } catch (ConfigurationException e) {
        options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_SIZE_KEY, "1");
    }
    try {
        options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_UNIT_KEY, "MONTHS");
        validateOptions(options);
        fail(String.format("Invalid %s should be rejected", TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_UNIT_KEY));
    } catch (ConfigurationException e) {
        options.put(TimeWindowCompactionStrategyOptions.COMPACTION_WINDOW_UNIT_KEY, "MINUTES");
    }
    try {
        options.put(TimeWindowCompactionStrategyOptions.UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY, "not-a-boolean");
        validateOptions(options);
        fail(String.format("Invalid %s should be rejected", TimeWindowCompactionStrategyOptions.UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY));
    } catch (ConfigurationException e) {
        options.put(TimeWindowCompactionStrategyOptions.UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_KEY, "true");
    }
    options.put(AbstractCompactionStrategy.UNCHECKED_TOMBSTONE_COMPACTION_OPTION, "true");
    Keyspace keyspace = Keyspace.open(KEYSPACE1);
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
    TimeWindowCompactionStrategy twcs = new TimeWindowCompactionStrategy(cfs, options);
    assertFalse(twcs.disableTombstoneCompactions);
    options.put(AbstractCompactionStrategy.UNCHECKED_TOMBSTONE_COMPACTION_OPTION, "false");
    twcs = new TimeWindowCompactionStrategy(cfs, options);
    assertTrue(twcs.disableTombstoneCompactions);
    options.put("bad_option", "1.0");
    unvalidated = validateOptions(options);
    assertTrue(unvalidated.containsKey("bad_option"));
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 59 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class MerkleTree method deserialize.

public static MerkleTree deserialize(DataInputPlus in, boolean offHeapRequested, int version) throws IOException {
    int hashDepth = in.readByte();
    long maxSize = in.readLong();
    int innerNodeCount = Ints.checkedCast(in.readLong());
    IPartitioner partitioner;
    try {
        partitioner = FBUtilities.newPartitioner(in.readUTF());
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    Token left = Token.serializer.deserialize(in, partitioner, version);
    Token right = Token.serializer.deserialize(in, partitioner, version);
    Range<Token> fullRange = new Range<>(left, right);
    Node root = deserializeTree(in, partitioner, innerNodeCount, offHeapRequested, version);
    return new MerkleTree(root, partitioner, fullRange, hashDepth, maxSize, innerNodeCount);
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Token(org.apache.cassandra.dht.Token) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 60 with ConfigurationException

use of org.apache.cassandra.exceptions.ConfigurationException in project cassandra by apache.

the class FBUtilities method resourceToFile.

public static String resourceToFile(String filename) throws ConfigurationException {
    ClassLoader loader = FBUtilities.class.getClassLoader();
    URL scpurl = loader.getResource(filename);
    if (scpurl == null)
        throw new ConfigurationException("unable to locate " + filename);
    return new File(scpurl.getFile()).absolutePath();
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) File(org.apache.cassandra.io.util.File)

Aggregations

ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)84 IOException (java.io.IOException)12 URL (java.net.URL)6 HashMap (java.util.HashMap)6 Keyspace (org.apache.cassandra.db.Keyspace)5 DataInputStream (java.io.DataInputStream)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HttpURLConnection (java.net.HttpURLConnection)4 Map (java.util.Map)4 Matcher (java.util.regex.Matcher)4 File (org.apache.cassandra.io.util.File)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 IPartitioner (org.apache.cassandra.dht.IPartitioner)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 HashSet (java.util.HashSet)2