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();
}
}
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();
}
}
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;
}
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();
}
}
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");
}
Aggregations