Search in sources :

Example 21 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class Ec2Snitch method awsApiCall.

String awsApiCall(String url) throws IOException, ConfigurationException {
    // Populate the region and zone by introspection, fail if 404 on metadata
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    try {
        conn.setRequestMethod("GET");
        if (conn.getResponseCode() != 200)
            throw new ConfigurationException("Ec2Snitch was unable to execute the API call. Not an ec2 node?");
        // Read the information. I wish I could say (String) conn.getContent() here...
        int cl = conn.getContentLength();
        byte[] b = new byte[cl];
        DataInputStream d = new DataInputStream((FilterInputStream) conn.getContent());
        d.readFully(b);
        return new String(b, Charsets.UTF_8);
    } finally {
        conn.disconnect();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ConfigurationException(org.apache.cassandra.config.ConfigurationException) DataInputStream(java.io.DataInputStream) URL(java.net.URL)

Example 22 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class PropertyFileSnitch method reloadConfiguration.

public void reloadConfiguration() throws ConfigurationException {
    HashMap<InetAddress, String[]> reloadedMap = new HashMap<InetAddress, String[]>();
    Properties properties = new Properties();
    InputStream stream = null;
    try {
        stream = getClass().getClassLoader().getResourceAsStream(RACK_PROPERTY_FILENAME);
        properties.load(stream);
    } catch (IOException e) {
        throw new ConfigurationException("Unable to read " + RACK_PROPERTY_FILENAME, e);
    } finally {
        FileUtils.closeQuietly(stream);
    }
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (key.equals("default")) {
            String[] newDefault = value.split(":");
            if (newDefault.length < 2)
                newDefault = new String[] { "default", "default" };
            defaultDCRack = newDefault;
        } else {
            InetAddress host;
            String hostString = key.replace("/", "");
            try {
                host = InetAddress.getByName(hostString);
            } catch (UnknownHostException e) {
                throw new ConfigurationException("Unknown host " + hostString, e);
            }
            String[] token = value.split(":");
            if (token.length < 2)
                token = new String[] { "default", "default" };
            reloadedMap.put(host, token);
        }
    }
    logger.debug("loaded network topology {}", FBUtilities.toString(reloadedMap));
    endpointMap = reloadedMap;
    ShortNodeId.updateShortNodeIds(reloadedMap);
    if (StorageService.instance != null)
        StorageService.instance.getTokenMetadata().invalidateCaches();
}
Also used : UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) ConfigurationException(org.apache.cassandra.config.ConfigurationException) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class FBUtilities method resourceToFile.

public static String resourceToFile(String filename) throws ConfigurationException {
    ClassLoader loader = PropertyFileSnitch.class.getClassLoader();
    URL scpurl = loader.getResource(filename);
    if (scpurl == null)
        throw new ConfigurationException("unable to locate " + filename);
    return scpurl.getFile();
}
Also used : ConfigurationException(org.apache.cassandra.config.ConfigurationException) URL(java.net.URL)

Example 24 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class CreateColumnFamilyStatement method validate.

/**
 * Perform validation of parsed params
 */
private void validate(List<String> variables) throws InvalidRequestException {
    cfProps.validate();
    // Column family name
    if (!name.matches("\\w+"))
        throw new InvalidRequestException(String.format("\"%s\" is not a valid column family name", name));
    if (name.length() > 32)
        throw new InvalidRequestException(String.format("Column family names shouldn't be more than 32 character long (got \"%s\")", name));
    // Ensure that exactly one key has been specified.
    if (keyValidator.size() < 1)
        throw new InvalidRequestException("You must specify a PRIMARY KEY");
    else if (keyValidator.size() > 1)
        throw new InvalidRequestException("You may only specify one PRIMARY KEY");
    AbstractType<?> comparator;
    try {
        comparator = cfProps.getComparator();
    } catch (ConfigurationException e) {
        throw new InvalidRequestException(e.toString());
    }
    for (Map.Entry<Term, String> column : columns.entrySet()) {
        ByteBuffer name = column.getKey().getByteBuffer(comparator, variables);
        if (keyAlias != null && keyAlias.equals(name))
            throw new InvalidRequestException("Invalid column name: " + column.getKey().getText() + ", because it equals to the key_alias.");
    }
}
Also used : ConfigurationException(org.apache.cassandra.config.ConfigurationException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) HashMap(java.util.HashMap) Map(java.util.Map) ByteBuffer(java.nio.ByteBuffer)

Example 25 with ConfigurationException

use of org.apache.cassandra.config.ConfigurationException in project eiger by wlloyd.

the class CreateColumnFamilyStatement method getColumns.

// Column definitions
private Map<ByteBuffer, ColumnDefinition> getColumns(AbstractType<?> comparator) throws InvalidRequestException {
    Map<ByteBuffer, ColumnDefinition> columnDefs = new HashMap<ByteBuffer, ColumnDefinition>();
    for (Map.Entry<Term, String> col : columns.entrySet()) {
        try {
            ByteBuffer columnName = comparator.fromString(col.getKey().getText());
            String validatorClassName = CFPropDefs.comparators.containsKey(col.getValue()) ? CFPropDefs.comparators.get(col.getValue()) : col.getValue();
            AbstractType<?> validator = TypeParser.parse(validatorClassName);
            columnDefs.put(columnName, new ColumnDefinition(columnName, validator, null, null, null));
        } catch (ConfigurationException e) {
            InvalidRequestException ex = new InvalidRequestException(e.toString());
            ex.initCause(e);
            throw ex;
        }
    }
    return columnDefs;
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.cassandra.config.ConfigurationException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) ByteBuffer(java.nio.ByteBuffer) HashMap(java.util.HashMap) Map(java.util.Map) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Aggregations

ConfigurationException (org.apache.cassandra.config.ConfigurationException)26 IOException (java.io.IOException)10 ByteBuffer (java.nio.ByteBuffer)6 HashMap (java.util.HashMap)4 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)4 Map (java.util.Map)3 CFMetaData (org.apache.cassandra.config.CFMetaData)3 AbstractType (org.apache.cassandra.db.marshal.AbstractType)3 File (java.io.File)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ExecutionException (java.util.concurrent.ExecutionException)2 Future (java.util.concurrent.Future)2 QueryPath (org.apache.cassandra.db.filter.QueryPath)2 Migration (org.apache.cassandra.db.migration.Migration)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 IOError (java.io.IOError)1 InputStream (java.io.InputStream)1