Search in sources :

Example 16 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraMessageRepository method tryToExecute.

private ResultSet tryToExecute(Statement statement, String errorMessage) throws OperationFailedException {
    ResultSet results;
    try {
        results = cassandra.execute(statement);
    } catch (Exception ex) {
        LOG.error("Failed to execute Cassandra statement: {}", statement, ex);
        throw new OperationFailedException(errorMessage + " | " + ex.getMessage());
    }
    checkThat(results).throwing(OperationFailedException.class).usingMessage("Cassandra returned null response").is(notNull());
    return results;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) MessageDoesNotExistException(tech.aroma.thrift.exceptions.MessageDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 17 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraApplicationRepository method deleteApplication.

@Override
public void deleteApplication(String applicationId) throws TException {
    checkApplicationId(applicationId);
    // Must fetch the full Application first
    Application app = this.getById(applicationId);
    Statement statement = createDeleteStatementFor(app);
    try {
        cassandra.execute(statement);
        LOG.debug("Successfully deleted Application with ID {}", applicationId);
    } catch (Exception ex) {
        LOG.error("Failed to delete application with ID [{}] from Cassandra", applicationId, ex);
        throw new OperationFailedException("Could not delete Application with ID: " + applicationId);
    }
}
Also used : BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) RequestAssertions.validApplication(tech.aroma.data.assertions.RequestAssertions.validApplication) Application(tech.aroma.thrift.Application) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 18 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraApplicationRepository method saveApplication.

@Override
public void saveApplication(Application application) throws TException {
    checkThat(application).throwing(InvalidArgumentException.class).is(validApplication());
    Statement statement = createStatementToSave(application);
    try {
        cassandra.execute(statement);
        LOG.debug("Successfully saved Application in Cassandra: {}", application);
    } catch (Exception ex) {
        LOG.error("Failed to store Application in Cassandra: {}", application, ex);
        throw new OperationFailedException("Could not save Application: " + ex.getMessage());
    }
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 19 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraApplicationRepository method getById.

@Override
public Application getById(String applicationId) throws TException {
    checkApplicationId(applicationId);
    Statement query = createQueryForAppWithId(applicationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for application with ID {}", applicationId, ex);
        throw new OperationFailedException("Could not Query Application with ID: " + applicationId);
    }
    Row row = results.one();
    checkRowNotMissing(applicationId, row);
    Application app = createApplicationFromRow(row);
    return app;
}
Also used : BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) RequestAssertions.validApplication(tech.aroma.data.assertions.RequestAssertions.validApplication) Application(tech.aroma.thrift.Application) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 20 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraFollowerRepository method followingExists.

@Override
public boolean followingExists(String userId, String applicationId) throws TException {
    checkUserId(userId);
    checkAppId(applicationId);
    Statement query = createStatementToCheckIfFollowingExists(userId, applicationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for following between User: [{}] App: [{}]", userId, applicationId, ex);
        throw new OperationFailedException("Could not query for following: " + ex.getMessage());
    }
    Row row = results.one();
    checkRowExists(row);
    long count = row.getLong(0);
    return count > 0;
}
Also used : BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Aggregations

OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)40 TException (org.apache.thrift.TException)32 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)32 Statement (com.datastax.driver.core.Statement)29 ResultSet (com.datastax.driver.core.ResultSet)19 Row (com.datastax.driver.core.Row)17 BatchStatement (com.datastax.driver.core.BatchStatement)13 OrganizationDoesNotExistException (tech.aroma.thrift.exceptions.OrganizationDoesNotExistException)9 Test (org.junit.Test)8 ApplicationDoesNotExistException (tech.aroma.thrift.exceptions.ApplicationDoesNotExistException)7 RequestAssertions.validApplication (tech.aroma.data.assertions.RequestAssertions.validApplication)6 Application (tech.aroma.thrift.Application)6 DontRepeat (tech.sirwellington.alchemy.test.junit.runners.DontRepeat)6 RequestAssertions.validUser (tech.aroma.data.assertions.RequestAssertions.validUser)4 User (tech.aroma.thrift.User)4 RequestAssertions.validMessage (tech.aroma.data.assertions.RequestAssertions.validMessage)2 Message (tech.aroma.thrift.Message)2 InvalidTokenException (tech.aroma.thrift.exceptions.InvalidTokenException)2 MessageDoesNotExistException (tech.aroma.thrift.exceptions.MessageDoesNotExistException)2 Session (com.datastax.driver.core.Session)1