use of org.apache.cassandra.thrift.NotFoundException in project brisk by riptano.
the class TrackerManager method getCurrentJobtrackerLocation.
/**
* Retrieves the current job tracker IP.
*
* @return the current job tracker IP
* @throws TrackerManagerException
*/
public static InetAddress getCurrentJobtrackerLocation() throws TrackerManagerException {
ReadCommand rc = new SliceByNamesReadCommand(BriskSchema.KEYSPACE_NAME, currentJobtrackerKey, cp, Arrays.asList(columnName));
String result;
try {
List<Row> rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.QUORUM);
IColumn col = validateAndGetColumn(rows, columnName);
// ByteBuffer util duplicates for us the value.
result = ByteBufferUtil.string(col.value());
return InetAddress.getByName(result);
} catch (NotFoundException e) {
return null;
} catch (Exception e) {
throw new TrackerManagerException(e);
}
}
use of org.apache.cassandra.thrift.NotFoundException in project titan by thinkaurelius.
the class CassandraThriftStoreManager method ensureKeyspaceExists.
private KsDef ensureKeyspaceExists(String keyspaceName) throws NotFoundException, InvalidRequestException, TException, SchemaDisagreementException, StorageException {
CTConnection connection = null;
try {
connection = pool.borrowObject(SYSTEM_KS);
Cassandra.Client client = connection.getClient();
try {
// Side effect: throws Exception if keyspaceName doesn't exist
// Don't remove
client.set_keyspace(keyspaceName);
client.set_keyspace(SYSTEM_KS);
log.debug("Found existing keyspace {}", keyspaceName);
} catch (InvalidRequestException e) {
// Keyspace didn't exist; create it
log.debug("Creating keyspace {}...", keyspaceName);
KsDef ksdef = new KsDef().setName(keyspaceName).setCf_defs(// cannot be null but can be empty
new LinkedList<CfDef>()).setStrategy_class("org.apache.cassandra.locator.SimpleStrategy").setStrategy_options(ImmutableMap.of("replication_factor", String.valueOf(replicationFactor)));
client.set_keyspace(SYSTEM_KS);
try {
client.system_add_keyspace(ksdef);
log.debug("Created keyspace {}", keyspaceName);
} catch (InvalidRequestException ire) {
log.error("system_add_keyspace failed for keyspace=" + keyspaceName, ire);
throw ire;
}
}
return client.describe_keyspace(keyspaceName);
} catch (Exception e) {
throw new TemporaryStorageException(e);
} finally {
pool.returnObjectUnsafe(SYSTEM_KS, connection);
}
}
use of org.apache.cassandra.thrift.NotFoundException in project scale7-pelops by s7.
the class Operand method tryOperation.
protected <ReturnType> ReturnType tryOperation(IOperation<ReturnType> operation, OperandPolicy operandPolicy) throws PelopsException {
Set<String> avoidNodes = null;
Exception lastException = null;
int retries = 0;
do {
// Get a connection to a Cassandra node
IPooledConnection conn = null;
try {
conn = thrift.getConnectionExcept(avoidNodes);
} catch (Exception e) {
// the pool is responsible for blocking and waiting for a connection, so don't retry
throw operandPolicy.getExceptionTranslator().translate(e);
}
try {
// Return result!
return operation.execute(conn);
} catch (Exception e) {
// Should we try again?
if (e instanceof TimedOutException || e instanceof TTransportException || e instanceof UnavailableException) {
logger.warn("Operation failed as result of network exception. Connection to node {} is being marked as corrupt " + "(and will probably be be destroyed). Cause of failure is {}", conn.getNode().getAddress(), e);
// This connection is "broken" by network timeout or other problem.
conn.corrupted();
// to avoid create the set for every request create the set here
if (avoidNodes == null)
avoidNodes = new HashSet<String>(10);
avoidNodes.add(conn.getNode().getAddress());
retries++;
lastException = e;
} else if (e instanceof NotFoundException) {
// Re-throw application-level exceptions immediately.
throw operandPolicy.getExceptionTranslator().translate(e);
} else {
// This connection is "broken" by network timeout or other problem.
conn.corrupted();
// Re-throw application-level exceptions immediately.
throw operandPolicy.getExceptionTranslator().translate(e);
}
} finally {
conn.release();
}
} while (retries < operandPolicy.getMaxOpRetries());
throw operandPolicy.getExceptionTranslator().translate(lastException);
}
Aggregations