Search in sources :

Example 61 with ConfigurationException

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

the class GoogleCloudSnitch method gceApiCall.

String gceApiCall(String url) throws IOException, ConfigurationException {
    // Populate the region and zone by introspection, fail if 404 on metadata
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    DataInputStream d = null;
    try {
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Metadata-Flavor", "Google");
        if (conn.getResponseCode() != 200)
            throw new ConfigurationException("GoogleCloudSnitch was unable to execute the API call. Not a gce node?");
        // Read the information.
        int cl = conn.getContentLength();
        byte[] b = new byte[cl];
        d = new DataInputStream((FilterInputStream) conn.getContent());
        d.readFully(b);
        return new String(b, StandardCharsets.UTF_8);
    } finally {
        FileUtils.close(d);
        conn.disconnect();
    }
}
Also used : FilterInputStream(java.io.FilterInputStream) HttpURLConnection(java.net.HttpURLConnection) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) DataInputStream(java.io.DataInputStream) URL(java.net.URL)

Example 62 with ConfigurationException

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

the class CloudstackSnitch method csQueryMetadata.

String csQueryMetadata(String url) throws ConfigurationException, IOException {
    HttpURLConnection conn = null;
    DataInputStream is = null;
    try {
        conn = (HttpURLConnection) new URL(url).openConnection();
    } catch (Exception e) {
        throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
    }
    try {
        conn.setRequestMethod("GET");
        if (conn.getResponseCode() != 200) {
            throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
        }
        int cl = conn.getContentLength();
        byte[] b = new byte[cl];
        is = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
        is.readFully(b);
        return new String(b, StandardCharsets.UTF_8);
    } finally {
        FileUtils.close(is);
        conn.disconnect();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) URL(java.net.URL) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 63 with ConfigurationException

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

the class CloudstackSnitch method csEndpointFromLease.

String csEndpointFromLease(File lease) throws ConfigurationException {
    String line;
    String endpoint = null;
    Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
    try (BufferedReader reader = new BufferedReader(new FileReader(lease))) {
        while ((line = reader.readLine()) != null) {
            Matcher matcher = identifierPattern.matcher(line);
            if (matcher.find()) {
                endpoint = matcher.group(1);
                break;
            }
        }
    } catch (Exception e) {
        throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
    }
    if (endpoint == null) {
        throw new ConfigurationException("No metadata server could be found in lease file.");
    }
    return "http://" + endpoint;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) BufferedReader(java.io.BufferedReader) FileReader(org.apache.cassandra.io.util.FileReader) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 64 with ConfigurationException

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

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();
    DataInputStream d = null;
    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];
        d = new DataInputStream((FilterInputStream) conn.getContent());
        d.readFully(b);
        return new String(b, StandardCharsets.UTF_8);
    } finally {
        FileUtils.close(d);
        conn.disconnect();
    }
}
Also used : FilterInputStream(java.io.FilterInputStream) HttpURLConnection(java.net.HttpURLConnection) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) DataInputStream(java.io.DataInputStream) URL(java.net.URL)

Example 65 with ConfigurationException

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

the class KeyspaceAttributes method validate.

public void validate() {
    validate(validKeywords, obsoleteKeywords);
    Map<String, String> replicationOptions = getAllReplicationOptions();
    if (!replicationOptions.isEmpty() && !replicationOptions.containsKey(ReplicationParams.CLASS))
        throw new ConfigurationException("Missing replication strategy class");
}
Also used : ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

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