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